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);
}
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();
});
}
}
Aggregations