I'm trying to integrate EmbeddedKafka (https://github.com/spring-projects/spring-kafka/blob/master/src/reference/asciidoc/testing.adoc) with my Unit Tests.
No always but very often I get errors during EmbeddedKafka startup.
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:java.io.tmpdir=C:\tmp\
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:java.compiler=<NA>
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:os.name=Windows 10
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:os.arch=amd64
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:os.version=10.0
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:user.name=user
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:user.home=C:\Users\user
2019-10-08T11:23:43.894Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Server environment:user.dir=C:\work\
2019-10-08T11:23:43.913Z INFO [main] org.apache.zookeeper.server.ZooKeeperServer: Created server with tickTime 500 minSessionTimeout 1000 maxSessionTimeout 10000 datadir C:\tmp\kafka-2406612557331641452\version-2 snapdir C:\tmp\kafka-919479945966258903\version-2
2019-10-08T11:23:43.923Z INFO [main] org.apache.zookeeper.server.NIOServerCnxnFactory: binding to port /127.0.0.1:0
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.146 sec <<< FAILURE! - in kafka.KafkaTopicUtilsTest
kafka.KafkaTopicUtilsTest Time elapsed: 0.146 sec <<< ERROR!
org.I0Itec.zkclient.exception.ZkInterruptedException: java.lang.InterruptedException
Caused by: java.lang.InterruptedException
pom.xml:
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
<version>2.2.1</kafka>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.7.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.7.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<version>2.2.9.RELEASE</version>
<scope>test</scope>
</dependency>
KafkaTopicUtilsTest.java server initialization thru @Rule:
@RunWith(MockitoJUnitRunner.class)
public class KafkaTopicUtilsTest {
static final String INITIAL_TOPIC = "initial_topic";
@ClassRule
public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1, true, 5, INITIAL_TOPIC);
...
}
As mentioned almost always it is working well when I run test in InteliJ.
Executing from INteliJ (Run 'KafkaTopicUtilsTest') works fine.
Executing test via maven mvn clean install is failing.
Explicit test executions mvn -Dtest=KafkaTopicUtilsTest test works fine.
Anyone faced such issues? Any clue what could be wrong?
Issue solved
The problem was related to other test cases. Another test (not using EmbeddedKafka) was throwing and InterrupedException and checking if the code correctly react on it. Interrupted state was maintained with thru call of Thread.currentThread().interrupt(). Looks like the VM kept Interrupted state and EmbeddedKafka react on it.