Search in sources :

Example 1 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class KStreamSessionWindowAggregateProcessorTest method initializeStore.

@Before
public void initializeStore() {
    final File stateDir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext(stateDir, Serdes.String(), Serdes.String(), new NoOpRecordCollector(), new ThreadCache(new LogContext("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) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) File(java.io.File) Before(org.junit.Before)

Example 2 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBKeyValueStoreSupplierTest method shouldCreateLoggingEnabledStoreWhenStoreLogged.

@Test
public void shouldCreateLoggingEnabledStoreWhenStoreLogged() {
    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 InternalMockProcessorContext context = new InternalMockProcessorContext(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) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Serializer(org.apache.kafka.common.serialization.Serializer) Test(org.junit.Test)

Example 3 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBSegmentedBytesStoreTest method before.

@Before
public void before() {
    schema.init("topic");
    bytesStore = new RocksDBSegmentedBytesStore(storeName, retention, numSegments, schema);
    stateDir = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext(stateDir, Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    bytesStore.init(context, bytesStore);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) 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 4 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBSessionStoreTest method before.

@Before
public void before() {
    final SessionKeySchema schema = new SessionKeySchema();
    schema.init("topic");
    final RocksDBSegmentedBytesStore bytesStore = new RocksDBSegmentedBytesStore("session-store", 10000L, 3, schema);
    sessionStore = new RocksDBSessionStore<>(bytesStore, Serdes.String(), Serdes.Long());
    context = new InternalMockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    sessionStore.init(context, sessionStore);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) 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 5 with InternalMockProcessorContext

use of org.apache.kafka.test.InternalMockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBStoreTest method shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir.

@Test(expected = ProcessorStateException.class)
public void shouldThrowProcessorStateExceptionOnOpeningReadOnlyDir() throws IOException {
    final File tmpDir = TestUtils.tempDirectory();
    InternalMockProcessorContext tmpContext = new InternalMockProcessorContext(tmpDir, Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    tmpDir.setReadOnly();
    rocksDBStore.openDB(tmpContext);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) File(java.io.File) 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