use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics 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);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics 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());
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldNotFlushAfterDelete.
@Test
public void shouldNotFlushAfterDelete() throws Exception {
final Bytes key = Bytes.wrap(new byte[] { 0 });
final ThreadCache cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
final List<ThreadCache.DirtyEntry> received = new ArrayList<>();
final String namespace = "namespace";
cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
received.addAll(dirty);
}
});
cache.put(namespace, key, dirtyEntry(key.get()));
assertEquals(key.get(), cache.delete(namespace, key).value);
// flushing should have no further effect
cache.flush(namespace);
assertEquals(0, received.size());
assertEquals(cache.flushes(), 1);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldEvictAfterPutIfAbsent.
@Test
public void shouldEvictAfterPutIfAbsent() 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.putIfAbsent(namespace, Bytes.wrap(new byte[] { 0 }), dirtyEntry(new byte[] { 5 }));
cache.putIfAbsent(namespace, Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[] { 6 }));
cache.putIfAbsent(namespace, Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[] { 6 }));
assertEquals(cache.evicts(), 3);
assertEquals(received.size(), 3);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class KStreamSessionWindowAggregateProcessorTest method initializeStore.
@SuppressWarnings("unchecked")
@Before
public void initializeStore() {
final File stateDir = TestUtils.tempDirectory();
context = new MockProcessorContext(stateDir, Serdes.String(), Serdes.String(), new NoOpRecordCollector(), new ThreadCache("testCache", 100000, new MockStreamsMetrics(new Metrics()))) {
@Override
public <K, V> void forward(final K key, final V value) {
results.add(KeyValue.pair(key, value));
}
};
initStore(true);
processor.init(context);
}
Aggregations