use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class DropwizardNodeMetricUpdaterTest method should_not_log_warning_when_provided_eviction_time_setting_is_acceptable.
@Test
@UseDataProvider(value = "acceptableEvictionTimes")
public void should_not_log_warning_when_provided_eviction_time_setting_is_acceptable(Duration expireAfter) {
// given
LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(AbstractMetricUpdater.class, Level.WARN);
Node node = mock(Node.class);
InternalDriverContext context = mock(InternalDriverContext.class);
DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
DriverConfig config = mock(DriverConfig.class);
Set<NodeMetric> enabledMetrics = Collections.singleton(DefaultNodeMetric.CQL_MESSAGES);
// when
when(context.getSessionName()).thenReturn("prefix");
when(context.getConfig()).thenReturn(config);
when(config.getDefaultProfile()).thenReturn(profile);
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
DropwizardNodeMetricUpdater updater = new DropwizardNodeMetricUpdater(node, context, enabledMetrics, new MetricRegistry()) {
@Override
protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Supplier<Number> supplier) {
// do nothing
}
@Override
protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
@Override
protected void initializeHdrTimer(NodeMetric metric, DriverExecutionProfile profile, DriverOption highestLatency, DriverOption significantDigits, DriverOption interval) {
// do nothing
}
};
// then
assertThat(updater.getExpireAfter()).isEqualTo(expireAfter);
verify(logger.appender, timeout(500).times(0)).doAppend(logger.loggingEventCaptor.capture());
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class PerProfileLoadBalancingPolicyIT method setup.
@BeforeClass
public static void setup() {
// sanity checks
DriverContext context = SESSION_RULE.session().getContext();
DriverConfig config = context.getConfig();
assertThat(config.getProfiles()).containsKeys("profile1", "profile2");
assertThat(context.getLoadBalancingPolicies()).hasSize(3).containsKeys(DriverExecutionProfile.DEFAULT_NAME, "profile1", "profile2");
LoadBalancingPolicy defaultPolicy = context.getLoadBalancingPolicy(DriverExecutionProfile.DEFAULT_NAME);
LoadBalancingPolicy policy1 = context.getLoadBalancingPolicy("profile1");
LoadBalancingPolicy policy2 = context.getLoadBalancingPolicy("profile2");
assertThat(defaultPolicy).isSameAs(policy2).isNotSameAs(policy1);
for (Node node : SESSION_RULE.session().getMetadata().getNodes().values()) {
// if node is in dc2 it should be ignored, otherwise (dc1, dc3) it should be local.
NodeDistance expectedDistance = Objects.equals(node.getDatacenter(), "dc2") ? NodeDistance.IGNORED : NodeDistance.LOCAL;
assertThat(node.getDistance()).isEqualTo(expectedDistance);
}
}
use of com.datastax.oss.driver.api.core.config.DriverConfig 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.config.DriverConfig in project java-driver by datastax.
the class SpeculativeExecutionIT method buildSessionWithProfile.
private CqlSession buildSessionWithProfile(int defaultMaxSpeculativeExecutions, long defaultSpeculativeDelayMs, int profile1MaxSpeculativeExecutions, long profile1SpeculativeDelayMs) {
ProgrammaticDriverConfigLoaderBuilder builder = SessionUtils.configLoaderBuilder().withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofMillis(SPECULATIVE_DELAY * 10)).withBoolean(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE, true).withClass(DefaultDriverOption.LOAD_BALANCING_POLICY_CLASS, SortingLoadBalancingPolicy.class);
if (defaultMaxSpeculativeExecutions != -1 || defaultSpeculativeDelayMs != -1) {
builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, ConstantSpeculativeExecutionPolicy.class);
if (defaultMaxSpeculativeExecutions != -1) {
builder = builder.withInt(DefaultDriverOption.SPECULATIVE_EXECUTION_MAX, defaultMaxSpeculativeExecutions);
}
if (defaultSpeculativeDelayMs != -1) {
builder = builder.withDuration(DefaultDriverOption.SPECULATIVE_EXECUTION_DELAY, Duration.ofMillis(defaultSpeculativeDelayMs));
}
} else {
builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, NoSpeculativeExecutionPolicy.class);
}
builder = builder.startProfile("profile1");
if (profile1MaxSpeculativeExecutions != -1 || profile1SpeculativeDelayMs != -1) {
builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, ConstantSpeculativeExecutionPolicy.class);
if (profile1MaxSpeculativeExecutions != -1) {
builder = builder.withInt(DefaultDriverOption.SPECULATIVE_EXECUTION_MAX, profile1MaxSpeculativeExecutions);
}
if (profile1SpeculativeDelayMs != -1) {
builder = builder.withDuration(DefaultDriverOption.SPECULATIVE_EXECUTION_DELAY, Duration.ofMillis(profile1SpeculativeDelayMs));
}
} else {
builder = builder.withClass(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS, NoSpeculativeExecutionPolicy.class);
}
builder = builder.startProfile("profile2").withString(DefaultDriverOption.REQUEST_CONSISTENCY, "ONE");
CqlSession session = SessionUtils.newSession(SIMULACRON_RULE, builder.build());
// validate profile data
DriverContext context = session.getContext();
DriverConfig driverConfig = context.getConfig();
assertThat(driverConfig.getProfiles()).containsKeys("profile1", "profile2");
assertThat(context.getSpeculativeExecutionPolicies()).hasSize(3).containsKeys(DriverExecutionProfile.DEFAULT_NAME, "profile1", "profile2");
SpeculativeExecutionPolicy defaultPolicy = context.getSpeculativeExecutionPolicy(DriverExecutionProfile.DEFAULT_NAME);
SpeculativeExecutionPolicy policy1 = context.getSpeculativeExecutionPolicy("profile1");
SpeculativeExecutionPolicy policy2 = context.getSpeculativeExecutionPolicy("profile2");
Class<? extends SpeculativeExecutionPolicy> expectedDefaultPolicyClass = defaultMaxSpeculativeExecutions != -1 || defaultSpeculativeDelayMs != -1 ? ConstantSpeculativeExecutionPolicy.class : NoSpeculativeExecutionPolicy.class;
assertThat(defaultPolicy).isInstanceOf(expectedDefaultPolicyClass).isSameAs(policy2);
// If configuration was same, same policy instance should be used.
if (defaultMaxSpeculativeExecutions == profile1MaxSpeculativeExecutions && defaultSpeculativeDelayMs == profile1SpeculativeDelayMs) {
assertThat(defaultPolicy).isSameAs(policy1);
} else {
assertThat(defaultPolicy).isNotSameAs(policy1);
}
Class<? extends SpeculativeExecutionPolicy> expectedProfile1PolicyClass = profile1MaxSpeculativeExecutions != -1 || profile1SpeculativeDelayMs != -1 ? ConstantSpeculativeExecutionPolicy.class : NoSpeculativeExecutionPolicy.class;
assertThat(policy1).isInstanceOf(expectedProfile1PolicyClass);
return session;
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class CompositeDriverConfigLoader method getInitialConfig.
@NonNull
@Override
public DriverConfig getInitialConfig() {
DriverConfig primaryConfig = primaryConfigLoader.getInitialConfig();
DriverConfig fallbackConfig = fallbackConfigLoader.getInitialConfig();
return new CompositeDriverConfig(primaryConfig, fallbackConfig);
}
Aggregations