Search in sources :

Example 6 with AllNodesFailedException

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);
    }
}
Also used : Entry(java.util.Map.Entry) AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) Node(com.datastax.oss.driver.api.core.metadata.Node) Iterator(java.util.Iterator) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) List(java.util.List) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 7 with AllNodesFailedException

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);
    }
}
Also used : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) UnsupportedProtocolVersionException(com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) CassandraRequirement(com.datastax.oss.driver.api.testinfra.CassandraRequirement)

Example 8 with AllNodesFailedException

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);
        });
    }
}
Also used : PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) Error(com.datastax.oss.protocol.internal.response.Error) SpeculativeExecutionPolicy(com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) List(java.util.List) CapturedTimeout(com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 9 with AllNodesFailedException

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);
    }
}
Also used : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 10 with AllNodesFailedException

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);
}
Also used : Path(java.nio.file.Path) AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test)

Aggregations

AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)16 Test (org.junit.Test)16 CqlSession (com.datastax.oss.driver.api.core.CqlSession)8 Node (com.datastax.oss.driver.api.core.metadata.Node)8 List (java.util.List)6 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)5 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 SpeculativeExecutionPolicy (com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy)4 CapturedTimeout (com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout)4 Error (com.datastax.oss.protocol.internal.response.Error)4 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)3 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)2 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)2 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)2 UnsupportedProtocolVersionException (com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException)2 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)2 Statement (com.datastax.oss.driver.api.core.cql.Statement)2 CassandraRequirement (com.datastax.oss.driver.api.testinfra.CassandraRequirement)2 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)2 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)2