use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class ContinuousGraphRequestHandlerSpeculativeExecutionTest method should_fail_if_no_more_nodes_and_speculative_execution_is_last.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "idempotentGraphConfig")
public void should_fail_if_no_more_nodes_and_speculative_execution_is_last(boolean defaultIdempotence, GraphStatement<?> statement) throws Exception {
GraphRequestHandlerTestHarness.Builder harnessBuilder = GraphRequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
PoolBehavior node1Behavior = harnessBuilder.customBehavior(node1);
PoolBehavior node2Behavior = harnessBuilder.customBehavior(node2);
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
// 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 a BOOTSTRAPPING error that triggers a RETRY_NEXT
// but the query plan is empty so the initial execution stops
node1Behavior.setResponseSuccess(defaultDseFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message")));
// Same thing with node2, so the speculative execution should reach the end of the query plan
// and fail the request
node2Behavior.setResponseSuccess(defaultDseFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message")));
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);
});
}
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class ContinuousGraphRequestHandlerSpeculativeExecutionTest method should_not_schedule_speculative_executions_if_not_idempotent.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "nonIdempotentGraphConfig")
public void should_not_schedule_speculative_executions_if_not_idempotent(boolean defaultIdempotence, GraphStatement<?> statement) {
GraphRequestHandlerTestHarness.Builder harnessBuilder = GraphRequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
PoolBehavior node1Behavior = harnessBuilder.customBehavior(node1);
try (GraphRequestHandlerTestHarness harness = harnessBuilder.build()) {
SpeculativeExecutionPolicy speculativeExecutionPolicy = harness.getContext().getSpeculativeExecutionPolicy(DriverExecutionProfile.DEFAULT_NAME);
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
new ContinuousGraphRequestHandler(statement, harness.getSession(), harness.getContext(), "test", module, graphSupportChecker).handle();
node1Behavior.verifyWrite();
node1Behavior.setWriteSuccess();
// should not schedule any timeout
assertThat(harness.nextScheduledTimeout()).isNull();
verifyNoMoreInteractions(speculativeExecutionPolicy);
verifyNoMoreInteractions(nodeMetricUpdater1);
}
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class ContinuousGraphRequestHandlerSpeculativeExecutionTest method should_stop_retrying_other_executions_if_result_complete.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "idempotentGraphConfig")
public void should_stop_retrying_other_executions_if_result_complete(boolean defaultIdempotence, GraphStatement<?> statement) throws Exception {
GraphRequestHandlerTestHarness.Builder harnessBuilder = GraphRequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
PoolBehavior node1Behavior = harnessBuilder.customBehavior(node1);
PoolBehavior node2Behavior = harnessBuilder.customBehavior(node2);
PoolBehavior node3Behavior = harnessBuilder.customBehavior(node3);
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();
// 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);
node2Behavior.verifyWrite();
node2Behavior.setWriteSuccess();
// Complete the request from the initial execution
node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(GraphProtocol.GRAPH_BINARY_1_0, module)));
assertThatStage(resultSetFuture).isSuccess();
// node2 replies with a response that would trigger a RETRY_NEXT if the request was still
// running
node2Behavior.setResponseSuccess(defaultDseFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message")));
// The speculative execution should not move to node3 because it is stopped
node3Behavior.verifyNoWrite();
}
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule 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());
}
use of com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule in project java-driver by datastax.
the class ReactiveGraphRequestProcessorTest method should_complete_single_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersionsAndSupportedGraphProtocols", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version, GraphProtocol graphProtocol) throws IOException {
when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (GraphRequestHandlerTestHarness harness = builder.build()) {
DefaultSession session = harness.getSession();
DefaultDriverContext context = harness.getContext();
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("g.V()");
GraphBinaryModule graphBinaryModule = createGraphBinaryModule(context);
when(asyncProcessor.getGraphBinaryModule()).thenReturn(graphBinaryModule);
ReactiveGraphResultSet publisher = new ReactiveGraphRequestProcessor(asyncProcessor).process(graphStatement, session, context, "test");
Flowable<ReactiveGraphNode> rowsPublisher = Flowable.fromPublisher(publisher).cache();
rowsPublisher.subscribe();
// emulate single page
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 1, true)));
List<ReactiveGraphNode> rows = rowsPublisher.toList().blockingGet();
assertThat(rows).hasSize(10);
checkResultSet(rows);
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).hasSize(1).containsExactly(rows.get(0).getExecutionInfo());
}
}
Aggregations