Search in sources :

Example 26 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldNotClashWithOverlappingNames.

@Test
public void shouldNotClashWithOverlappingNames() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    final Bytes nameByte = Bytes.wrap(new byte[] { 0 });
    final Bytes name1Byte = Bytes.wrap(new byte[] { 1 });
    cache.put("name", nameByte, dirtyEntry(nameByte.get()));
    cache.put("name1", nameByte, dirtyEntry(name1Byte.get()));
    assertArrayEquals(nameByte.get(), cache.get("name", nameByte).value);
    assertArrayEquals(name1Byte.get(), cache.get("name1", nameByte).value);
}
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 27 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldNotFlushCleanEntriesForNamespace.

@Test
public void shouldNotFlushCleanEntriesForNamespace() 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[]> toInsert = Arrays.asList(new byte[] { 0 }, new byte[] { 1 }, new byte[] { 2 });
    for (byte[] bytes : toInsert) {
        cache.put("1", Bytes.wrap(bytes), cleanEntry(bytes));
    }
    cache.put("2", Bytes.wrap(new byte[] { 4 }), cleanEntry(new byte[] { 4 }));
    cache.flush("1");
    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 28 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldReturnNullIfKeyIsNull.

@Test
public void shouldReturnNullIfKeyIsNull() throws Exception {
    final ThreadCache threadCache = new ThreadCache("testCache", 10, new MockStreamsMetrics(new Metrics()));
    threadCache.put("one", Bytes.wrap(new byte[] { 1 }), cleanEntry(new byte[] { 1 }));
    assertNull(threadCache.get("one", null));
}
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 29 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldPutAll.

@Test
public void shouldPutAll() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 100000, new MockStreamsMetrics(new Metrics()));
    cache.putAll("name", Arrays.asList(KeyValue.pair(Bytes.wrap(new byte[] { 0 }), dirtyEntry(new byte[] { 5 })), KeyValue.pair(Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[] { 6 }))));
    assertArrayEquals(new byte[] { 5 }, cache.get("name", Bytes.wrap(new byte[] { 0 })).value);
    assertArrayEquals(new byte[] { 6 }, cache.get("name", Bytes.wrap(new byte[] { 1 })).value);
}
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 30 with MockStreamsMetrics

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

the class ThreadCacheTest method shouldGetSameKeyAsPeekNext.

@Test
public void shouldGetSameKeyAsPeekNext() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    final Bytes theByte = Bytes.wrap(new byte[] { 0 });
    final String namespace = "streams";
    cache.put(namespace, theByte, dirtyEntry(theByte.get()));
    final ThreadCache.MemoryLRUCacheBytesIterator iterator = cache.range(namespace, theByte, Bytes.wrap(new byte[] { 1 }));
    assertEquals(iterator.peekNextKey(), iterator.next().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)

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