Search in sources :

Example 1 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project kafka by apache.

the class TopologyBuilderTest method shouldThroughOnUnassignedStateStoreAccess.

@Test(expected = TopologyBuilderException.class)
public void shouldThroughOnUnassignedStateStoreAccess() {
    final String sourceNodeName = "source";
    final String goodNodeName = "goodGuy";
    final String badNodeName = "badGuy";
    final Properties config = new Properties();
    config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "host:1");
    config.put(StreamsConfig.APPLICATION_ID_CONFIG, "appId");
    final StreamsConfig streamsConfig = new StreamsConfig(config);
    try {
        final TopologyBuilder builder = new TopologyBuilder();
        builder.addSource(sourceNodeName, "topic").addProcessor(goodNodeName, new LocalMockProcessorSupplier(), sourceNodeName).addStateStore(Stores.create(LocalMockProcessorSupplier.STORE_NAME).withStringKeys().withStringValues().inMemory().build(), goodNodeName).addProcessor(badNodeName, new LocalMockProcessorSupplier(), sourceNodeName);
        final ProcessorTopologyTestDriver driver = new ProcessorTopologyTestDriver(streamsConfig, builder);
        driver.process("topic", null, null);
    } catch (final StreamsException e) {
        final Throwable cause = e.getCause();
        if (cause != null && cause instanceof TopologyBuilderException && cause.getMessage().equals("Invalid topology building: Processor " + badNodeName + " has no access to StateStore " + LocalMockProcessorSupplier.STORE_NAME)) {
            throw (TopologyBuilderException) cause;
        } else {
            throw new RuntimeException("Did expect different exception. Did catch:", e);
        }
    }
}
Also used : TopologyBuilderException(org.apache.kafka.streams.errors.TopologyBuilderException) ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) StreamsException(org.apache.kafka.streams.errors.StreamsException) Properties(java.util.Properties) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 2 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorTopologyTest method testDrivingStatefulTopology.

@Test
public void testDrivingStatefulTopology() {
    final String storeName = "entries";
    driver = new ProcessorTopologyTestDriver(config, createStatefulTopology(storeName).internalTopologyBuilder);
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key1", "value4", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNoOutputRecord(OUTPUT_TOPIC_1);
    final KeyValueStore<String, String> store = driver.getKeyValueStore(storeName);
    assertEquals("value4", store.get("key1"));
    assertEquals("value2", store.get("key2"));
    assertEquals("value3", store.get("key3"));
    assertNull(store.get("key4"));
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 3 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorTopologyTest method testDrivingInternalRepartitioningTopology.

@Test
public void testDrivingInternalRepartitioningTopology() {
    driver = new ProcessorTopologyTestDriver(config, createInternalRepartitioningTopology().internalTopologyBuilder);
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key1", "value1");
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key2", "value2");
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key3", "value3");
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Example 4 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorTopologyTest method testDrivingForwardToSourceTopology.

@Test
public void testDrivingForwardToSourceTopology() {
    driver = new ProcessorTopologyTestDriver(config, createForwardToSourceTopology().internalTopologyBuilder);
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key1", "value1");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key2", "value2");
    assertNextOutputRecord(OUTPUT_TOPIC_2, "key3", "value3");
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Example 5 with ProcessorTopologyTestDriver

use of org.apache.kafka.test.ProcessorTopologyTestDriver in project apache-kafka-on-k8s by banzaicloud.

the class ProcessorTopologyTest method testDrivingSimpleTopology.

@Test
public void testDrivingSimpleTopology() {
    final int partition = 10;
    driver = new ProcessorTopologyTestDriver(config, createSimpleTopology(partition).internalTopologyBuilder);
    driver.process(INPUT_TOPIC_1, "key1", "value1", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key1", "value1", partition);
    assertNoOutputRecord(OUTPUT_TOPIC_2);
    driver.process(INPUT_TOPIC_1, "key2", "value2", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key2", "value2", partition);
    assertNoOutputRecord(OUTPUT_TOPIC_2);
    driver.process(INPUT_TOPIC_1, "key3", "value3", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key4", "value4", STRING_SERIALIZER, STRING_SERIALIZER);
    driver.process(INPUT_TOPIC_1, "key5", "value5", STRING_SERIALIZER, STRING_SERIALIZER);
    assertNoOutputRecord(OUTPUT_TOPIC_2);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key3", "value3", partition);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key4", "value4", partition);
    assertNextOutputRecord(OUTPUT_TOPIC_1, "key5", "value5", partition);
}
Also used : ProcessorTopologyTestDriver(org.apache.kafka.test.ProcessorTopologyTestDriver) Test(org.junit.Test)

Aggregations

ProcessorTopologyTestDriver (org.apache.kafka.test.ProcessorTopologyTestDriver)17 Test (org.junit.Test)17 Properties (java.util.Properties)4 StreamsException (org.apache.kafka.streams.errors.StreamsException)4 StreamsConfig (org.apache.kafka.streams.StreamsConfig)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 TopologyBuilderException (org.apache.kafka.streams.errors.TopologyBuilderException)1 StateStoreSupplier (org.apache.kafka.streams.processor.StateStoreSupplier)1 TopologyBuilder (org.apache.kafka.streams.processor.TopologyBuilder)1 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)1 MockStateStore (org.apache.kafka.test.MockStateStore)1