use of com.baidu.hugegraph.backend.cache.CacheManager in project incubator-hugegraph by apache.
the class CacheManagerTest method teardown.
@After
public void teardown() {
CacheManager manager = CacheManager.instance();
Assert.assertNotNull(this.originCaches);
Whitebox.setInternalState(manager, "caches", this.originCaches);
}
use of com.baidu.hugegraph.backend.cache.CacheManager in project incubator-hugegraph by apache.
the class CacheManagerTest method testCacheGetPut.
@Test
public void testCacheGetPut() {
final String name = "test-cache";
CacheManager manager = CacheManager.instance();
Mockito.when(this.mockCaches.containsKey(name)).thenReturn(false);
@SuppressWarnings("rawtypes") final Cache[] cache = new Cache[1];
Mockito.when(this.mockCaches.putIfAbsent(Mockito.anyString(), Mockito.any())).thenAnswer(i -> cache[0] = (Cache<?, ?>) i.getArguments()[1]);
Mockito.when(this.mockCaches.get(name)).thenAnswer(i -> cache[0]);
Cache<Id, Object> cache1 = manager.cache(name);
Assert.assertNotNull(cache1);
Mockito.verify(this.mockCaches).putIfAbsent(name, cache1);
Mockito.when(this.mockCaches.containsKey(name)).thenReturn(true);
Mockito.when(this.mockCaches.get(name)).thenReturn(cache1);
Cache<Id, Object> cache2 = manager.cache(name);
Assert.assertSame(cache1, cache2);
Mockito.verify(this.mockCaches, Mockito.atMost(1)).putIfAbsent(Mockito.anyString(), Mockito.any());
}
use of com.baidu.hugegraph.backend.cache.CacheManager in project incubator-hugegraph by apache.
the class CacheManagerTest method testCacheListModify.
@Test
public void testCacheListModify() {
Assert.assertThrows(UnsupportedOperationException.class, () -> {
CacheManager manager = CacheManager.instance();
manager.caches().put("test", null);
});
}
Aggregations