use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class RegexSourceIntegrationTest method shouldAddStateStoreToRegexDefinedSource.
@SuppressWarnings("deprecation")
@Test
public void shouldAddStateStoreToRegexDefinedSource() throws InterruptedException {
final ProcessorSupplier<String, String> processorSupplier = new MockProcessorSupplier<>();
final MockStateStoreSupplier stateStoreSupplier = new MockStateStoreSupplier("testStateStore", false);
final long thirtySecondTimeout = 30 * 1000;
final TopologyBuilder builder = new TopologyBuilder().addSource("ingest", Pattern.compile("topic-\\d+")).addProcessor("my-processor", processorSupplier, "ingest").addStateStore(stateStoreSupplier, "my-processor");
streams = new KafkaStreams(builder, streamsConfiguration);
try {
streams.start();
final TestCondition stateStoreNameBoundToSourceTopic = new TestCondition() {
@Override
public boolean conditionMet() {
final Map<String, List<String>> stateStoreToSourceTopic = builder.stateStoreNameToSourceTopics();
final List<String> topicNamesList = stateStoreToSourceTopic.get("testStateStore");
return topicNamesList != null && !topicNamesList.isEmpty() && topicNamesList.get(0).equals("topic-1");
}
};
TestUtils.waitForCondition(stateStoreNameBoundToSourceTopic, thirtySecondTimeout, "Did not find topic: [topic-1] connected to state store: [testStateStore]");
} finally {
streams.close();
}
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableAggregateTest method testRemoveOldBeforeAddNew.
@Test
public void testRemoveOldBeforeAddNew() {
final StreamsBuilder builder = new StreamsBuilder();
final String input = "count-test-input";
final MockProcessorSupplier<String, String> proc = new MockProcessorSupplier<>();
builder.table(input, consumed).groupBy(new KeyValueMapper<String, String, KeyValue<String, String>>() {
@Override
public KeyValue<String, String> apply(String key, String value) {
return KeyValue.pair(String.valueOf(key.charAt(0)), String.valueOf(key.charAt(1)));
}
}, stringSerialzied).aggregate(new Initializer<String>() {
@Override
public String apply() {
return "";
}
}, new Aggregator<String, String, String>() {
@Override
public String apply(String aggKey, String value, String aggregate) {
return aggregate + value;
}
}, new Aggregator<String, String, String>() {
@Override
public String apply(String key, String value, String aggregate) {
return aggregate.replaceAll(value, "");
}
}, Serdes.String(), "someStore").toStream().process(proc);
driver.setUp(builder, stateDir);
driver.process(input, "11", "A");
driver.flushState();
driver.process(input, "12", "B");
driver.flushState();
driver.process(input, "11", null);
driver.flushState();
driver.process(input, "12", "C");
driver.flushState();
assertEquals(Utils.mkList("1:1", "1:12", "1:2", "1:2"), proc.processed);
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableAggregateTest method testCount.
@Test
public void testCount() {
final StreamsBuilder builder = new StreamsBuilder();
final String input = "count-test-input";
final MockProcessorSupplier<String, Long> proc = new MockProcessorSupplier<>();
builder.table(input, consumed).groupBy(MockMapper.<String, String>selectValueKeyValueMapper(), stringSerialzied).count("count").toStream().process(proc);
testCountHelper(builder, input, proc);
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableAggregateTest method testAggBasic.
@Test
public void testAggBasic() {
final StreamsBuilder builder = new StreamsBuilder();
final String topic1 = "topic1";
final MockProcessorSupplier<String, String> proc = new MockProcessorSupplier<>();
KTable<String, String> table1 = builder.table(topic1, consumed);
KTable<String, String> table2 = table1.groupBy(MockMapper.<String, String>noOpKeyValueMapper(), stringSerialzied).aggregate(MockInitializer.STRING_INIT, MockAggregator.TOSTRING_ADDER, MockAggregator.TOSTRING_REMOVER, stringSerde, "topic1-Canonized");
table2.toStream().process(proc);
driver.setUp(builder, stateDir, Serdes.String(), Serdes.String());
driver.process(topic1, "A", "1");
driver.flushState();
driver.process(topic1, "B", "2");
driver.flushState();
driver.process(topic1, "A", "3");
driver.flushState();
driver.process(topic1, "B", "4");
driver.flushState();
driver.process(topic1, "C", "5");
driver.flushState();
driver.process(topic1, "D", "6");
driver.flushState();
driver.process(topic1, "B", "7");
driver.flushState();
driver.process(topic1, "C", "8");
driver.flushState();
assertEquals(Utils.mkList("A:0+1", "B:0+2", "A:0+1-1+3", "B:0+2-2+4", "C:0+5", "D:0+6", "B:0+2-2+4-4+7", "C:0+5-5+8"), proc.processed);
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableImplTest method testKTable.
@Test
public void testKTable() {
final StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
String topic2 = "topic2";
String storeName2 = "storeName2";
KTable<String, String> table1 = builder.table(topic1, consumed);
MockProcessorSupplier<String, String> proc1 = new MockProcessorSupplier<>();
table1.toStream().process(proc1);
KTable<String, Integer> table2 = table1.mapValues(new ValueMapper<String, Integer>() {
@Override
public Integer apply(String value) {
return new Integer(value);
}
});
MockProcessorSupplier<String, Integer> proc2 = new MockProcessorSupplier<>();
table2.toStream().process(proc2);
KTable<String, Integer> table3 = table2.filter(new Predicate<String, Integer>() {
@Override
public boolean test(String key, Integer value) {
return (value % 2) == 0;
}
});
MockProcessorSupplier<String, Integer> proc3 = new MockProcessorSupplier<>();
table3.toStream().process(proc3);
KTable<String, String> table4 = table1.through(stringSerde, stringSerde, topic2, storeName2);
MockProcessorSupplier<String, String> proc4 = new MockProcessorSupplier<>();
table4.toStream().process(proc4);
driver.setUp(builder, stateDir);
driver.process(topic1, "A", "01");
driver.flushState();
driver.process(topic1, "B", "02");
driver.flushState();
driver.process(topic1, "C", "03");
driver.flushState();
driver.process(topic1, "D", "04");
driver.flushState();
driver.flushState();
assertEquals(Utils.mkList("A:01", "B:02", "C:03", "D:04"), proc1.processed);
assertEquals(Utils.mkList("A:1", "B:2", "C:3", "D:4"), proc2.processed);
assertEquals(Utils.mkList("A:null", "B:2", "C:null", "D:4"), proc3.processed);
assertEquals(Utils.mkList("A:01", "B:02", "C:03", "D:04"), proc4.processed);
}
Aggregations