I've read the spring-kafka documentation, examples I found, and half of stackoverflow, but I fail to understand, who @EmbeddedKafka should work. Especially for integration tests.
@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}"}
)
and I had to add into test application.properties following:
….kafka.bootstrap-servers=${spring.embedded.kafka.brokers}
with all this in place, when test it executed, it complains several lines about kafka not being accessible:
[Producer clientId=producer-2] Connection to node 0 could not be established. Broker may not be available.
but after half of screen it proceeds, test succeds and finished with last unplesant message:
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)
questions: 1/ why there are those messages about broker inavailability at the start of each method, even if the context wasn't dirties and reintialized? 2/ why is the ugly message with unclosed thread present? What's wrong?