use of org.apache.kafka.common.serialization.IntegerSerializer in project kafka by apache.
the class CogroupedKStreamImplTest method shouldCoGroupStreamsWithDifferentInputTypes.
@Test
public void shouldCoGroupStreamsWithDifferentInputTypes() {
final StreamsBuilder builder = new StreamsBuilder();
final Consumed<String, Integer> integerConsumed = Consumed.with(Serdes.String(), Serdes.Integer());
final KStream<String, String> stream1 = builder.stream("one", stringConsumed);
final KStream<String, Integer> stream2 = builder.stream("two", integerConsumed);
final KGroupedStream<String, String> grouped1 = stream1.groupByKey();
final KGroupedStream<String, Integer> grouped2 = stream2.groupByKey();
final KTable<String, Integer> customers = grouped1.cogroup(STRING_SUM_AGGREGATOR).cogroup(grouped2, SUM_AGGREGATOR).aggregate(SUM_INITIALIZER, Materialized.<String, Integer, KeyValueStore<Bytes, byte[]>>as("store1").withValueSerde(Serdes.Integer()));
customers.toStream().to(OUTPUT);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<String, String> testInputTopic = driver.createInputTopic("one", new StringSerializer(), new StringSerializer());
final TestInputTopic<String, Integer> testInputTopic2 = driver.createInputTopic("two", new StringSerializer(), new IntegerSerializer());
final TestOutputTopic<String, Integer> testOutputTopic = driver.createOutputTopic(OUTPUT, new StringDeserializer(), new IntegerDeserializer());
testInputTopic.pipeInput("k1", "1", 0L);
testInputTopic.pipeInput("k2", "1", 1L);
testInputTopic.pipeInput("k1", "1", 10L);
testInputTopic.pipeInput("k2", "1", 100L);
testInputTopic2.pipeInput("k2", 2, 100L);
testInputTopic2.pipeInput("k2", 2, 200L);
testInputTopic2.pipeInput("k1", 2, 1L);
testInputTopic2.pipeInput("k2", 2, 500L);
testInputTopic2.pipeInput("k1", 2, 500L);
testInputTopic2.pipeInput("k2", 3, 500L);
testInputTopic2.pipeInput("k3", 2, 500L);
testInputTopic2.pipeInput("k2", 2, 100L);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", 1, 0);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", 1, 1);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", 2, 10);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", 2, 100);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", 4, 100);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", 6, 200);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", 4, 10);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", 8, 500);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", 6, 500);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", 11, 500);
assertOutputKeyValueTimestamp(testOutputTopic, "k3", 2, 500);
}
}
use of org.apache.kafka.common.serialization.IntegerSerializer in project kafka by apache.
the class KStreamFilterTest method testFilter.
@Test
public void testFilter() {
final StreamsBuilder builder = new StreamsBuilder();
final int[] expectedKeys = new int[] { 1, 2, 3, 4, 5, 6, 7 };
final KStream<Integer, String> stream;
final MockApiProcessorSupplier<Integer, String, Void, Void> supplier = new MockApiProcessorSupplier<>();
stream = builder.stream(topicName, Consumed.with(Serdes.Integer(), Serdes.String()));
stream.filter(isMultipleOfThree).process(supplier);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<Integer, String> inputTopic = driver.createInputTopic(topicName, new IntegerSerializer(), new StringSerializer());
for (final int expectedKey : expectedKeys) {
inputTopic.pipeInput(expectedKey, "V" + expectedKey);
}
}
assertEquals(2, supplier.theCapturedProcessor().processed().size());
}
use of org.apache.kafka.common.serialization.IntegerSerializer in project kafka by apache.
the class GlobalStateTaskTest method shouldThrowStreamsExceptionWhenKeyDeserializationFails.
@Test
public void shouldThrowStreamsExceptionWhenKeyDeserializationFails() {
final byte[] key = new LongSerializer().serialize(topic2, 1L);
final byte[] recordValue = new IntegerSerializer().serialize(topic2, 10);
maybeDeserialize(globalStateTask, key, recordValue, true);
}
use of org.apache.kafka.common.serialization.IntegerSerializer in project kafka by apache.
the class GlobalStateTaskTest method shouldProcessRecordsForOtherTopic.
@Test
public void shouldProcessRecordsForOtherTopic() {
final byte[] integerBytes = new IntegerSerializer().serialize("foo", 1);
globalStateTask.initialize();
globalStateTask.update(record(topic2, 1, 1, integerBytes, integerBytes));
assertEquals(1, sourceTwo.numReceived);
assertEquals(0, sourceOne.numReceived);
}
use of org.apache.kafka.common.serialization.IntegerSerializer in project kafka by apache.
the class GlobalStateTaskTest method shouldNotThrowStreamsExceptionWhenValueDeserializationFails.
@Test
public void shouldNotThrowStreamsExceptionWhenValueDeserializationFails() {
final GlobalStateUpdateTask globalStateTask2 = new GlobalStateUpdateTask(logContext, topology, context, stateMgr, new LogAndContinueExceptionHandler());
final byte[] key = new IntegerSerializer().serialize(topic2, 1);
final byte[] recordValue = new LongSerializer().serialize(topic2, 10L);
maybeDeserialize(globalStateTask2, key, recordValue, false);
}
Aggregations