use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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.DriverExecutionProfile in project java-driver by datastax.
the class MicroProfileMetricsFactoryTest method should_throw_if_wrong_or_missing_registry_type.
@Test
@UseDataProvider(value = "invalidRegistryTypes")
public void should_throw_if_wrong_or_missing_registry_type(Object registryObj, String expectedMsg) {
// 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(registryObj);
when(profile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(AbstractMetricUpdater.MIN_EXPIRE_AFTER);
when(profile.getStringList(DefaultDriverOption.METRICS_SESSION_ENABLED)).thenReturn(enabledMetrics);
// then
try {
new MicroProfileMetricsFactory(context);
fail("MetricsFactory should require correct registry object type: " + MetricRegistry.class.getName());
} catch (IllegalArgumentException iae) {
assertThat(iae.getMessage()).isEqualTo(expectedMsg);
}
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class MonotonicTimestampGenerator method buildClock.
private static Clock buildClock(DriverContext context) {
DriverExecutionProfile config = context.getConfig().getDefaultProfile();
boolean forceJavaClock = config.getBoolean(DefaultDriverOption.TIMESTAMP_GENERATOR_FORCE_JAVA_CLOCK, false);
return Clock.getInstance(forceJavaClock);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class ProfileIT method should_override_mapper_profile.
@Test
public void should_override_mapper_profile() {
DriverExecutionProfile clThreeProfile = SESSION_RULE.session().getContext().getConfig().getDefaultProfile().withString(DefaultDriverOption.REQUEST_CONSISTENCY, "THREE");
SimpleMapper mapper = mapperBuilder.withDefaultExecutionProfile(clThreeProfile).build();
SimpleDao dao = mapper.simpleDao(clTwoProfile);
assertClForAllQueries(dao, ConsistencyLevel.TWO);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphRequestHandler method logServerWarnings.
private void logServerWarnings(GraphStatement<?> statement, List<String> warnings) {
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
// use the RequestLogFormatter to format the query
StringBuilder statementString = new StringBuilder();
context.getRequestLogFormatter().appendRequest(statement, executionProfile.getInt(DefaultDriverOption.REQUEST_LOGGER_MAX_QUERY_LENGTH, RequestLogger.DEFAULT_REQUEST_LOGGER_MAX_QUERY_LENGTH), executionProfile.getBoolean(DefaultDriverOption.REQUEST_LOGGER_VALUES, RequestLogger.DEFAULT_REQUEST_LOGGER_SHOW_VALUES), executionProfile.getInt(DefaultDriverOption.REQUEST_LOGGER_MAX_VALUES, RequestLogger.DEFAULT_REQUEST_LOGGER_MAX_VALUES), executionProfile.getInt(DefaultDriverOption.REQUEST_LOGGER_MAX_VALUE_LENGTH, RequestLogger.DEFAULT_REQUEST_LOGGER_MAX_VALUE_LENGTH), statementString);
// log each warning separately
warnings.forEach((warning) -> LOG.warn("Query '{}' generated server side warning(s): {}", statementString, warning));
}
Aggregations