Embedded Kafka Message From Previous Test Exists In New Test
See original GitHub issueIm using embeddedkafka 2.1.1 with sbt 1.3.0 and scala 2.11.12. I have a test that should be ignored
\"publish corresponding message to Kafka\" in {
val uri = new URI(\"http\", \"localhost:9000", "/v1/data/datasets/", """datasetIds=["dataset1","dataset2"]""", null)
val aRequest = play.api.test.FakeRequest(method = "DELETE", uri = uri.toASCIIString, headers = play.api.test.FakeHeaders(), body = AnyContentAsEmpty)
when(mockMDSRepo.deleteMetaDatasets(Set("dataset1", "dataset2"))) thenReturn DeleteSuccess
implicit val config: EmbeddedKafkaConfig = EmbeddedKafkaConfig(kafkaPort = 9092, zooKeeperPort = 2181)
runningwithkafka
val kafkaPublisher = new KafkaPublisherImpl
val dsController = new MetaDatasetController(mockMDSRepo, mockSchemaRepo, mockJobRepo, mockAppRepo, kafkaPublisher) {
override def controllerComponents: ControllerComponents = Helpers.stubControllerComponents()
}
val results = dsController.deleteDatasets().apply(aRequest)
status(results) mustBe 204
contentType(results) mustBe None
consumeFirstStringMessageFrom(bpa.kafkaTopic) mustBe KafkaMessages.datasetDeletedMessage1
consumeFirstStringMessageFrom(bpa.kafkaTopic) mustBe KafkaMessages.datasetDeletedMessage2
EmbeddedKafka.stop()
}
How ever in a later test
"publish proper dataset created message" in {
when(mockAppRepo.getAllBPAApplications) thenReturn Set(bpa)
implicit val config: EmbeddedKafkaConfig = EmbeddedKafkaConfig(kafkaPort = 9092, zooKeeperPort = 2181)
withRunningKafka {
val kafkaPublisher = new KafkaPublisherImpl
val kafkaUtil = new KafkaUtil(kafkaPublisher, mockAppRepo)
kafkaUtil.publisDatasetCreatedMessage(testMetadataset)
consumeFirstStringMessageFrom(bpa.kafkaTopic) mustBe KafkaMessages.datasetCreatedMessage1
}
}
the test fails as the consumeFirstStringMessageFrom(bpa.kafkaTopic) results in the KafkaMessages.datasetDeletedMessage1 (from ignored test) instead of the testMetadataset that was supposed to be put into kafka
I tried the test classes with BeforeAndAfterEach and BeforeEach starting Embedded kafka and AfterEach stopping Embedded kafka, but i would still get the test failing.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Spring Kafka Embedded - topic already exists between tests
with embedded kafka (spring-kafka-test), and when I run them sometimes (not always) I got "Topic 'some_name' already exists" on one or more ......
Read more >Testing Kafka and Spring Boot - Baeldung
In this section, we'll take a look at how to use an in-memory Kafka instance to run our tests against. This is also...
Read more >Testing Spring Embedded Kafka consumer and producer
For testing, I'm going to use another Spring library that is called spring-kafka-test. It provides much functionality to ease our job in the ......
Read more >Testing an Apache Kafka Integration within a Spring Boot ...
This blog post will show how you can setup your Kafka tests to use an embedded Kafka server. Project Setup. Either use your...
Read more >Acceptance Tests with embedded Kafka – Best Practices
With the changes above, in an acceptance test, we are now able to receive messages only created by a specific scenario. However. There...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Are your test scenarios running concurrently, maybe? Here we use the following settings:
I havent been able to solve this, but it’s okay. I’ll close this issue and thanks again for the help 👍