Search in sources :

Example 11 with GraphResultSet

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

the class GraphRequestHandlerTest method should_return_results_for_statements.

@Test
@UseDataProvider("supportedGraphProtocolsWithDseVersions")
public void should_return_results_for_statements(GraphProtocol graphProtocol, Version dseVersion) throws IOException {
    GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol).withDseVersionInMetadata(dseVersion);
    PoolBehavior node1Behavior = builder.customBehavior(node);
    GraphRequestHandlerTestHarness harness = builder.build();
    GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
    // ideally we would be able to provide a function here to
    // produce results instead of a static predefined response.
    // Function to which we would pass the harness instance or a (mocked)DriverContext.
    // Since that's not possible in the RequestHandlerTestHarness API at the moment, we
    // have to use another DseDriverContext and GraphBinaryModule here,
    // instead of reusing the one in the harness' DriverContext
    node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(graphProtocol, module)));
    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);
    GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName("test-graph");
    GraphResultSet grs = new GraphRequestSyncProcessor(p).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 vRead = graphNode.asVertex();
    assertThat(vRead.label()).isEqualTo("person");
    assertThat(vRead.id()).isEqualTo(1);
    if (!graphProtocol.isGraphBinary()) {
        // GraphBinary does not encode properties regardless of whether they are present in the
        // parent element or not :/
        assertThat(vRead.property("name").id()).isEqualTo(11);
        assertThat(vRead.property("name").value()).isEqualTo("marko");
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 12 with GraphResultSet

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

the class GraphResultSetsTest method should_create_result_set_from_single_page.

@Test
public void should_create_result_set_from_single_page() {
    // Given
    AsyncGraphResultSet page1 = mockPage(false, 0, 1, 2);
    // When
    GraphResultSet resultSet = GraphResultSets.toSync(page1);
    // Then
    assertThat(resultSet.getRequestExecutionInfo()).isSameAs(page1.getRequestExecutionInfo());
    Iterator<GraphNode> iterator = resultSet.iterator();
    assertNextRow(iterator, 0);
    assertNextRow(iterator, 1);
    assertNextRow(iterator, 2);
    assertThat(iterator.hasNext()).isFalse();
}
Also used : AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) 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 13 with GraphResultSet

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

the class GraphTraversalMultiPropertiesIT method should_parse_multiple_cardinality_properties.

/**
 * Ensures that a traversal that yields a vertex with a property name that is present multiple
 * times that the properties are parsed and made accessible via {@link
 * Vertex#properties(String...)}.
 *
 * @test_category dse:graph
 */
@Test
public void should_parse_multiple_cardinality_properties() {
    // given a schema that defines multiple cardinality properties.
    SESSION_RULE.session().execute(ScriptGraphStatement.newInstance(MULTI_PROPS));
    // when adding a vertex with a multiple cardinality property
    GraphResultSet result = SESSION_RULE.session().execute(newInstance(g.addV("multi_v").property("multi_prop", "Hello").property("multi_prop", "Sweet").property("multi_prop", "World")));
    Vertex v = result.one().asVertex();
    assertThat(v).hasProperty("multi_prop");
    Iterator<VertexProperty<String>> multiProp = v.properties("multi_prop");
    assertThat(multiProp).toIterable().extractingResultOf("value").containsExactly("Hello", "Sweet", "World");
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) Test(org.junit.Test)

Example 14 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_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 15 with GraphResultSet

use of com.datastax.dse.driver.api.core.graph.GraphResultSet 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)

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