Search in sources :

Example 11 with GremlinRequest

use of com.baidu.hugegraph.api.gremlin.GremlinRequest in project incubator-hugegraph-toolchain by apache.

the class GremlinApiTest method testPrimitiveObject.

@Test
public void testPrimitiveObject() {
    GremlinRequest request = new GremlinRequest("1 + 2");
    ResultSet resultSet = gremlin().execute(request);
    Assert.assertEquals(1, resultSet.size());
    Iterator<Result> results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Integer.class, object.getClass());
        Assert.assertEquals(3, object);
    }
}
Also used : ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) GremlinRequest(com.baidu.hugegraph.api.gremlin.GremlinRequest) Result(com.baidu.hugegraph.structure.gremlin.Result) Test(org.junit.Test)

Example 12 with GremlinRequest

use of com.baidu.hugegraph.api.gremlin.GremlinRequest in project incubator-hugegraph-toolchain by apache.

the class GremlinApiTest method testAttachedManager.

@Test
public void testAttachedManager() {
    GremlinRequest request = new GremlinRequest("g.V()");
    ResultSet resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    Iterator<Result> results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Vertex.class, object.getClass());
        Vertex vertex = (Vertex) object;
        Assert.assertNotNull(Whitebox.getInternalState(vertex, "manager"));
    }
    request = new GremlinRequest("g.E()");
    resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Edge.class, object.getClass());
        Edge edge = (Edge) object;
        Assert.assertNotNull(Whitebox.getInternalState(edge, "manager"));
    }
    request = new GremlinRequest("g.V().outE().path()");
    resultSet = gremlin().execute(request);
    Assert.assertEquals(6, resultSet.size());
    results = resultSet.iterator();
    while (results.hasNext()) {
        Result result = results.next();
        Object object = result.getObject();
        Assert.assertEquals(Path.class, object.getClass());
        Path path = (Path) object;
        Assert.assertNotNull(path.objects());
        for (Object pathObject : path.objects()) {
            Assert.assertTrue(pathObject instanceof GraphAttachable);
            Assert.assertNotNull(Whitebox.getInternalState(pathObject, "manager"));
        }
        Assert.assertNull(path.crosspoint());
    }
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphAttachable(com.baidu.hugegraph.structure.constant.GraphAttachable) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) GremlinRequest(com.baidu.hugegraph.api.gremlin.GremlinRequest) Edge(com.baidu.hugegraph.structure.graph.Edge) Result(com.baidu.hugegraph.structure.gremlin.Result) Test(org.junit.Test)

Aggregations

GremlinRequest (com.baidu.hugegraph.api.gremlin.GremlinRequest)12 Test (org.junit.Test)11 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)9 Vertex (com.baidu.hugegraph.structure.graph.Vertex)2 Result (com.baidu.hugegraph.structure.gremlin.Result)2 HugeClient (com.baidu.hugegraph.driver.HugeClient)1 Task (com.baidu.hugegraph.structure.Task)1 GraphAttachable (com.baidu.hugegraph.structure.constant.GraphAttachable)1 Edge (com.baidu.hugegraph.structure.graph.Edge)1 Path (com.baidu.hugegraph.structure.graph.Path)1 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)1