Search in sources :

Example 1 with Error

use of com.datastax.oss.protocol.internal.response.Error in project java-driver by datastax.

the class CqlRequestHandlerSpeculativeExecutionTest method should_fail_if_no_more_nodes_and_initial_execution_is_last.

@Test
@UseDataProvider("idempotentConfig")
public void should_fail_if_no_more_nodes_and_initial_execution_is_last(boolean defaultIdempotence, Statement<?> statement) throws Exception {
    RequestHandlerTestHarness.Builder harnessBuilder = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
    PoolBehavior node1Behavior = harnessBuilder.customBehavior(node1);
    harnessBuilder.withResponse(node2, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message")));
    try (RequestHandlerTestHarness 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);
        CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
        node1Behavior.verifyWrite();
        node1Behavior.setWriteSuccess();
        // do not simulate a response from node1 yet
        // Discard the timeout task
        harness.nextScheduledTimeout();
        // 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(defaultFrameOf(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 : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) Node(com.datastax.oss.driver.api.core.metadata.Node) Error(com.datastax.oss.protocol.internal.response.Error) SpeculativeExecutionPolicy(com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy) 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 2 with Error

use of com.datastax.oss.protocol.internal.response.Error in project java-driver by datastax.

the class CqlRequestHandlerSpeculativeExecutionTest method should_fail_if_no_more_nodes_and_speculative_execution_is_last.

@Test
@UseDataProvider("idempotentConfig")
public void should_fail_if_no_more_nodes_and_speculative_execution_is_last(boolean defaultIdempotence, Statement<?> statement) throws Exception {
    RequestHandlerTestHarness.Builder harnessBuilder = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
    PoolBehavior node1Behavior = harnessBuilder.customBehavior(node1);
    PoolBehavior node2Behavior = harnessBuilder.customBehavior(node2);
    try (RequestHandlerTestHarness 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);
        CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
        node1Behavior.verifyWrite();
        node1Behavior.setWriteSuccess();
        // do not simulate a response from node1 yet
        // Discard the timeout task
        harness.nextScheduledTimeout();
        // 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(defaultFrameOf(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(defaultFrameOf(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 : AllNodesFailedException(com.datastax.oss.driver.api.core.AllNodesFailedException) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) Node(com.datastax.oss.driver.api.core.metadata.Node) Error(com.datastax.oss.protocol.internal.response.Error) SpeculativeExecutionPolicy(com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy) 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 3 with Error

use of com.datastax.oss.protocol.internal.response.Error in project java-driver by datastax.

the class CqlRequestHandlerRetryTest method should_always_rethrow_query_validation_error.

@Test
@UseDataProvider("allIdempotenceConfigs")
public void should_always_rethrow_query_validation_error(boolean defaultIdempotence, Statement<?> statement) {
    try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.INVALID, "mock message"))).build()) {
        CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isFailed(error -> {
            assertThat(error).isInstanceOf(InvalidQueryException.class).hasMessage("mock message");
            verifyNoMoreInteractions(harness.getContext().getRetryPolicy(anyString()));
            verify(nodeMetricUpdater1).incrementCounter(DefaultNodeMetric.OTHER_ERRORS, DriverExecutionProfile.DEFAULT_NAME);
            verify(nodeMetricUpdater1, atMost(1)).isEnabled(DefaultNodeMetric.CQL_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
            verify(nodeMetricUpdater1).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
            verifyNoMoreInteractions(nodeMetricUpdater1);
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) Error(com.datastax.oss.protocol.internal.response.Error) ServerError(com.datastax.oss.driver.api.core.servererrors.ServerError) InvalidQueryException(com.datastax.oss.driver.api.core.servererrors.InvalidQueryException) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with Error

use of com.datastax.oss.protocol.internal.response.Error in project java-driver by datastax.

the class CqlRequestHandlerTrackerTest method should_invoke_request_tracker.

@Test
public void should_invoke_request_tracker() {
    try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(true).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
        RequestTracker requestTracker = mock(RequestTracker.class);
        when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
        CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isSuccess(resultSet -> {
            verify(requestTracker).onNodeError(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), any(BootstrappingException.class), anyLong(), any(DriverExecutionProfile.class), eq(node1), any(String.class));
            verify(requestTracker).onNodeSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), any(String.class));
            verify(requestTracker).onSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), any(String.class));
            verifyNoMoreInteractions(requestTracker);
        });
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Error(com.datastax.oss.protocol.internal.response.Error) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) BootstrappingException(com.datastax.oss.driver.api.core.servererrors.BootstrappingException) Test(org.junit.Test)

Example 5 with Error

use of com.datastax.oss.protocol.internal.response.Error in project java-driver by datastax.

the class CqlRequestHandlerTrackerTest method should_not_invoke_noop_request_tracker.

@Test
public void should_not_invoke_noop_request_tracker() {
    try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withDefaultIdempotence(true).withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(singleRow())).build()) {
        RequestTracker requestTracker = spy(new NoopRequestTracker(harness.getContext()));
        when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
        CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isSuccess(resultSet -> verifyNoMoreInteractions(requestTracker));
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) Error(com.datastax.oss.protocol.internal.response.Error) NoopRequestTracker(com.datastax.oss.driver.internal.core.tracker.NoopRequestTracker) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) Test(org.junit.Test)

Aggregations

Error (com.datastax.oss.protocol.internal.response.Error)27 Test (org.junit.Test)24 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)15 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)8 Node (com.datastax.oss.driver.api.core.metadata.Node)8 SpeculativeExecutionPolicy (com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy)8 CapturedTimeout (com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout)8 Frame (com.datastax.oss.protocol.internal.Frame)8 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)4 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)4 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)4 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)4 ServerError (com.datastax.oss.driver.api.core.servererrors.ServerError)4 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)4 DefaultNode (com.datastax.oss.driver.internal.core.metadata.DefaultNode)4 List (java.util.List)4 UnsupportedProtocolVersionException (com.datastax.oss.driver.api.core.UnsupportedProtocolVersionException)3 InetSocketAddress (java.net.InetSocketAddress)3 ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)2 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)2