Search in sources :

Example 1 with CachedGraphTransaction

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());
}
Also used : CachedGraphTransaction(com.baidu.hugegraph.backend.cache.CachedGraphTransaction) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 2 with CachedGraphTransaction

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());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) CachedGraphTransaction(com.baidu.hugegraph.backend.cache.CachedGraphTransaction) Before(org.junit.Before)

Example 3 with CachedGraphTransaction

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

Example 4 with CachedGraphTransaction

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

Example 5 with CachedGraphTransaction

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);
}
Also used : CachedGraphTransaction(com.baidu.hugegraph.backend.cache.CachedGraphTransaction) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) HugeVertex(com.baidu.hugegraph.structure.HugeVertex) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

CachedGraphTransaction (com.baidu.hugegraph.backend.cache.CachedGraphTransaction)5 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)4 Test (org.junit.Test)4 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)2 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)2 HugeGraph (com.baidu.hugegraph.HugeGraph)1 Before (org.junit.Before)1