use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.
the class DropwizardMetricsFactoryTest method should_throw_if_registry_of_wrong_type.
@Test
public void should_throw_if_registry_of_wrong_type() {
// given
InternalDriverContext context = mock(InternalDriverContext.class);
DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
DriverConfig config = mock(DriverConfig.class);
List<String> enabledMetrics = Collections.singletonList(DefaultSessionMetric.CQL_REQUESTS.getPath());
// when
when(config.getDefaultProfile()).thenReturn(profile);
when(context.getConfig()).thenReturn(config);
when(context.getSessionName()).thenReturn("MockSession");
// registry object is not a registry type
when(context.getMetricRegistry()).thenReturn(Integer.MAX_VALUE);
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(Duration.ofHours(1));
when(profile.getStringList(DefaultDriverOption.METRICS_SESSION_ENABLED)).thenReturn(enabledMetrics);
// then
try {
new DropwizardMetricsFactory(context);
fail("MetricsFactory should require correct registry object type: " + MetricRegistry.class.getName());
} catch (IllegalArgumentException iae) {
assertThat(iae.getMessage()).isEqualTo("Unexpected Metrics registry object. " + "Expected registry object to be of type '%s', but was '%s'", MetricRegistry.class.getName(), Integer.class.getName());
}
}
use of com.datastax.oss.driver.internal.core.context.InternalDriverContext 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.internal.core.context.InternalDriverContext in project java-driver by datastax.
the class DropwizardMetricsIT method assertNodeMetricsNotEvicted.
@Override
protected void assertNodeMetricsNotEvicted(CqlSession session, Node node) {
InternalDriverContext context = (InternalDriverContext) session.getContext();
MetricRegistry registry = (MetricRegistry) context.getMetricRegistry();
assertThat(registry).isNotNull();
for (String id : nodeMetricIds(context, node)) {
assertThat(registry.getMetrics()).containsKey(id);
}
}
use of com.datastax.oss.driver.internal.core.context.InternalDriverContext 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);
}
use of com.datastax.oss.driver.internal.core.context.InternalDriverContext in project java-driver by datastax.
the class MicrometerMetricsIT method assertNodeMetricsNotEvicted.
@Override
protected void assertNodeMetricsNotEvicted(CqlSession session, Node node) {
InternalDriverContext context = (InternalDriverContext) session.getContext();
MetricIdGenerator metricIdGenerator = context.getMetricIdGenerator();
MeterRegistry registry = (MeterRegistry) context.getMetricRegistry();
assertThat(registry).isNotNull();
for (DefaultNodeMetric metric : ENABLED_NODE_METRICS) {
MetricId id = metricIdGenerator.nodeMetricId(node, metric);
Iterable<Tag> tags = MicrometerTags.toMicrometerTags(id.getTags());
Meter m = registry.find(id.getName()).tags(tags).meter();
assertThat(m).isNotNull();
}
}
Aggregations