Search in sources :

Example 11 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_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);
        });
    }
}
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 12 with AllNodesFailedException

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);
    }
}
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 13 with AllNodesFailedException

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());
        });
    }
}
Also used : InOrder(org.mockito.InOrder) AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) Node(com.datastax.oss.driver.api.core.metadata.Node) Request(com.datastax.oss.driver.api.core.session.Request) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) LoadBalancingPolicyWrapper(com.datastax.oss.driver.internal.core.metadata.LoadBalancingPolicyWrapper) List(java.util.List) Session(com.datastax.oss.driver.api.core.session.Session) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 14 with AllNodesFailedException

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);
    }
}
Also used : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Statement(com.datastax.oss.driver.api.core.cql.Statement) Node(com.datastax.oss.driver.api.core.metadata.Node) BoundNode(com.datastax.oss.simulacron.server.BoundNode) NoNodeAvailableException(com.datastax.oss.driver.api.core.NoNodeAvailableException) Test(org.junit.Test)

Example 15 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_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);
    }
}
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)

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