Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.testcontainers.utility.ComparableVersion;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
Expand Down Expand Up @@ -45,6 +46,8 @@ public class KafkaContainer extends GenericContainer<KafkaContainer> {

private static final String STARTER_SCRIPT = "/tmp/testcontainers_start.sh";

private static final String STARTER_SCRIPT_SENTINEL = STARTER_SCRIPT + ".ready";

// https://docs.confluent.io/platform/7.0.0/release-notes/index.html#ak-raft-kraft
private static final String MIN_KRAFT_TAG = "7.0.0";

Expand Down Expand Up @@ -200,6 +203,11 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) {
// Run the original command
command += "/etc/confluent/docker/run \n";
copyFileToContainer(Transferable.of(command, 0777), STARTER_SCRIPT);
try {
execInContainer("touch", STARTER_SCRIPT_SENTINEL);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}

protected String commandKraft() {
Expand Down Expand Up @@ -272,7 +280,7 @@ private static class KafkaContainerDef extends ContainerDef {
addExposedTcpPort(KAFKA_PORT);

setEntrypoint("sh");
setCommand("-c", "while [ ! -f " + STARTER_SCRIPT + " ]; do sleep 0.1; done; " + STARTER_SCRIPT);
setCommand("-c", "while [ ! -f " + STARTER_SCRIPT_SENTINEL + " ]; do sleep 0.1; done; " + STARTER_SCRIPT);

setWaitStrategy(Wait.forLogMessage(".*\\[KafkaServer id=\\d+\\] started.*", 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -66,6 +67,11 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) {

command += "/etc/confluent/docker/run \n";
copyFileToContainer(Transferable.of(command, 0777), KafkaHelper.STARTER_SCRIPT);
try {
execInContainer("touch", KafkaHelper.STARTER_SCRIPT_SENTINEL);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -72,6 +73,11 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) {

command += "/etc/kafka/docker/run \n";
copyFileToContainer(Transferable.of(command, 0777), STARTER_SCRIPT);
try {
execInContainer("touch", KafkaHelper.STARTER_SCRIPT_SENTINEL);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class KafkaHelper {

static final String STARTER_SCRIPT = "/tmp/testcontainers_start.sh";

static final String STARTER_SCRIPT_SENTINEL = STARTER_SCRIPT + ".ready";

static final String[] COMMAND = {
"sh",
"-c",
"while [ ! -f " + STARTER_SCRIPT + " ]; do sleep 0.1; done; " + STARTER_SCRIPT,
"while [ ! -f " + STARTER_SCRIPT_SENTINEL + " ]; do sleep 0.1; done; " + STARTER_SCRIPT,
};

static final WaitStrategy WAIT_STRATEGY = Wait.forLogMessage(".*Transitioning from RECOVERY to RUNNING.*", 1);
Expand Down