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());
}
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);
}
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());
}
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;
}
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;
}
Aggregations