IntegrationTests的正确@EmbeddedKafka用法是什么?

时间:2019-06-17 10:39:51

标签: spring-kafka spring-kafka-test

我已经阅读了spring-kafka文档,发现的示例以及一半的stackoverflow,但我不明白@EmbeddedKafka应该由谁工作。尤其是对于集成测试。

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@EnableKafka
@EmbeddedKafka(controlledShutdown = true
//        brokerProperties = {"log.dir=${kafka.broker.logs-dir}",
//                "listeners=PLAINTEXT://localhost:${kafka.broker.port:3333}",
//                "auto.create.topics.enable=${kafka.broker.topics-enable:true}"}
                )

,我必须将以下内容添加到测试application.properties中:

….kafka.bootstrap-servers=${spring.embedded.kafka.brokers}

所有这些都准备就绪,在执行测试时,它会抱怨几行有关无法访问kafka的信息:

[Producer clientId=producer-2] Connection to node 0 could not be established. Broker may not be available.

但在屏幕显示一半后,测试成功并结束了最后一条令人不快的消息:

2019-06-17 12:31:54.438  WARN [testing,,,] 32448 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [testing] appears to have started a thread named [kafka-producer-network-thread | producer-3] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.nio.ch.EPollArrayWrapper.epollWait(Native Method)
 sun.nio.ch.EPollArrayWrapper.poll(EPollArrayWrapper.java:269)
 sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:93)
 sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86)
 sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
 org.apache.kafka.common.network.Selector.select(Selector.java:674)
 org.apache.kafka.common.network.Selector.poll(Selector.java:396)
 org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:460)
 org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:239)
 org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:163)
 java.lang.Thread.run(Thread.java:748)

问题: 1 /为什么在每种方法开始时都会出现关于代理不可用的消息,即使上下文不是肮脏和重新初始化的也是如此? 2 /为什么存在带有未关闭线程的丑陋消息?怎么了?

0 个答案:

没有答案