use of org.apache.kafka.common.serialization.IntegerSerializer in project kafka by apache.
the class KTableSourceTest method testKTable.
@Test
public void testKTable() {
final StreamsBuilder builder = new StreamsBuilder();
final String topic1 = "topic1";
final KTable<String, Integer> table1 = builder.table(topic1, Consumed.with(Serdes.String(), Serdes.Integer()));
final MockApiProcessorSupplier<String, Integer, Void, Void> supplier = new MockApiProcessorSupplier<>();
table1.toStream().process(supplier);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<String, Integer> inputTopic = driver.createInputTopic(topic1, new StringSerializer(), new IntegerSerializer());
inputTopic.pipeInput("A", 1, 10L);
inputTopic.pipeInput("B", 2, 11L);
inputTopic.pipeInput("C", 3, 12L);
inputTopic.pipeInput("D", 4, 13L);
inputTopic.pipeInput("A", null, 14L);
inputTopic.pipeInput("B", null, 15L);
}
assertEquals(asList(new KeyValueTimestamp<>("A", 1, 10L), new KeyValueTimestamp<>("B", 2, 11L), new KeyValueTimestamp<>("C", 3, 12L), new KeyValueTimestamp<>("D", 4, 13L), new KeyValueTimestamp<>("A", null, 14L), new KeyValueTimestamp<>("B", null, 15L)), supplier.theCapturedProcessor().processed());
}
use of org.apache.kafka.common.serialization.IntegerSerializer in project kafka by apache.
the class KTableSourceTest method testKTableSourceEmitOnChange.
// we have disabled KIP-557 until KAFKA-12508 can be properly addressed
@Ignore
@Test
public void testKTableSourceEmitOnChange() {
final StreamsBuilder builder = new StreamsBuilder();
final String topic1 = "topic1";
builder.table(topic1, Consumed.with(Serdes.String(), Serdes.Integer()), Materialized.as("store")).toStream().to("output");
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<String, Integer> inputTopic = driver.createInputTopic(topic1, new StringSerializer(), new IntegerSerializer());
final TestOutputTopic<String, Integer> outputTopic = driver.createOutputTopic("output", new StringDeserializer(), new IntegerDeserializer());
inputTopic.pipeInput("A", 1, 10L);
inputTopic.pipeInput("B", 2, 11L);
inputTopic.pipeInput("A", 1, 12L);
inputTopic.pipeInput("B", 3, 13L);
// this record should be kept since this is out of order, so the timestamp
// should be updated in this scenario
inputTopic.pipeInput("A", 1, 9L);
assertEquals(1.0, getMetricByName(driver.metrics(), "idempotent-update-skip-total", "stream-processor-node-metrics").metricValue());
assertEquals(asList(new TestRecord<>("A", 1, Instant.ofEpochMilli(10L)), new TestRecord<>("B", 2, Instant.ofEpochMilli(11L)), new TestRecord<>("B", 3, Instant.ofEpochMilli(13L)), new TestRecord<>("A", 1, Instant.ofEpochMilli(9L))), outputTopic.readRecordsToList());
}
}
use of org.apache.kafka.common.serialization.IntegerSerializer in project apache-kafka-on-k8s by banzaicloud.
the class GlobalStateTaskTest method shouldProcessRecordsForOtherTopic.
@Test
public void shouldProcessRecordsForOtherTopic() {
final byte[] integerBytes = new IntegerSerializer().serialize("foo", 1);
globalStateTask.initialize();
globalStateTask.update(new ConsumerRecord<>(topic2, 1, 1, integerBytes, integerBytes));
assertEquals(1, sourceTwo.numReceived);
assertEquals(0, sourceOne.numReceived);
}
use of org.apache.kafka.common.serialization.IntegerSerializer in project apache-kafka-on-k8s by banzaicloud.
the class GlobalStateTaskTest method shouldThrowStreamsExceptionWhenKeyDeserializationFails.
@Test
public void shouldThrowStreamsExceptionWhenKeyDeserializationFails() throws Exception {
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 apache-kafka-on-k8s by banzaicloud.
the class GlobalStateTaskTest method shouldNotThrowStreamsExceptionWhenKeyDeserializationFailsWithSkipHandler.
@Test
public void shouldNotThrowStreamsExceptionWhenKeyDeserializationFailsWithSkipHandler() throws Exception {
final GlobalStateUpdateTask globalStateTask2 = new GlobalStateUpdateTask(topology, context, stateMgr, new LogAndContinueExceptionHandler(), logContext);
final byte[] key = new LongSerializer().serialize(topic2, 1L);
final byte[] recordValue = new IntegerSerializer().serialize(topic2, 10);
maybeDeserialize(globalStateTask2, key, recordValue, false);
}
Aggregations