use of org.apache.kafka.test.KStreamTestDriver in project kafka by apache.
the class KTableSourceTest method testKTable.
@Test
public void testKTable() {
final KStreamBuilder builder = new KStreamBuilder();
String topic1 = "topic1";
KTable<String, Integer> table1 = builder.table(stringSerde, intSerde, topic1, "anyStoreName");
MockProcessorSupplier<String, Integer> proc1 = new MockProcessorSupplier<>();
table1.toStream().process(proc1);
driver = new KStreamTestDriver(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.KStreamTestDriver in project kafka by apache.
the class KTableSourceTest method testNotSendingOldValue.
@Test
public void testNotSendingOldValue() throws IOException {
final KStreamBuilder builder = new KStreamBuilder();
String topic1 = "topic1";
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(stringSerde, stringSerde, topic1, "anyStoreName");
MockProcessorSupplier<String, Integer> proc1 = new MockProcessorSupplier<>();
builder.addProcessor("proc1", proc1, table1.name);
driver = new KStreamTestDriver(builder, stateDir, null, null);
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<-null)", "B:(02<-null)");
driver.process(topic1, "A", "03");
driver.flushState();
proc1.checkAndClearProcessResult("A:(03<-null)");
driver.process(topic1, "A", null);
driver.process(topic1, "B", null);
driver.flushState();
proc1.checkAndClearProcessResult("A:(null<-null)", "B:(null<-null)");
}
use of org.apache.kafka.test.KStreamTestDriver in project kafka by apache.
the class KTableSourceTest method testSendingOldValue.
@Test
public void testSendingOldValue() throws IOException {
final KStreamBuilder builder = new KStreamBuilder();
String topic1 = "topic1";
KTableImpl<String, String, String> table1 = (KTableImpl<String, String, String>) builder.table(stringSerde, stringSerde, topic1, "anyStoreName");
table1.enableSendingOldValues();
assertTrue(table1.sendingOldValueEnabled());
MockProcessorSupplier<String, Integer> proc1 = new MockProcessorSupplier<>();
builder.addProcessor("proc1", proc1, table1.name);
driver = new KStreamTestDriver(builder, stateDir, null, null);
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.KStreamTestDriver in project kafka by apache.
the class KeyValuePrinterProcessorTest method testPrintKeyValueDefaultSerde.
@Test
public void testPrintKeyValueDefaultSerde() throws Exception {
KeyValuePrinter<String, String> keyValuePrinter = new KeyValuePrinter<>(printStream, null);
String[] suppliedKeys = { "foo", "bar", null };
String[] suppliedValues = { "value1", "value2", "value3" };
String[] expectedValues = { "[null]: foo , value1", "[null]: bar , value2", "[null]: null , value3" };
KStream<String, String> stream = builder.stream(stringSerde, stringSerde, topicName);
stream.process(keyValuePrinter);
driver = new KStreamTestDriver(builder);
for (int i = 0; i < suppliedKeys.length; i++) {
driver.process(topicName, suppliedKeys[i], suppliedValues[i]);
}
String[] capturedValues = new String(baos.toByteArray(), Charset.forName("UTF-8")).split("\n");
for (int i = 0; i < capturedValues.length; i++) {
assertEquals(capturedValues[i], expectedValues[i]);
}
}
use of org.apache.kafka.test.KStreamTestDriver in project kafka by apache.
the class KeyValuePrinterProcessorTest method testPrintKeyValuesWithName.
@Test
public void testPrintKeyValuesWithName() throws Exception {
KeyValuePrinter<String, String> keyValuePrinter = new KeyValuePrinter<>(printStream, "test-stream");
String[] suppliedKeys = { "foo", "bar", null };
String[] suppliedValues = { "value1", "value2", "value3" };
String[] expectedValues = { "[test-stream]: foo , value1", "[test-stream]: bar , value2", "[test-stream]: null , value3" };
KStream<String, String> stream = builder.stream(stringSerde, stringSerde, topicName);
stream.process(keyValuePrinter);
driver = new KStreamTestDriver(builder);
for (int i = 0; i < suppliedKeys.length; i++) {
driver.process(topicName, suppliedKeys[i], suppliedValues[i]);
}
String[] capturedValues = new String(baos.toByteArray(), Charset.forName("UTF-8")).split("\n");
for (int i = 0; i < capturedValues.length; i++) {
assertEquals(capturedValues[i], expectedValues[i]);
}
}
Aggregations