Search in sources :

Example 71 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project apache-kafka-on-k8s by banzaicloud.

the class ThreadCacheTest method shouldNotForwardCleanEntryOnEviction.

@Test
public void shouldNotForwardCleanEntryOnEviction() {
    final ThreadCache cache = new ThreadCache(logContext, 0, new MockStreamsMetrics(new Metrics()));
    final List<ThreadCache.DirtyEntry> received = new ArrayList<>();
    cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            received.addAll(dirty);
        }
    });
    cache.put(namespace, Bytes.wrap(new byte[] { 1 }), cleanEntry(new byte[] { 0 }));
    assertEquals(0, received.size());
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ArrayList(java.util.ArrayList) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Example 72 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project apache-kafka-on-k8s by banzaicloud.

the class ThreadCacheTest method shouldDelete.

@Test
public void shouldDelete() {
    final ThreadCache cache = new ThreadCache(logContext, 10000L, new MockStreamsMetrics(new Metrics()));
    final Bytes key = Bytes.wrap(new byte[] { 0 });
    cache.put(namespace, key, dirtyEntry(key.get()));
    assertEquals(key.get(), cache.delete(namespace, key).value);
    assertNull(cache.get(namespace, key));
}
Also used : Bytes(org.apache.kafka.common.utils.Bytes) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Example 73 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project apache-kafka-on-k8s by banzaicloud.

the class ThreadCacheTest method shouldThrowIfNoPeekNextKey.

@Test(expected = NoSuchElementException.class)
public void shouldThrowIfNoPeekNextKey() {
    final ThreadCache cache = new ThreadCache(logContext, 10000L, new MockStreamsMetrics(new Metrics()));
    final ThreadCache.MemoryLRUCacheBytesIterator iterator = cache.range(namespace, Bytes.wrap(new byte[] { 0 }), Bytes.wrap(new byte[] { 1 }));
    iterator.peekNextKey();
}
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) Test(org.junit.Test)

Example 74 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project apache-kafka-on-k8s by banzaicloud.

the class ThreadCacheTest method shouldNotFlushCleanEntriesForNamespace.

@Test
public void shouldNotFlushCleanEntriesForNamespace() {
    final ThreadCache cache = new ThreadCache(logContext, 100000, new MockStreamsMetrics(new Metrics()));
    final List<byte[]> received = new ArrayList<>();
    cache.addDirtyEntryFlushListener(namespace1, new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            for (ThreadCache.DirtyEntry dirtyEntry : dirty) {
                received.add(dirtyEntry.key().get());
            }
        }
    });
    final List<byte[]> toInsert = Arrays.asList(new byte[] { 0 }, new byte[] { 1 }, new byte[] { 2 });
    for (byte[] bytes : toInsert) {
        cache.put(namespace1, Bytes.wrap(bytes), cleanEntry(bytes));
    }
    cache.put(namespace2, Bytes.wrap(new byte[] { 4 }), cleanEntry(new byte[] { 4 }));
    cache.flush(namespace1);
    assertEquals(Collections.EMPTY_LIST, received);
}
Also used : MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Metrics(org.apache.kafka.common.metrics.Metrics) ArrayList(java.util.ArrayList) MockStreamsMetrics(org.apache.kafka.streams.processor.internals.MockStreamsMetrics) Test(org.junit.Test)

Example 75 with MockStreamsMetrics

use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics 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)

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