Search in sources :

Example 6 with GraphResultSet

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

the class GraphTraversalITBase method should_use_vertex_id_as_parameter.

/**
 * Ensures that a previously returned {@link Vertex}'s {@link Vertex#id()} can be used as an input
 * to {@link
 * org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource#V(Object...)} to
 * retrieve the {@link Vertex} and that the returned {@link Vertex} is the same.
 *
 * @test_category dse:graph
 */
@Test
public void should_use_vertex_id_as_parameter() {
    GraphTraversal<Vertex, Vertex> query = graphTraversalSource().V().hasLabel("person").has("name", "marko");
    GraphResultSet resultSet = session().execute(newInstance(query));
    List<GraphNode> results = resultSet.all();
    assertThat(results.size()).isEqualTo(1);
    Vertex marko = results.get(0).asVertex();
    if (isGraphBinary()) {
        Map<Object, Object> properties = session().execute(newInstance(query.elementMap("name"))).one().asMap();
        assertThatContainsProperties(properties, "name", "marko");
    } else {
        assertThat(marko).hasProperty("name", "marko");
    }
    resultSet = session().execute(newInstance(graphTraversalSource().V(marko.id())));
    results = resultSet.all();
    assertThat(results.size()).isEqualTo(1);
    Vertex marko2 = results.get(0).asVertex();
    // Ensure that the returned vertex is the same as the first.
    assertThat(marko2).isEqualTo(marko);
}
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) Test(org.junit.Test)

Example 7 with GraphResultSet

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

the class GraphTraversalITBase method should_resolve_path_without_labels.

/**
 * Validates that when traversing a path and labeling none of the elements during the traversal
 * that all the labels are empty in the result.
 *
 * @test_category dse:graph
 */
@Test
public void should_resolve_path_without_labels() {
    GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").has("name", "marko").outE("knows").inV().outE("created").inV().path()));
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(2);
    for (GraphNode result : results) {
        Path path = result.asPath();
        validatePathObjects(path);
        assertThat(path.labels()).hasSize(5);
        for (int i = 0; i < 5; i++) assertThat(path).hasNoLabel(i);
    }
}
Also used : Path(org.apache.tinkerpop.gremlin.process.traversal.Path) 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 8 with GraphResultSet

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

the class GraphTraversalITBase method should_allow_use_of_dsl_graph_binary.

/**
 * 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_graph_binary() throws Exception {
    Assumptions.assumeThat(isGraphBinary()).isTrue();
    SocialTraversalSource gSocial = socialTraversalSource();
    GraphStatement gs = newInstance(gSocial.persons("marko").knows("vadas").elementMap("name", "age"));
    GraphResultSet rs = session().execute(gs);
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(1);
    assertThatContainsProperties(results.get(0).asMap(), "name", "marko", "age", 29);
    Assertions.assertThat(results.get(0).asMap().values()).contains("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 9 with GraphResultSet

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

the class GraphTraversalMetaPropertiesIT method should_parse_meta_properties.

/**
 * Ensures that a traversal that yields a vertex with a property that has its own properties that
 * is appropriately parsed and made accessible via {@link VertexProperty#property(String)}.
 *
 * @test_category dse:graph
 */
@Test
public void should_parse_meta_properties() {
    SESSION_RULE.session().execute(ScriptGraphStatement.newInstance(META_PROPS));
    GraphResultSet result = SESSION_RULE.session().execute(newInstance(g.addV("meta_v").property("meta_prop", "hello", "sub_prop", "hi", "sub_prop2", "hi2")));
    Vertex v = result.one().asVertex();
    assertThat(v).hasProperty("meta_prop");
    VertexProperty<String> metaProp = v.property("meta_prop");
    assertThat(metaProp).hasValue("hello").hasProperty("sub_prop", "hi").hasProperty("sub_prop2", "hi2");
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) Test(org.junit.Test)

Example 10 with GraphResultSet

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

the class GraphRequestHandlerTest method should_invoke_request_tracker_and_update_metrics.

@Test
@UseDataProvider("dseVersionsWithDefaultGraphProtocol")
public void should_invoke_request_tracker_and_update_metrics(GraphProtocol graphProtocol, Version dseVersion) throws IOException {
    when(nodeMetricUpdater1.isEnabled(DseNodeMetric.GRAPH_MESSAGES, DriverExecutionProfile.DEFAULT_NAME)).thenReturn(true);
    GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol).withDseVersionInMetadata(dseVersion);
    PoolBehavior node1Behavior = builder.customBehavior(node);
    GraphRequestHandlerTestHarness harness = builder.build();
    GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
    GraphSupportChecker graphSupportChecker = mock(GraphSupportChecker.class);
    when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
    when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
    GraphRequestAsyncProcessor p = Mockito.spy(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker));
    when(p.getGraphBinaryModule()).thenReturn(module);
    RequestTracker requestTracker = mock(RequestTracker.class);
    when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
    GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery");
    node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(graphProtocol, module)));
    GraphResultSet grs = new GraphRequestSyncProcessor(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker)).process(graphStatement, harness.getSession(), harness.getContext(), "test-graph");
    List<GraphNode> nodes = grs.all();
    assertThat(nodes.size()).isEqualTo(1);
    GraphNode graphNode = nodes.get(0);
    assertThat(graphNode.isVertex()).isTrue();
    Vertex actual = graphNode.asVertex();
    assertThat(actual.label()).isEqualTo("person");
    assertThat(actual.id()).isEqualTo(1);
    if (!graphProtocol.isGraphBinary()) {
        // GraphBinary does not encode properties regardless of whether they are present in the
        // parent element or not :/
        assertThat(actual.property("name").id()).isEqualTo(11);
        assertThat(actual.property("name").value()).isEqualTo("marko");
    }
    verify(requestTracker).onSuccess(eq(graphStatement), anyLong(), any(DriverExecutionProfile.class), eq(node), matches(LOG_PREFIX_PER_REQUEST));
    verify(requestTracker).onNodeSuccess(eq(graphStatement), anyLong(), any(DriverExecutionProfile.class), eq(node), matches(LOG_PREFIX_PER_REQUEST));
    verifyNoMoreInteractions(requestTracker);
    verify(nodeMetricUpdater1).isEnabled(DseNodeMetric.GRAPH_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
    verify(nodeMetricUpdater1).updateTimer(eq(DseNodeMetric.GRAPH_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
    verifyNoMoreInteractions(nodeMetricUpdater1);
    verify(harness.getSession().getMetricUpdater()).isEnabled(DseSessionMetric.GRAPH_REQUESTS, DriverExecutionProfile.DEFAULT_NAME);
    verify(harness.getSession().getMetricUpdater()).updateTimer(eq(DseSessionMetric.GRAPH_REQUESTS), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
    verifyNoMoreInteractions(harness.getSession().getMetricUpdater());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

GraphResultSet (com.datastax.dse.driver.api.core.graph.GraphResultSet)22 Test (org.junit.Test)22 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)18 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)17 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)8 FluentGraphStatement (com.datastax.dse.driver.api.core.graph.FluentGraphStatement)4 GraphStatement (com.datastax.dse.driver.api.core.graph.GraphStatement)4 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)4 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)4 SocialTraversalSource (com.datastax.dse.driver.api.core.graph.SocialTraversalSource)3 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)2 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)2 InvalidQueryException (com.datastax.oss.driver.api.core.servererrors.InvalidQueryException)2 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Map (java.util.Map)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2 FluentGraphStatement.newInstance (com.datastax.dse.driver.api.core.graph.FluentGraphStatement.newInstance)1 TinkerGraphAssertions.assertThat (com.datastax.dse.driver.api.core.graph.TinkerGraphAssertions.assertThat)1