Search in sources :

Example 16 with MockProcessorContext

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

the class RocksDBSessionStoreSupplierTest method shouldCreateLoggingEnabledStoreWhenStoreLogged.

@Test
public void shouldCreateLoggingEnabledStoreWhenStoreLogged() throws Exception {
    store = createStore(true, 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(new Windowed<>("a", new SessionWindow(0, 10)), "b");
    assertFalse(logged.isEmpty());
}
Also used : NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) ArrayList(java.util.ArrayList) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Example 17 with MockProcessorContext

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

the class RocksDBSessionStoreSupplierTest method shouldNotBeLoggingEnabledStoreWhenLoggingNotEnabled.

@Test
public void shouldNotBeLoggingEnabledStoreWhenLoggingNotEnabled() 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(new Windowed<>("a", new SessionWindow(0, 10)), "b");
    assertTrue(logged.isEmpty());
}
Also used : NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) ArrayList(java.util.ArrayList) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) SessionWindow(org.apache.kafka.streams.kstream.internals.SessionWindow) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Example 18 with MockProcessorContext

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

the class KStreamSessionWindowAggregateProcessorTest method initializeStore.

@SuppressWarnings("unchecked")
@Before
public void initializeStore() {
    final File stateDir = TestUtils.tempDirectory();
    context = new MockProcessorContext(stateDir, Serdes.String(), Serdes.String(), new NoOpRecordCollector(), new ThreadCache("testCache", 100000, new MockStreamsMetrics(new Metrics()))) {

        @Override
        public <K, V> void forward(final K key, final V value) {
            results.add(KeyValue.pair(key, value));
        }
    };
    initStore(true);
    processor.init(context);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) ThreadCache(org.apache.kafka.streams.state.internals.ThreadCache) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) File(java.io.File) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) Before(org.junit.Before)

Example 19 with MockProcessorContext

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

the class RocksDBWindowStoreSupplierTest method shouldCreateLoggingEnabledStoreWhenWindowStoreLogged.

@Test
public void shouldCreateLoggingEnabledStoreWhenWindowStoreLogged() throws Exception {
    store = createStore(true, 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");
    assertFalse(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)

Example 20 with MockProcessorContext

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

the class StateStoreTestUtils method newKeyValueStore.

public static <K, V> KeyValueStore<K, V> newKeyValueStore(String name, Class<K> keyType, Class<V> valueType) {
    final InMemoryKeyValueStoreSupplier<K, V> supplier = new InMemoryKeyValueStoreSupplier<>(name, null, null, new MockTime(), false, Collections.<String, String>emptyMap());
    final StateStore stateStore = supplier.get();
    stateStore.init(new MockProcessorContext(StateSerdes.withBuiltinTypes(name, keyType, valueType), new NoOpRecordCollector()), stateStore);
    return (KeyValueStore<K, V>) stateStore;
}
Also used : NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) StateStore(org.apache.kafka.streams.processor.StateStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore) MockProcessorContext(org.apache.kafka.test.MockProcessorContext) MockTime(org.apache.kafka.common.utils.MockTime)

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