Search in sources :

Example 71 with Metrics

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

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

Example 73 with Metrics

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

the class ThreadCacheTest method shouldThrowIfNoPeekNextKey.

@Test(expected = NoSuchElementException.class)
public void shouldThrowIfNoPeekNextKey() 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 }));
    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 Metrics

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

the class ThreadCacheTest method evict.

@Test
public void evict() throws IOException {
    final List<KeyValue<String, String>> received = new ArrayList<>();
    List<KeyValue<String, String>> expected = Collections.singletonList(new KeyValue<>("K1", "V1"));
    List<KeyValue<String, String>> toInsert = Arrays.asList(new KeyValue<>("K1", "V1"), new KeyValue<>("K2", "V2"), new KeyValue<>("K3", "V3"), new KeyValue<>("K4", "V4"), new KeyValue<>("K5", "V5"));
    final KeyValue<String, String> kv = toInsert.get(0);
    final String namespace = "kafka";
    ThreadCache cache = new ThreadCache("testCache", memoryCacheEntrySize(kv.key.getBytes(), kv.value.getBytes(), ""), new MockStreamsMetrics(new Metrics()));
    cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {

        @Override
        public void apply(final List<ThreadCache.DirtyEntry> dirty) {
            for (ThreadCache.DirtyEntry dirtyEntry : dirty) {
                received.add(new KeyValue<>(dirtyEntry.key().toString(), new String(dirtyEntry.newValue())));
            }
        }
    });
    for (KeyValue<String, String> kvToInsert : toInsert) {
        final Bytes key = Bytes.wrap(kvToInsert.key.getBytes());
        final byte[] value = kvToInsert.value.getBytes();
        cache.put(namespace, key, new LRUCacheEntry(value, true, 1, 1, 1, ""));
    }
    for (int i = 0; i < expected.size(); i++) {
        KeyValue<String, String> expectedRecord = expected.get(i);
        KeyValue<String, String> actualRecord = received.get(i);
        assertEquals(expectedRecord, actualRecord);
    }
    assertEquals(cache.evicts(), 4);
}
Also used : KeyValue(org.apache.kafka.streams.KeyValue) ArrayList(java.util.ArrayList) 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 75 with Metrics

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

the class ThreadCacheTest method shouldCleanupNamedCacheOnClose.

@Test
public void shouldCleanupNamedCacheOnClose() throws Exception {
    final ThreadCache cache = new ThreadCache("testCache", 100000, new MockStreamsMetrics(new Metrics()));
    cache.put("one", Bytes.wrap(new byte[] { 1 }), cleanEntry(new byte[] { 1 }));
    cache.put("two", Bytes.wrap(new byte[] { 1 }), cleanEntry(new byte[] { 1 }));
    assertEquals(cache.size(), 2);
    cache.close("two");
    assertEquals(cache.size(), 1);
    assertNull(cache.get("two", Bytes.wrap(new byte[] { 1 })));
}
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)

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