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);
}
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());
}
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);
}
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());
}
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 })));
}
Aggregations