All Projects → mguenther → kafka-junit

mguenther / kafka-junit

Licence: Apache-2.0 license
Enables you to start and stop a fully-fledged embedded Kafka cluster from within JUnit and provides a rich set of convenient accessors and fault injectors through a lean API. Supports working against external clusters as well.

Programming Languages

java
68154 projects - #9 most used programming language
CSS
56736 projects

Projects that are alternatives of or similar to kafka-junit

MongoDb-Sink-Connector
Kafka MongoDb sink connector
Stars: ✭ 19 (-50%)
Mutual labels:  kafka-connect
jbehave-junit-runner
Integrate JBehave better with JUnit. Reports all Stories, Scenarios and Steps as JUnit Suites and Test Cases.
Stars: ✭ 70 (+84.21%)
Mutual labels:  junit
CI-Report-Converter
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).
Stars: ✭ 17 (-55.26%)
Mutual labels:  junit
kafka-connect-jenkins
Kafka Connect Connector for Jenkins Open Source Continuous Integration Tool
Stars: ✭ 29 (-23.68%)
Mutual labels:  kafka-connect
junit-report-rs
JUnit compatible XML reports in Rust
Stars: ✭ 15 (-60.53%)
Mutual labels:  junit
kafka-connect-arangodb
🥑 Kafka connect sink connector for ArangoDB
Stars: ✭ 22 (-42.11%)
Mutual labels:  kafka-connect
ginkgo4j
A Java BDD Testing Framework (based on RSpec and Ginkgo)
Stars: ✭ 25 (-34.21%)
Mutual labels:  junit
test-class
Test::Class - an xUnit testing framework for Perl 5.x
Stars: ✭ 18 (-52.63%)
Mutual labels:  junit
ForgeModdingSkeleton
Skeletons for building Forge mods
Stars: ✭ 21 (-44.74%)
Mutual labels:  junit
cassandra.realtime
Different ways to process data into Cassandra in realtime with technologies such as Kafka, Spark, Akka, Flink
Stars: ✭ 25 (-34.21%)
Mutual labels:  kafka-connect
faketime
Fake currentTimeMillis() without class loader hacks
Stars: ✭ 100 (+163.16%)
Mutual labels:  junit
junit-insights
Extension for JUnit which provides insights for the runtime of contexts, classes and methods
Stars: ✭ 112 (+194.74%)
Mutual labels:  junit
wdio-junit-reporter
A WebdriverIO v4 plugin. Report results in junit xml format.
Stars: ✭ 13 (-65.79%)
Mutual labels:  junit
giulius-selenium-tests
A test harness that allows Selenium tests to be run using JUnit and test fixtures to be created and injected by a WebDriver-aware Guice
Stars: ✭ 12 (-68.42%)
Mutual labels:  junit
to-string-verifier
To String Verifier provides an easy and convenient way to test the toString method on your class.
Stars: ✭ 25 (-34.21%)
Mutual labels:  junit
kafka-connect-http
Kafka Connect connector that enables Change Data Capture from JSON/HTTP APIs into Kafka.
Stars: ✭ 81 (+113.16%)
Mutual labels:  kafka-connect
bigquery-kafka-connect
☁️ nodejs kafka connect connector for Google BigQuery
Stars: ✭ 17 (-55.26%)
Mutual labels:  kafka-connect
connor
A commandline tool for resetting Kafka Connect source connector offsets.
Stars: ✭ 17 (-55.26%)
Mutual labels:  kafka-connect
tutorial-java-tdd
Tutorials about implementing TDD in Java
Stars: ✭ 66 (+73.68%)
Mutual labels:  junit
kit-assignment-tests
Test collection for KIT programming assignments (WS16/17)
Stars: ✭ 18 (-52.63%)
Mutual labels:  junit

Kafka for JUnit

Build Status Maven Central

Kafka for JUnit enables developers to start and stop a complete Kafka cluster comprised of Kafka brokers and distributed Kafka Connect workers from within a JUnit test. It also provides a rich set of convenient accessors to interact with such an embedded Kafka cluster in a lean and non-obtrusive way.

Kafka for JUnit can be used to both whitebox-test individual Kafka-based components of your application or to blackbox-test applications that offer an incoming and/or outgoing Kafka-based interface.

Using Kafka for JUnit in your tests

Kafka for JUnit provides the necessary infrastructure to exercise your Kafka-based components against an embeddable Kafka cluster. However, Kafka for JUnit got you covered as well if you are simply interested in using the convenient accessors against Kafka clusters that are already present in your infrastructure. Checkout sections Working with an embedded Kafka cluster and Working with an external Kafka cluster in the user's guide for more information.

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static net.mguenther.kafka.junit.EmbeddedKafkaCluster.provisionWith;
import static net.mguenther.kafka.junit.EmbeddedKafkaClusterConfig.defaultClusterConfig;

class KafkaTest {

    private EmbeddedKafkaCluster kafka;

    @BeforeEach
    void setupKafka() {
        kafka = provisionWith(defaultClusterConfig());
        kafka.start();
    }

    @AfterEach
    void tearDownKafka() {
        kafka.stop();
    }

    @Test
    void shouldWaitForRecordsToBePublished() throws Exception {
        kafka.send(to("test-topic", "a", "b", "c"));
        kafka.observe(on("test-topic", 4));
    }
}

This starts an embedded Kafka cluster and submits three records to the topic named test-topic. The call to kafka.observe(on("test-topic", 3)) watches that same topic for a configurable amount of time and checks if it observes the previously submitted records. If it doesn't, Kafka for JUnit raises an AssertionError which would fail the test. Surely, Kafka for JUnit provides lots of more ways to interact with a Kafka cluster.

Since EmbeddedKafkaCluster implements the AutoCloseable interface, you can achieve the same behavior using a try-with-resources-construct.

import org.junit.jupiter.api.Test;

import static net.mguenther.kafka.junit.EmbeddedKafkaCluster.provisionWith;
import static net.mguenther.kafka.junit.EmbeddedKafkaClusterConfig.defaultClusterConfig;

class KafkaTest {

  @Test
  void shouldWaitForRecordsToBePublished() throws Exception {

    try (EmbeddedKafkaCluster kafka = provisionWith(defaultClusterConfig())) {
      kafka.start();
      kafka.send(to("test-topic", "a", "b", "c"));
      kafka.observe(on("test-topic", 3));
    }
  }
}

Supported versions of Apache Kafka

Version of Kafka for JUnit Supports (up to)
0.1.x Apache Kafka 1.0.0
0.2.x Apache Kafka 1.0.0
0.3.x Apache Kafka 1.0.0
1.0.x Apache Kafka 1.1.1
2.0.x Apache Kafka 2.0.0
2.1.x Apache Kafka 2.1.1
2.2.x Apache Kafka 2.2.1
2.3.x Apache Kafka 2.3.0
2.4.x Apache Kafka 2.4.0
2.5.x Apache Kafka 2.5.1
2.6.x Apache Kafka 2.6.0
2.7.x Apache Kafka 2.7.0
2.8.0 Apache Kafka 2.8.0
3.0.0 Apache Kafka 3.0.0
3.1.0 Apache Kafka 3.1.0
3.2.0 Apache Kafka 3.2.0

Interacting with the Kafka cluster

See the comprehensive user's guide for examples on how to interact with the Kafka cluster from within your JUnit test.

License

This work is released under the terms of the Apache 2.0 license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].