Search in sources :

Example 86 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.

the class MergedSortedCacheKeyValueBytesStoreIteratorTest method shouldPeekNextKeyReverse.

@Test
public void shouldPeekNextKeyReverse() {
    final KeyValueStore<Bytes, byte[]> kv = new InMemoryKeyValueStore("one");
    final ThreadCache cache = new ThreadCache(new LogContext("testCache "), 1000000L, new MockStreamsMetrics(new Metrics()));
    final byte[][] bytes = { { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 } };
    for (int i = 0; i < bytes.length - 1; i += 2) {
        kv.put(Bytes.wrap(bytes[i]), bytes[i]);
        cache.put(namespace, Bytes.wrap(bytes[i + 1]), new LRUCacheEntry(bytes[i + 1]));
    }
    final Bytes from = Bytes.wrap(new byte[] { 2 });
    final Bytes to = Bytes.wrap(new byte[] { 9 });
    final KeyValueIterator<Bytes, byte[]> storeIterator = kv.reverseRange(from, to);
    final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.reverseRange(namespace, from, to);
    final MergedSortedCacheKeyValueBytesStoreIterator iterator = new MergedSortedCacheKeyValueBytesStoreIterator(cacheIterator, storeIterator, false);
    final byte[][] values = new byte[8][];
    int index = 0;
    int bytesIndex = 9;
    while (iterator.hasNext()) {
        final byte[] keys = iterator.peekNextKey().get();
        values[index++] = keys;
        assertArrayEquals(bytes[bytesIndex--], keys);
        iterator.next();
    }
    iterator.close();
}
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) Test(org.junit.Test)

Example 87 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.

the class MergedSortedCacheKeyValueBytesStoreIteratorTest method setUp.

@Before
public void setUp() {
    store = new InMemoryKeyValueStore(namespace);
    cache = new ThreadCache(new LogContext("testCache "), 10000L, new MockStreamsMetrics(new Metrics()));
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Before(org.junit.Before)

Example 88 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.

the class NamedCacheTest method setUp.

@Before
public void setUp() {
    final Metrics innerMetrics = new Metrics();
    final StreamsMetricsImpl metrics = new MockStreamsMetrics(innerMetrics);
    cache = new NamedCache("dummy-name", metrics);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) StreamsMetricsImpl(org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl) Before(org.junit.Before)

Example 89 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.

the class ListValueStoreTest method setup.

@Before
public void setup() {
    listStore = buildStore(Serdes.Integer(), Serdes.String());
    final MockRecordCollector recordCollector = new MockRecordCollector();
    final InternalMockProcessorContext<Integer, String> context = new InternalMockProcessorContext<>(baseDir, Serdes.String(), Serdes.Integer(), recordCollector, new ThreadCache(new LogContext("testCache"), 0, new MockStreamsMetrics(new Metrics())));
    context.setTime(1L);
    listStore.init((StateStoreContext) context, listStore);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockRecordCollector(org.apache.kafka.test.MockRecordCollector) 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 90 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.

the class KeyValueSegmentsTest method createContext.

@Before
public void createContext() {
    stateDirectory = TestUtils.tempDirectory();
    context = new InternalMockProcessorContext<>(stateDirectory, Serdes.String(), Serdes.Long(), new MockRecordCollector(), new ThreadCache(new LogContext("testCache "), 0, new MockStreamsMetrics(new Metrics())));
    segments = new KeyValueSegments(storeName, METRICS_SCOPE, RETENTION_PERIOD, SEGMENT_INTERVAL);
    segments.openExisting(context, -1L);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockRecordCollector(org.apache.kafka.test.MockRecordCollector) LogContext(org.apache.kafka.common.utils.LogContext) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Before(org.junit.Before)

Aggregations

MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)103 Metrics (org.apache.kafka.common.metrics.Metrics)101 Test (org.junit.Test)59 Before (org.junit.Before)38 LogContext (org.apache.kafka.common.utils.LogContext)32 Bytes (org.apache.kafka.common.utils.Bytes)27 ArrayList (java.util.ArrayList)17 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)15 InternalMockProcessorContext (org.apache.kafka.test.InternalMockProcessorContext)14 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)12 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)10 File (java.io.File)7 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)7 MockTime (org.apache.kafka.common.utils.MockTime)7 KeyValue (org.apache.kafka.streams.KeyValue)7 MockRecordCollector (org.apache.kafka.test.MockRecordCollector)7 StreamsMetricsImpl (org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl)6 Properties (java.util.Properties)5 Serializer (org.apache.kafka.common.serialization.Serializer)4 StreamsConfig (org.apache.kafka.streams.StreamsConfig)4