use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableAggregateTest method testCountWithInternalStore.
@Test
public void testCountWithInternalStore() {
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().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 testAggRepartition.
@Test
public void testAggRepartition() {
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(new KeyValueMapper<String, String, KeyValue<String, String>>() {
@Override
public KeyValue<String, String> apply(String key, String value) {
switch(key) {
case "null":
return KeyValue.pair(null, value);
case "NULL":
return null;
default:
return KeyValue.pair(value, value);
}
}
}, stringSerialzied).aggregate(MockInitializer.STRING_INIT, MockAggregator.TOSTRING_ADDER, MockAggregator.TOSTRING_REMOVER, stringSerde, "topic1-Canonized");
table2.toStream().process(proc);
driver.setUp(builder, stateDir);
driver.process(topic1, "A", "1");
driver.flushState();
driver.process(topic1, "A", null);
driver.flushState();
driver.process(topic1, "A", "1");
driver.flushState();
driver.process(topic1, "B", "2");
driver.flushState();
driver.process(topic1, "null", "3");
driver.flushState();
driver.process(topic1, "B", "4");
driver.flushState();
driver.process(topic1, "NULL", "5");
driver.flushState();
driver.process(topic1, "B", "7");
driver.flushState();
assertEquals(Utils.mkList("1:0+1", "1:0+1-1", "1:0+1-1+1", "2:0+2", // noop
"2:0+2-2", "4:0+4", // noop
"4:0+4-4", "7:0+7"), proc.processed);
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableAggregateTest method testCountCoalesced.
@Test
public void testCountCoalesced() {
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);
driver.setUp(builder, stateDir);
driver.process(input, "A", "green");
driver.process(input, "B", "green");
driver.process(input, "A", "blue");
driver.process(input, "C", "yellow");
driver.process(input, "D", "green");
driver.flushState();
assertEquals(Utils.mkList("blue:1", "yellow:1", "green:2"), proc.processed);
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableMapKeysTest method testMapKeysConvertingToStream.
@Test
public void testMapKeysConvertingToStream() {
final StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic_map_keys";
KTable<Integer, String> table1 = builder.table(topic1, Consumed.with(integerSerde, stringSerde));
final Map<Integer, String> keyMap = new HashMap<>();
keyMap.put(1, "ONE");
keyMap.put(2, "TWO");
keyMap.put(3, "THREE");
KeyValueMapper<Integer, String, String> keyMapper = new KeyValueMapper<Integer, String, String>() {
@Override
public String apply(Integer key, String value) {
return keyMap.get(key);
}
};
KStream<String, String> convertedStream = table1.toStream(keyMapper);
final String[] expected = new String[] { "ONE:V_ONE", "TWO:V_TWO", "THREE:V_THREE" };
final int[] originalKeys = new int[] { 1, 2, 3 };
final String[] values = new String[] { "V_ONE", "V_TWO", "V_THREE" };
MockProcessorSupplier<String, String> processor = new MockProcessorSupplier<>();
convertedStream.process(processor);
driver.setUp(builder, stateDir);
for (int i = 0; i < originalKeys.length; i++) {
driver.process(topic1, originalKeys[i], values[i]);
}
driver.flushState();
assertEquals(3, processor.processed.size());
for (int i = 0; i < expected.length; i++) {
assertEquals(expected[i], processor.processed.get(i));
}
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableMapValuesTest method testQueryableKTable.
@Test
public void testQueryableKTable() {
final StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
KTable<String, String> table1 = builder.table(topic1, consumed);
KTable<String, Integer> table2 = table1.mapValues(new ValueMapper<CharSequence, Integer>() {
@Override
public Integer apply(CharSequence value) {
return value.charAt(0) - 48;
}
}, Materialized.<String, Integer, KeyValueStore<Bytes, byte[]>>as("anyName").withValueSerde(Serdes.Integer()));
MockProcessorSupplier<String, Integer> proc2 = new MockProcessorSupplier<>();
table2.toStream().process(proc2);
doTestKTable(builder, topic1, proc2);
}
Aggregations