Search in sources :

Example 61 with RecordHeaders

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

the class BufferValueTest method shouldAccountForDeduplicationInSizeEstimate.

@Test
public void shouldAccountForDeduplicationInSizeEstimate() {
    final ProcessorRecordContext context = new ProcessorRecordContext(0L, 0L, 0, "topic", new RecordHeaders());
    assertEquals(25L, new BufferValue(null, null, null, context).residentMemorySizeEstimate());
    assertEquals(26L, new BufferValue(new byte[] { (byte) 0 }, null, null, context).residentMemorySizeEstimate());
    assertEquals(26L, new BufferValue(null, new byte[] { (byte) 0 }, null, context).residentMemorySizeEstimate());
    assertEquals(26L, new BufferValue(new byte[] { (byte) 0 }, new byte[] { (byte) 0 }, null, context).residentMemorySizeEstimate());
    assertEquals(27L, new BufferValue(new byte[] { (byte) 0 }, new byte[] { (byte) 1 }, null, context).residentMemorySizeEstimate());
    // new value should get counted, but doesn't get deduplicated
    assertEquals(28L, new BufferValue(new byte[] { (byte) 0 }, new byte[] { (byte) 1 }, new byte[] { (byte) 0 }, context).residentMemorySizeEstimate());
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) Test(org.junit.Test)

Example 62 with RecordHeaders

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

the class CachingPersistentSessionStoreTest method setUpCloseTests.

private void setUpCloseTests() {
    underlyingStore.close();
    underlyingStore = EasyMock.createNiceMock(SessionStore.class);
    EasyMock.expect(underlyingStore.name()).andStubReturn("store-name");
    EasyMock.expect(underlyingStore.isOpen()).andStubReturn(true);
    EasyMock.replay(underlyingStore);
    cachingStore = new CachingSessionStore(underlyingStore, SEGMENT_INTERVAL);
    cache = EasyMock.niceMock(ThreadCache.class);
    final InternalMockProcessorContext context = new InternalMockProcessorContext<>(TestUtils.tempDirectory(), null, null, null, cache);
    context.setRecordContext(new ProcessorRecordContext(10, 0, 0, TOPIC, new RecordHeaders()));
    cachingStore.init((StateStoreContext) context, cachingStore);
}
Also used : SessionStore(org.apache.kafka.streams.state.SessionStore) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext)

Example 63 with RecordHeaders

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

the class CachingInMemorySessionStoreTest method setUpCloseTests.

private void setUpCloseTests() {
    underlyingStore = EasyMock.createNiceMock(SessionStore.class);
    EasyMock.expect(underlyingStore.name()).andStubReturn("store-name");
    EasyMock.expect(underlyingStore.isOpen()).andStubReturn(true);
    EasyMock.replay(underlyingStore);
    cachingStore = new CachingSessionStore(underlyingStore, SEGMENT_INTERVAL);
    cache = EasyMock.niceMock(ThreadCache.class);
    final InternalMockProcessorContext context = new InternalMockProcessorContext<>(TestUtils.tempDirectory(), null, null, null, cache);
    context.setRecordContext(new ProcessorRecordContext(10, 0, 0, TOPIC, new RecordHeaders()));
    cachingStore.init((StateStoreContext) context, cachingStore);
}
Also used : SessionStore(org.apache.kafka.streams.state.SessionStore) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext)

Example 64 with RecordHeaders

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

the class CachingInMemorySessionStoreTest method before.

@Before
public void before() {
    underlyingStore = new InMemorySessionStore("store-name", Long.MAX_VALUE, "metric-scope");
    cachingStore = new CachingSessionStore(underlyingStore, SEGMENT_INTERVAL);
    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 : 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) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Before(org.junit.Before)

Example 65 with RecordHeaders

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

the class CachingPersistentWindowStoreTest method setUpCloseTests.

private void setUpCloseTests() {
    underlyingStore = EasyMock.createNiceMock(WindowStore.class);
    EasyMock.expect(underlyingStore.name()).andStubReturn("store-name");
    EasyMock.expect(underlyingStore.isOpen()).andStubReturn(true);
    EasyMock.replay(underlyingStore);
    cachingStore = new CachingWindowStore(underlyingStore, WINDOW_SIZE, SEGMENT_INTERVAL);
    cache = EasyMock.createNiceMock(ThreadCache.class);
    context = new InternalMockProcessorContext<>(TestUtils.tempDirectory(), null, null, null, cache);
    context.setRecordContext(new ProcessorRecordContext(10, 0, 0, TOPIC, new RecordHeaders()));
    cachingStore.init((StateStoreContext) context, cachingStore);
}
Also used : WindowStore(org.apache.kafka.streams.state.WindowStore) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext)

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