Search in sources :

Example 66 with RecordHeaders

use of org.apache.kafka.common.header.internals.RecordHeaders 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 67 with RecordHeaders

use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.

the class ChangeLoggingSessionBytesStoreTest method shouldLogPutsWithPosition.

@Test
public void shouldLogPutsWithPosition() {
    EasyMock.expect(inner.getPosition()).andReturn(POSITION).anyTimes();
    inner.put(key1, value1);
    EasyMock.expectLastCall();
    init();
    final Bytes binaryKey = SessionKeySchema.toBinary(key1);
    EasyMock.reset(context);
    final RecordMetadata recordContext = new ProcessorRecordContext(0L, 1L, 0, "", new RecordHeaders());
    EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.of(recordContext));
    EasyMock.expect(context.timestamp()).andStubReturn(0L);
    context.logChange(store.name(), binaryKey, value1, 0L, POSITION);
    EasyMock.replay(context);
    store.put(key1, value1);
    EasyMock.verify(inner, context);
}
Also used : RecordMetadata(org.apache.kafka.streams.processor.api.RecordMetadata) Bytes(org.apache.kafka.common.utils.Bytes) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Test(org.junit.Test)

Example 68 with RecordHeaders

use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.

the class ChangeLoggingKeyValueBytesStoreTest method shouldLogPositionOnPut.

@Test
public void shouldLogPositionOnPut() {
    context.setRecordContext(new ProcessorRecordContext(-1, INPUT_OFFSET, INPUT_PARTITION, INPUT_TOPIC_NAME, new RecordHeaders()));
    context.setTime(1L);
    store.put(hi, there);
    assertThat(collector.collected().size(), equalTo(1));
    assertThat(collector.collected().get(0).headers(), is(notNullValue()));
    final Header versionHeader = collector.collected().get(0).headers().lastHeader(ChangelogRecordDeserializationHelper.CHANGELOG_VERSION_HEADER_KEY);
    assertThat(versionHeader, is(notNullValue()));
    assertThat(versionHeader.equals(ChangelogRecordDeserializationHelper.CHANGELOG_VERSION_HEADER_RECORD_CONSISTENCY), is(true));
    final Header vectorHeader = collector.collected().get(0).headers().lastHeader(ChangelogRecordDeserializationHelper.CHANGELOG_POSITION_HEADER_KEY);
    assertThat(vectorHeader, is(notNullValue()));
    final Position position = PositionSerde.deserialize(ByteBuffer.wrap(vectorHeader.value()));
    assertThat(position.getPartitionPositions(INPUT_TOPIC_NAME), is(notNullValue()));
    assertThat(position.getPartitionPositions(INPUT_TOPIC_NAME), hasEntry(0, 100L));
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Header(org.apache.kafka.common.header.Header) Position(org.apache.kafka.streams.query.Position) Test(org.junit.Test)

Example 69 with RecordHeaders

use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.

the class ChangeLoggingWindowBytesStoreTest method shouldLogPutsWithPosition.

@Test
public void shouldLogPutsWithPosition() {
    EasyMock.expect(inner.getPosition()).andReturn(POSITION).anyTimes();
    inner.put(bytesKey, value, 0);
    EasyMock.expectLastCall();
    init();
    final Bytes key = WindowKeySchema.toStoreKeyBinary(bytesKey, 0, 0);
    EasyMock.reset(context);
    final RecordMetadata recordContext = new ProcessorRecordContext(0L, 1L, 0, "", new RecordHeaders());
    EasyMock.expect(context.recordMetadata()).andStubReturn(Optional.of(recordContext));
    EasyMock.expect(context.timestamp()).andStubReturn(0L);
    final Position position = Position.fromMap(mkMap(mkEntry("", mkMap(mkEntry(0, 1L)))));
    context.logChange(store.name(), key, value, 0L, position);
    EasyMock.replay(context);
    store.put(bytesKey, value, context.timestamp());
    EasyMock.verify(inner, context);
}
Also used : RecordMetadata(org.apache.kafka.streams.processor.api.RecordMetadata) Bytes(org.apache.kafka.common.utils.Bytes) 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 70 with RecordHeaders

use of org.apache.kafka.common.header.internals.RecordHeaders in project kafka by apache.

the class InMemoryWindowStoreTest method shouldMatchPositionAfterPut.

@Test
public void shouldMatchPositionAfterPut() {
    final MeteredWindowStore<Integer, String> meteredSessionStore = (MeteredWindowStore<Integer, String>) windowStore;
    final ChangeLoggingWindowBytesStore changeLoggingSessionBytesStore = (ChangeLoggingWindowBytesStore) meteredSessionStore.wrapped();
    final InMemoryWindowStore inMemoryWindowStore = (InMemoryWindowStore) changeLoggingSessionBytesStore.wrapped();
    context.setRecordContext(new ProcessorRecordContext(0, 1, 0, "", new RecordHeaders()));
    windowStore.put(0, "0", SEGMENT_INTERVAL);
    context.setRecordContext(new ProcessorRecordContext(0, 2, 0, "", new RecordHeaders()));
    windowStore.put(1, "1", SEGMENT_INTERVAL);
    context.setRecordContext(new ProcessorRecordContext(0, 3, 0, "", new RecordHeaders()));
    windowStore.put(2, "2", SEGMENT_INTERVAL);
    context.setRecordContext(new ProcessorRecordContext(0, 4, 0, "", new RecordHeaders()));
    windowStore.put(3, "3", SEGMENT_INTERVAL);
    final Position expected = Position.fromMap(mkMap(mkEntry("", mkMap(mkEntry(0, 4L)))));
    final Position actual = inMemoryWindowStore.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)

Aggregations

RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)149 Test (org.junit.Test)107 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)49 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)41 Headers (org.apache.kafka.common.header.Headers)33 RecordHeader (org.apache.kafka.common.header.internals.RecordHeader)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)24 TopicPartition (org.apache.kafka.common.TopicPartition)22 Position (org.apache.kafka.streams.query.Position)17 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ByteBuffer (java.nio.ByteBuffer)11 Struct (org.apache.kafka.connect.data.Struct)11 Test (org.junit.jupiter.api.Test)11 Header (org.apache.kafka.common.header.Header)10 LinkedHashMap (java.util.LinkedHashMap)9 Bytes (org.apache.kafka.common.utils.Bytes)9 StreamsException (org.apache.kafka.streams.errors.StreamsException)9 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)8 Metrics (org.apache.kafka.common.metrics.Metrics)8