public @Test void testBuildPrecondition() { ex.expect(IllegalArgumentException.class); createCache(10, -1); }
public @Test void testL1WriteBack() { final int L1Capacity = 1000; cache = createCache(L1Capacity, maxCacheSizeBytes); List<RevObject> objects = createObjects(100); objects.forEach((o) -> cache.put(repo1Id.create(o.getId()), o)); objects.forEach((o) -> assertNull(cache.getIfPresent(repo2Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); }
public @Test void testPutIfAbsent() { cache = createCache(10, maxCacheSizeBytes); CacheKey k1 = repo1Id.create(obj.getId()); assertNotNull(cache.put(k1, obj)); assertNull(cache.put(k1, obj)); }
@Ignore // too fragile depending on the jvm test heap public @Test void testInvalidateAll() { final int L1Capacity = 10; cache = createCache(L1Capacity, 32 * 1024 * 1024); List<RevObject> objects = createObjects(500); objects.forEach((o) -> cache.put(repo1Id.create(o.getId()), o)); objects.forEach((o) -> cache.put(repo2Id.create(o.getId()), o)); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo2Id.create(o.getId())))); cache.invalidateAll(); objects.forEach((o) -> assertNull(cache.getIfPresent(repo2Id.create(o.getId())))); objects.forEach((o) -> assertNull(cache.getIfPresent(repo1Id.create(o.getId())))); }
public @Test void testCacheDisabled() { cache = createCache(0, 0L); CacheKey k1 = repo1Id.create(obj.getId()); cache.put(k1, obj); assertFalse(cache.contains(k1)); assertEquals(0L, cache.sizeBytes()); }
@Ignore // too fragile depending on the jvm test heap public @Test void testInvalidateAllForPrefix() { final int L1Capacity = 10; cache = createCache(L1Capacity, 32 * 1024 * 1024); List<RevObject> objects = createObjects(100); objects.forEach((o) -> cache.put(repo1Id.create(o.getId()), o)); objects.forEach((o) -> cache.put(repo2Id.create(o.getId()), o)); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo2Id.create(o.getId())))); cache.invalidateAll(repo2Id); objects.forEach((o) -> assertNull(cache.getIfPresent(repo2Id.create(o.getId())))); objects.forEach((o) -> assertNotNull(cache.getIfPresent(repo1Id.create(o.getId())))); cache.invalidateAll(repo1Id); objects.forEach((o) -> assertNull(cache.getIfPresent(repo1Id.create(o.getId())))); }
public @Test void testGetIfPresentEnsureL2Cache() throws Exception { cache = createCache(10, maxCacheSizeBytes); CacheKey k1 = repo1Id.create(obj.getId()); assertNull(cache.getIfPresent(k1)); Future<?> l2Future = cache.put(k1, obj); assertNotNull(l2Future); l2Future.get(); RevObject cached = cache.getIfPresent(k1); assertNotNull(cached); assertNull(cache.getIfPresent(repo2Id.create(obj.getId()))); assertEquals(obj, cached); }
public @Test void testKeyPrefix() { cache = createCache(10, maxCacheSizeBytes); CacheKey k1 = repo1Id.create(obj.getId()); CacheKey k2 = repo2Id.create(obj.getId()); cache.put(k1, obj); assertTrue(cache.contains(k1)); assertFalse(cache.contains(k2)); }
public @Test void testGetIfPresentImmediately() { cache = createCache(10, maxCacheSizeBytes); CacheKey k1 = repo1Id.create(obj.getId()); assertNull(cache.getIfPresent(k1)); assertNotNull(cache.put(k1, obj)); RevObject cached = cache.getIfPresent(k1); assertNotNull(cached); assertNull(cache.getIfPresent(repo2Id.create(obj.getId()))); assertEquals(obj, cached); }