Skip to content
Merged
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 @@ -13,6 +13,7 @@
import java.net.ServerSocket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand All @@ -21,6 +22,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.apache.kafka.common.KafkaException;
import org.apache.kafka.common.utils.Time;
import org.apache.zookeeper.server.ServerCnxnFactory;
import org.apache.zookeeper.server.ZooKeeperServer;
Expand All @@ -39,12 +41,14 @@
import scala.Option;

import static org.apache.kafka.server.common.MetadataVersion.MINIMUM_BOOTSTRAP_VERSION;
import static org.awaitility.Awaitility.await;

/**
* Configures and manages an in process (within the JVM) Kafka cluster.
*/
public class InVMKafkaCluster implements KafkaCluster {
private static final System.Logger LOGGER = System.getLogger(InVMKafkaCluster.class.getName());
private static final int STARTUP_TIMEOUT = 30;

private final KafkaClusterConfig clusterConfig;
private final Path tempDirectory;
Expand Down Expand Up @@ -182,7 +186,15 @@ public void start() {
}
}

servers.stream().parallel().forEach(Server::startup);
servers.stream().parallel().forEach(server -> await().atMost(Duration.ofSeconds(STARTUP_TIMEOUT))
.catchUncaughtExceptions()
.ignoreException(KafkaException.class)
.pollInterval(Duration.ofMillis(50))
.until(() -> {
// Hopefully we can remove this once a fix for https://issues.apache.org/jira/browse/KAFKA-14908 actually lands.
server.startup();
return true;
}));
Utils.awaitExpectedBrokerCountInCluster(clusterConfig.getAnonConnectConfigForCluster(kafkaEndpoints), 120, TimeUnit.SECONDS, clusterConfig.getBrokersNum());
}

Expand Down