diff --git a/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java b/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java index 80ab60647adae..3e29fc2a29b92 100644 --- a/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java @@ -163,7 +163,7 @@ void prepareEnvironment() throws InterruptedException { @After public void cleanup() throws InterruptedException { - CLUSTER.deleteTopicsAndWait(120000, INPUT_TOPIC_LEFT, INPUT_TOPIC_RIGHT, OUTPUT_TOPIC); + CLUSTER.deleteAllTopicsAndWait(120000); } private void checkResult(final String outputTopic, final List expectedResult) throws InterruptedException { diff --git a/streams/src/test/java/org/apache/kafka/streams/integration/utils/EmbeddedKafkaCluster.java b/streams/src/test/java/org/apache/kafka/streams/integration/utils/EmbeddedKafkaCluster.java index ce6324df617a5..ab52649dee4bb 100644 --- a/streams/src/test/java/org/apache/kafka/streams/integration/utils/EmbeddedKafkaCluster.java +++ b/streams/src/test/java/org/apache/kafka/streams/integration/utils/EmbeddedKafkaCluster.java @@ -274,6 +274,24 @@ public void deleteTopicsAndWait(final long timeoutMs, final String... topics) th } } + /** + * Deletes all topics and blocks until all topics got deleted. + * + * @param timeoutMs the max time to wait for the topics to be deleted (does not block if {@code <= 0}) + */ + public void deleteAllTopicsAndWait(final long timeoutMs) throws InterruptedException { + final Set topics = new HashSet<>(JavaConverters.seqAsJavaListConverter(zkUtils.getAllTopics()).asJava()); + for (final String topic : topics) { + try { + brokers[0].deleteTopic(topic); + } catch (final UnknownTopicOrPartitionException e) { } + } + + if (timeoutMs > 0) { + TestUtils.waitForCondition(new TopicsDeletedCondition(topics), timeoutMs, "Topics not deleted after " + timeoutMs + " milli seconds."); + } + } + public void deleteAndRecreateTopics(final String... topics) throws InterruptedException { deleteTopicsAndWait(TOPIC_DELETION_TIMEOUT, topics); createTopics(topics); @@ -295,6 +313,10 @@ private TopicsDeletedCondition(final String... topics) { Collections.addAll(deletedTopics, topics); } + public TopicsDeletedCondition(final Set topics) { + deletedTopics.addAll(topics); + } + @Override public boolean conditionMet() { final Set allTopics = new HashSet<>(