Search in sources :

Example 1 with ConstantSpeculativeExecutionPolicy

use of com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy in project java-driver by datastax.

the class ConstantSpeculativeExecutionPolicyTest method should_return_delay_until_max.

@Test
public void should_return_delay_until_max() {
    mockOptions(3, 10);
    SpeculativeExecutionPolicy policy = new ConstantSpeculativeExecutionPolicy(context, DriverExecutionProfile.DEFAULT_NAME);
    // Initial execution starts, schedule first speculative execution
    assertThat(policy.nextExecution(null, null, request, 1)).isEqualTo(10);
    // First speculative execution starts, schedule second one
    assertThat(policy.nextExecution(null, null, request, 2)).isEqualTo(10);
    // Second speculative execution starts, we're at 3 => stop
    assertThat(policy.nextExecution(null, null, request, 3)).isNegative();
}
Also used : ConstantSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy) ConstantSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy) Test(org.junit.Test)

Example 2 with ConstantSpeculativeExecutionPolicy

use of com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy in project java-driver by datastax.

the class ReflectionTest method should_build_policies_per_profile.

@Test
public void should_build_policies_per_profile() {
    String configSource = "advanced.speculative-execution-policy {\n" + "  class = ConstantSpeculativeExecutionPolicy\n" + "  max-executions = 3\n" + "  delay = 100 milliseconds\n" + "}\n" + "profiles {\n" + // Inherits from default profile
    "  profile1 {}\n" + // Inherits but changes one option
    "  profile2 { \n" + "    advanced.speculative-execution-policy.max-executions = 2" + "  }\n" + // Same as previous profile, should share the same policy instance
    "  profile3 { \n" + "    advanced.speculative-execution-policy.max-executions = 2" + "  }\n" + // Completely overrides default profile
    "  profile4 { \n" + "    advanced.speculative-execution-policy.class = NoSpeculativeExecutionPolicy\n" + "  }\n" + "}\n";
    InternalDriverContext context = mock(InternalDriverContext.class);
    TypesafeDriverConfig config = new TypesafeDriverConfig(ConfigFactory.parseString(configSource));
    when(context.getConfig()).thenReturn(config);
    Map<String, SpeculativeExecutionPolicy> policies = Reflection.buildFromConfigProfiles(context, DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY, SpeculativeExecutionPolicy.class, "com.datastax.oss.driver.internal.core.specex");
    assertThat(policies).hasSize(5);
    SpeculativeExecutionPolicy defaultPolicy = policies.get(DriverExecutionProfile.DEFAULT_NAME);
    SpeculativeExecutionPolicy policy1 = policies.get("profile1");
    SpeculativeExecutionPolicy policy2 = policies.get("profile2");
    SpeculativeExecutionPolicy policy3 = policies.get("profile3");
    SpeculativeExecutionPolicy policy4 = policies.get("profile4");
    assertThat(defaultPolicy).isInstanceOf(ConstantSpeculativeExecutionPolicy.class).isSameAs(policy1);
    assertThat(policy2).isInstanceOf(ConstantSpeculativeExecutionPolicy.class).isSameAs(policy3);
    assertThat(policy4).isInstanceOf(NoSpeculativeExecutionPolicy.class);
}
Also used : TypesafeDriverConfig(com.datastax.oss.driver.internal.core.config.typesafe.TypesafeDriverConfig) ConstantSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy) NoSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.NoSpeculativeExecutionPolicy) SpeculativeExecutionPolicy(com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) ConstantSpeculativeExecutionPolicy(com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy) Test(org.junit.Test)

Aggregations

ConstantSpeculativeExecutionPolicy (com.datastax.oss.driver.internal.core.specex.ConstantSpeculativeExecutionPolicy)2 Test (org.junit.Test)2 SpeculativeExecutionPolicy (com.datastax.oss.driver.api.core.specex.SpeculativeExecutionPolicy)1 TypesafeDriverConfig (com.datastax.oss.driver.internal.core.config.typesafe.TypesafeDriverConfig)1 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)1 NoSpeculativeExecutionPolicy (com.datastax.oss.driver.internal.core.specex.NoSpeculativeExecutionPolicy)1