Search in sources :

Example 21 with Position

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;
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) Position(org.apache.kafka.streams.query.Position) Headers(org.apache.kafka.common.header.Headers) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ArrayList(java.util.ArrayList) RecordHeader(org.apache.kafka.common.header.internals.RecordHeader) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord)

Example 22 with Position

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);
}
Also used : Windowed(org.apache.kafka.streams.kstream.Windowed) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Position(org.apache.kafka.streams.query.Position) Test(org.junit.Test)

Example 23 with Position

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);
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Position(org.apache.kafka.streams.query.Position) Test(org.junit.Test)

Example 24 with Position

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));
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Position(org.apache.kafka.streams.query.Position) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Example 25 with Position

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);
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Position(org.apache.kafka.streams.query.Position) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Test(org.junit.Test)

Aggregations

Position (org.apache.kafka.streams.query.Position)33 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)17 Test (org.junit.Test)17 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)11 Windowed (org.apache.kafka.streams.kstream.Windowed)9 Objects (java.util.Objects)7 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)7 Bytes (org.apache.kafka.common.utils.Bytes)7 QueryResult (org.apache.kafka.streams.query.QueryResult)7 KeyValueIterator (org.apache.kafka.streams.state.KeyValueIterator)7 Headers (org.apache.kafka.common.header.Headers)6 PositionBound (org.apache.kafka.streams.query.PositionBound)6 RecordHeader (org.apache.kafka.common.header.internals.RecordHeader)5 KeyValue (org.apache.kafka.streams.KeyValue)5 ValueAndTimestamp (org.apache.kafka.streams.state.ValueAndTimestamp)5 ImmutableList (com.google.common.collect.ImmutableList)4 Streams (com.google.common.collect.Streams)4 GenericKey (io.confluent.ksql.GenericKey)4 GenericRow (io.confluent.ksql.GenericRow)4 MaterializationException (io.confluent.ksql.execution.streams.materialization.MaterializationException)4