use of com.datastax.oss.driver.internal.core.cql.PoolBehavior in project java-driver by datastax.
the class ContinuousCqlRequestHandlerTest method should_cancel_future_if_session_cancelled.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_cancel_future_if_session_cancelled(DseProtocolVersion version) {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test");
CompletionStage<ContinuousAsyncResultSet> page1Future = handler.handle();
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
// will be discarded
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, false)));
ContinuousAsyncResultSet page1 = CompletableFutures.getUninterruptibly(page1Future);
page1.cancel();
assertThat(handler.getState()).isEqualTo(-2);
assertThat(page1.fetchNextPage()).isCancelled();
}
}
use of com.datastax.oss.driver.internal.core.cql.PoolBehavior in project java-driver by datastax.
the class ContinuousCqlRequestReactiveProcessorTest method should_complete_multi_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(DseProtocolVersion version) {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
Flowable<ReactiveRow> rowsPublisher = Flowable.fromPublisher(publisher).cache();
rowsPublisher.subscribe();
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, true)));
List<ReactiveRow> rows = rowsPublisher.toList().blockingGet();
assertThat(rows).hasSize(20);
ReactiveRow first = rows.get(0);
ExecutionInfo firstExecutionInfo = first.getExecutionInfo();
assertThat(firstExecutionInfo.getCoordinator()).isEqualTo(node1);
assertThat(firstExecutionInfo.getErrors()).isEmpty();
assertThat(firstExecutionInfo.getIncomingPayload()).isEmpty();
assertThat(firstExecutionInfo.getPagingState()).isNotNull();
assertThat(firstExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(firstExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(firstExecutionInfo.getWarnings()).isEmpty();
ReactiveRow inSecondPage = rows.get(10);
ExecutionInfo secondExecutionInfo = inSecondPage.getExecutionInfo();
assertThat(secondExecutionInfo.getCoordinator()).isEqualTo(node1);
assertThat(secondExecutionInfo.getErrors()).isEmpty();
assertThat(secondExecutionInfo.getIncomingPayload()).isEmpty();
assertThat(secondExecutionInfo.getPagingState()).isNull();
assertThat(secondExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(secondExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(secondExecutionInfo.getWarnings()).isEmpty();
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(firstExecutionInfo, secondExecutionInfo);
Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(first.getColumnDefinitions());
Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(first.wasApplied());
}
}
use of com.datastax.oss.driver.internal.core.cql.PoolBehavior 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());
}
}
use of com.datastax.oss.driver.internal.core.cql.PoolBehavior in project java-driver by datastax.
the class ReactiveGraphRequestProcessorTest method should_complete_multi_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersionsAndSupportedGraphProtocols", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(DseProtocolVersion version, GraphProtocol graphProtocol) throws IOException {
when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(true);
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 page 1
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 1, false)));
// emulate page 2
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 2, true)));
List<ReactiveGraphNode> rows = rowsPublisher.toList().blockingGet();
assertThat(rows).hasSize(20);
checkResultSet(rows);
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).hasSize(2).containsExactly(rows.get(0).getExecutionInfo(), rows.get(10).getExecutionInfo());
}
}
use of com.datastax.oss.driver.internal.core.cql.PoolBehavior 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