All Projects → carlosmenezes → mockafka

carlosmenezes / mockafka

Licence: MIT License
A testing DSL for kafka-streams

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to mockafka

Httpretty
Intercept HTTP requests at the Python socket level. Fakes the whole socket module
Stars: ✭ 1,930 (+13685.71%)
Mutual labels:  mock, testing-tools
Mockito Scala
Mockito for Scala language
Stars: ✭ 231 (+1550%)
Mutual labels:  mock, testing-tools
Mockito
Most popular Mocking framework for unit tests written in Java
Stars: ✭ 12,453 (+88850%)
Mutual labels:  mock, testing-tools
Nsubstitute
A friendly substitute for .NET mocking libraries.
Stars: ✭ 1,646 (+11657.14%)
Mutual labels:  mock, testing-tools
deckard
DNS test harness
Stars: ✭ 28 (+100%)
Mutual labels:  mock, testing-tools
Ava Playback
📼 🚀 Record and playback http requests from your ava tests
Stars: ✭ 124 (+785.71%)
Mutual labels:  mock, testing-tools
Charlatan
Go Interface Mocking Tool
Stars: ✭ 195 (+1292.86%)
Mutual labels:  mock, testing-tools
Lyrebird
移动应用插件化测试工作台
Stars: ✭ 663 (+4635.71%)
Mutual labels:  mock, testing-tools
ts-mock-imports
Intuitive mocking library for Typescript class imports
Stars: ✭ 103 (+635.71%)
Mutual labels:  mock, testing-tools
mocat
🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.
Stars: ✭ 27 (+92.86%)
Mutual labels:  mock, testing-tools
Prig
Prig is a lightweight framework for test indirections in .NET Framework.
Stars: ✭ 106 (+657.14%)
Mutual labels:  mock, testing-tools
laika
Log, test, intercept and modify Apollo Client's operations
Stars: ✭ 99 (+607.14%)
Mutual labels:  mock, testing-tools
Mongodb Memory Server
Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).
Stars: ✭ 1,376 (+9728.57%)
Mutual labels:  mock, testing-tools
Superagent Mocker
Pretty simple in-browser mocks for CRUD and REST API
Stars: ✭ 127 (+807.14%)
Mutual labels:  mock, testing-tools
Webmockr
R library for stubbing and setting expectations on HTTP requests
Stars: ✭ 37 (+164.29%)
Mutual labels:  mock, testing-tools
Mocktopus
Mocking framework for Rust
Stars: ✭ 179 (+1178.57%)
Mutual labels:  mock, testing-tools
DeepfakeHTTP
DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.
Stars: ✭ 373 (+2564.29%)
Mutual labels:  mock, testing-tools
Miragejs
A client-side server to build, test and share your JavaScript app
Stars: ✭ 4,384 (+31214.29%)
Mutual labels:  mock, testing-tools
ruby-dns-mock
DNS mock server written on 💎 Ruby. Mimic any DNS records for your test environment with fake DNS server.
Stars: ✭ 50 (+257.14%)
Mutual labels:  mock, testing-tools
main
Mocks Server monorepo
Stars: ✭ 109 (+678.57%)
Mutual labels:  mock, testing-tools

Mockafka

Codacy Badge

Mockafka is a DSL which allows testing of kafka-streams topologies without need of a kafka and zookeeper installation. It is a Java 8 port of jpzk/mockedstreams.

Add it to your pom.xml...

<dependency>
  <groupId>com.github.carlosmenezes</groupId>
  <artifactId>mockafka</artifactId>
  <version>0.1.2</version>
  <scope>test</scope>
</dependency>

or to your build.gradle.

testCompile "com.github.carlosmenezes:mockafka:0.1.2"

Examples

List<Message<Integer, Integer>> input = Stream.of(1, 2, 3, 4, 5, 6, 7)
    .map(i -> new Message<>(i, i))
    .collect(Collectors.toList());

Serde<Integer> integerSerde = Serdes.Integer();

List<Message<Integer, Integer>> output = Mockafka
    .builder()
    .topology(builder ->
        builder.stream(integerSerde, integerSerde, "numbersTopic")
            .filter((key, value) -> value % 2 == 1)
            .to(integerSerde, integerSerde, "oddNumbersTopic")
    )
    .input("numbersTopic", integerSerde, integerSerde, input)
    .output("oddNumbersTopic", integerSerde, integerSerde, 4);

List<Message<Integer, Integer>> expected = Arrays.asList(new Message<>(1, 1), new Message<>(3, 3), new Message<>(5, 5), new Message<>(7, 7));
assertEquals(4, output.size());
assertEquals(expected, output);

Multiple inputs/outputs

MockafkaBuilder builder = Mockafka
  .builder()
  .topology(builder -> {...})
  .input("someInput", Serdes.String(), Serdes.String(), someInput)
  .input("anotherInput", Serdes.String(), Serdes.String(), anotherInput);
  
List<Message<String, String>> someOutput = builder.output("someOutput", Serdes.String(), Serdes.String(), 10);
List<Message<String, String>> anotherOutput = builder.output("anotherOutput", Serdes.String(), Serdes.String(), 10);

Using State Stores

You can create state stores using .stores(String... stores) method and verify it's contents with .stateTable(String name) method:

MockafkaBuilder builder = Mockafka
  .builder()
  .topology(builder -> {...})
  .input("someInput", Serdes.String(), Serdes.String(), someInput)
  .stores("someStore");
  
Map<String, String> someStore = builder.stateTable("someStore");  
assertEquals(10, someStore.size());

Using Window State Stores

When defining a timestamp extractor in .config(Properties config) you can verify the content as windowed state stores using the method .windowStateTable(String name, K key, long timeFrom, long timeTo).

Properties properties = new Properties();
properties.put(StreamsConfig.DEFAULT_TIMESTAMP_EXTRACTOR_CLASS_CONFIG, TestTimestampExtractor.class.getName());

MockafkaBuilder builder = Mockafka
    .builder()
    .topology(TopologyUtil::windowStateTopology)
    .input(TopologyUtil.WINDOW_TOPIC, TopologyUtil.stringSerde, TopologyUtil.integerSerde, createInputKeyValueForWindow().toArray(new Message[]{}))
    .stores(TEST_STORE)
    .config(properties);

Map<String, Long> actualSomeKey = builder.windowStateTable(TEST_STORE, "somekey", 0, Long.MAX_VALUE);
Map<Long, Long> expectedSomeKey = new HashMap<>();
expectedSomeKey.put(25L, 1L);
expectedSomeKey.put(42L, 2L);
assertEquals(expectedSomeKey, actualSomeKey);

Map<String, Long> actualAnotherKey = builder.windowStateTable(TEST_STORE, "anotherkey", 0, Long.MAX_VALUE);
Map<Long, Long> expectedAnotherKey = new HashMap<>();
expectedAnotherKey.put(50L, 2L);
expectedAnotherKey.put(90L, 1L);
assertEquals(expectedAnotherKey, actualAnotherKey);

Configuring Streams

If you need some custom configuration, just use the method .config(Properties config):

Properties properties = new Properties();
properties.put(StreamsConfig.DEFAULT_TIMESTAMP_EXTRACTOR_CLASS_CONFIG, TestTimestampExtractor.class.getName());

MockafkaBuilder builder = Mockafka
    .builder()
    .topology({...})
    .input({...})
    .stores({...})
    .config(properties);
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].