Skip to content

Commit a55830f

Browse files
author
bramvonk
committed
BSR work also around the currently broken cosmos db emulator image
1 parent 0308d70 commit a55830f

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

modules/azure/src/main/java/org/testcontainers/containers/CosmosDBEmulatorContainer.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.testcontainers.utility.DockerImageName;
55

66
import java.security.KeyStore;
7+
import java.time.Duration;
78

89
/**
910
* Testcontainers implementation for CosmosDB Emulator.
@@ -14,6 +15,8 @@
1415
*/
1516
public class CosmosDBEmulatorContainer extends GenericContainer<CosmosDBEmulatorContainer> {
1617

18+
static final String CERTIFICATE_ENDPOINT = "/_explorer/emulator.pem";
19+
1720
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(
1821
"mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator"
1922
);
@@ -27,13 +30,15 @@ public CosmosDBEmulatorContainer(final DockerImageName dockerImageName) {
2730
super(dockerImageName);
2831
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
2932
withExposedPorts(PORT);
30-
waitingFor(Wait.forLogMessage(".*Started\\r\\n$", 1));
33+
// Wait.forLogMessage(".*Started\\r\\n$") is not sufficient with the current version of cosmos db emulator (vnext-EN20251022),
34+
// see https://github.com/Azure/azure-cosmos-db-emulator-docker/issues/209 .
35+
waitingFor(Wait.forHttps(CERTIFICATE_ENDPOINT).allowInsecure().withStartupTimeout(Duration.ofSeconds(120)));
3136
}
3237

3338
/**
3439
* @return new KeyStore built with PKCS12
3540
*/
36-
public KeyStore buildNewKeyStore() {
41+
public KeyStore buildNewKeyStore() throws InterruptedException {
3742
return KeyStoreBuilder.buildByDownloadingCertificate(getEmulatorEndpoint(), getEmulatorKey());
3843
}
3944

modules/azure/src/main/java/org/testcontainers/containers/KeyStoreBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static OkHttpClient buildTrustAllClient(TrustManager[] trustManagers) th
6565
}
6666

6767
private static Request buildRequest(String endpoint) {
68-
return new Request.Builder().get().url(endpoint + "/_explorer/emulator.pem").build();
68+
return new Request.Builder().get().url(endpoint + CosmosDBEmulatorContainer.CERTIFICATE_ENDPOINT).build();
6969
}
7070

7171
private static KeyStore buildKeyStore(InputStream certificateStream, String keyStorePassword) throws Exception {

modules/azure/src/test/java/org/testcontainers/containers/CosmosDBEmulatorContainerTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ void testWithCosmosClient() throws Exception {
4343
);
4444
// }
4545
) {
46+
// emulator.addEnv("AZURE_COSMOS_EMULATOR_PARTITION_COUNT", "3");
47+
// emulator.addEnv("LOG_LEVEL", "debug");
48+
// emulator.addEnv("ENABLE_CONSOLE_EXPORTER", "true");
4649
emulator.start();
4750
// buildAndSaveNewKeyStore {
4851
Path keyStoreFile = tempFolder.resolve("azure-cosmos-emulator.keystore");

0 commit comments

Comments
 (0)