|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|