use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableMapValuesTest method testSendingOldValue.
@Test
public void testSendingOldValue() {
StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(topic1, consumed);
KTableImpl<String, String, Integer> table2 = (KTableImpl<String, String, Integer>) table1.mapValues(new ValueMapper<String, Integer>() {
@Override
public Integer apply(String value) {
return new Integer(value);
}
});
table2.enableSendingOldValues();
MockProcessorSupplier<String, Integer> proc = new MockProcessorSupplier<>();
builder.build().addProcessor("proc", proc, table2.name);
driver.setUp(builder, stateDir);
assertTrue(table1.sendingOldValueEnabled());
assertTrue(table2.sendingOldValueEnabled());
driver.process(topic1, "A", "01");
driver.process(topic1, "B", "01");
driver.process(topic1, "C", "01");
driver.flushState();
proc.checkAndClearProcessResult("A:(1<-null)", "B:(1<-null)", "C:(1<-null)");
driver.process(topic1, "A", "02");
driver.process(topic1, "B", "02");
driver.flushState();
proc.checkAndClearProcessResult("A:(2<-1)", "B:(2<-1)");
driver.process(topic1, "A", "03");
driver.flushState();
proc.checkAndClearProcessResult("A:(3<-2)");
driver.process(topic1, "A", null);
driver.flushState();
proc.checkAndClearProcessResult("A:(null<-3)");
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableSourceTest method testKTable.
@Test
public void testKTable() {
final StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
KTable<String, Integer> table1 = builder.table(topic1, Consumed.with(stringSerde, intSerde));
MockProcessorSupplier<String, Integer> proc1 = new MockProcessorSupplier<>();
table1.toStream().process(proc1);
driver.setUp(builder, stateDir);
driver.process(topic1, "A", 1);
driver.process(topic1, "B", 2);
driver.process(topic1, "C", 3);
driver.process(topic1, "D", 4);
driver.flushState();
driver.process(topic1, "A", null);
driver.process(topic1, "B", null);
driver.flushState();
assertEquals(Utils.mkList("A:1", "B:2", "C:3", "D:4", "A:null", "B:null"), proc1.processed);
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KTableSourceTest method testSendingOldValue.
@Test
public void testSendingOldValue() {
final StreamsBuilder builder = new StreamsBuilder();
String topic1 = "topic1";
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(topic1, stringConsumed);
table1.enableSendingOldValues();
assertTrue(table1.sendingOldValueEnabled());
MockProcessorSupplier<String, Integer> proc1 = new MockProcessorSupplier<>();
builder.build().addProcessor("proc1", proc1, table1.name);
driver.setUp(builder, stateDir);
driver.process(topic1, "A", "01");
driver.process(topic1, "B", "01");
driver.process(topic1, "C", "01");
driver.flushState();
proc1.checkAndClearProcessResult("A:(01<-null)", "B:(01<-null)", "C:(01<-null)");
driver.process(topic1, "A", "02");
driver.process(topic1, "B", "02");
driver.flushState();
proc1.checkAndClearProcessResult("A:(02<-01)", "B:(02<-01)");
driver.process(topic1, "A", "03");
driver.flushState();
proc1.checkAndClearProcessResult("A:(03<-02)");
driver.process(topic1, "A", null);
driver.process(topic1, "B", null);
driver.flushState();
proc1.checkAndClearProcessResult("A:(null<-03)", "B:(null<-02)");
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KStreamFlatMapValuesTest method testFlatMapValuesWithKeys.
@Test
public void testFlatMapValuesWithKeys() {
StreamsBuilder builder = new StreamsBuilder();
ValueMapperWithKey<Integer, Number, Iterable<String>> mapper = new ValueMapperWithKey<Integer, Number, Iterable<String>>() {
@Override
public Iterable<String> apply(final Integer readOnlyKey, final Number value) {
ArrayList<String> result = new ArrayList<>();
result.add("v" + value);
result.add("k" + readOnlyKey);
return result;
}
};
final int[] expectedKeys = { 0, 1, 2, 3 };
final KStream<Integer, Integer> stream = builder.stream(topicName, Consumed.with(Serdes.Integer(), Serdes.Integer()));
final MockProcessorSupplier<Integer, String> processor = new MockProcessorSupplier<>();
stream.flatMapValues(mapper).process(processor);
driver.setUp(builder);
for (final int expectedKey : expectedKeys) {
driver.process(topicName, expectedKey, expectedKey);
}
String[] expected = { "0:v0", "0:k0", "1:v1", "1:k1", "2:v2", "2:k2", "3:v3", "3:k3" };
assertArrayEquals(expected, processor.processed.toArray());
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class KStreamFlatMapValuesTest method testFlatMapValues.
@Test
public void testFlatMapValues() {
StreamsBuilder builder = new StreamsBuilder();
ValueMapper<Number, Iterable<String>> mapper = new ValueMapper<Number, Iterable<String>>() {
@Override
public Iterable<String> apply(Number value) {
ArrayList<String> result = new ArrayList<String>();
result.add("v" + value);
result.add("V" + value);
return result;
}
};
final int[] expectedKeys = { 0, 1, 2, 3 };
final KStream<Integer, Integer> stream = builder.stream(topicName, Consumed.with(Serdes.Integer(), Serdes.Integer()));
final MockProcessorSupplier<Integer, String> processor = new MockProcessorSupplier<>();
stream.flatMapValues(mapper).process(processor);
driver.setUp(builder);
for (final int expectedKey : expectedKeys) {
driver.process(topicName, expectedKey, expectedKey);
}
String[] expected = { "0:v0", "0:V0", "1:v1", "1:V1", "2:v2", "2:V2", "3:v3", "3:V3" };
assertArrayEquals(expected, processor.processed.toArray());
}
Aggregations