testcontainers / testcontainers/testcontainers-java
[Enhancement]: JdbcDatabaseContainer - Improve ``waitUntilContainerStarted``
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 8.7k
- Forks
- 1.9k
- Ø Merge
- 2 T. 17 Std.
- Gemergte PRs (30 T.)
- 9
Beschreibung
Module
Core
Proposal
Currently https://github.com/testcontainers/testcontainers-java/blob/7d8301903a6b45591605fd376702d24fc878a61d/modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java#L176-L216 behaves very weird and this also impacts performance:
- It doesn't utilize
WaitStrategyand completely ignores/overrides it - It constantly tries to query if the container is running or builds database connections (these are very costly in terms of CPU usage)
- These attempts use a hardcoded throttling value of 100ms and completely ignore the RateLimiter of
WaitStrategy
- These attempts use a hardcoded throttling value of 100ms and completely ignore the RateLimiter of
I would propose that you use - as in all other containers - the WaitStrategy.
- Remove the override/method
JdbcDatabaseContainer#waitUntilContainerStarted - Create a custom WaitStrategy called
JDBCWaitStrategy. It could look like this:class JDBCWaitStrategy extends AbstractWaitStrategy { @Override protected void waitUntilReady() { if(!(this.waitStrategyTarget instanceof final JdbcDatabaseContainer<?> container)) { throw new IllegalArgumentException( "Container must implement JdbcDatabaseContainer"); } try { Unreliables.retryUntilTrue( (int)this.startupTimeout.getSeconds(), TimeUnit.SECONDS, () -> this.getRateLimiter().getWhenReady(() -> { try(final Connection connection = container.createConnection(""); final Statement statement = connection.createStatement()) { return statement.execute(container.getTestQueryString()); } }) ); } catch(final TimeoutException e) { throw new ContainerLaunchException( "JDBCContainer cannot be accessed by (JDBC URL: " + container.getJdbcUrl() + "), please check container logs"); } } } - Use the following default WaitStrategy for JDBCDatabaseContainer:
new WaitAllStrategy() .withStrategy(Wait.defaultWaitStrategy()) .withStrategy(new JDBCWaitStrategy())
Full example implementation:
- https://github.com/xdev-software/tci-base/blob/13ca7984f6a732981cbd1912d9535076969004fa/tci-advanced-demo/tci-db/src/main/java/software/xdev/tci/demo/tci/db/containers/WaitableJDBCContainer.java
- https://github.com/xdev-software/tci-base/blob/13ca7984f6a732981cbd1912d9535076969004fa/tci-advanced-demo/tci-db/src/main/java/software/xdev/tci/demo/tci/db/containers/DBContainer.java
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java, insbesondere bei waitUntilContainerStarted, und lies die vorhandenen WaitStrategy- und AbstractWaitStrategy-APIs. Füge die im Issue beschriebene JDBC-spezifische Strategie und kombinierte Standardstrategie hinzu; fertig ist die Änderung, wenn der Start den konfigurierten Rate Limiter verwendet und nicht mehr das alte hartcodierte Polling- oder Überschreibungsverhalten ausführt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- databases, testing
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100