Search in sources :

Example 21 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphRequestHandler method setFinalResult.

private void setFinalResult(Result resultMessage, Frame responseFrame, NodeResponseCallback callback) {
    try {
        ExecutionInfo executionInfo = buildExecutionInfo(callback, responseFrame);
        DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(callback.statement, context);
        GraphProtocol subProtocol = GraphConversions.resolveGraphSubProtocol(callback.statement, graphSupportChecker, context);
        Queue<GraphNode> graphNodes = new ArrayDeque<>();
        for (List<ByteBuffer> row : ((Rows) resultMessage).getData()) {
            if (subProtocol.isGraphBinary()) {
                graphNodes.offer(GraphConversions.createGraphBinaryGraphNode(row, GraphRequestHandler.this.graphBinaryModule));
            } else {
                graphNodes.offer(GraphSONUtils.createGraphNode(row, subProtocol));
            }
        }
        DefaultAsyncGraphResultSet resultSet = new DefaultAsyncGraphResultSet(executionInfo, graphNodes, subProtocol);
        if (result.complete(resultSet)) {
            cancelScheduledTasks();
            throttler.signalSuccess(this);
            // Only call nanoTime() if we're actually going to use it
            long completionTimeNanos = NANOTIME_NOT_MEASURED_YET, totalLatencyNanos = NANOTIME_NOT_MEASURED_YET;
            if (!(requestTracker instanceof NoopRequestTracker)) {
                completionTimeNanos = System.nanoTime();
                totalLatencyNanos = completionTimeNanos - startTimeNanos;
                long nodeLatencyNanos = completionTimeNanos - callback.nodeStartTimeNanos;
                requestTracker.onNodeSuccess(callback.statement, nodeLatencyNanos, executionProfile, callback.node, logPrefix);
                requestTracker.onSuccess(callback.statement, totalLatencyNanos, executionProfile, callback.node, logPrefix);
            }
            if (sessionMetricUpdater.isEnabled(DseSessionMetric.GRAPH_REQUESTS, executionProfile.getName())) {
                if (completionTimeNanos == NANOTIME_NOT_MEASURED_YET) {
                    completionTimeNanos = System.nanoTime();
                    totalLatencyNanos = completionTimeNanos - startTimeNanos;
                }
                sessionMetricUpdater.updateTimer(DseSessionMetric.GRAPH_REQUESTS, executionProfile.getName(), totalLatencyNanos, TimeUnit.NANOSECONDS);
            }
        }
        // log the warnings if they have NOT been disabled
        if (!executionInfo.getWarnings().isEmpty() && executionProfile.getBoolean(DefaultDriverOption.REQUEST_LOG_WARNINGS) && LOG.isWarnEnabled()) {
            logServerWarnings(callback.statement, executionInfo.getWarnings());
        }
    } catch (Throwable error) {
        setFinalError(callback.statement, error, callback.node, NO_SUCCESSFUL_EXECUTION);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultExecutionInfo(com.datastax.oss.driver.internal.core.cql.DefaultExecutionInfo) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) ByteBuffer(java.nio.ByteBuffer) ArrayDeque(java.util.ArrayDeque) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) Rows(com.datastax.oss.protocol.internal.response.result.Rows)

Example 22 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphTraversalITBase method should_allow_use_of_dsl_graphson.

/**
 * A simple smoke test to ensure that a user can supply a custom {@link GraphTraversalSource} for
 * use with DSLs.
 *
 * @test_category dse:graph
 */
@Test
public void should_allow_use_of_dsl_graphson() throws Exception {
    Assumptions.assumeThat(isGraphBinary()).isFalse();
    SocialTraversalSource gSocial = socialTraversalSource();
    GraphStatement gs = newInstance(gSocial.persons("marko").knows("vadas"));
    GraphResultSet rs = session().execute(gs);
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(1);
    assertThat(results.get(0).asVertex()).hasProperty("name", "marko").hasProperty("age", 29).hasLabel("person");
}
Also used : GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) FluentGraphStatement(com.datastax.dse.driver.api.core.graph.FluentGraphStatement) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) SocialTraversalSource(com.datastax.dse.driver.api.core.graph.SocialTraversalSource) Test(org.junit.Test)

Example 23 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphTraversalITBase method should_handle_subgraph_graphson.

/**
 * Ensures that a traversal that returns a sub graph can be retrieved.
 *
 * <p>The subgraph is all members in a knows relationship, thus is all people who marko knows and
 * the edges that connect them.
 */
@Test
public void should_handle_subgraph_graphson() {
    Assumptions.assumeThat(isGraphBinary()).isFalse();
    GraphResultSet rs = session().execute(newInstance(graphTraversalSource().E().hasLabel("knows").subgraph("subGraph").cap("subGraph")));
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(1);
    Graph graph = results.get(0).as(Graph.class);
    assertThat(graph.edges()).toIterable().hasSize(2);
    assertThat(graph.vertices()).toIterable().hasSize(3);
}
Also used : Graph(org.apache.tinkerpop.gremlin.structure.Graph) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test)

Example 24 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphTraversalITBase method should_handle_subgraph_grap_binary.

/**
 * Ensures that a traversal that returns a sub graph can be retrieved.
 *
 * <p>The subgraph is all members in a knows relationship, thus is all people who marko knows and
 * the edges that connect them.
 */
@Test
public void should_handle_subgraph_grap_binary() {
    Assumptions.assumeThat(isGraphBinary()).isTrue();
    GraphResultSet rs = session().execute(newInstance(graphTraversalSource().E().hasLabel("knows").subgraph("subGraph").cap("subGraph")));
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(1);
    String graph = results.get(0).as(String.class);
    assertThat(graph).contains("vertices:3").contains("edges:2");
}
Also used : AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test)

Example 25 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphTraversalITBase method should_use_edge_id_as_parameter.

/**
 * Ensures that a previously returned {@link Edge}'s {@link Edge#id()} can be used as an input to
 * {@link
 * org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource#E(Object...)} to
 * retrieve the {@link Edge} and that the returned {@link Edge} is the same.
 *
 * @test_category dse:graph
 */
@Test
public void should_use_edge_id_as_parameter() {
    GraphTraversal<Edge, Edge> query = graphTraversalSource().E().has("weight", 0.2f);
    GraphResultSet resultSet = session().execute(newInstance(query));
    List<GraphNode> results = resultSet.all();
    assertThat(results.size()).isEqualTo(1);
    Edge created = results.get(0).asEdge();
    if (isGraphBinary()) {
        Map<Object, Object> properties = session().execute(newInstance(query.elementMap("weight", "software", "person"))).one().asMap();
        assertThatContainsProperties(properties, "weight", 0.2f);
        assertThatContainsLabel(properties, Direction.IN, "software");
        assertThatContainsLabel(properties, Direction.OUT, "person");
    } else {
        assertThat(created).hasProperty("weight", 0.2f).hasInVLabel("software").hasOutVLabel("person");
    }
    if (isGraphBinary()) {
        Map<Object, Object> inProperties = session().execute(newInstance(graphTraversalSource().E(created.id()).inV().elementMap("name", "lang"))).one().asMap();
        assertThatContainsProperties(inProperties, "name", "lop", "lang", "java");
    } else {
        resultSet = session().execute(newInstance(graphTraversalSource().E(created.id()).inV()));
        results = resultSet.all();
        assertThat(results.size()).isEqualTo(1);
        Vertex lop = results.get(0).asVertex();
        assertThat(lop).hasLabel("software").hasProperty("name", "lop").hasProperty("lang", "java");
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Aggregations

GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)41 Test (org.junit.Test)34 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)19 GraphResultSet (com.datastax.dse.driver.api.core.graph.GraphResultSet)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)4 FluentGraphStatement (com.datastax.dse.driver.api.core.graph.FluentGraphStatement)3 GraphStatement (com.datastax.dse.driver.api.core.graph.GraphStatement)3 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)3 SocialTraversalSource (com.datastax.dse.driver.api.core.graph.SocialTraversalSource)3 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)3 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)3 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)3 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)3 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)3 ByteBuffer (java.nio.ByteBuffer)3 DetachedVertex (org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex)3 ArrayDeque (java.util.ArrayDeque)2 Map (java.util.Map)2