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