0

I have the Consumer test set up with Embedded Kafka and local Maven stubs. Test props set either via application.properties file or @DynamicPropertySource.

@SpringBootTest(
        webEnvironment = SpringBootTest.WebEnvironment.NONE)
@AutoConfigureStubRunner(
        stubsMode = StubRunnerProperties.StubsMode.LOCAL,
        ids = "com.example:service:+:stubs:8468")
@EmbeddedKafka(topics = "topic")
@ActiveProfiles("test")
public class ConsumerTests

The test fails with:

18:07:26.818 [Test worker] INFO  org.springframework.cloud.contract.stubrunner.AetherStubDownloader - Unpacking stub from JAR [URI: file:/Users/me/.m2/repository/com/example/service/2021.0.0/service-2021.0.0-stubs.jar]
18:07:26.823 [Test worker] INFO  org.springframework.cloud.contract.stubrunner.AetherStubDownloader - Unpacked file to [/var/folders/_n/kc_mgwps6255wyp6z6wsw88m0000gn/T/contracts-1653059246818-0]
18:07:28.287 [Test worker] INFO  org.springframework.cloud.contract.stubrunner.StubServer - Started stub server for project [com.example:service:2021.0.0:stubs] on port -1 with [0] mappings
18:07:28.287 [Test worker] INFO  org.springframework.cloud.contract.stubrunner.StubRunnerExecutor - All stubs are now running RunningStubs [namesAndPorts={com.example:service:2021.0.0:stubs=-1}]
18:07:28.289 [Test worker] INFO  org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'batchStubRunner' of type [org.springframework.cloud.contract.stubrunner.BatchStubRunner] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

.

org.apache.kafka.common.KafkaException: Failed to construct kafka producer
at org.springframework.cloud.contract.verifier.messaging.kafka.KafkaStubMessages.send(KafkaStubMessages.java:72)
    at org.springframework.cloud.contract.verifier.messaging.kafka.KafkaStubMessages.send(KafkaStubMessages.java:92)
    at org.springframework.cloud.contract.stubrunner.spring.LazyMessageVerifier.send(StubRunnerConfiguration.java:198)
    at org.springframework.cloud.contract.stubrunner.StubRunnerExecutor.sendMessage(StubRunnerExecutor.java:252)
    at org.springframework.cloud.contract.stubrunner.StubRunnerExecutor.triggerForDsls(StubRunnerExecutor.java:205)
    at org.springframework.cloud.contract.stubrunner.StubRunnerExecutor.trigger(StubRunnerExecutor.java:191)
    at org.springframework.cloud.contract.stubrunner.StubRunner.trigger(StubRunner.java:152).....
No resolvable bootstrap urls given in bootstrap.servers

While Kafka consumer port looks good in logs, I see no port for producer: org.apache.kafka.clients.producer.ProducerConfig - ProducerConfig values: bootstrap.servers = []

I suspect it could be related to stubs running on port -1 (not running in reality?). Another suspect: no mappings generated as stubs by Producer, I have only contracts in stubs folder. Should there be mappings generated by Producer for Kafka messaging not rest-apis?

Is there a way to check if the stubs are truly accessible?

Ivanna
  • 11
  • 2
  • You have a messaging contract from my understanding - why would you like it to be running an http server? -1 means that there is no http server running cause there were no http contracts – Marcin Grzejszczak May 23 '22 at 08:30
  • right, thank you for the answer. Any ideas where to look at why Producer is not up? – Ivanna May 23 '22 at 08:39
  • You can check this sample https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/main/producer_kafka and preferably this one https://github.com/spring-cloud-samples/spring-cloud-contract-samples/tree/main/producer_kafka_middleware . The latter uses testcontainers and is the suggested approach instead of the one using kafka test – Marcin Grzejszczak May 23 '22 at 08:50
  • Thank you, I'd love to do this with TestContainers as already used them in other types of tests but have this issue. https://stackoverflow.com/questions/72317642/spring-contract-kafka-test-containers-contractverifiermessaging-receive-is – Ivanna May 23 '22 at 09:05
  • I've replied there too, please check the provided sample cause it should work (famous last words ;) ) – Marcin Grzejszczak May 23 '22 at 09:21

0 Answers0