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_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();
}
use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.
the class ContinuousGraphRequestHandlerTest method should_return_paged_results.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_return_paged_results(GraphProtocol graphProtocol) throws IOException {
String profileName = "test-graph";
when(nodeMetricUpdater1.isEnabled(DseNodeMetric.GRAPH_MESSAGES, profileName)).thenReturn(true);
GraphBinaryModule module = createGraphBinaryModule(mockContext);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol);
PoolBehavior node1Behavior = builder.customBehavior(node);
try (RequestHandlerTestHarness harness = builder.build()) {
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName(profileName);
ContinuousGraphRequestHandler handler = new ContinuousGraphRequestHandler(graphStatement, harness.getSession(), harness.getContext(), "test", module, new GraphSupportChecker());
// send the initial request
CompletionStage<AsyncGraphResultSet> page1Future = handler.handle();
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, module, 1, false)));
assertThatStage(page1Future).isSuccess(page1 -> {
assertThat(page1.hasMorePages()).isTrue();
assertThat(page1.currentPage()).hasSize(10).allMatch(GraphNode::isVertex);
ExecutionInfo executionInfo = page1.getRequestExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
});
AsyncGraphResultSet page1 = CompletableFutures.getCompleted(page1Future);
CompletionStage<AsyncGraphResultSet> page2Future = page1.fetchNextPage();
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, module, 2, true)));
assertThatStage(page2Future).isSuccess(page2 -> {
assertThat(page2.hasMorePages()).isFalse();
assertThat(page2.currentPage()).hasSize(10).allMatch(GraphNode::isVertex);
ExecutionInfo executionInfo = page2.getRequestExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
});
validateMetrics(profileName, harness);
}
}
use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.
the class GraphNodeTest method should_check_if_node_is_vertex.
@Test
@UseDataProvider("allGraphProtocols")
public void should_check_if_node_is_vertex(GraphProtocol graphProtocol) throws IOException {
// when
GraphNode vertexNode = serdeAndCreateGraphNode(new DetachedVertex("a", "l", null), graphProtocol);
// then
assertThat(vertexNode.isVertex()).isTrue();
assertThat(vertexNode.asVertex()).isNotNull();
}
use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.
the class GraphNodeTest method should_check_if_node_is_path.
@Test
@UseDataProvider("objectGraphNodeProtocols")
public void should_check_if_node_is_path(GraphProtocol graphProtocol) throws IOException {
// when
GraphNode pathNode = serdeAndCreateGraphNode(EmptyPath.instance(), graphProtocol);
// then
assertThat(pathNode.isPath()).isTrue();
assertThat(pathNode.asPath()).isNotNull();
}
use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.
the class GraphNodeTest method should_create_graph_node_for_map.
@Test
@UseDataProvider("allGraphProtocols")
public void should_create_graph_node_for_map(GraphProtocol graphProtocol) throws IOException {
// when
GraphNode graphNode = serdeAndCreateGraphNode(ImmutableMap.of("value", 1234), graphProtocol);
// then
assertThat(graphNode.isMap()).isTrue();
Map<String, Integer> result = graphNode.asMap();
assertThat(result).isEqualTo(ImmutableMap.of("value", 1234));
}
Aggregations