use of org.apache.kafka.common.serialization.LongDeserializer in project apache-kafka-on-k8s by banzaicloud.
the class KStreamAggregationIntegrationTest method shouldCountHelper.
private void shouldCountHelper() throws Exception {
startStreams();
produceMessages(mockTime.milliseconds());
final List<KeyValue<String, Long>> results = receiveMessages(new StringDeserializer(), new LongDeserializer(), 10);
Collections.sort(results, new Comparator<KeyValue<String, Long>>() {
@Override
public int compare(final KeyValue<String, Long> o1, final KeyValue<String, Long> o2) {
return KStreamAggregationIntegrationTest.compare(o1, o2);
}
});
assertThat(results, is(Arrays.asList(KeyValue.pair("A", 1L), KeyValue.pair("A", 2L), KeyValue.pair("B", 1L), KeyValue.pair("B", 2L), KeyValue.pair("C", 1L), KeyValue.pair("C", 2L), KeyValue.pair("D", 1L), KeyValue.pair("D", 2L), KeyValue.pair("E", 1L), KeyValue.pair("E", 2L))));
}
use of org.apache.kafka.common.serialization.LongDeserializer in project kafka by apache.
the class KStreamAggregationIntegrationTest method shouldGroupByKey.
@SuppressWarnings("deprecation")
@Test
public void shouldGroupByKey() throws Exception {
final long timestamp = mockTime.milliseconds();
produceMessages(timestamp);
produceMessages(timestamp);
// noinspection deprecation
stream.groupByKey(Grouped.with(Serdes.Integer(), Serdes.String())).windowedBy(TimeWindows.of(ofMillis(500L))).count().toStream((windowedKey, value) -> windowedKey.key() + "@" + windowedKey.window().start()).to(outputTopic, Produced.with(Serdes.String(), Serdes.Long()));
startStreams();
final List<KeyValueTimestamp<String, Long>> results = receiveMessages(new StringDeserializer(), new LongDeserializer(), 10);
results.sort(KStreamAggregationIntegrationTest::compare);
final long window = timestamp / 500 * 500;
assertThat(results, is(Arrays.asList(new KeyValueTimestamp("1@" + window, 1L, timestamp), new KeyValueTimestamp("1@" + window, 2L, timestamp), new KeyValueTimestamp("2@" + window, 1L, timestamp), new KeyValueTimestamp("2@" + window, 2L, timestamp), new KeyValueTimestamp("3@" + window, 1L, timestamp), new KeyValueTimestamp("3@" + window, 2L, timestamp), new KeyValueTimestamp("4@" + window, 1L, timestamp), new KeyValueTimestamp("4@" + window, 2L, timestamp), new KeyValueTimestamp("5@" + window, 1L, timestamp), new KeyValueTimestamp("5@" + window, 2L, timestamp))));
}
use of org.apache.kafka.common.serialization.LongDeserializer in project kafka by apache.
the class KStreamAggregationIntegrationTest method shouldCountHelper.
private void shouldCountHelper() throws Exception {
startStreams();
produceMessages(mockTime.milliseconds());
final List<KeyValueTimestamp<String, Long>> results = receiveMessages(new StringDeserializer(), new LongDeserializer(), 10);
results.sort(KStreamAggregationIntegrationTest::compare);
assertThat(results, is(Arrays.asList(new KeyValueTimestamp("A", 1L, mockTime.milliseconds()), new KeyValueTimestamp("A", 2L, mockTime.milliseconds()), new KeyValueTimestamp("B", 1L, mockTime.milliseconds()), new KeyValueTimestamp("B", 2L, mockTime.milliseconds()), new KeyValueTimestamp("C", 1L, mockTime.milliseconds()), new KeyValueTimestamp("C", 2L, mockTime.milliseconds()), new KeyValueTimestamp("D", 1L, mockTime.milliseconds()), new KeyValueTimestamp("D", 2L, mockTime.milliseconds()), new KeyValueTimestamp("E", 1L, mockTime.milliseconds()), new KeyValueTimestamp("E", 2L, mockTime.milliseconds()))));
}
use of org.apache.kafka.common.serialization.LongDeserializer in project kafka by apache.
the class KStreamRepartitionIntegrationTest method shouldGoThroughRebalancingCorrectly.
@Test
public void shouldGoThroughRebalancingCorrectly() throws Exception {
final String repartitionName = "rebalancing-test";
final long timestamp = System.currentTimeMillis();
sendEvents(timestamp, Arrays.asList(new KeyValue<>(1, "A"), new KeyValue<>(2, "B")));
final StreamsBuilder builder = new StreamsBuilder();
final Repartitioned<String, String> repartitioned = Repartitioned.<String, String>as(repartitionName).withKeySerde(Serdes.String()).withValueSerde(Serdes.String()).withNumberOfPartitions(2);
builder.stream(inputTopic, Consumed.with(Serdes.Integer(), Serdes.String())).selectKey((key, value) -> key.toString()).repartition(repartitioned).groupByKey().count().toStream().to(outputTopic);
startStreams(builder);
final Properties streamsToCloseConfigs = new Properties();
streamsToCloseConfigs.putAll(streamsConfiguration);
streamsToCloseConfigs.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath() + "-2");
final KafkaStreams kafkaStreamsToClose = startStreams(builder, streamsToCloseConfigs);
validateReceivedMessages(new StringDeserializer(), new LongDeserializer(), Arrays.asList(new KeyValue<>("1", 1L), new KeyValue<>("2", 1L)));
kafkaStreamsToClose.close();
sendEvents(timestamp, Arrays.asList(new KeyValue<>(1, "C"), new KeyValue<>(2, "D")));
validateReceivedMessages(new StringDeserializer(), new LongDeserializer(), Arrays.asList(new KeyValue<>("1", 2L), new KeyValue<>("2", 2L)));
final String repartitionTopicName = toRepartitionTopicName(repartitionName);
assertTrue(topicExists(repartitionTopicName));
assertEquals(2, getNumberOfPartitionsForTopic(repartitionTopicName));
}
use of org.apache.kafka.common.serialization.LongDeserializer in project kafka by apache.
the class KStreamRepartitionIntegrationTest method shouldPerformKeySelectOperationWhenRepartitionOperationIsUsedWithKeySelector.
@Test
public void shouldPerformKeySelectOperationWhenRepartitionOperationIsUsedWithKeySelector() throws Exception {
final String repartitionedName = "new-key";
final long timestamp = System.currentTimeMillis();
sendEvents(timestamp, Arrays.asList(new KeyValue<>(1, "A"), new KeyValue<>(2, "B")));
final StreamsBuilder builder = new StreamsBuilder();
final Repartitioned<String, String> repartitioned = Repartitioned.<String, String>as(repartitionedName).withKeySerde(Serdes.String());
builder.stream(inputTopic, Consumed.with(Serdes.Integer(), Serdes.String())).selectKey((key, value) -> key.toString(), Named.as(repartitionedName)).repartition(repartitioned).groupByKey().count().toStream().to(outputTopic);
startStreams(builder);
validateReceivedMessages(new StringDeserializer(), new LongDeserializer(), Arrays.asList(new KeyValue<>("1", 1L), new KeyValue<>("2", 1L)));
final String topology = builder.build().describe().toString();
final String repartitionTopicName = toRepartitionTopicName(repartitionedName);
assertTrue(topicExists(repartitionTopicName));
assertEquals(1, countOccurrencesInTopology(topology, "Sink: .*" + repartitionedName + "-repartition.*"));
assertEquals(1, countOccurrencesInTopology(topology, "<-- " + repartitionedName + "\n"));
}
Aggregations