use of com.baidu.hugegraph.backend.cache.CachedGraphTransaction in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method testEdgeCacheClearWhenDeleteVertex.
@Test
public void testEdgeCacheClearWhenDeleteVertex() {
CachedGraphTransaction cache = this.cache();
HugeVertex v1 = this.newVertex(IdGenerator.of(1));
HugeVertex v2 = this.newVertex(IdGenerator.of(2));
HugeVertex v3 = this.newVertex(IdGenerator.of(3));
cache.addVertex(v1);
cache.addVertex(v2);
cache.commit();
HugeEdge edge = this.newEdge(v1, v2);
cache.addEdge(edge);
cache.commit();
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.removeVertex(v3);
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.removeVertex(v1);
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
Assert.assertFalse(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
}
use of com.baidu.hugegraph.backend.cache.CachedGraphTransaction in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method setup.
@Before
public void setup() {
HugeGraph graph = HugeFactory.open(FakeObjects.newConfig());
this.params = Whitebox.getInternalState(graph, "params");
this.cache = new CachedGraphTransaction(this.params, this.params.loadGraphStore());
}
use of com.baidu.hugegraph.backend.cache.CachedGraphTransaction in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method testEventInvalid.
@Test
public void testEventInvalid() throws Exception {
CachedGraphTransaction cache = this.cache();
cache.addVertex(this.newVertex(IdGenerator.of(1)));
cache.addVertex(this.newVertex(IdGenerator.of(2)));
cache.commit();
Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "verticesCache", "size"));
this.params.graphEventHub().notify(Events.CACHE, "invalid", HugeType.VERTEX, IdGenerator.of(1)).get();
Assert.assertEquals(1L, Whitebox.invoke(cache, "verticesCache", "size"));
Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext());
Assert.assertEquals(1L, Whitebox.invoke(cache, "verticesCache", "size"));
Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "verticesCache", "size"));
}
use of com.baidu.hugegraph.backend.cache.CachedGraphTransaction in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method testEventClear.
@Test
public void testEventClear() throws Exception {
CachedGraphTransaction cache = this.cache();
cache.addVertex(this.newVertex(IdGenerator.of(1)));
cache.addVertex(this.newVertex(IdGenerator.of(2)));
cache.commit();
Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "verticesCache", "size"));
this.params.graphEventHub().notify(Events.CACHE, "clear", null).get();
Assert.assertEquals(0L, Whitebox.invoke(cache, "verticesCache", "size"));
Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext());
Assert.assertEquals(1L, Whitebox.invoke(cache, "verticesCache", "size"));
Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "verticesCache", "size"));
}
use of com.baidu.hugegraph.backend.cache.CachedGraphTransaction in project incubator-hugegraph by apache.
the class CachedGraphTransactionTest method testEdgeCacheClearWhenUpdateVertex.
@Test
public void testEdgeCacheClearWhenUpdateVertex() {
CachedGraphTransaction cache = this.cache();
HugeVertex v1 = this.newVertex(IdGenerator.of(1));
HugeVertex v2 = this.newVertex(IdGenerator.of(2));
HugeVertex v3 = this.newVertex(IdGenerator.of(3));
cache.addVertex(v1);
cache.addVertex(v2);
cache.commit();
HugeEdge edge = this.newEdge(v1, v2);
cache.addEdge(edge);
cache.commit();
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.addVertexProperty(new HugeVertexProperty<>(v3, cache.graph().schema().getPropertyKey("name"), "test-name"));
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(1)).hasNext());
Assert.assertTrue(cache.queryEdgesByVertex(IdGenerator.of(2)).hasNext());
Assert.assertEquals(2L, Whitebox.invoke(cache, "edgesCache", "size"));
cache.addVertexProperty(new HugeVertexProperty<>(v1, cache.graph().schema().getPropertyKey("name"), "test-name"));
cache.commit();
Assert.assertEquals(0L, Whitebox.invoke(cache, "edgesCache", "size"));
String name = cache.queryEdgesByVertex(IdGenerator.of(1)).next().outVertex().value("name");
Assert.assertEquals("test-name", name);
}
Aggregations