Search in sources :

Example 31 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project kafka by apache.

the class RecordQueueTest method shouldDropOnNegativeTimestamp.

@Test
public void shouldDropOnNegativeTimestamp() {
    final List<ConsumerRecord<byte[], byte[]>> records = Collections.singletonList(new ConsumerRecord<>("topic", 1, 1, -1L, TimestampType.CREATE_TIME, 0, 0, recordKey, recordValue, new RecordHeaders(), Optional.empty()));
    final RecordQueue queue = new RecordQueue(new TopicPartition("topic", 1), mockSourceNodeWithMetrics, new LogAndSkipOnInvalidTimestamp(), new LogAndContinueExceptionHandler(), new InternalMockProcessorContext(), new LogContext());
    queue.addRawRecords(records);
    assertEquals(0, queue.size());
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) TopicPartition(org.apache.kafka.common.TopicPartition) LogAndSkipOnInvalidTimestamp(org.apache.kafka.streams.processor.LogAndSkipOnInvalidTimestamp) LogContext(org.apache.kafka.common.utils.LogContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) LogAndContinueExceptionHandler(org.apache.kafka.streams.errors.LogAndContinueExceptionHandler) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 32 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project kafka by apache.

the class GlobalStateManagerImplTest method before.

@Before
public void before() {
    final Map<String, String> storeToTopic = new HashMap<>();
    storeToTopic.put(storeName1, t1.topic());
    storeToTopic.put(storeName2, t2.topic());
    storeToTopic.put(storeName3, t3.topic());
    storeToTopic.put(storeName4, t4.topic());
    store1 = new NoOpReadOnlyStore<>(storeName1, true);
    store2 = new ConverterStore<>(storeName2, true);
    store3 = new NoOpReadOnlyStore<>(storeName3);
    store4 = new NoOpReadOnlyStore<>(storeName4);
    topology = withGlobalStores(asList(store1, store2, store3, store4), storeToTopic);
    streamsConfig = new StreamsConfig(new Properties() {

        {
            put(StreamsConfig.APPLICATION_ID_CONFIG, "appId");
            put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234");
            put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath());
        }
    });
    stateDirectory = new StateDirectory(streamsConfig, time, true, false);
    consumer = new MockConsumer<>(OffsetResetStrategy.NONE);
    stateManager = new GlobalStateManagerImpl(new LogContext("test"), time, topology, consumer, stateDirectory, stateRestoreListener, streamsConfig);
    processorContext = new InternalMockProcessorContext(stateDirectory.globalStateDir(), streamsConfig);
    stateManager.setGlobalProcessorContext(processorContext);
    checkpointFile = new File(stateManager.baseDir(), StateManagerUtil.CHECKPOINT_FILE_NAME);
}
Also used : HashMap(java.util.HashMap) LogContext(org.apache.kafka.common.utils.LogContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Properties(java.util.Properties) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) File(java.io.File) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Before(org.junit.Before)

Example 33 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project kafka by apache.

the class CachingPersistentSessionStoreTest method before.

@Before
public void before() {
    final RocksDBSegmentedBytesStore segmented = new RocksDBSegmentedBytesStore("store-name", "metric-scope", Long.MAX_VALUE, SEGMENT_INTERVAL, new SessionKeySchema());
    underlyingStore = new RocksDBSessionStore(segmented);
    cachingStore = new CachingSessionStore(underlyingStore, SEGMENT_INTERVAL);
    cache = new ThreadCache(new LogContext("testCache "), MAX_CACHE_SIZE_BYTES, new MockStreamsMetrics(new Metrics()));
    final InternalMockProcessorContext 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) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 34 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project kafka by apache.

the class AbstractRocksDBSegmentedBytesStoreTest method shouldLogAndMeasureExpiredRecords.

@Test
public void shouldLogAndMeasureExpiredRecords() {
    final Properties streamsConfig = StreamsTestUtils.getStreamsConfig();
    final AbstractRocksDBSegmentedBytesStore<S> bytesStore = getBytesStore();
    final InternalMockProcessorContext context = new InternalMockProcessorContext(TestUtils.tempDirectory(), new StreamsConfig(streamsConfig));
    final Time time = new SystemTime();
    context.setSystemTimeMs(time.milliseconds());
    bytesStore.init((StateStoreContext) context, bytesStore);
    try (final LogCaptureAppender appender = LogCaptureAppender.createAndRegister()) {
        // write a record to advance stream time, with a high enough timestamp
        // that the subsequent record in windows[0] will already be expired.
        bytesStore.put(serializeKey(new Windowed<>("dummy", nextSegmentWindow)), serializeValue(0));
        final Bytes key = serializeKey(new Windowed<>("a", windows[0]));
        final byte[] value = serializeValue(5);
        bytesStore.put(key, value);
        final List<String> messages = appender.getMessages();
        assertThat(messages, hasItem("Skipping record for expired segment."));
    }
    final Map<MetricName, ? extends Metric> metrics = context.metrics().metrics();
    final String threadId = Thread.currentThread().getName();
    final Metric dropTotal;
    final Metric dropRate;
    dropTotal = metrics.get(new MetricName("dropped-records-total", "stream-task-metrics", "", mkMap(mkEntry("thread-id", threadId), mkEntry("task-id", "0_0"))));
    dropRate = metrics.get(new MetricName("dropped-records-rate", "stream-task-metrics", "", mkMap(mkEntry("thread-id", threadId), mkEntry("task-id", "0_0"))));
    assertEquals(1.0, dropTotal.metricValue());
    assertNotEquals(0.0, dropRate.metricValue());
    bytesStore.close();
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) Time(org.apache.kafka.common.utils.Time) SystemTime(org.apache.kafka.common.utils.SystemTime) Properties(java.util.Properties) Windowed(org.apache.kafka.streams.kstream.Windowed) Bytes(org.apache.kafka.common.utils.Bytes) MetricName(org.apache.kafka.common.MetricName) LogCaptureAppender(org.apache.kafka.streams.processor.internals.testutil.LogCaptureAppender) Metric(org.apache.kafka.common.Metric) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsConfig(org.apache.kafka.streams.StreamsConfig) SystemTime(org.apache.kafka.common.utils.SystemTime) Test(org.junit.Test)

Example 35 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project kafka by apache.

the class ChangeLoggingKeyValueBytesStoreTest method shouldDelegateInit.

@Test
public void shouldDelegateInit() {
    final InternalMockProcessorContext context = mockContext();
    final KeyValueStore<Bytes, byte[]> innerMock = EasyMock.mock(InMemoryKeyValueStore.class);
    final StateStore outer = new ChangeLoggingKeyValueBytesStore(innerMock);
    innerMock.init((StateStoreContext) context, outer);
    EasyMock.expectLastCall();
    EasyMock.replay(innerMock);
    outer.init((StateStoreContext) context, outer);
    EasyMock.verify(innerMock);
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) StateStore(org.apache.kafka.streams.processor.StateStore) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Test(org.junit.Test)

Aggregations

InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)44 Test (org.junit.Test)23 LogContext (org.apache.kafka.common.utils.LogContext)20 Metrics (org.apache.kafka.common.metrics.Metrics)19 Before (org.junit.Before)17 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)14 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)14 StreamsConfig (org.apache.kafka.streams.StreamsConfig)10 Properties (java.util.Properties)8 Bytes (org.apache.kafka.common.utils.Bytes)8 StateStore (org.apache.kafka.streams.processor.StateStore)7 File (java.io.File)6 MockTime (org.apache.kafka.common.utils.MockTime)6 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)6 ArrayList (java.util.ArrayList)5 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)5 Serializer (org.apache.kafka.common.serialization.Serializer)5 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)4 MetricName (org.apache.kafka.common.MetricName)4 HashMap (java.util.HashMap)3