Search in sources :

Example 6 with MockProcessorContext

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

the class CachingKeyValueStoreTest method setUp.

@Before
public void setUp() throws Exception {
    final String storeName = "store";
    underlyingStore = new InMemoryKeyValueStore<>(storeName, Serdes.Bytes(), Serdes.ByteArray());
    cacheFlushListener = new CacheFlushListenerStub<>();
    store = new CachingKeyValueStore<>(underlyingStore, Serdes.String(), Serdes.String());
    store.setFlushListener(cacheFlushListener);
    cache = new ThreadCache("testCache", maxCacheSizeBytes, new MockStreamsMetrics(new Metrics()));
    final MockProcessorContext context = new MockProcessorContext(null, null, null, (RecordCollector) null, cache);
    topic = "topic";
    context.setRecordContext(new ProcessorRecordContext(10, 0, 0, topic));
    store.init(context, null);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Before(org.junit.Before)

Example 7 with MockProcessorContext

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

the class ProcessorStateManagerTest method testFlushAndClose.

@Test
public void testFlushAndClose() throws IOException {
    checkpoint.write(Collections.<TopicPartition, Long>emptyMap());
    // set up ack'ed offsets
    final HashMap<TopicPartition, Long> ackedOffsets = new HashMap<>();
    ackedOffsets.put(new TopicPartition(persistentStoreTopicName, 1), 123L);
    ackedOffsets.put(new TopicPartition(nonPersistentStoreTopicName, 1), 456L);
    ackedOffsets.put(new TopicPartition(ProcessorStateManager.storeChangelogTopic(applicationId, "otherTopic"), 1), 789L);
    ProcessorStateManager stateMgr = new ProcessorStateManager(taskId, noPartitions, false, stateDirectory, new HashMap<String, String>() {

        {
            put(persistentStoreName, persistentStoreTopicName);
            put(nonPersistentStoreName, nonPersistentStoreTopicName);
        }
    }, changelogReader);
    try {
        // make sure the checkpoint file isn't deleted
        assertTrue(checkpointFile.exists());
        stateMgr.register(persistentStore, true, persistentStore.stateRestoreCallback);
        stateMgr.register(nonPersistentStore, true, nonPersistentStore.stateRestoreCallback);
    } finally {
        // close the state manager with the ack'ed offsets
        stateMgr.flush(new MockProcessorContext(StateSerdes.withBuiltinTypes("foo", String.class, String.class), new NoOpRecordCollector()));
        stateMgr.close(ackedOffsets);
    }
    // make sure all stores are closed, and the checkpoint file is written.
    assertTrue(persistentStore.flushed);
    assertTrue(persistentStore.closed);
    assertTrue(nonPersistentStore.flushed);
    assertTrue(nonPersistentStore.closed);
    assertTrue(checkpointFile.exists());
    // the checkpoint file should contain an offset from the persistent store only.
    final Map<TopicPartition, Long> checkpointedOffsets = checkpoint.read();
    assertEquals(1, checkpointedOffsets.size());
    assertEquals(new Long(124), checkpointedOffsets.get(new TopicPartition(persistentStoreTopicName, 1)));
}
Also used : HashMap(java.util.HashMap) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) TopicPartition(org.apache.kafka.common.TopicPartition) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Test(org.junit.Test)

Example 8 with MockProcessorContext

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

the class ChangeLoggingKeyValueBytesStoreTest method before.

@Before
public void before() {
    final NoOpRecordCollector collector = new NoOpRecordCollector() {

        @Override
        public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
            sent.put(key, value);
        }
    };
    final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), collector, new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
    context.setTime(0);
    store.init(context, store);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Serializer(org.apache.kafka.common.serialization.Serializer) Before(org.junit.Before)

Example 9 with MockProcessorContext

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

the class ChangeLoggingKeyValueStoreTest method before.

@Before
public void before() {
    final NoOpRecordCollector collector = new NoOpRecordCollector() {

        @Override
        public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
            sent.put(key, value);
        }
    };
    final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), collector, new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
    context.setTime(0);
    store.init(context, store);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Serializer(org.apache.kafka.common.serialization.Serializer) Before(org.junit.Before)

Example 10 with MockProcessorContext

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

the class RocksDBWindowStoreSupplierTest method shouldNotBeLoggingEnabledStoreWhenLogginNotEnabled.

@Test
public void shouldNotBeLoggingEnabledStoreWhenLogginNotEnabled() throws Exception {
    store = createStore(false, false);
    final List<ProducerRecord> logged = new ArrayList<>();
    final NoOpRecordCollector collector = new NoOpRecordCollector() {

        @Override
        public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
            logged.add(new ProducerRecord<K, V>(topic, partition, timestamp, key, value));
        }
    };
    final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.String(), collector, cache);
    context.setTime(1);
    store.init(context, store);
    store.put("a", "b");
    assertTrue(logged.isEmpty());
}
Also used : NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) ArrayList(java.util.ArrayList) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Aggregations

MockProcessorContext (org.apache.kafka.test.MockProcessorContext)29 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)17 Test (org.junit.Test)15 Metrics (org.apache.kafka.common.metrics.Metrics)13 Serializer (org.apache.kafka.common.serialization.Serializer)13 Before (org.junit.Before)13 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)11 ArrayList (java.util.ArrayList)6 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)6 StateSerdes (org.apache.kafka.streams.state.StateSerdes)5 MockProducer (org.apache.kafka.clients.producer.MockProducer)4 StreamsException (org.apache.kafka.streams.errors.StreamsException)4 Bytes (org.apache.kafka.common.utils.Bytes)3 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 SessionWindow (org.apache.kafka.streams.kstream.internals.SessionWindow)2 File (java.io.File)1 HashMap (java.util.HashMap)1 MetricName (org.apache.kafka.common.MetricName)1 TopicPartition (org.apache.kafka.common.TopicPartition)1