Search in sources :

Example 76 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class CacheTest method testMultiThreadsGetWith2Items.

@Test
public void testMultiThreadsGetWith2Items() {
    Cache<Id, Object> cache = newCache(10);
    Id id1 = IdGenerator.of("1");
    cache.update(id1, "value-1");
    Id id2 = IdGenerator.of("2");
    cache.update(id2, "value-2");
    Assert.assertEquals(2, cache.size());
    runWithThreads(THREADS_NUM, () -> {
        for (int i = 0; i < 10000 * 100; i++) {
            Assert.assertEquals("value-1", cache.get(id1));
            Assert.assertEquals("value-2", cache.get(id2));
            Assert.assertEquals("value-1", cache.get(id1));
        }
    });
    Assert.assertEquals(2, cache.size());
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 77 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class CacheTest method testMultiThreadsUpdateWithGtCapacity.

@Test
public void testMultiThreadsUpdateWithGtCapacity() {
    int limit = 80;
    Cache<Id, Object> cache = newCache(limit);
    runWithThreads(THREADS_NUM, () -> {
        int size = 10000 * 100;
        for (int i = 0; i < size; i++) {
            Id id = IdGenerator.of(Thread.currentThread().getName() + "-" + i);
            cache.update(id, "value-" + i);
        }
    });
    this.checkSize(cache, limit, null);
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 78 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class CacheTest method testMultiThreadsGetAndUpdate.

@Test
public void testMultiThreadsGetAndUpdate() {
    Cache<Id, Object> cache = newCache(10);
    Id id1 = IdGenerator.of("1");
    cache.update(id1, "value-1");
    Id id2 = IdGenerator.of("2");
    cache.update(id2, "value-2");
    Id id3 = IdGenerator.of("3");
    cache.update(id3, "value-3");
    Assert.assertEquals(3, cache.size());
    runWithThreads(THREADS_NUM, () -> {
        for (int i = 0; i < 10000 * 100; i++) {
            Assert.assertEquals("value-1", cache.get(id1));
            Assert.assertEquals("value-2", cache.get(id2));
            Assert.assertEquals("value-2", cache.get(id2));
            Assert.assertEquals("value-3", cache.get(id3));
            cache.update(id2, "value-2");
            Assert.assertEquals("value-1", cache.get(id1));
        }
    });
    Assert.assertEquals(3, cache.size());
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 79 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class TestGraph method initBackend.

@Watched
protected void initBackend() {
    BackendStoreSystemInfo sysInfo = this.graph.backendStoreSystemInfo();
    if (!sysInfo.exists()) {
        this.graph.initBackend();
    } else {
        // May reopen a closed graph
        assert sysInfo.exists() && !this.graph.closed();
    }
    Id id = IdGenerator.of("server-tinkerpop");
    this.graph.serverStarted(id, NodeRole.MASTER);
    this.initedBackend = true;
}
Also used : BackendStoreSystemInfo(com.baidu.hugegraph.backend.store.BackendStoreSystemInfo) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 80 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class CassandraStore method query.

@Override
public Iterator<BackendEntry> query(Query query) {
    this.checkOpened();
    HugeType type = CassandraTable.tableType(query);
    String tableName = query.olap() ? this.olapTableName(type) : type.string();
    CassandraTable table = this.table(tableName);
    Iterator<BackendEntry> entries = table.query(this.session(), query);
    // Merge olap results as needed
    Set<Id> olapPks = query.olapPks();
    if (this.isGraphStore && !olapPks.isEmpty()) {
        List<Iterator<BackendEntry>> iterators = new ArrayList<>();
        for (Id pk : olapPks) {
            Query q = query.copy();
            table = this.table(this.olapTableName(pk));
            iterators.add(table.query(this.session(), q));
        }
        entries = new MergeIterator<>(entries, iterators, BackendEntry::mergeable);
    }
    return entries;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Query(com.baidu.hugegraph.backend.query.Query) Iterator(java.util.Iterator) MergeIterator(com.baidu.hugegraph.backend.serializer.MergeIterator) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

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