Search in sources :

Example 31 with GraphNode

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

the class GraphResultSetTestBase method assertNextRow.

protected void assertNextRow(Iterator<GraphNode> iterator, int expectedValue) {
    assertThat(iterator.hasNext()).isTrue();
    GraphNode row = iterator.next();
    assertThat(row.asInt()).isEqualTo(expectedValue);
}
Also used : GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode)

Example 32 with GraphNode

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

the class GraphResultSetsTest method should_create_result_set_from_multiple_pages.

@Test
public void should_create_result_set_from_multiple_pages() {
    // Given
    AsyncGraphResultSet page1 = mockPage(true, 0, 1, 2);
    AsyncGraphResultSet page2 = mockPage(true, 3, 4, 5);
    AsyncGraphResultSet page3 = mockPage(false, 6, 7, 8);
    complete(page1.fetchNextPage(), page2);
    complete(page2.fetchNextPage(), page3);
    // When
    GraphResultSet resultSet = GraphResultSets.toSync(page1);
    // Then
    assertThat(resultSet.iterator().hasNext()).isTrue();
    assertThat(resultSet.getRequestExecutionInfo()).isSameAs(page1.getRequestExecutionInfo());
    assertThat(((MultiPageGraphResultSet) resultSet).getRequestExecutionInfos()).containsExactly(page1.getRequestExecutionInfo());
    Iterator<GraphNode> iterator = resultSet.iterator();
    assertNextRow(iterator, 0);
    assertNextRow(iterator, 1);
    assertNextRow(iterator, 2);
    assertThat(iterator.hasNext()).isTrue();
    // This should have triggered the fetch of page2
    assertThat(resultSet.getRequestExecutionInfo()).isEqualTo(page2.getRequestExecutionInfo());
    assertThat(((MultiPageGraphResultSet) resultSet).getRequestExecutionInfos()).containsExactly(page1.getRequestExecutionInfo(), page2.getRequestExecutionInfo());
    assertNextRow(iterator, 3);
    assertNextRow(iterator, 4);
    assertNextRow(iterator, 5);
    assertThat(iterator.hasNext()).isTrue();
    // This should have triggered the fetch of page3
    assertThat(resultSet.getRequestExecutionInfo()).isEqualTo(page3.getRequestExecutionInfo());
    assertThat(((MultiPageGraphResultSet) resultSet).getRequestExecutionInfos()).containsExactly(page1.getRequestExecutionInfo(), page2.getRequestExecutionInfo(), page3.getRequestExecutionInfo());
    assertNextRow(iterator, 6);
    assertNextRow(iterator, 7);
    assertNextRow(iterator, 8);
}
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 33 with GraphNode

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

the class GraphTraversalITBase method should_resolve_path_with_labels.

/**
 * Validates that when traversing a path and labeling all of the elements during the traversal
 * that the output elements are properly labeled.
 *
 * @test_category dse:graph
 */
@Test
public void should_resolve_path_with_labels() {
    GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("person").has("name", "marko").as("a").outE("knows").as("b").inV().as("c", "d").outE("created").as("e", "f", "g").inV().as("h").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);
        assertThat(path).hasLabel(0, "a").hasLabel(1, "b").hasLabel(2, "c", "d").hasLabel(3, "e", "f", "g").hasLabel(4, "h");
    }
}
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 34 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 35 with GraphNode

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

the class GraphTraversalITBase method should_handle_asynchronous_execution_graph_binary.

@Test
public void should_handle_asynchronous_execution_graph_binary() {
    Assumptions.assumeThat(isGraphBinary()).isTrue();
    StringBuilder names = new StringBuilder();
    CompletionStage<AsyncGraphResultSet> future = session().executeAsync(FluentGraphStatement.newInstance(graphTraversalSource().V().hasLabel("person")));
    try {
        // dumb processing to make sure the completable future works correctly and correct results are
        // returned
        Iterable<GraphNode> results = future.thenApply(AsyncGraphResultSet::currentPage).toCompletableFuture().get();
        for (GraphNode gn : results) {
            names.append(gn.asVertex().id());
        }
    } catch (InterruptedException | ExecutionException e) {
        fail("Shouldn't have thrown an exception waiting for the result to complete");
    }
    assertThat(names.toString()).contains("peter", "marko", "vadas", "josh");
}
Also used : AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) ExecutionException(java.util.concurrent.ExecutionException) 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