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);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldSkipEntriesWhereValueHasBeenEvictedFromCache.
@Test
public void shouldSkipEntriesWhereValueHasBeenEvictedFromCache() throws Exception {
final String namespace = "streams";
final int entrySize = memoryCacheEntrySize(new byte[1], new byte[1], "");
final ThreadCache cache = new ThreadCache("testCache", entrySize * 5, new MockStreamsMetrics(new Metrics()));
cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
}
});
byte[][] bytes = { { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 } };
for (int i = 0; i < 5; i++) {
cache.put(namespace, Bytes.wrap(bytes[i]), dirtyEntry(bytes[i]));
}
assertEquals(5, cache.size());
final ThreadCache.MemoryLRUCacheBytesIterator range = cache.range(namespace, Bytes.wrap(new byte[] { 0 }), Bytes.wrap(new byte[] { 5 }));
// should evict byte[] {0}
cache.put(namespace, Bytes.wrap(new byte[] { 6 }), dirtyEntry(new byte[] { 6 }));
assertEquals(Bytes.wrap(new byte[] { 1 }), range.peekNextKey());
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class MergedSortedCacheKeyValueStoreIteratorTest method setUp.
@Before
public void setUp() throws Exception {
store = new InMemoryKeyValueStore<>(namespace, Serdes.Bytes(), Serdes.ByteArray());
cache = new ThreadCache("testCache", 10000L, new MockStreamsMetrics(new Metrics()));
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class MergedSortedCacheKeyValueStoreIteratorTest method shouldPeekNextKey.
@Test
public void shouldPeekNextKey() throws Exception {
final KeyValueStore<Bytes, byte[]> kv = new InMemoryKeyValueStore<>("one", Serdes.Bytes(), Serdes.ByteArray());
final ThreadCache cache = new ThreadCache("testCache", 1000000L, new MockStreamsMetrics(new Metrics()));
byte[][] bytes = { { 0 }, { 1 }, { 2 }, { 3 }, { 4 }, { 5 }, { 6 }, { 7 }, { 8 }, { 9 }, { 10 } };
final String namespace = "one";
for (int i = 0; i < bytes.length - 1; i += 2) {
kv.put(Bytes.wrap(bytes[i]), bytes[i]);
cache.put(namespace, Bytes.wrap(bytes[i + 1]), new LRUCacheEntry(bytes[i + 1]));
}
final Bytes from = Bytes.wrap(new byte[] { 2 });
final Bytes to = Bytes.wrap(new byte[] { 9 });
final KeyValueIterator<Bytes, byte[]> storeIterator = kv.range(from, to);
final ThreadCache.MemoryLRUCacheBytesIterator cacheIterator = cache.range(namespace, from, to);
final MergedSortedCacheKeyValueStoreIterator<byte[], byte[]> iterator = new MergedSortedCacheKeyValueStoreIterator<>(cacheIterator, storeIterator, serdes);
final byte[][] values = new byte[8][];
int index = 0;
int bytesIndex = 2;
while (iterator.hasNext()) {
final byte[] keys = iterator.peekNextKey();
values[index++] = keys;
assertArrayEquals(bytes[bytesIndex++], keys);
iterator.next();
}
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class RocksDBSessionStoreTest method before.
@Before
public void before() {
final RocksDBSegmentedBytesStore bytesStore = new RocksDBSegmentedBytesStore("session-store", 10000L, 3, new SessionKeySchema());
sessionStore = new RocksDBSessionStore<>(bytesStore, Serdes.String(), Serdes.Long());
final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
sessionStore.init(context, sessionStore);
}
Aggregations