Skip to content

Commit

Permalink
Tests: Unflaky docker test (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
eolivelli authored Apr 11, 2024
1 parent 2bd0fd9 commit 830dc25
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DockerTest {
private static final String TEST_PULSAR_DOCKER_IMAGE_NAME =
System.getProperty("testPulsarDockerImageName");
public static final String LUNASTREAMING = "datastax/lunastreaming:2.10_4.4";
public static final String LUNASTREAMING_31 = "datastax/lunastreaming:3.1_3.0";
public static final String LUNASTREAMING_31 = "datastax/lunastreaming:3.1_3.1";

@TempDir Path tempDir;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@

import static org.junit.jupiter.api.Assertions.assertTrue;

import com.datastax.oss.pulsar.jms.shaded.org.apache.pulsar.client.admin.PulsarAdmin;
import com.datastax.oss.pulsar.jms.shaded.org.apache.pulsar.client.admin.PulsarAdminBuilder;
import com.datastax.oss.pulsar.jms.shaded.org.apache.pulsar.client.impl.auth.AuthenticationToken;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.shaded.org.apache.commons.io.IOUtils;
import org.testcontainers.shaded.org.awaitility.Awaitility;

@Slf4j
public class PulsarContainer implements AutoCloseable {
Expand Down Expand Up @@ -117,6 +123,38 @@ public void start() throws Exception {
pulsarContainer.start();

assertTrue(pulsarReady.await(1, TimeUnit.MINUTES));

// wait for system to be ready
PulsarAdminBuilder pulsarAdminBuilder =
PulsarAdmin.builder().serviceHttpUrl(getHttpServiceUrl());
if (enableAuthentication) {
String token =
IOUtils.toString(
DockerTest.class.getResourceAsStream("/token.jwt"), StandardCharsets.UTF_8);
pulsarAdminBuilder.authentication(
AuthenticationToken.class.getName(), "token:" + token.trim());
}

try (PulsarAdmin admin = pulsarAdminBuilder.build(); ) {
Awaitility.await()
.until(
() -> {
try {
List<String> tenants = admin.tenants().getTenants();
log.info("tenants={}", tenants);
if (!tenants.contains("public")) {
return false;
}
List<String> namespaces = admin.namespaces().getNamespaces("public");
log.info("namespaces={}", namespaces);
return !namespaces.isEmpty();
} catch (Exception error) {
log.info("cannot get tenants/namespaces", error);
return false;
}
});
}

if (transactions) {
pulsarContainer.execInContainer(
"/pulsar/bin/pulsar", "initialize-transaction-coordinator-metadata");
Expand Down

0 comments on commit 830dc25

Please sign in to comment.