[Enhancement]: JdbcDatabaseContainer - Improve ``waitUntilContainerStarted``
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 modules/jdbc/src/main/java/org/testcontainers/containers/JdbcDatabaseContainer.java 開始,特別查看 waitUntilContainerStarted,並閱讀現有的 WaitStrategy 和 AbstractWaitStrategy API。加入 issue 中描述的 JDBC 專用 strategy 和預設的 combined strategy;完成的標準是啟動流程使用已設定的 rate limiter,且不再執行舊的硬編碼 polling 或 override 行為。
由索引模型根據 Issue 內容生成。
描述
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
- 主要語言
- Java
- 星號
- 8.8k
- 分支
- 2k
- 平均合併
- 5 天 21 小時
- 30 天內合併 PR
- 15
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 提供 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
testcontainers/testcontainers-java 的其他 Issue
-
[Bug]: withStartupTimeout() changes the startup timeout of all containers that use the default wait strategy可能已有人在做 @aymenjamaaoui 於 1 天前認領。 未關閉type/bug
難度 2/5 1-3 小時 新手友好度 64/100
testcontainers/testcontainers-java#12171 ·
維護者通常 1 天內回覆
-
[Enhancement]: Document why singleton containers are required under Spring's test context caching可能已有人在做 @zakaullah075 於 95 天前認領。 未關閉type/enhancement
難度 1/5 1 小時以內 新手友好度 85/100
testcontainers/testcontainers-java#11967 · 1 則留言 ·
維護者通常 1 天內回覆
-
[Bug]: Cannot reuse Selenium BrowserWebDriverContainers under Linux可能已有人在做 @kdelay 於 116 天前認領。 未關閉type/bug
難度 2/5 1-3 小時 新手友好度 78/100
testcontainers/testcontainers-java#11941 ·
維護者通常 1 天內回覆
-
[Bug]: DockerDesktopClientProviderStrategy is always applicable可能已有人在做 @seonwooj0810 於 165 天前認領。 未關閉type/bug
難度 2/5 1-3 小時 新手友好度 74/100
testcontainers/testcontainers-java#11829 · 1 則留言 ·
維護者通常 1 天內回覆
-
[Enhancement]: cleanup document after removing junit4 support可能已有人在做 @SJvaca30 於 173 天前認領。 未關閉type/enhancement
難度 2/5 1-3 小時 新手友好度 65/100
testcontainers/testcontainers-java#11578 ·
維護者通常 1 天內回覆
查看 testcontainers/testcontainers-java 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 75/100
SAP/ai-sdk-java#1206 ·
維護者通常 1 天內回覆
-
enhancement good first issue insight-module
難度 2/5 1-3 小時 新手友好度 86/100
sdlc-pro/spring-lens#606 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
apache/cloudstack#14719 ·
維護者通常 1 天內回覆
-
enhancement
難度 2/5 1-3 小時 新手友好度 75/100
apache/maven-surefire#3605 ·
維護者通常 1 天內回覆