Search in sources :

Example 1 with RetryPolicy

use of com.datastax.oss.driver.api.core.retry.RetryPolicy in project java-driver by datastax.

the class PerProfileRetryPolicyIT method setup.

@BeforeClass
public static void setup() {
    // node 0 will return an unavailable to query.
    SIMULACRON_RULE.cluster().node(0).prime(when(QUERY_STRING).then(unavailable(com.datastax.oss.simulacron.common.codec.ConsistencyLevel.ONE, 1, 0)));
    // node 1 will return a valid empty rows response.
    SIMULACRON_RULE.cluster().node(1).prime(when(QUERY_STRING).then(noRows()));
    // sanity checks
    DriverContext context = SESSION_RULE.session().getContext();
    DriverConfig config = context.getConfig();
    assertThat(config.getProfiles()).containsKeys("profile1", "profile2");
    assertThat(context.getRetryPolicies()).hasSize(3).containsKeys(DriverExecutionProfile.DEFAULT_NAME, "profile1", "profile2");
    RetryPolicy defaultPolicy = context.getRetryPolicy(DriverExecutionProfile.DEFAULT_NAME);
    RetryPolicy policy1 = context.getRetryPolicy("profile1");
    RetryPolicy policy2 = context.getRetryPolicy("profile2");
    assertThat(defaultPolicy).isInstanceOf(DefaultRetryPolicy.class).isSameAs(policy2).isNotSameAs(policy1);
    assertThat(policy1).isInstanceOf(NoRetryPolicy.class);
}
Also used : DriverContext(com.datastax.oss.driver.api.core.context.DriverContext) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) RetryPolicy(com.datastax.oss.driver.api.core.retry.RetryPolicy) DefaultRetryPolicy(com.datastax.oss.driver.internal.core.retry.DefaultRetryPolicy) BeforeClass(org.junit.BeforeClass)

Example 2 with RetryPolicy

use of com.datastax.oss.driver.api.core.retry.RetryPolicy in project java-driver by datastax.

the class CqlPrepareHandlerTest method should_fail_if_retry_policy_ignores_error.

@Test
public void should_fail_if_retry_policy_ignores_error() {
    RequestHandlerTestHarness.Builder harnessBuilder = RequestHandlerTestHarness.builder().withResponse(node1, defaultFrameOf(new Error(ProtocolConstants.ErrorCode.OVERLOADED, "mock message")));
    PoolBehavior node2Behavior = harnessBuilder.customBehavior(node2);
    PoolBehavior node3Behavior = harnessBuilder.customBehavior(node3);
    try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
        // Make node1's error unrecoverable, will rethrow
        RetryPolicy mockRetryPolicy = harness.getContext().getRetryPolicy(DriverExecutionProfile.DEFAULT_NAME);
        when(mockRetryPolicy.onErrorResponseVerdict(eq(PREPARE_REQUEST), any(OverloadedException.class), eq(0))).thenReturn(RetryVerdict.IGNORE);
        CompletionStage<PreparedStatement> prepareFuture = new CqlPrepareHandler(PREPARE_REQUEST, harness.getSession(), harness.getContext(), "test").handle();
        // Success on node2, reprepare on node3
        assertThatStage(prepareFuture).isFailed(error -> {
            assertThat(error).isInstanceOf(IllegalArgumentException.class).hasMessage("IGNORE decisions are not allowed for prepare requests, " + "please fix your retry policy.");
            node2Behavior.verifyNoWrite();
            node3Behavior.verifyNoWrite();
        });
    }
}
Also used : Error(com.datastax.oss.protocol.internal.response.Error) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) OverloadedException(com.datastax.oss.driver.api.core.servererrors.OverloadedException) RetryPolicy(com.datastax.oss.driver.api.core.retry.RetryPolicy) Test(org.junit.Test)

Aggregations

RetryPolicy (com.datastax.oss.driver.api.core.retry.RetryPolicy)2 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)1 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 OverloadedException (com.datastax.oss.driver.api.core.servererrors.OverloadedException)1 DefaultRetryPolicy (com.datastax.oss.driver.internal.core.retry.DefaultRetryPolicy)1 Error (com.datastax.oss.protocol.internal.response.Error)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1