Search in sources :

Example 11 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldEvictAfterPutAll.

@Test
public void shouldEvictAfterPutAll() throws Exception {
    final List<ThreadCache.DirtyEntry> received = new ArrayList<>();
    final String namespace = "namespace";
    final ThreadCache cache = new ThreadCache("testCache", 1, new MockStreamsMetrics(new Metrics()));
    cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            received.addAll(dirty);
        }
    });
    cache.putAll(namespace, Arrays.asList(KeyValue.pair(Bytes.wrap(new byte[] { 0 }), dirtyEntry(new byte[] { 5 })), KeyValue.pair(Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[] { 6 }))));
    assertEquals(cache.evicts(), 2);
    assertEquals(received.size(), 2);
}
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 12 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldReturnFalseIfNoNextKey.

@Test
public void shouldReturnFalseIfNoNextKey() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    final ThreadCache.MemoryLRUCacheBytesIterator iterator = cache.range("", Bytes.wrap(new byte[] { 0 }), Bytes.wrap(new byte[] { 1 }));
    assertFalse(iterator.hasNext());
}
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 13 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldFlushDirtyEntriesForNamespace.

@Test
public void shouldFlushDirtyEntriesForNamespace() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 100000, new MockStreamsMetrics(new Metrics()));
    final List<byte[]> received = new ArrayList<>();
    cache.addDirtyEntryFlushListener("1", 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[]> expected = Arrays.asList(new byte[] { 0 }, new byte[] { 1 }, new byte[] { 2 });
    for (byte[] bytes : expected) {
        cache.put("1", Bytes.wrap(bytes), dirtyEntry(bytes));
    }
    cache.put("2", Bytes.wrap(new byte[] { 4 }), dirtyEntry(new byte[] { 4 }));
    cache.flush("1");
    assertEquals(expected, 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 14 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldNotForwardCleanEntryOnEviction.

@Test
public void shouldNotForwardCleanEntryOnEviction() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics()));
    final List<ThreadCache.DirtyEntry> received = new ArrayList<>();
    cache.addDirtyEntryFlushListener("name", new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            received.addAll(dirty);
        }
    });
    cache.put("name", 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 15 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldNotBlowUpOnNonExistentKeyWhenDeleting.

@Test
public void shouldNotBlowUpOnNonExistentKeyWhenDeleting() throws Exception {
    final Bytes key = Bytes.wrap(new byte[] { 0 });
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    cache.put("name", key, dirtyEntry(key.get()));
    assertNull(cache.delete("name", Bytes.wrap(new byte[] { 1 })));
}
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)

Aggregations

Metrics (org.apache.kafka.common.metrics.Metrics)40 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)40 Test (org.junit.Test)26 Bytes (org.apache.kafka.common.utils.Bytes)14 Before (org.junit.Before)13 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)11 NoOpRecordCollector (org.apache.kafka.test.NoOpRecordCollector)8 ArrayList (java.util.ArrayList)7 Serializer (org.apache.kafka.common.serialization.Serializer)3 ProcessorRecordContext (org.apache.kafka.streams.processor.internals.ProcessorRecordContext)3 KeyValue (org.apache.kafka.streams.KeyValue)2 File (java.io.File)1 ThreadCache (org.apache.kafka.streams.state.internals.ThreadCache)1