From d7fcec1ada429e2a95387b3927e5f1883fb39778 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 10 Jul 2018 21:17:02 +0100 Subject: [PATCH] Remove the use of a bean override form SampleKafkaApplicationTests See gh-13609 --- .../kafka/SampleKafkaApplicationTests.java | 31 +++---------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java index 2eed0de557..7123c19a30 100644 --- a/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka/SampleKafkaApplicationTests.java @@ -15,17 +15,12 @@ */ package sample.kafka; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.TestConfiguration; import org.springframework.boot.test.rule.OutputCapture; -import org.springframework.context.annotation.Bean; import org.springframework.kafka.test.context.EmbeddedKafka; import org.springframework.test.context.junit4.SpringRunner; @@ -43,34 +38,18 @@ import static org.assertj.core.api.Assertions.assertThat; @EmbeddedKafka public class SampleKafkaApplicationTests { - private static final CountDownLatch latch = new CountDownLatch(1); - @Rule public OutputCapture outputCapture = new OutputCapture(); @Test public void testVanillaExchange() throws Exception { - assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); + long end = System.currentTimeMillis() + 10000; + while (!this.outputCapture.toString().contains("A simple test message") + && System.currentTimeMillis() < end) { + Thread.sleep(250); + } assertThat(this.outputCapture.toString().contains("A simple test message")) .isTrue(); } - @TestConfiguration - public static class Config { - - @Bean - public Consumer consumer() { - return new Consumer() { - - @Override - public void processMessage(SampleMessage message) { - super.processMessage(message); - latch.countDown(); - } - - }; - } - - } - }