1

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.

Remi
  • 766
  • 9
  • 15
  • whats the actual failure msg? im betting its an issue with the port already being in use (everything runs sequentially in an IDE) – radai Oct 08 '19 at 13:57
  • Unfortunately not much to be added - logs are always the same: just after NIOServerCnxnFactory: **binding to port /127.0.0.1:0**, I see **org.I0Itec.zkclient.exception.ZkInterruptedException: java.lang.InterruptedException**. Any suggestion how to gather more details? – Remi Oct 08 '19 at 16:06
  • Are there other tests? The two cases that work (IntelliJ and `mvn test`) are running single test classes. If `mvn clean install` fails with multiple tests, that's often a sign that earlier tests are not cleaning up after themselves properly, or tests are running in parallel and are stepping on each other. Test order is non-deterministic. – user944849 Oct 09 '19 at 00:09
  • This is the only test that use EmbeddedKafka - other tests are in independent and working fine. I think there may be some problems with ports used for Kafka and Zookeeper - this is guess but I don't know how to determine those ports. Looking into this now. – Remi Oct 09 '19 at 07:40

0 Answers0