|
|
|
@ -388,6 +388,24 @@ public class ThreadCacheTest {
@@ -388,6 +388,24 @@ public class ThreadCacheTest {
|
|
|
|
|
shouldEvictImmediatelyIfCacheSizeIsZeroOrVerySmall(cache); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldEvictAfterPutAll() throws Exception { |
|
|
|
|
final List<ThreadCache.DirtyEntry> received = new ArrayList<>(); |
|
|
|
|
final String namespace = "namespace"; |
|
|
|
|
final ThreadCache cache = new ThreadCache(1); |
|
|
|
|
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(new byte[]{0}, dirtyEntry(new byte[]{5})), |
|
|
|
|
KeyValue.pair(new byte[]{1}, dirtyEntry(new byte[]{6})))); |
|
|
|
|
|
|
|
|
|
assertEquals(cache.evicts(), 2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldPutAll() throws Exception { |
|
|
|
|
final ThreadCache cache = new ThreadCache(100000); |
|
|
|
@ -422,6 +440,25 @@ public class ThreadCacheTest {
@@ -422,6 +440,25 @@ public class ThreadCacheTest {
|
|
|
|
|
assertArrayEquals(value, cache.get("n", key).value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void shouldEvictAfterPutIfAbsent() throws Exception { |
|
|
|
|
final List<ThreadCache.DirtyEntry> received = new ArrayList<>(); |
|
|
|
|
final String namespace = "namespace"; |
|
|
|
|
final ThreadCache cache = new ThreadCache(1); |
|
|
|
|
cache.addDirtyEntryFlushListener(namespace, new ThreadCache.DirtyEntryFlushListener() { |
|
|
|
|
@Override |
|
|
|
|
public void apply(final List<ThreadCache.DirtyEntry> dirty) { |
|
|
|
|
received.addAll(dirty); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
cache.putIfAbsent(namespace, new byte[]{0}, dirtyEntry(new byte[]{5})); |
|
|
|
|
cache.putIfAbsent(namespace, new byte[]{1}, dirtyEntry(new byte[]{6})); |
|
|
|
|
cache.putIfAbsent(namespace, new byte[]{1}, dirtyEntry(new byte[]{6})); |
|
|
|
|
|
|
|
|
|
assertEquals(cache.evicts(), 3); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private LRUCacheEntry dirtyEntry(final byte[] key) { |
|
|
|
|
return new LRUCacheEntry(key, true, -1, -1, -1, ""); |
|
|
|
|
} |
|
|
|
|