Skip to content

Make container names unique and migrate all tests to singletons#22294

Draft
gnodet wants to merge 3 commits intoapache:mainfrom
gnodet:mesquite-planet
Draft

Make container names unique and migrate all tests to singletons#22294
gnodet wants to merge 3 commits intoapache:mainfrom
gnodet:mesquite-planet

Conversation

@gnodet
Copy link
Copy Markdown
Contributor

@gnodet gnodet commented Mar 27, 2026

Summary

This PR makes test infrastructure safe for both cross-JVM (mvnd parallel builds) and within-JVM (parallel test classes) execution by ensuring Docker container name uniqueness and migrating tests to share singleton service instances.

Commit 1: Make Docker container names unique per instance

  • Append PID + AtomicInteger counter to container names in ContainerEnvironmentUtil.containerName() for cross-JVM and within-JVM uniqueness
  • Remove hardcoded container name "nameserver" from RocketMQNameserverContainer (the network alias is sufficient for inter-container communication)

Commit 2: Add createSingletonService() to 32 test-infra service factories

  • Add singleton factory methods following the established KafkaServiceFactory pattern (inner singleton class, lazy holder, factory method) to 32 service factories that previously only had createService()
  • Change SingletonService.shutdown() from throwing IllegalArgumentException to a debug-level no-op, since many service interfaces have afterEach lifecycle callbacks that call shutdown() (e.g., ChatScriptService, CliService)

Commit 3: Migrate all test classes from createService() to createSingletonService()

  • Migrate ~69 test files from createService() to createSingletonService() to share Docker containers across test classes
  • Fix test isolation for shared services:
    • Hashicorp Vault: Use getClass().getSimpleName() for unique secret paths per test class
    • Google PubSub: Use unique topic/subscription names per test class
  • Keep createService() for tests that need exclusive instances:
    • BaseExclusiveKafkaTestSupport (intentionally needs isolation)
    • KafkaHealthCheckTestSupport (tests intentionally shut down Kafka to verify health check DOWN behavior)
    • AbstractLRATestSupport (LRA coordinator state leaks between test classes)
    • MasterEndpointFailoverIT (manages its own ZooKeeper lifecycle)

Test plan

  • CI passes on JDK 17, 21, 25
  • No container name collisions with parallel execution
  • Singleton services create exactly one container per JVM
  • Tests that shut down services (health checks, LRA) use non-singleton instances

@github-actions
Copy link
Copy Markdown
Contributor

🌟 Thank you for your contribution to the Apache Camel project! 🌟
🤖 CI automation will test this PR automatically.

🐫 Apache Camel Committers, please review the following items:

  • First-time contributors require MANUAL approval for the GitHub Actions to run
  • You can use the command /component-test (camel-)component-name1 (camel-)component-name2.. to request a test from the test bot although they are normally detected and executed by CI.
  • You can label PRs using build-all, build-dependents, skip-tests and test-dependents to fine-tune the checks executed by this PR.
  • Build and test logs are available in the summary page. Only Apache Camel committers have access to the summary.

⚠️ Be careful when sharing logs. Review their contents before sharing them publicly.

@gnodet gnodet changed the title Add createSingletonService() to all test-infra service factories Add createSingletonService() to test-infra factories and migrate tests Mar 27, 2026
@gnodet gnodet changed the title Add createSingletonService() to test-infra factories and migrate tests Add createSingletonService() to test-infra service factories Mar 27, 2026
@gnodet gnodet changed the title Add createSingletonService() to test-infra service factories Add createSingletonService() to test-infra factories and migrate tests Mar 27, 2026
@gnodet gnodet force-pushed the mesquite-planet branch 5 times, most recently from 4061f61 to 36d7b4f Compare March 27, 2026 15:22
@orpiske
Copy link
Copy Markdown
Contributor

orpiske commented Mar 27, 2026

LGTM, but this one likely needs a full CI test to make sure it runs fine.

@gnodet
Copy link
Copy Markdown
Contributor Author

gnodet commented Mar 27, 2026

LGTM, but this one likely needs a full CI test to make sure it runs fine.

Yes, I'm running tests locally for each modified factory to make sure it works.
The one that don't work will have a comment:
https://github.com/apache/camel/pull/22294/changes#diff-4677c71b137d3f514242cb2407edc44042f5f8068594d75177c07522fb0de878R48

It's not completely done yet...

@gnodet gnodet force-pushed the mesquite-planet branch 3 times, most recently from 3f7fe53 to d68f67d Compare March 27, 2026 20:40
@gnodet gnodet changed the title Add createSingletonService() to test-infra factories and migrate tests Add createSingletonService() to all test-infra factories and migrate all tests Mar 27, 2026
@gnodet gnodet force-pushed the mesquite-planet branch 3 times, most recently from 16de556 to fdb9557 Compare March 27, 2026 21:45
@gnodet gnodet changed the title Add createSingletonService() to all test-infra factories and migrate all tests Make container names unique and migrate all tests to singletons Mar 27, 2026
Append PID and AtomicInteger counter to container names generated
by ContainerEnvironmentUtil.containerName(). This prevents container
name collisions both across JVMs (parallel builds via mvnd) and
within the same JVM (singleton containers coexisting with tests
that create their own containers).

Also remove hardcoded container name from RocketMQNameserverContainer
which bypassed ContainerEnvironmentUtil. The network alias "nameserver"
(which is network-scoped) is sufficient for inter-container communication.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet force-pushed the mesquite-planet branch 3 times, most recently from 17c3c4c to d2a0b14 Compare March 27, 2026 23:37
gnodet and others added 2 commits March 28, 2026 01:15
Add singleton service support to all test-infra service factories that
previously only had createService(). Each follows the established
pattern (inner SingletonXxxService, lazy holder, factory method).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ce()

Migrate every test class that used createService() to use
createSingletonService(). Tests that needed isolation fixes:
- Google PubSub: catch AlreadyExistsException for reruns + unique
  topic names for conflicting test pairs (DeadLetterIT/MessageOrderingIT,
  CustomSerializerIT/BodyTypesIT, SingleExchangeRound*IT)
- Hashicorp Vault: secretPath() helper using getClass().getSimpleName()
  for per-class secret path isolation
- Spring-RabbitMQ: uniqueName() helper for exchange/queue names
- LRA: delta-tolerant assertions for shared coordinator state
- Consul: remove manual initialization (singleton handles lifecycle)

89 test files migrated across 30+ components.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants