use of com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet 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.AsyncGraphResultSet in project java-driver by datastax.
the class ContinuousGraphRequestHandlerTest method should_honor_default_timeout.
@Test
public void should_honor_default_timeout() throws Exception {
// given
GraphBinaryModule binaryModule = createGraphBinaryModule(mockContext);
Duration defaultTimeout = Duration.ofSeconds(1);
RequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphTimeout(defaultTimeout);
PoolBehavior node1Behavior = builder.customBehavior(node);
try (RequestHandlerTestHarness harness = builder.build()) {
DriverExecutionProfile profile = harness.getContext().getConfig().getDefaultProfile();
when(profile.isDefined(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(true);
when(profile.getString(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(GraphProtocol.GRAPH_BINARY_1_0.toInternalCode());
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery");
// when
ContinuousGraphRequestHandler handler = new ContinuousGraphRequestHandler(graphStatement, harness.getSession(), harness.getContext(), "test", binaryModule, new GraphSupportChecker());
// send the initial request
CompletionStage<AsyncGraphResultSet> page1Future = handler.handle();
// acknowledge the write, will set the global timeout
node1Behavior.verifyWrite();
node1Behavior.setWriteSuccess();
CapturedTimeout globalTimeout = harness.nextScheduledTimeout();
assertThat(globalTimeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(defaultTimeout.toNanos());
// will trigger the global timeout and complete it exceptionally
globalTimeout.task().run(globalTimeout);
assertThat(page1Future.toCompletableFuture()).isCompletedExceptionally();
assertThatThrownBy(() -> page1Future.toCompletableFuture().get()).hasRootCauseExactlyInstanceOf(DriverTimeoutException.class).hasMessageContaining("Query timed out after " + defaultTimeout);
}
}
use of com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet 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");
}
use of com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_handle_asynchronous_execution_graphson.
@Test
public void should_handle_asynchronous_execution_graphson() {
Assumptions.assumeThat(isGraphBinary()).isFalse();
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().property("name").value());
}
} 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");
}
use of com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet in project java-driver by datastax.
the class ContinuousGraphRequestHandlerSpeculativeExecutionTest method should_fail_if_no_more_nodes_and_initial_execution_is_last.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "idempotentGraphConfig")
public void should_fail_if_no_more_nodes_and_initial_execution_is_last(boolean defaultIdempotence, GraphStatement<?> statement) throws Exception {
GraphRequestHandlerTestHarness.Builder harnessBuilder = GraphRequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
PoolBehavior node1Behavior = harnessBuilder.customBehavior(node1);
harnessBuilder.withResponse(node2, defaultDseFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message")));
try (GraphRequestHandlerTestHarness harness = harnessBuilder.build()) {
SpeculativeExecutionPolicy speculativeExecutionPolicy = harness.getContext().getSpeculativeExecutionPolicy(DriverExecutionProfile.DEFAULT_NAME);
long firstExecutionDelay = 100L;
when(speculativeExecutionPolicy.nextExecution(any(Node.class), eq(null), eq(statement), eq(1))).thenReturn(firstExecutionDelay);
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
CompletionStage<AsyncGraphResultSet> resultSetFuture = new ContinuousGraphRequestHandler(statement, harness.getSession(), harness.getContext(), "test", module, graphSupportChecker).handle();
node1Behavior.verifyWrite();
node1Behavior.setWriteSuccess();
// do not simulate a response from node1 yet
// Run the next scheduled task to start the speculative execution. node2 will reply with a
// BOOTSTRAPPING error, causing a RETRY_NEXT; but the query plan is now empty so the
// speculative execution stops.
// next scheduled timeout should be the first speculative execution. Get it and run it.
CapturedTimeout speculativeExecution1 = harness.nextScheduledTimeout();
assertThat(speculativeExecution1.getDelay(TimeUnit.MILLISECONDS)).isEqualTo(firstExecutionDelay);
speculativeExecution1.task().run(speculativeExecution1);
// node1 now replies with the same response, that triggers a RETRY_NEXT
node1Behavior.setResponseSuccess(defaultDseFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message")));
// But again the query plan is empty so that should fail the request
assertThatStage(resultSetFuture).isFailed(error -> {
assertThat(error).isInstanceOf(AllNodesFailedException.class);
Map<Node, List<Throwable>> nodeErrors = ((AllNodesFailedException) error).getAllErrors();
assertThat(nodeErrors).containsOnlyKeys(node1, node2);
assertThat(nodeErrors.get(node1).get(0)).isInstanceOf(BootstrappingException.class);
assertThat(nodeErrors.get(node2).get(0)).isInstanceOf(BootstrappingException.class);
});
}
}
Aggregations