8

I have a problem with spring embedded kafka which I want to use to test my kafka sender/receiver.

When I try to run my tests using:

@RunWith(MockitoJUnitRunner.class)
@SpringBootTest
@DirtiesContext
public class myTestClass {

    @ClassRule
    public static EmbeddedKafkaRule embeddedKafka =
        new EmbeddedKafkaRule(1, true, RECEIVER_TOPIC);

    @Test public void test() {
        System.out.println("@Test");
    }
}

I get an error:

java.io.IOException: Failed to load C:\Users\username\AppData\Local\Temp\kafka-8251150311475880576 during broker startup
...
15:29:33.135 [main] ERROR kafka.log.LogManager - Shutdown broker because none of the specified log dirs from C:\Users\username\AppData\Local\Temp\kafka-8251150311475880576 can be created or validated

Im sure that as a user I have access to this directory and when I'm running tests I can see that kafka is creating this kind of diretories (empty) on temp folder but still not working.

This is my pom configuration:

    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka-test</artifactId>
        <version>2.2.0.RC1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.kafka</groupId>
        <artifactId>spring-kafka</artifactId>
        <version>2.2.0.RC1</version>
        <scope>test</scope>
    </dependency>

appliacation.properties:

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

The interesting thing is that I have an example of kafka embedded used for testing purposes cloned from the internet and it just works fine but when I apply it to my project it just crushes as above.

Any suggestions what am I doing wrong?

Tomek
  • 81
  • 1
  • 2
  • Maybe you can share your project on GitHub and we'll take a look what's going on? – Artem Bilan Feb 04 '19 at 15:14
  • I have exactly the same problem with `org.apache.kafka:kafka-clients:2.1.1`. If I use `org.apache.kafka:kafka-clients:2.0.0` the problem disappears. I have no idea how to fix it, unfortunately. – redsk Mar 25 '19 at 00:31
  • Update: the same happens in both MacOs and Linux (Docker). – redsk Mar 25 '19 at 01:06
  • 2
    Update2: `2.0.1` also works, `2.1.0` does not work. – redsk Mar 25 '19 at 01:16
  • Did you ever resolve this? I'm seeing the exact same problem - though oddly the test runs fine in the IDE, but fails at the command line (using Gradle). I've tried a tiny project to reproduce it, and it works fine. There's clearly an interaction with something, just need to narrow down exactly. what. – gdt Jul 15 '19 at 12:56
  • 2
    Update; Yes, my problem was the same mismatch between kafka-clients. I was picking up kafka-clients 2.0.1 from org.springframework.kafka:spring-kafka:2.2.7.RELEASE (compile time) and kafka-clients:2.2.1 from org.apache.kafka:kafka-streams-test-utils:2.2.1 (run time) Removing kafka-streams-test-utils dependency fixed it forme. – gdt Jul 17 '19 at 11:29

0 Answers0