use of org.apache.kafka.common.serialization.StringDeserializer in project kafka by apache.
the class TimeWindowedCogroupedKStreamImplTest method timeWindowMixAggregatorsTest.
@Test
public void timeWindowMixAggregatorsTest() {
final KTable<Windowed<String>, String> customers = windowedCogroupedStream.aggregate(MockInitializer.STRING_INIT, Materialized.with(Serdes.String(), Serdes.String()));
customers.toStream().to(OUTPUT);
try (final TopologyTestDriver driver = new TopologyTestDriver(builder.build(), props)) {
final TestInputTopic<String, String> testInputTopic = driver.createInputTopic(TOPIC, new StringSerializer(), new StringSerializer());
final TestInputTopic<String, String> testInputTopic2 = driver.createInputTopic(TOPIC2, new StringSerializer(), new StringSerializer());
final TestOutputTopic<Windowed<String>, String> testOutputTopic = driver.createOutputTopic(OUTPUT, new TimeWindowedDeserializer<>(new StringDeserializer(), WINDOW_SIZE), new StringDeserializer());
testInputTopic.pipeInput("k1", "A", 0);
testInputTopic.pipeInput("k2", "A", 0);
testInputTopic.pipeInput("k2", "A", 1);
testInputTopic.pipeInput("k1", "A", 2);
testInputTopic2.pipeInput("k1", "B", 3);
testInputTopic2.pipeInput("k2", "B", 3);
testInputTopic2.pipeInput("k2", "B", 4);
testInputTopic2.pipeInput("k1", "B", 4);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", "0+A", 0);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", "0+A", 0);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", "0+A+A", 1);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", "0+A+A", 2);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", "0+A+A-B", 3);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", "0+A+A-B", 3);
assertOutputKeyValueTimestamp(testOutputTopic, "k2", "0+A+A-B-B", 4);
assertOutputKeyValueTimestamp(testOutputTopic, "k1", "0+A+A-B-B", 4);
}
}
use of org.apache.kafka.common.serialization.StringDeserializer in project kafka by apache.
the class CachingPersistentSessionStoreTest method shouldForwardChangedValuesDuringFlush.
@Test
public void shouldForwardChangedValuesDuringFlush() {
final Windowed<Bytes> a = new Windowed<>(keyA, new SessionWindow(2, 4));
final Windowed<Bytes> b = new Windowed<>(keyA, new SessionWindow(1, 2));
final Windowed<String> aDeserialized = new Windowed<>("a", new SessionWindow(2, 4));
final Windowed<String> bDeserialized = new Windowed<>("a", new SessionWindow(1, 2));
final CacheFlushListenerStub<Windowed<String>, String> flushListener = new CacheFlushListenerStub<>(new SessionWindowedDeserializer<>(new StringDeserializer()), new StringDeserializer());
cachingStore.setFlushListener(flushListener, true);
cachingStore.put(b, "1".getBytes());
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(bDeserialized, new Change<>("1", null), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.put(a, "1".getBytes());
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(aDeserialized, new Change<>("1", null), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.put(a, "2".getBytes());
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(aDeserialized, new Change<>("2", "1"), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.remove(a);
cachingStore.flush();
assertEquals(Collections.singletonList(new KeyValueTimestamp<>(aDeserialized, new Change<>(null, "2"), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.put(a, "1".getBytes());
cachingStore.put(a, "2".getBytes());
cachingStore.remove(a);
cachingStore.flush();
assertEquals(Collections.emptyList(), flushListener.forwarded);
flushListener.forwarded.clear();
}
use of org.apache.kafka.common.serialization.StringDeserializer in project kafka by apache.
the class CachingPersistentSessionStoreTest method shouldNotForwardChangedValuesDuringFlushWhenSendOldValuesDisabled.
@Test
public void shouldNotForwardChangedValuesDuringFlushWhenSendOldValuesDisabled() {
final Windowed<Bytes> a = new Windowed<>(keyA, new SessionWindow(0, 0));
final Windowed<String> aDeserialized = new Windowed<>("a", new SessionWindow(0, 0));
final CacheFlushListenerStub<Windowed<String>, String> flushListener = new CacheFlushListenerStub<>(new SessionWindowedDeserializer<>(new StringDeserializer()), new StringDeserializer());
cachingStore.setFlushListener(flushListener, false);
cachingStore.put(a, "1".getBytes());
cachingStore.flush();
cachingStore.put(a, "2".getBytes());
cachingStore.flush();
cachingStore.remove(a);
cachingStore.flush();
assertEquals(asList(new KeyValueTimestamp<>(aDeserialized, new Change<>("1", null), DEFAULT_TIMESTAMP), new KeyValueTimestamp<>(aDeserialized, new Change<>("2", null), DEFAULT_TIMESTAMP), new KeyValueTimestamp<>(aDeserialized, new Change<>(null, null), DEFAULT_TIMESTAMP)), flushListener.forwarded);
flushListener.forwarded.clear();
cachingStore.put(a, "1".getBytes());
cachingStore.put(a, "2".getBytes());
cachingStore.remove(a);
cachingStore.flush();
assertEquals(Collections.emptyList(), flushListener.forwarded);
flushListener.forwarded.clear();
}
use of org.apache.kafka.common.serialization.StringDeserializer 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);
}
use of org.apache.kafka.common.serialization.StringDeserializer in project kafka by apache.
the class TopologyTestDriverTest method shouldThrowNoSuchElementExceptionForUnusedOutputTopicWithDynamicRouting.
@Test
public void shouldThrowNoSuchElementExceptionForUnusedOutputTopicWithDynamicRouting() {
testDriver = new TopologyTestDriver(setupSourceSinkTopology(), config);
final TestOutputTopic<String, String> outputTopic = new TestOutputTopic<>(testDriver, "unused-topic", new StringDeserializer(), new StringDeserializer());
assertTrue(outputTopic.isEmpty());
assertThrows(NoSuchElementException.class, outputTopic::readRecord);
}
Aggregations