use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class CacheTest method testUpdateIfAbsent.
@Test
public void testUpdateIfAbsent() {
Cache<Id, Object> cache = newCache();
Id id = IdGenerator.of("1");
cache.updateIfAbsent(id, "value-1");
Assert.assertEquals("value-1", cache.get(id));
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class CacheTest method testEnableMetrics.
@Test
public void testEnableMetrics() {
Cache<Id, Object> cache = newCache();
Assert.assertEquals(false, cache.enableMetrics(false));
Assert.assertEquals(false, cache.enableMetrics(true));
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(0L, cache.miss());
Id id = IdGenerator.of("1");
cache.update(id, "value-1");
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(0L, cache.miss());
cache.get(IdGenerator.of("not-exist"));
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(1L, cache.miss());
cache.get(IdGenerator.of("1"));
Assert.assertEquals(1L, cache.hits());
Assert.assertEquals(1L, cache.miss());
cache.get(IdGenerator.of("not-exist"));
Assert.assertEquals(1L, cache.hits());
Assert.assertEquals(2L, cache.miss());
cache.get(IdGenerator.of("1"));
Assert.assertEquals(2L, cache.hits());
Assert.assertEquals(2L, cache.miss());
Assert.assertEquals(true, cache.enableMetrics(false));
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(0L, cache.miss());
cache.get(IdGenerator.of("not-exist"));
cache.get(IdGenerator.of("1"));
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(0L, cache.miss());
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class CacheTest method testUpdateAndGet.
@Test
public void testUpdateAndGet() {
Cache<Id, Object> cache = newCache();
Id id = IdGenerator.of("1");
Assert.assertNull(cache.get(id));
cache.update(id, "value-1");
Assert.assertEquals("value-1", cache.get(id));
cache.update(id, "value-2");
Assert.assertEquals("value-2", cache.get(id));
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class LocksTableTest method testLockTableSameLock1MillionTimes.
@Test
public void testLockTableSameLock1MillionTimes() {
// ReadLock max lock times is 65535, this test ensures that there is no
// repeated locking in LocksTable
Id id = IdGenerator.of(1);
for (int i = 0; i < 1000000; i++) {
this.locksTable.lockReads("group", id);
}
LockUtil.Locks locks = Whitebox.getInternalState(this.locksTable, "locks");
Map<String, Set<Id>> table = Whitebox.getInternalState(this.locksTable, "table");
Assert.assertEquals(1, table.size());
Assert.assertTrue(table.containsKey("group"));
Set<Id> ids = table.get("group");
Assert.assertEquals(1, ids.size());
Set<Id> expect = ImmutableSet.of(id);
Assert.assertEquals(expect, ids);
List<Lock> lockList = Whitebox.getInternalState(locks, "lockList");
Assert.assertEquals(1, lockList.size());
this.locksTable.unlock();
Assert.assertEquals(0, table.size());
Assert.assertEquals(0, lockList.size());
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class LocksTableTest method testLocksTableDifferentGroupDifferentLocks.
@Test
public void testLocksTableDifferentGroupDifferentLocks() {
Id id1 = IdGenerator.of(1);
Id id2 = IdGenerator.of(2);
Id id3 = IdGenerator.of(3);
Id id4 = IdGenerator.of(4);
this.locksTable.lockReads("group", id1);
this.locksTable.lockReads("group", id2);
this.locksTable.lockReads("group", id3);
this.locksTable.lockReads("group", id4);
this.locksTable.lockReads("group1", id1);
this.locksTable.lockReads("group1", id2);
this.locksTable.lockReads("group1", id1);
LockUtil.Locks locks = Whitebox.getInternalState(this.locksTable, "locks");
Map<String, Set<Id>> table = Whitebox.getInternalState(this.locksTable, "table");
Assert.assertEquals(2, table.size());
Assert.assertTrue(table.containsKey("group"));
Assert.assertTrue(table.containsKey("group1"));
Set<Id> ids = table.get("group");
Assert.assertEquals(4, ids.size());
Set<Id> expect = ImmutableSet.of(id1, id2, id3, id4);
Assert.assertEquals(expect, ids);
ids = table.get("group1");
Assert.assertEquals(2, ids.size());
expect = ImmutableSet.of(id1, id2);
Assert.assertEquals(expect, ids);
List<Lock> lockList = Whitebox.getInternalState(locks, "lockList");
Assert.assertEquals(6, lockList.size());
this.locksTable.unlock();
Assert.assertEquals(0, table.size());
Assert.assertEquals(0, lockList.size());
}
Aggregations