use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class ThreadCacheTest method shouldEvictImmediatelyIfCacheSizeIsVerySmall.
@Test
public void shouldEvictImmediatelyIfCacheSizeIsVerySmall() throws Exception {
final ThreadCache cache = new ThreadCache("testCache", 1, new MockStreamsMetrics(new Metrics()));
shouldEvictImmediatelyIfCacheSizeIsZeroOrVerySmall(cache);
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class RocksDBSegmentedBytesStoreTest method before.
@Before
public void before() {
bytesStore = new RocksDBSegmentedBytesStore(storeName, retention, numSegments, new SessionKeySchema());
stateDir = TestUtils.tempDirectory();
final MockProcessorContext context = new MockProcessorContext(stateDir, Serdes.String(), Serdes.Long(), new NoOpRecordCollector(), new ThreadCache("testCache", 0, new MockStreamsMetrics(new Metrics())));
bytesStore.init(context, bytesStore);
}
use of org.apache.kafka.common.metrics.Metrics in project kafka by apache.
the class ThreadCacheTest method shouldNotLoopForEverWhenEvictingAndCurrentCacheIsEmpty.
@Test
public void shouldNotLoopForEverWhenEvictingAndCurrentCacheIsEmpty() throws Exception {
final int maxCacheSizeInBytes = 100;
final ThreadCache threadCache = new ThreadCache("testCache", maxCacheSizeInBytes, new MockStreamsMetrics(new Metrics()));
// trigger a put into another cache on eviction from "name"
threadCache.addDirtyEntryFlushListener("name", new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
// put an item into an empty cache when the total cache size
// is already > than maxCacheSizeBytes
threadCache.put("other", Bytes.wrap(new byte[] { 0 }), dirtyEntry(new byte[2]));
}
});
threadCache.addDirtyEntryFlushListener("other", new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
//
}
});
threadCache.addDirtyEntryFlushListener("another", new ThreadCache.DirtyEntryFlushListener() {
@Override
public void apply(final List<ThreadCache.DirtyEntry> dirty) {
}
});
threadCache.put("another", Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[1]));
threadCache.put("name", Bytes.wrap(new byte[] { 1 }), dirtyEntry(new byte[1]));
// Put a large item such that when the eldest item is removed
// cache sizeInBytes() > maxCacheSizeBytes
int remaining = (int) (maxCacheSizeInBytes - threadCache.sizeBytes());
threadCache.put("name", Bytes.wrap(new byte[] { 2 }), dirtyEntry(new byte[remaining + 100]));
}
use of org.apache.kafka.common.metrics.Metrics 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.common.metrics.Metrics 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());
}
Aggregations