use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method shouldEvictImmediatelyIfCacheSizeIsZero.
@Test
public void shouldEvictImmediatelyIfCacheSizeIsZero() throws Exception {
final ThreadCache cache = new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics()));
shouldEvictImmediatelyIfCacheSizeIsZeroOrVerySmall(cache);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ThreadCacheTest method checkOverheads.
private void checkOverheads(double entryFactor, double systemFactor, long desiredCacheSize, int keySizeBytes, int valueSizeBytes) {
Runtime runtime = Runtime.getRuntime();
final String name = "name";
long numElements = desiredCacheSize / memoryCacheEntrySize(new byte[keySizeBytes], new byte[valueSizeBytes], "");
System.gc();
long prevRuntimeMemory = runtime.totalMemory() - runtime.freeMemory();
ThreadCache cache = new ThreadCache("testCache", desiredCacheSize, new MockStreamsMetrics(new Metrics()));
long size = cache.sizeBytes();
assertEquals(size, 0);
for (int i = 0; i < numElements; i++) {
String keyStr = "K" + i;
Bytes key = Bytes.wrap(keyStr.getBytes());
byte[] value = new byte[valueSizeBytes];
cache.put(name, key, new LRUCacheEntry(value, true, 1L, 1L, 1, ""));
}
System.gc();
double ceiling = desiredCacheSize + desiredCacheSize * entryFactor;
long usedRuntimeMemory = runtime.totalMemory() - runtime.freeMemory() - prevRuntimeMemory;
assertTrue((double) cache.sizeBytes() <= ceiling);
assertTrue("Used memory size " + usedRuntimeMemory + " greater than expected " + cache.sizeBytes() * systemFactor, cache.sizeBytes() * systemFactor >= usedRuntimeMemory);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class CachingWindowStoreTest method setUp.
@Before
public void setUp() throws Exception {
keySchema = new WindowKeySchema();
underlying = new RocksDBSegmentedBytesStore("test", 30000, 3, keySchema);
final RocksDBWindowStore<Bytes, byte[]> windowStore = new RocksDBWindowStore<>(underlying, Serdes.Bytes(), Serdes.ByteArray(), false);
cacheListener = new CachingKeyValueStoreTest.CacheFlushListenerStub<>();
cachingStore = new CachingWindowStore<>(windowStore, Serdes.String(), Serdes.String(), WINDOW_SIZE);
cachingStore.setFlushListener(cacheListener);
cache = new ThreadCache("testCache", MAX_CACHE_SIZE_BYTES, new MockStreamsMetrics(new Metrics()));
topic = "topic";
final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), null, null, (RecordCollector) null, cache);
context.setRecordContext(new ProcessorRecordContext(DEFAULT_TIMESTAMP, 0, 0, topic));
cachingStore.init(context, cachingStore);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class ChangeLoggingSegmentedBytesStoreTest method setUp.
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
final NoOpRecordCollector collector = new NoOpRecordCollector() {
@Override
public <K, V> void send(final String topic, K key, V value, Integer partition, Long timestamp, Serializer<K> keySerializer, Serializer<V> valueSerializer) {
sent.put(key, value);
}
};
final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), Serdes.String(), Serdes.Long(), collector, new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
context.setTime(0);
store.init(context, store);
}
use of org.apache.kafka.streams.processor.internals.MockStreamsMetrics in project kafka by apache.
the class CachingSessionStoreTest method setUp.
@Before
public void setUp() throws Exception {
underlying = new RocksDBSegmentedBytesStore("test", 60000, 3, new SessionKeySchema());
final RocksDBSessionStore<Bytes, byte[]> sessionStore = new RocksDBSessionStore<>(underlying, Serdes.Bytes(), Serdes.ByteArray());
cachingStore = new CachingSessionStore<>(sessionStore, Serdes.String(), Serdes.Long());
cache = new ThreadCache("testCache", MAX_CACHE_SIZE_BYTES, new MockStreamsMetrics(new Metrics()));
final MockProcessorContext context = new MockProcessorContext(TestUtils.tempDirectory(), null, null, (RecordCollector) null, cache);
context.setRecordContext(new ProcessorRecordContext(DEFAULT_TIMESTAMP, 0, 0, "topic"));
cachingStore.init(context, cachingStore);
}
Aggregations