Search in sources :

Example 66 with Id

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

Example 67 with 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());
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 68 with Id

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

Example 69 with 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());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) LockUtil(com.baidu.hugegraph.util.LockUtil) Id(com.baidu.hugegraph.backend.id.Id) Lock(java.util.concurrent.locks.Lock) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 70 with Id

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());
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) LockUtil(com.baidu.hugegraph.util.LockUtil) Id(com.baidu.hugegraph.backend.id.Id) Lock(java.util.concurrent.locks.Lock) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)381 Test (org.junit.Test)124 HugeGraph (com.baidu.hugegraph.HugeGraph)104 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)71 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)54 Timed (com.codahale.metrics.annotation.Timed)41 Produces (jakarta.ws.rs.Produces)40 AuthManager (com.baidu.hugegraph.auth.AuthManager)39 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)37 ArrayList (java.util.ArrayList)35 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)33 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)33 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)32 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)32 Directions (com.baidu.hugegraph.type.define.Directions)29 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)25 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)25 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)24 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 HugeType (com.baidu.hugegraph.type.HugeType)21