Search in sources :

Example 6 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testMilCompleteEdges.

@Test
public void testMilCompleteEdges() {
    ArrayList<SqlgVertex> persons = createMilPersonVertex();
    ArrayList<SqlgVertex> cars = createMilCarVertex();
    this.sqlgGraph.tx().commit();
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.sqlgGraph.tx().streamingBatchModeOn();
    LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
    keyValues.put("name", "halo");
    keyValues.put("name2", "halo");
    for (int i = 0; i < NUMBER_OF_VERTICES; i++) {
        SqlgVertex person = persons.get(0);
        SqlgVertex car = cars.get(i);
        person.streamEdge("person_car", car, keyValues);
    }
    this.sqlgGraph.tx().commit();
    int mb = 1024 * 1024;
    // get Runtime instance
    Runtime instance = Runtime.getRuntime();
    System.out.println("***** Heap utilization statistics [MB] *****\n");
    // available memory
    System.out.println("Total Memory: " + instance.totalMemory() / mb);
    // free memory
    System.out.println("Free Memory: " + instance.freeMemory() / mb);
    // used memory
    System.out.println("Used Memory: " + (instance.totalMemory() - instance.freeMemory()) / mb);
    // Maximum available memory
    System.out.println("Max Memory: " + instance.maxMemory() / mb);
    Assert.assertEquals(NUMBER_OF_VERTICES, this.sqlgGraph.traversal().V(persons.get(0)).out("person_car").toList().size());
    stopWatch.stop();
    System.out.println("testMilCompleteEdges took " + stopWatch.toString());
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) StopWatch(org.apache.commons.lang3.time.StopWatch) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Example 7 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testStreamLocalTime.

@Test
public void testStreamLocalTime() throws InterruptedException {
    this.sqlgGraph.tx().streamingBatchModeOn();
    LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
    keyValues.put("name", "halo");
    keyValues.put("surname", "halo");
    for (int i = 0; i < 10; i++) {
        keyValues.put("age", i);
        this.sqlgGraph.streamVertex("Man", keyValues);
    }
    this.sqlgGraph.tx().flush();
    for (int i = 0; i < 10; i++) {
        keyValues.put("age", i);
        this.sqlgGraph.streamVertex("Female", keyValues);
    }
    this.sqlgGraph.tx().flush();
    int count = 0;
    List<Vertex> men = this.sqlgGraph.traversal().V().hasLabel("Man").toList();
    List<Vertex> females = this.sqlgGraph.traversal().V().hasLabel("Female").toList();
    LinkedHashMap<String, Object> edgeKeyValues = new LinkedHashMap<>();
    LocalTime localTime = LocalTime.now();
    edgeKeyValues.put("localTime", localTime);
    for (Vertex man : men) {
        SqlgVertex female = (SqlgVertex) females.get(count++);
        ((SqlgVertex) man).streamEdge("married", female, edgeKeyValues);
    }
    this.sqlgGraph.tx().commit();
    testStreamLocalTime_assert(this.sqlgGraph, localTime);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testStreamLocalTime_assert(this.sqlgGraph1, localTime);
    }
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Example 8 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testCanNotCreateBatchEdgeWhileBatchVertexInProgress.

@Test(expected = IllegalStateException.class)
public void testCanNotCreateBatchEdgeWhileBatchVertexInProgress() {
    SqlgVertex v1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "Dog");
    SqlgVertex v2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "House");
    this.sqlgGraph.tx().streamingBatchModeOn();
    LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
    keyValues.put("name", "test");
    this.sqlgGraph.streamVertex("A", keyValues);
    this.sqlgGraph.streamVertex("A", keyValues);
    v1.streamEdge("a", v2);
    Assert.fail();
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Example 9 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testStreamJson.

@Test
public void testStreamJson() throws InterruptedException {
    this.sqlgGraph.tx().streamingBatchModeOn();
    LinkedHashMap<String, Object> keyValues = new LinkedHashMap<>();
    keyValues.put("name", "halo");
    keyValues.put("surname", "halo");
    for (int i = 0; i < 10; i++) {
        keyValues.put("age", i);
        this.sqlgGraph.streamVertex("Man", keyValues);
    }
    this.sqlgGraph.tx().flush();
    for (int i = 0; i < 10; i++) {
        keyValues.put("age", i);
        this.sqlgGraph.streamVertex("Female", keyValues);
    }
    this.sqlgGraph.tx().flush();
    int count = 0;
    List<Vertex> men = this.sqlgGraph.traversal().V().hasLabel("Man").toList();
    List<Vertex> females = this.sqlgGraph.traversal().V().hasLabel("Female").toList();
    LinkedHashMap<String, Object> edgeKeyValues = new LinkedHashMap<>();
    ObjectMapper objectMapper = new ObjectMapper();
    ObjectNode json = new ObjectNode(objectMapper.getNodeFactory());
    json.put("username", "john");
    edgeKeyValues.put("doc", json);
    for (Vertex man : men) {
        SqlgVertex female = (SqlgVertex) females.get(count++);
        ((SqlgVertex) man).streamEdge("married", female, edgeKeyValues);
    }
    this.sqlgGraph.tx().commit();
    testStreamJson_assert(this.sqlgGraph, json);
    if (this.sqlgGraph1 != null) {
        Thread.sleep(SLEEP_TIME);
        testStreamJson_assert(this.sqlgGraph1, json);
    }
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedHashMap(java.util.LinkedHashMap) BaseTest(org.umlg.sqlg.test.BaseTest)

Example 10 with SqlgVertex

use of org.umlg.sqlg.structure.SqlgVertex in project sqlg by pietermartin.

the class TestBatchStreamEdge method testEdgeLabelRemainsTheSame.

@Test(expected = IllegalStateException.class)
public void testEdgeLabelRemainsTheSame() {
    SqlgVertex v1 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
    SqlgVertex v2 = (SqlgVertex) this.sqlgGraph.addVertex(T.label, "A");
    this.sqlgGraph.tx().commit();
    this.sqlgGraph.tx().streamingBatchModeOn();
    v1.streamEdge("a", v2);
    v1.streamEdge("b", v2);
    Assert.fail();
}
Also used : SqlgVertex(org.umlg.sqlg.structure.SqlgVertex) BaseTest(org.umlg.sqlg.test.BaseTest)

Aggregations

SqlgVertex (org.umlg.sqlg.structure.SqlgVertex)27 BaseTest (org.umlg.sqlg.test.BaseTest)22 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)17 LinkedHashMap (java.util.LinkedHashMap)16 StopWatch (org.apache.commons.lang3.time.StopWatch)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)3 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 PropertyType (org.umlg.sqlg.structure.PropertyType)1 SchemaTable (org.umlg.sqlg.structure.SchemaTable)1 VertexLabel (org.umlg.sqlg.structure.topology.VertexLabel)1