Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2eTest for continuous receive #193

Closed
wants to merge 1 commit into from
Closed

Add e2eTest for continuous receive #193

wants to merge 1 commit into from

Conversation

osoykan
Copy link

@osoykan osoykan commented May 17, 2024

I thought the problem in on KafkaReceiver but it is the default polling timeout was too low (100ms). When I changed it, it worked. So we have extra tests 😄

We are free to discard the MR.


This PR adds testing of Kotlin-kafka library while using an example use case.

The entrance point of all the tests is, ProjectConfig, where Kafka is configured:

class ProjectConfig : AbstractProjectConfig() {
    override suspend fun beforeProject(): Unit = TestSystem()
        .with {
            kafka {
                KafkaSystemOptions(
                    configureExposedConfiguration = { cfg ->
                        listOf(
                            "kafka.servers=${cfg.bootstrapServers}",
                            "kafka.interceptor-classes=${cfg.interceptorClass}",
                            "kafka.receive-method=traditional" // here we can change to: 'kotlin-kafka' or 'traditional'
                        )
                    }
                )
            }
            applicationUnderTest(KafkaApplicationUnderTest())
        }.run()

    override suspend fun afterProject(): Unit = TestSystem.stop()
}

kotlin-kafka and traditional while loop can be switched with the configuration.

  "kafka.receive-method=traditional" // here we can change to: 'kotlin-kafka' or 'traditional'

Tests are located under the test-e2e folder and can be invoked with kotest plugin by pressing the play button on the test.

It will need a docker engine running locally.

The expected behaviour is shouldBeConsumed should be true.

class KafkaSystemTests : FunSpec({
  val randomString = { Random.nextInt(0, Int.MAX_VALUE).toString() }

  test("message should be committed and consumed successfully") {
    validate {
      kafka {
        val productId = randomString() + "[productCreated]"
        publish("product", message = ProductCreated(productId), key = randomString().some())
        shouldBeConsumed<ProductCreated>(10.seconds) {
          actual.productId == productId
        }
      }
    }
  }
})

@osoykan osoykan changed the title Add test for simulating the problem for continuous receive Add e2eTest for continuous receive May 17, 2024
@osoykan osoykan closed this May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant