use of com.datastax.oss.driver.api.core.AllNodesFailedException 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);
});
}
}
use of com.datastax.oss.driver.api.core.AllNodesFailedException in project java-driver by datastax.
the class DseProxyAuthenticationIT method should_not_allow_plain_text_unauthorized_user_to_login_as.
/**
* Validates that a connection does not succeed as user 'alice' using the credentials of a user
* 'steve' assuming 'steve' does not have PROXY.LOGIN authorization on alice.
*/
@Test
public void should_not_allow_plain_text_unauthorized_user_to_login_as() {
try (CqlSession session = SessionUtils.newSession(ads.ccm, SessionUtils.configLoaderBuilder().withString(DseDriverOption.AUTH_PROVIDER_AUTHORIZATION_ID, "alice").withString(DefaultDriverOption.AUTH_PROVIDER_USER_NAME, "steve").withString(DefaultDriverOption.AUTH_PROVIDER_PASSWORD, "fakePasswordForSteve").withClass(DefaultDriverOption.AUTH_PROVIDER_CLASS, PlainTextAuthProvider.class).build())) {
SimpleStatement select = SimpleStatement.builder("select * from aliceks.alicetable").build();
session.execute(select);
fail("Should have thrown AllNodesFailedException on login.");
} catch (AllNodesFailedException anfe) {
verifyException(anfe);
}
}
use of com.datastax.oss.driver.api.core.AllNodesFailedException in project java-driver by datastax.
the class ContinuousCqlRequestHandlerNodeTargetingTest method should_fail_if_targeted_node_not_available.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_fail_if_targeted_node_not_available(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withResponse(node1, defaultFrameOf(DseTestFixtures.singleDseRow())).withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow())).withEmptyPool(node3).withProtocolVersion(version).build()) {
LoadBalancingPolicyWrapper loadBalancingPolicy = harness.getContext().getLoadBalancingPolicyWrapper();
InOrder invocations = Mockito.inOrder(loadBalancingPolicy);
// target node3, which should be unavailable
CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT.setNode(node3), harness.getSession(), harness.getContext(), "target node 3, unavailable").handle();
assertThatStage(resultSetFuture).isFailed(error -> {
assertThat(error).isInstanceOf(AllNodesFailedException.class);
Map<Node, List<Throwable>> errors = ((AllNodesFailedException) error).getAllErrors();
assertThat(errors).hasSize(1);
List<Throwable> nodeErrors = errors.values().iterator().next();
assertThat(nodeErrors).singleElement().isInstanceOf(NodeUnavailableException.class);
invocations.verify(loadBalancingPolicy, never()).newQueryPlan(any(Request.class), anyString(), any(Session.class));
});
resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "no node targeting, should use node 1").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
assertThat(resultSet.getExecutionInfo().getCoordinator()).isEqualTo(node1);
invocations.verify(loadBalancingPolicy).newQueryPlan(UNDEFINED_IDEMPOTENCE_STATEMENT, DriverExecutionProfile.DEFAULT_NAME, harness.getSession());
});
resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "no node targeting, should use node 2").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
assertThat(resultSet.getExecutionInfo().getCoordinator()).isEqualTo(node2);
invocations.verify(loadBalancingPolicy).newQueryPlan(UNDEFINED_IDEMPOTENCE_STATEMENT, DriverExecutionProfile.DEFAULT_NAME, harness.getSession());
});
}
}
use of com.datastax.oss.driver.api.core.AllNodesFailedException in project java-driver by datastax.
the class NodeTargetingIT method should_fail_if_node_is_not_connected.
@Test
public void should_fail_if_node_is_not_connected() {
// given a statement with node explicitly set that for which we have no active pool.
Node node4 = getNode(4);
Statement statement = SimpleStatement.newInstance("select * system.local").setNode(node4);
try {
// when statement is executed
SESSION_RULE.session().execute(statement);
fail("Query should have failed");
} catch (NoNodeAvailableException e) {
assertThat(e.getAllErrors()).isEmpty();
} catch (AllNodesFailedException e) {
// its also possible that the query is tried. This can happen if the node was marked
// down, but not all connections have been closed yet. In this case, just verify that
// the expected host failed.
assertThat(e.getAllErrors().size()).isEqualTo(1);
assertThat(e.getAllErrors()).containsOnlyKeys(node4);
}
}
use of com.datastax.oss.driver.api.core.AllNodesFailedException in project java-driver by datastax.
the class ProtocolVersionInitialNegotiationIT method should_fail_if_provided_v5_is_not_supported_oss.
@CassandraRequirement(min = "2.1", max = "4.0-rc1", description = "Only C* in [2.1,4.0-rc1[ has V5 unsupported or supported as beta")
@Test
public void should_fail_if_provided_v5_is_not_supported_oss() {
Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V5").build();
try (CqlSession ignored = SessionUtils.newSession(ccm, loader)) {
fail("Expected an AllNodesFailedException");
} catch (AllNodesFailedException anfe) {
Throwable cause = anfe.getAllErrors().values().iterator().next().get(0);
assertThat(cause).isInstanceOf(UnsupportedProtocolVersionException.class);
UnsupportedProtocolVersionException unsupportedException = (UnsupportedProtocolVersionException) cause;
assertThat(unsupportedException.getAttemptedVersions()).containsOnly(DefaultProtocolVersion.V5);
}
}
Aggregations