Search in sources :

Example 36 with Metrics

use of org.apache.kafka.common.metrics.Metrics 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 37 with Metrics

use of org.apache.kafka.common.metrics.Metrics 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 38 with Metrics

use of org.apache.kafka.common.metrics.Metrics 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)

Example 39 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ThreadCacheTest method shouldPeekAndIterateOverRange.

@Test
public void shouldPeekAndIterateOverRange() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
    final byte[][] bytes = { { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 } };
    final String namespace = "streams";
    for (final byte[] aByte : bytes) {
        cache.put(namespace, Bytes.wrap(aByte), dirtyEntry(aByte));
    }
    final ThreadCache.MemoryLRUCacheBytesIterator iterator = cache.range(namespace, Bytes.wrap(new byte[] { 1 }), Bytes.wrap(new byte[] { 4 }));
    int bytesIndex = 1;
    while (iterator.hasNext()) {
        Bytes peekedKey = iterator.peekNextKey();
        final KeyValue<Bytes, LRUCacheEntry> next = iterator.next();
        assertArrayEquals(bytes[bytesIndex], peekedKey.get());
        assertArrayEquals(bytes[bytesIndex], next.key.get());
        bytesIndex++;
    }
    assertEquals(5, bytesIndex);
}
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 40 with Metrics

use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.

the class ThreadCacheTest method shouldPeekNextKey.

@Test
public void shouldPeekNextKey() 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(theByte, iterator.peekNextKey());
    assertEquals(theByte, iterator.peekNextKey());
}
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)103 Test (org.junit.Test)76 MockStreamsMetrics (org.apache.kafka.streams.processor.internals.MockStreamsMetrics)41 HashMap (java.util.HashMap)31 StreamsConfig (org.apache.kafka.streams.StreamsConfig)28 TaskId (org.apache.kafka.streams.processor.TaskId)27 Before (org.junit.Before)22 MockTime (org.apache.kafka.common.utils.MockTime)21 TopicPartition (org.apache.kafka.common.TopicPartition)20 HashSet (java.util.HashSet)19 StreamsMetrics (org.apache.kafka.streams.StreamsMetrics)17 MockClientSupplier (org.apache.kafka.test.MockClientSupplier)17 UUID (java.util.UUID)16 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)15 Bytes (org.apache.kafka.common.utils.Bytes)14 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)14 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)13 SubscriptionInfo (org.apache.kafka.streams.processor.internals.assignment.SubscriptionInfo)13 MockProcessorContext (org.apache.kafka.test.MockProcessorContext)13 MockInternalTopicManager (org.apache.kafka.test.MockInternalTopicManager)11