Did you have these exceptions? ClassNotFoundException: org.apache.kafka.common.security.auth.SecurityProtocol IOException: No JAAS configuration section named 'Server' was foundin 'gss.conf' Then I feel your pain…

I’ve done some Kafka testing I’m not very proud of. It’s because it sometimes took me sooooo much time to make basic test work it’s really annoying. At least I have some experience that I can share - that’s why this blog exists.

Meet IOException: No JAAS configuration section named ‘Server’ was found

java.io.IOException: No JAAS configuration section named 'Server' was foundin 'gss.conf'.
	at org.apache.zookeeper.server.ServerCnxnFactory.configureSaslLogin(ServerCnxnFactory.java:200)
	at org.apache.zookeeper.server.NIOServerCnxnFactory.configure(NIOServerCnxnFactory.java:82)
	at kafka.zk.EmbeddedZookeeper.<init>(EmbeddedZookeeper.scala:35)
	at org.springframework.kafka.test.rule.KafkaEmbedded.startZookeeper(KafkaEmbedded.java:310)
	at org.springframework.kafka.test.rule.KafkaEmbedded.before(KafkaEmbedded.java:175)
	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
	at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
	at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
	at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
	at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:62)
	at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:62)
	at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:62)
  (...)

You see, it has something to do with server security as it’s exception while configuring SASL. Also I’ve seen this in tests which have a few others WireMocks started (there is WireMock in stacktrace) but even after removing them, error still remains. I’ve really tried to dig into it but then I surprisingly fixed it with…

Solution

Changing

@Rule
public KafkaEmbedded embeddedKafka

to:

@ClassRule
public static KafkaEmbedded embeddedKafka

Yep, that’s all there is and it suddenly works.

Meet ClassNotFoundException: org.apache.kafka.common.security.auth.SecurityProtocol

I can’t even paste stacktrace here because I couldn’t reproduce it. But whenever there is ClassNotFoundException it’s good bet to blame maven or gradle for it (maven or gradle user, to be precise). I updated spring-kafka-test version but I could swear that what really helped was…

Solution

Surprise surprise! Changing

@Rule
public KafkaEmbedded embeddedKafka

to:

@ClassRule
public static KafkaEmbedded embeddedKafka

But this exception is really suspicious so I would also really recommend checking your maven dependencies if nothing went bad. Maybe you are using different versions of spring-kafka-test and spring-kafka? And updating to the latest versions definitely wouldn’t hurt.

Summary

If you have really strange exception when using KafkaEmbedded in your tests, then follow this 5 steps:

  1. Update all Kafka-Spring related dependencies to the latest version.
  2. Make sure all Kafka-Spring related dependencies have the same version.
  3. Change KafkaEmbedded from @Rule to @ClassRule
  4. ???
  5. PROFIT!!!

BTW I lost so much time for these tiny issues. Sometimes understanding the problem is not really worth the effort. Yet I’m still learning to distinguish these moments.