Search in sources :

Example 6 with CacheManager

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);
}
Also used : CacheManager(com.baidu.hugegraph.backend.cache.CacheManager) After(org.junit.After)

Example 7 with CacheManager

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());
}
Also used : CacheManager(com.baidu.hugegraph.backend.cache.CacheManager) Id(com.baidu.hugegraph.backend.id.Id) RamCache(com.baidu.hugegraph.backend.cache.RamCache) Cache(com.baidu.hugegraph.backend.cache.Cache) OffheapCache(com.baidu.hugegraph.backend.cache.OffheapCache) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 8 with CacheManager

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);
    });
}
Also used : CacheManager(com.baidu.hugegraph.backend.cache.CacheManager) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

CacheManager (com.baidu.hugegraph.backend.cache.CacheManager)8 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)6 Test (org.junit.Test)6 Id (com.baidu.hugegraph.backend.id.Id)5 Cache (com.baidu.hugegraph.backend.cache.Cache)3 OffheapCache (com.baidu.hugegraph.backend.cache.OffheapCache)3 RamCache (com.baidu.hugegraph.backend.cache.RamCache)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 After (org.junit.After)1 Before (org.junit.Before)1