use of com.datastax.oss.driver.api.core.AllNodesFailedException in project java-driver by datastax.
the class AllNodesFailedIT method should_report_multiple_errors_per_node.
@Test
public void should_report_multiple_errors_per_node() {
SIMULACRON_RULE.cluster().prime(when("SELECT foo").then(readTimeout(ONE, 0, 0, false)));
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withClass(DefaultDriverOption.RETRY_POLICY_CLASS, MultipleRetryPolicy.class).build();
try (CqlSession session = (CqlSession) SessionUtils.baseBuilder().addContactEndPoints(SIMULACRON_RULE.getContactPoints()).withConfigLoader(loader).build()) {
// when executing a query.
session.execute("SELECT foo");
fail("AllNodesFailedException expected");
} catch (AllNodesFailedException ex) {
assertThat(ex.getAllErrors()).hasSize(2);
Iterator<Entry<Node, List<Throwable>>> iterator = ex.getAllErrors().entrySet().iterator();
// first node should have been tried twice
Entry<Node, List<Throwable>> node1Errors = iterator.next();
assertThat(node1Errors.getValue()).hasSize(2);
// second node should have been tried twice
Entry<Node, List<Throwable>> node2Errors = iterator.next();
assertThat(node2Errors.getValue()).hasSize(2);
}
}
use of com.datastax.oss.driver.api.core.AllNodesFailedException in project java-driver by datastax.
the class ProtocolVersionInitialNegotiationIT method should_fail_if_provided_v4_is_not_supported_oss.
@CassandraRequirement(max = "2.2", description = "Only C* in [*,2.2[ has V4 unsupported")
@Test
public void should_fail_if_provided_v4_is_not_supported_oss() {
Assume.assumeFalse("This test is only for OSS C*", ccm.getDseVersion().isPresent());
DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withString(DefaultDriverOption.PROTOCOL_VERSION, "V4").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.V4);
}
}
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_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.oss.driver.api.core.AllNodesFailedException in project java-driver by datastax.
the class DseProxyAuthenticationIT method should_not_allow_kerberos_unauthorized_user_to_login_as.
/**
* Validates that a connection does not succeed as user 'alice' using the credentials of a
* principal 'charlie@DATASTAX.COM' assuming 'charlie@DATASTAX.COM' does not have PROXY.LOGIN
* authorization on alice.
*/
@Test
public void should_not_allow_kerberos_unauthorized_user_to_login_as() throws Exception {
try (CqlSession session = ads.newKeyTabSession(charliePrincipal, ads.getKeytabForPrincipal(charliePrincipal).getAbsolutePath(), "alice")) {
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 CloudIT method should_fail_with_auth_error_when_connecting_using_bundle_with_username_password_in_config_json.
@Test
public void should_fail_with_auth_error_when_connecting_using_bundle_with_username_password_in_config_json() {
Path bundle = proxyRule.getProxy().getDefaultBundlePath();
// fails with auth error because username/password from config.json is ignored
AllNodesFailedException exception = null;
try {
CqlSession.builder().withCloudSecureConnectBundle(bundle).build();
} catch (AllNodesFailedException ex) {
exception = ex;
}
assertThat(exception).isNotNull();
List<Throwable> errors = exception.getAllErrors().values().iterator().next();
Throwable firstError = errors.get(0);
assertThat(firstError).isInstanceOf(AuthenticationException.class);
}
Aggregations