Search in sources :

Example 1 with TimeWindowedDeserializer

use of org.apache.kafka.streams.kstream.TimeWindowedDeserializer in project kafka by apache.

the class CachingPersistentWindowStoreTest method setUp.

@Before
public void setUp() {
    keySchema = new WindowKeySchema();
    bytesStore = new RocksDBSegmentedBytesStore("test", "metrics-scope", 0, SEGMENT_INTERVAL, keySchema);
    underlyingStore = new RocksDBWindowStore(bytesStore, false, WINDOW_SIZE);
    final TimeWindowedDeserializer<String> keyDeserializer = new TimeWindowedDeserializer<>(new StringDeserializer(), WINDOW_SIZE);
    keyDeserializer.setIsChangelogTopic(true);
    cacheListener = new CacheFlushListenerStub<>(keyDeserializer, new StringDeserializer());
    cachingStore = new CachingWindowStore(underlyingStore, WINDOW_SIZE, SEGMENT_INTERVAL);
    cachingStore.setFlushListener(cacheListener, false);
    cache = new ThreadCache(new LogContext("testCache "), MAX_CACHE_SIZE_BYTES, new MockStreamsMetrics(new Metrics()));
    context = new InternalMockProcessorContext<>(TestUtils.tempDirectory(), null, null, null, cache);
    context.setRecordContext(new ProcessorRecordContext(DEFAULT_TIMESTAMP, 0, 0, TOPIC, new RecordHeaders()));
    cachingStore.init((StateStoreContext) context, cachingStore);
}
Also used : StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) TimeWindowedDeserializer(org.apache.kafka.streams.kstream.TimeWindowedDeserializer) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Before(org.junit.Before)

Example 2 with TimeWindowedDeserializer

use of org.apache.kafka.streams.kstream.TimeWindowedDeserializer in project kafka by apache.

the class KStreamAggregationIntegrationTest method receiveMessages.

private <K, V> List<KeyValueTimestamp<K, V>> receiveMessages(final Deserializer<K> keyDeserializer, final Deserializer<V> valueDeserializer, final Class innerClass, final int numMessages) throws Exception {
    final String safeTestName = safeUniqueTestName(getClass(), testName);
    final Properties consumerProperties = new Properties();
    consumerProperties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
    consumerProperties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "group-" + safeTestName);
    consumerProperties.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    consumerProperties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializer.getClass().getName());
    consumerProperties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializer.getClass().getName());
    consumerProperties.put(StreamsConfig.WINDOW_SIZE_MS_CONFIG, 500L);
    if (keyDeserializer instanceof TimeWindowedDeserializer || keyDeserializer instanceof SessionWindowedDeserializer) {
        consumerProperties.setProperty(StreamsConfig.WINDOWED_INNER_CLASS_SERDE, Serdes.serdeFrom(innerClass).getClass().getName());
    }
    return IntegrationTestUtils.waitUntilMinKeyValueWithTimestampRecordsReceived(consumerProperties, outputTopic, numMessages, 60 * 1000);
}
Also used : Properties(java.util.Properties) TimeWindowedDeserializer(org.apache.kafka.streams.kstream.TimeWindowedDeserializer) SessionWindowedDeserializer(org.apache.kafka.streams.kstream.SessionWindowedDeserializer)

Example 3 with TimeWindowedDeserializer

use of org.apache.kafka.streams.kstream.TimeWindowedDeserializer in project kafka by apache.

the class KStreamAggregationIntegrationTest method receiveMessagesWithTimestamp.

private <K, V> List<KeyValueTimestamp<K, V>> receiveMessagesWithTimestamp(final Deserializer<K> keyDeserializer, final Deserializer<V> valueDeserializer, final Class innerClass, final int numMessages) throws Exception {
    final String safeTestName = safeUniqueTestName(getClass(), testName);
    final Properties consumerProperties = new Properties();
    consumerProperties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, CLUSTER.bootstrapServers());
    consumerProperties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "group-" + safeTestName);
    consumerProperties.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
    consumerProperties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializer.getClass().getName());
    consumerProperties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializer.getClass().getName());
    consumerProperties.put(StreamsConfig.WINDOW_SIZE_MS_CONFIG, 500L);
    if (keyDeserializer instanceof TimeWindowedDeserializer || keyDeserializer instanceof SessionWindowedDeserializer) {
        consumerProperties.setProperty(StreamsConfig.WINDOWED_INNER_CLASS_SERDE, Serdes.serdeFrom(innerClass).getClass().getName());
    }
    return IntegrationTestUtils.waitUntilMinKeyValueWithTimestampRecordsReceived(consumerProperties, outputTopic, numMessages, 60 * 1000);
}
Also used : Properties(java.util.Properties) TimeWindowedDeserializer(org.apache.kafka.streams.kstream.TimeWindowedDeserializer) SessionWindowedDeserializer(org.apache.kafka.streams.kstream.SessionWindowedDeserializer)

Aggregations

TimeWindowedDeserializer (org.apache.kafka.streams.kstream.TimeWindowedDeserializer)3 Properties (java.util.Properties)2 SessionWindowedDeserializer (org.apache.kafka.streams.kstream.SessionWindowedDeserializer)2 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 LogContext (org.apache.kafka.common.utils.LogContext)1 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)1 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)1 Before (org.junit.Before)1