question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embedded Kafka Message From Previous Test Exists In New Test

See original GitHub issue

Im 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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
francescopellegrinicommented, Dec 17, 2019

Are your test scenarios running concurrently, maybe? Here we use the following settings:

parallelExecution in ThisBuild := false
parallelExecution in Test := false
0reactions
no-stupid-questionscommented, Jan 8, 2020

I havent been able to solve this, but it’s okay. I’ll close this issue and thanks again for the help 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found