use of org.apache.kafka.common.serialization.LongDeserializer in project spring-cloud-stream by spring-cloud.
the class KafkaBinderTests method testConsumerCustomDeserializer.
@Test
@SuppressWarnings("unchecked")
void testConsumerCustomDeserializer() throws Exception {
Binding<?> binding = null;
try {
KafkaBinderConfigurationProperties configurationProperties = createConfigurationProperties();
Map<String, String> propertiesToOverride = configurationProperties.getConfiguration();
propertiesToOverride.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
propertiesToOverride.put("value.deserializer", "org.apache.kafka.common.serialization.LongDeserializer");
configurationProperties.setConfiguration(propertiesToOverride);
String testTopicName = "existing" + System.currentTimeMillis();
configurationProperties.setAutoCreateTopics(false);
Binder binder = getBinder(configurationProperties);
ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties();
DirectChannel input = createBindableChannel("input", createConsumerBindingProperties(consumerProperties));
binding = binder.bindConsumer(testTopicName, "test", input, consumerProperties);
DirectFieldAccessor consumerAccessor = new DirectFieldAccessor(getKafkaConsumer(binding));
assertThat(consumerAccessor.getPropertyValue("keyDeserializer") instanceof StringDeserializer).isTrue();
assertThat(consumerAccessor.getPropertyValue("valueDeserializer") instanceof LongDeserializer).isTrue();
} finally {
if (binding != null) {
binding.unbind();
}
}
}
use of org.apache.kafka.common.serialization.LongDeserializer in project starlight-for-kafka by datastax.
the class KStreamAggregationTest method shouldCountHelper.
private void shouldCountHelper() throws Exception {
startStreams();
produceMessages(mockTime.milliseconds());
final List<KeyValue<String, Long>> results = receiveMessages(new StringDeserializer(), new LongDeserializer(), 10);
results.sort(KStreamAggregationTest::compare);
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 kop by streamnative.
the class KStreamAggregationTest method shouldCountHelper.
private void shouldCountHelper() throws Exception {
startStreams();
produceMessages(mockTime.milliseconds());
final List<KeyValue<String, Long>> results = receiveMessages(new StringDeserializer(), new LongDeserializer(), 10);
results.sort(KStreamAggregationTest::compare);
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 kop by streamnative.
the class KStreamAggregationTest method shouldGroupByKey.
@Test
public void shouldGroupByKey() throws Exception {
final long timestamp = mockTime.milliseconds();
produceMessages(timestamp);
produceMessages(timestamp);
stream.groupByKey(Serialized.with(Serdes.Integer(), Serdes.String())).windowedBy(TimeWindows.of(500L)).count().toStream((windowedKey, value) -> windowedKey.key() + "@" + windowedKey.window().start()).to(outputTopic, Produced.with(Serdes.String(), Serdes.Long()));
startStreams();
final List<KeyValue<String, Long>> results = receiveMessages(new StringDeserializer(), new LongDeserializer(), 10);
results.sort(KStreamAggregationTest::compare);
final long window = timestamp / 500 * 500;
assertThat(results, is(Arrays.asList(KeyValue.pair("1@" + window, 1L), KeyValue.pair("1@" + window, 2L), KeyValue.pair("2@" + window, 1L), KeyValue.pair("2@" + window, 2L), KeyValue.pair("3@" + window, 1L), KeyValue.pair("3@" + window, 2L), KeyValue.pair("4@" + window, 1L), KeyValue.pair("4@" + window, 2L), KeyValue.pair("5@" + window, 1L), KeyValue.pair("5@" + window, 2L))));
}
use of org.apache.kafka.common.serialization.LongDeserializer in project kafka by apache.
the class WordCountDemoTest method setup.
@BeforeEach
public void setup() throws IOException {
final StreamsBuilder builder = new StreamsBuilder();
// Create Actual Stream Processing pipeline
WordCountDemo.createWordCountStream(builder);
testDriver = new TopologyTestDriver(builder.build(), WordCountDemo.getStreamsConfig(null));
inputTopic = testDriver.createInputTopic(WordCountDemo.INPUT_TOPIC, new StringSerializer(), new StringSerializer());
outputTopic = testDriver.createOutputTopic(WordCountDemo.OUTPUT_TOPIC, new StringDeserializer(), new LongDeserializer());
}
Aggregations