Search in sources :

Example 16 with InternalMockProcessorContext

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

the class SegmentIteratorTest method before.

@Before
public void before() {
    context = new InternalMockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.String(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    segmentOne.openDB(context);
    segmentTwo.openDB(context);
    segmentOne.put(Bytes.wrap("a".getBytes()), "1".getBytes());
    segmentOne.put(Bytes.wrap("b".getBytes()), "2".getBytes());
    segmentTwo.put(Bytes.wrap("c".getBytes()), "3".getBytes());
    segmentTwo.put(Bytes.wrap("d".getBytes()), "4".getBytes());
}
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 17 with InternalMockProcessorContext

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

the class MeteredWindowStoreTest method setUp.

@Before
public void setUp() throws Exception {
    final Metrics metrics = new Metrics();
    final StreamsMetrics streamsMetrics = new StreamsMetrics() {

        @Override
        public Map<MetricName, ? extends Metric> metrics() {
            return Collections.unmodifiableMap(metrics.metrics());
        }

        @Override
        public Sensor addLatencyAndThroughputSensor(String scopeName, String entityName, String operationName, Sensor.RecordingLevel recordLevel, String... tags) {
            return metrics.sensor(operationName);
        }

        @Override
        public void recordLatency(final Sensor sensor, final long startNs, final long endNs) {
            latencyRecorded.add(sensor.name());
        }

        @Override
        public Sensor addThroughputSensor(String scopeName, String entityName, String operationName, Sensor.RecordingLevel recordLevel, String... tags) {
            return metrics.sensor(operationName);
        }

        @Override
        public void recordThroughput(Sensor sensor, long value) {
            throughputRecorded.add(sensor.name());
        }

        @Override
        public void removeSensor(Sensor sensor) {
            metrics.removeSensor(sensor.name());
        }

        @Override
        public Sensor addSensor(String name, Sensor.RecordingLevel recordLevel) {
            return metrics.sensor(name);
        }

        @Override
        public Sensor addSensor(String name, Sensor.RecordingLevel recordLevel, Sensor... parents) {
            return metrics.sensor(name);
        }
    };
    context = new InternalMockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, streamsMetrics)) {

        @Override
        public StreamsMetrics metrics() {
            return streamsMetrics;
        }
    };
    EasyMock.expect(innerStoreMock.name()).andReturn("store").anyTimes();
}
Also used : MetricName(org.apache.kafka.common.MetricName) Metrics(org.apache.kafka.common.metrics.Metrics) StreamsMetrics(org.apache.kafka.streams.StreamsMetrics) NoOpRecordCollector(org.apache.kafka.test.NoOpRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) StreamsMetrics(org.apache.kafka.streams.StreamsMetrics) Sensor(org.apache.kafka.common.metrics.Sensor) Before(org.junit.Before)

Example 18 with InternalMockProcessorContext

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

the class RocksDBKeyValueStoreSupplierTest method shouldNotBeLoggingEnabledStoreWhenLoggingNotEnabled.

@Test
public void shouldNotBeLoggingEnabledStoreWhenLoggingNotEnabled() {
    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<>(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");
    assertTrue(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 19 with InternalMockProcessorContext

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

the class CachingSessionStoreTest method setUp.

@Before
public void setUp() {
    final SessionKeySchema schema = new SessionKeySchema();
    schema.init("topic");
    final int retention = 60000;
    final int numSegments = 3;
    underlying = new RocksDBSegmentedBytesStore("test", retention, numSegments, schema);
    final RocksDBSessionStore<Bytes, byte[]> sessionStore = new RocksDBSessionStore<>(underlying, Serdes.Bytes(), Serdes.ByteArray());
    cachingStore = new CachingSessionStore<>(sessionStore, Serdes.String(), Serdes.String(), Segments.segmentInterval(retention, numSegments));
    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"));
    cachingStore.init(context, cachingStore);
}
Also used : LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Example 20 with InternalMockProcessorContext

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

the class CachingWindowStoreTest method setUp.

@Before
public void setUp() {
    keySchema = new WindowKeySchema();
    final int retention = 30000;
    final int numSegments = 3;
    underlying = new RocksDBSegmentedBytesStore("test", retention, numSegments, keySchema);
    final RocksDBWindowStore<Bytes, byte[]> windowStore = new RocksDBWindowStore<>(underlying, Serdes.Bytes(), Serdes.ByteArray(), false, WINDOW_SIZE);
    cacheListener = new CachingKeyValueStoreTest.CacheFlushListenerStub<>();
    cachingStore = new CachingWindowStore<>(windowStore, Serdes.String(), Serdes.String(), WINDOW_SIZE, Segments.segmentInterval(retention, numSegments));
    cachingStore.setFlushListener(cacheListener, false);
    cache = new ThreadCache(new LogContext("testCache "), MAX_CACHE_SIZE_BYTES, new MockStreamsMetrics(new Metrics()));
    topic = "topic";
    context = new InternalMockProcessorContext(TestUtils.tempDirectory(), null, null, (RecordCollector) null, cache);
    context.setRecordContext(new ProcessorRecordContext(DEFAULT_TIMESTAMP, 0, 0, topic));
    cachingStore.init(context, cachingStore);
}
Also used : RecordCollector(org.apache.kafka.streams.processor.internals.RecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ProcessorRecordContext(org.apache.kafka.streams.processor.internals.ProcessorRecordContext) InternalMockProcessorContext(org.apache.kafka.test.InternalMockProcessorContext) Before(org.junit.Before)

Aggregations

InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)21 LogContext (org.apache.kafka.common.utils.LogContext)14 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)14 Metrics (org.apache.kafka.common.metrics.Metrics)13 Before (org.junit.Before)12 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)11 Test (org.junit.Test)8 Serializer (org.apache.kafka.common.serialization.Serializer)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)4 StreamsConfig (org.apache.kafka.streams.StreamsConfig)3 StateStore (org.apache.kafka.streams.processor.StateStore)3 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)3 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2 Bytes (org.apache.kafka.common.utils.Bytes)2 MockTime (org.apache.kafka.common.utils.MockTime)2 RecordCollector (org.apache.kafka.streams.processor.internals.RecordCollector)2 LinkedHashMap (java.util.LinkedHashMap)1