Java Code Examples for com.baidu.hugegraph.testutil.Assert#assertSame()

The following examples show how to use com.baidu.hugegraph.testutil.Assert#assertSame() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheManagerTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheList() {
    CacheManager manager = CacheManager.instance();

    Cache<Id, Object> cache1 = Mockito.mock(RamCache.class);
    Cache<Id, Object> cache2 = Mockito.mock(OffheapCache.class);

    Mockito.when(this.mockCaches.get("cache-1")).thenReturn(cache1);
    Mockito.when(this.mockCaches.get("cache-2")).thenReturn(cache2);
    Mockito.when(this.mockCaches.size()).thenReturn(2);

    Map<String, Cache<Id, Object>> caches = manager.caches();

    Assert.assertEquals(2, caches.size());
    Assert.assertSame(cache1, caches.get("cache-1"));
    Assert.assertSame(cache2, caches.get("cache-2"));

    Assert.assertArrayEquals(this.mockCaches.values().toArray(),
                             caches.values().toArray());
}
 
Example 2
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testLock() {
    Lock lock = this.group.lock("lock");
    Assert.assertTrue(lock instanceof ReentrantLock);
    Lock lock1 = this.group.lock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 3
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testAtomicLock() {
    AtomicLock lock = this.group.atomicLock("lock");
    Assert.assertNotNull(lock);
    AtomicLock lock1 = this.group.atomicLock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 4
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadWriteLock() {
    ReadWriteLock lock = this.group.readWriteLock("lock");
    Assert.assertTrue(lock instanceof ReentrantReadWriteLock);
    ReadWriteLock lock1 = this.group.readWriteLock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 5
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeyLock() {
    KeyLock lock = this.group.keyLock("lock");
    Assert.assertNotNull(lock);
    KeyLock lock1 = this.group.keyLock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 6
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeyLockWithSize() {
    KeyLock lock = this.group.keyLock("lock", 10);
    Assert.assertNotNull(lock);
    KeyLock lock1 = this.group.keyLock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 7
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testRowLock() {
    RowLock<?> lock = this.group.rowLock("lock");
    Assert.assertNotNull(lock);
    RowLock<?> lock1 = this.group.rowLock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 8
Source File: CacheManagerTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 9
Source File: CacheManagerTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachePutGetWithCapacity() {
    final String name = "test-cache";
    final int capacity = 12345;

    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, capacity);

    Assert.assertNotNull(cache1);
    Assert.assertEquals(capacity, cache1.capacity());
    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, capacity);

    Assert.assertEquals(capacity, cache2.capacity());
    Assert.assertSame(cache1, cache2);

    Assert.assertSame(cache1, manager.cache(name));
    Assert.assertSame(cache1, manager.cache(name, 0));
    Assert.assertSame(cache1, manager.cache(name, 1));
    Assert.assertSame(cache1, manager.cache(name, capacity));
    Assert.assertSame(cache1, manager.cache(name, capacity + 10));

    Mockito.verify(this.mockCaches, Mockito.atMost(1))
           .putIfAbsent(Mockito.anyString(), Mockito.any());
}