Java Code Examples for org.springframework.kafka.test.rule.EmbeddedKafkaRule#getEmbeddedKafka()

The following examples show how to use org.springframework.kafka.test.rule.EmbeddedKafkaRule#getEmbeddedKafka() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringMessagingITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final EmbeddedKafkaRule embeddedKafkaRule = TestUtil.retry(new Callable<EmbeddedKafkaRule>() {
    @Override
    public EmbeddedKafkaRule call() {
      final EmbeddedKafkaRule rule = new EmbeddedKafkaRule(1, true, 2);
      try {
        rule.before();
        return rule;
      }
      catch (final Exception e) {
        rule.after();
        throw e;
      }
    }
  }, 10);

  kafkaEmbedded = embeddedKafkaRule.getEmbeddedKafka();

  System.setProperty("spring.kafka.bootstrap-servers", kafkaEmbedded.getBrokersAsString());

  final CountDownLatch latch = TestUtil.initExpectedSpanLatch(5);
  try (final ConfigurableApplicationContext context = SpringApplication.run(SpringMessagingITest.class, args)) {
    TestUtil.checkSpan(true, latch, new ComponentSpanCount("spring-messaging", 2, true), new ComponentSpanCount("java-kafka", 2, true), new ComponentSpanCount("spring-kafka", 1));
  }
  catch (final Throwable t) {
    t.printStackTrace(System.err);
    embeddedKafkaRule.after();
    System.exit(1);
  }
  finally {
    embeddedKafkaRule.after();
    System.exit(0);
  }
}
 
Example 2
Source File: SpringKafkaITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
  final EmbeddedKafkaRule embeddedKafkaRule = TestUtil.retry(new Callable<EmbeddedKafkaRule>() {
    @Override
    public EmbeddedKafkaRule call() {
      final EmbeddedKafkaRule rule = new EmbeddedKafkaRule(1, true, 2, "users", "reply");
      try {
        rule.before();
        return rule;
      }
      catch (final Exception e) {
        rule.after();
        throw e;
      }
    }
  }, 10);

  kafkaEmbedded = embeddedKafkaRule.getEmbeddedKafka();

  final CountDownLatch latch = TestUtil.initExpectedSpanLatch(6);
  try (final ConfigurableApplicationContext context = SpringApplication.run(SpringKafkaITest.class, args)) {
    TestUtil.checkSpan(true, latch, new ComponentSpanCount("java-kafka", 4, true), new ComponentSpanCount("spring-kafka", 2, true));
  }
  catch (final Throwable t) {
    t.printStackTrace(System.err);
    embeddedKafkaRule.after();
    System.exit(1);
  }
  finally {
    embeddedKafkaRule.after();
    System.exit(0);
  }
}