use of org.apache.kafka.streams.query.Position in project kafka by apache.
the class AbstractRocksDBSegmentedBytesStoreTest method getChangelogRecordsWithTombstones.
private List<ConsumerRecord<byte[], byte[]>> getChangelogRecordsWithTombstones() {
final List<ConsumerRecord<byte[], byte[]>> records = new ArrayList<>();
final Headers headers = new RecordHeaders();
Position position = Position.emptyPosition();
position = position.withComponent("A", 0, 1);
headers.add(ChangelogRecordDeserializationHelper.CHANGELOG_VERSION_HEADER_RECORD_CONSISTENCY);
headers.add(new RecordHeader(ChangelogRecordDeserializationHelper.CHANGELOG_POSITION_HEADER_KEY, PositionSerde.serialize(position).array()));
records.add(new ConsumerRecord<>("", 0, 0L, RecordBatch.NO_TIMESTAMP, TimestampType.NO_TIMESTAMP_TYPE, -1, -1, serializeKey(new Windowed<>("a", windows[0])).get(), serializeValue(50L), headers, Optional.empty()));
position = position.withComponent("A", 0, 2);
headers.add(ChangelogRecordDeserializationHelper.CHANGELOG_VERSION_HEADER_RECORD_CONSISTENCY);
headers.add(new RecordHeader(ChangelogRecordDeserializationHelper.CHANGELOG_POSITION_HEADER_KEY, PositionSerde.serialize(position).array()));
records.add(new ConsumerRecord<>("", 0, 0L, RecordBatch.NO_TIMESTAMP, TimestampType.NO_TIMESTAMP_TYPE, -1, -1, serializeKey(new Windowed<>("a", windows[2])).get(), null, headers, Optional.empty()));
return records;
}
use of org.apache.kafka.streams.query.Position in project kafka by apache.
the class AbstractRocksDBSegmentedBytesStoreTest method shouldMatchPositionAfterPut.
@Test
public void shouldMatchPositionAfterPut() {
bytesStore.init((StateStoreContext) context, bytesStore);
final String keyA = "a";
final String keyB = "b";
final String keyC = "c";
context.setRecordContext(new ProcessorRecordContext(0, 1, 0, "", new RecordHeaders()));
bytesStore.put(serializeKey(new Windowed<>(keyA, windows[0])), serializeValue(10));
context.setRecordContext(new ProcessorRecordContext(0, 2, 0, "", new RecordHeaders()));
bytesStore.put(serializeKey(new Windowed<>(keyA, windows[1])), serializeValue(50));
context.setRecordContext(new ProcessorRecordContext(0, 3, 0, "", new RecordHeaders()));
bytesStore.put(serializeKey(new Windowed<>(keyB, windows[2])), serializeValue(100));
context.setRecordContext(new ProcessorRecordContext(0, 4, 0, "", new RecordHeaders()));
bytesStore.put(serializeKey(new Windowed<>(keyC, windows[3])), serializeValue(200));
final Position expected = Position.fromMap(mkMap(mkEntry("", mkMap(mkEntry(0, 4L)))));
final Position actual = bytesStore.getPosition();
assertEquals(expected, actual);
}
use of org.apache.kafka.streams.query.Position in project kafka by apache.
the class InMemoryKeyValueStoreTest method shouldMatchPositionAfterPut.
@Test
public void shouldMatchPositionAfterPut() {
inMemoryKeyValueStore.init((StateStoreContext) context, inMemoryKeyValueStore);
context.setRecordContext(new ProcessorRecordContext(0, 1, 0, "", new RecordHeaders()));
inMemoryKeyValueStore.put(bytesKey("key1"), bytesValue("value1"));
context.setRecordContext(new ProcessorRecordContext(0, 2, 0, "", new RecordHeaders()));
inMemoryKeyValueStore.put(bytesKey("key2"), bytesValue("value2"));
context.setRecordContext(new ProcessorRecordContext(0, 3, 0, "", new RecordHeaders()));
inMemoryKeyValueStore.put(bytesKey("key3"), bytesValue("value3"));
final Position expected = Position.fromMap(mkMap(mkEntry("", mkMap(mkEntry(0, 3L)))));
final Position actual = inMemoryKeyValueStore.getPosition();
assertEquals(expected, actual);
}
use of org.apache.kafka.streams.query.Position in project kafka by apache.
the class InMemorySessionStoreTest method shouldMatchPositionAfterPut.
@Test
public void shouldMatchPositionAfterPut() {
final MeteredSessionStore<String, Long> meteredSessionStore = (MeteredSessionStore<String, Long>) sessionStore;
final ChangeLoggingSessionBytesStore changeLoggingSessionBytesStore = (ChangeLoggingSessionBytesStore) meteredSessionStore.wrapped();
final InMemorySessionStore inMemorySessionStore = (InMemorySessionStore) changeLoggingSessionBytesStore.wrapped();
context.setRecordContext(new ProcessorRecordContext(0, 1, 0, "", new RecordHeaders()));
sessionStore.put(new Windowed<String>("a", new SessionWindow(0, 0)), 1L);
context.setRecordContext(new ProcessorRecordContext(0, 2, 0, "", new RecordHeaders()));
sessionStore.put(new Windowed<String>("aa", new SessionWindow(0, 10)), 2L);
context.setRecordContext(new ProcessorRecordContext(0, 3, 0, "", new RecordHeaders()));
sessionStore.put(new Windowed<String>("a", new SessionWindow(10, 20)), 3L);
final Position expected = Position.fromMap(mkMap(mkEntry("", mkMap(mkEntry(0, 3L)))));
final Position actual = inMemorySessionStore.getPosition();
assertThat(expected, is(actual));
}
use of org.apache.kafka.streams.query.Position in project kafka by apache.
the class RocksDBSessionStoreTest method shouldMatchPositionAfterPut.
@Test
public void shouldMatchPositionAfterPut() {
final MeteredSessionStore<String, Long> meteredSessionStore = (MeteredSessionStore<String, Long>) sessionStore;
final ChangeLoggingSessionBytesStore changeLoggingSessionBytesStore = (ChangeLoggingSessionBytesStore) meteredSessionStore.wrapped();
final RocksDBSessionStore rocksDBSessionStore = (RocksDBSessionStore) changeLoggingSessionBytesStore.wrapped();
context.setRecordContext(new ProcessorRecordContext(0, 1, 0, "", new RecordHeaders()));
sessionStore.put(new Windowed<String>("a", new SessionWindow(0, 0)), 1L);
context.setRecordContext(new ProcessorRecordContext(0, 2, 0, "", new RecordHeaders()));
sessionStore.put(new Windowed<String>("aa", new SessionWindow(0, SEGMENT_INTERVAL)), 2L);
context.setRecordContext(new ProcessorRecordContext(0, 3, 0, "", new RecordHeaders()));
sessionStore.put(new Windowed<String>("a", new SessionWindow(10, SEGMENT_INTERVAL)), 3L);
final Position expected = Position.fromMap(mkMap(mkEntry("", mkMap(mkEntry(0, 3L)))));
final Position actual = rocksDBSessionStore.getPosition();
assertEquals(expected, actual);
}
Aggregations