use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MicroProfileNodeMetricsUpdaterTest method should_log_warning_when_provided_eviction_time_setting_is_too_low.
@Test
public void should_log_warning_when_provided_eviction_time_setting_is_too_low() {
// 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);
Duration expireAfter = AbstractMetricUpdater.MIN_EXPIRE_AFTER.minusMinutes(1);
// 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);
MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {
@Override
protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Gauge<Number> supplier) {
// do nothing
}
@Override
protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
@Override
protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
};
// then
assertThat(updater.getExpireAfter()).isEqualTo(AbstractMetricUpdater.MIN_EXPIRE_AFTER);
verify(logger.appender, timeout(500).times(1)).doAppend(logger.loggingEventCaptor.capture());
assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains(String.format("[prefix] Value too low for %s: %s. Forcing to %s instead.", DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER.getPath(), expireAfter, AbstractMetricUpdater.MIN_EXPIRE_AFTER));
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MicroProfileNodeMetricsUpdaterTest 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);
MicroProfileNodeMetricUpdater updater = new MicroProfileNodeMetricUpdater(node, context, enabledMetrics, new MetricsRegistryImpl()) {
@Override
protected void initializeGauge(NodeMetric metric, DriverExecutionProfile profile, Gauge<Number> supplier) {
// do nothing
}
@Override
protected void initializeCounter(NodeMetric metric, DriverExecutionProfile profile) {
// do nothing
}
@Override
protected void initializeTimer(NodeMetric metric, DriverExecutionProfile profile) {
// 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 MicrometerNodeMetricUpdaterTest 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);
MetricIdGenerator generator = mock(MetricIdGenerator.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(context.getMetricIdGenerator()).thenReturn(generator);
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(expireAfter);
when(generator.nodeMetricId(node, DefaultNodeMetric.CQL_MESSAGES)).thenReturn(METRIC_ID);
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_HIGHEST)).thenReturn(Duration.ofSeconds(10));
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_LOWEST)).thenReturn(Duration.ofMillis(1));
when(profile.getInt(DefaultDriverOption.METRICS_NODE_CQL_MESSAGES_DIGITS)).thenReturn(5);
MicrometerNodeMetricUpdater updater = new MicrometerNodeMetricUpdater(node, context, enabledMetrics, new SimpleMeterRegistry());
// 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 Conversions method resolveExecutionProfile.
public static DriverExecutionProfile resolveExecutionProfile(Request request, DriverContext context) {
if (request.getExecutionProfile() != null) {
return request.getExecutionProfile();
} else {
DriverConfig config = context.getConfig();
String profileName = request.getExecutionProfileName();
return (profileName == null || profileName.isEmpty()) ? config.getDefaultProfile() : config.getProfile(profileName);
}
}
use of com.datastax.oss.driver.api.core.config.DriverConfig 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());
}
}
Aggregations