use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class ConfigAntiPatternsFinderTest method mockDefaultProfile.
private InternalDriverContext mockDefaultProfile(boolean sslEngineFactoryClassDefined, boolean hostnameValidation) {
InternalDriverContext context = mock(InternalDriverContext.class);
DriverConfig driverConfig = mock(DriverConfig.class);
when(context.getConfig()).thenReturn(driverConfig);
DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
when(profile.isDefined(SSL_ENGINE_FACTORY_CLASS)).thenReturn(sslEngineFactoryClassDefined);
when(profile.getBoolean(SSL_HOSTNAME_VALIDATION, false)).thenReturn(hostnameValidation);
when(driverConfig.getDefaultProfile()).thenReturn(profile);
return context;
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class InsightsClientTest method mockDefaultDriverContext.
private DefaultDriverContext mockDefaultDriverContext() throws UnknownHostException {
DefaultDriverContext context = mock(DefaultDriverContext.class);
mockConnectionPools(context);
MetadataManager manager = mock(MetadataManager.class);
when(context.getMetadataManager()).thenReturn(manager);
Metadata metadata = mock(Metadata.class);
when(manager.getMetadata()).thenReturn(metadata);
Node node = mock(Node.class);
when(node.getExtras()).thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Objects.requireNonNull(Version.parse("6.0.5"))));
when(metadata.getNodes()).thenReturn(ImmutableMap.of(UUID.randomUUID(), node));
DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile();
DriverExecutionProfile nonDefaultExecutionProfile = mockNonDefaultRequestTimeoutExecutionProfile();
Map<String, String> startupOptions = new HashMap<>();
startupOptions.put(StartupOptionsBuilder.CLIENT_ID_KEY, "client-id");
startupOptions.put(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "1.0.0");
startupOptions.put(StartupOptionsBuilder.APPLICATION_NAME_KEY, "app-name");
startupOptions.put(StartupOptionsBuilder.DRIVER_VERSION_KEY, "2.x");
startupOptions.put(StartupOptionsBuilder.DRIVER_NAME_KEY, "DataStax Enterprise Java Driver");
when(context.getStartupOptions()).thenReturn(startupOptions);
when(context.getProtocolVersion()).thenReturn(DSE_V2);
DefaultNode contactPoint = mock(DefaultNode.class);
EndPoint contactEndPoint = mock(EndPoint.class);
when(contactEndPoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 9999));
when(contactPoint.getEndPoint()).thenReturn(contactEndPoint);
when(manager.getContactPoints()).thenReturn(ImmutableSet.of(contactPoint));
DriverConfig driverConfig = mock(DriverConfig.class);
when(context.getConfig()).thenReturn(driverConfig);
Map<String, DriverExecutionProfile> profiles = ImmutableMap.of("default", defaultExecutionProfile, "non-default", nonDefaultExecutionProfile);
Mockito.<Map<String, ? extends DriverExecutionProfile>>when(driverConfig.getProfiles()).thenReturn(profiles);
when(driverConfig.getDefaultProfile()).thenReturn(defaultExecutionProfile);
ControlConnection controlConnection = mock(ControlConnection.class);
DriverChannel channel = mock(DriverChannel.class);
EndPoint controlConnectionEndpoint = mock(EndPoint.class);
when(controlConnectionEndpoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 10));
when(channel.getEndPoint()).thenReturn(controlConnectionEndpoint);
when(channel.localAddress()).thenReturn(new InetSocketAddress("127.0.0.1", 10));
when(controlConnection.channel()).thenReturn(channel);
when(context.getControlConnection()).thenReturn(controlConnection);
return context;
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MicrometerMetricsFactoryTest method should_throw_if_wrong_or_missing_registry_type.
@Test
public void should_throw_if_wrong_or_missing_registry_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 MicrometerMetricsFactory(context);
fail("MetricsFactory should require correct registry object type: " + MeterRegistry.class.getName());
} catch (IllegalArgumentException iae) {
assertThat(iae.getMessage()).isEqualTo("Unexpected Metrics registry object. " + "Expected registry object to be of type '%s', but was '%s'", MeterRegistry.class.getName(), Integer.class.getName());
}
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MicrometerNodeMetricUpdaterTest method should_create_timer.
@Test
@UseDataProvider(value = "timerMetrics")
public void should_create_timer(NodeMetric metric, DriverOption lowest, DriverOption highest, DriverOption digits, DriverOption sla) {
// given
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(metric);
// 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(Duration.ofHours(1));
when(profile.getDuration(lowest)).thenReturn(Duration.ofMillis(10));
when(profile.getDuration(highest)).thenReturn(Duration.ofSeconds(1));
when(profile.getInt(digits)).thenReturn(5);
when(profile.isDefined(sla)).thenReturn(true);
when(profile.getDurationList(sla)).thenReturn(Arrays.asList(Duration.ofMillis(100), Duration.ofMillis(500)));
when(generator.nodeMetricId(node, metric)).thenReturn(METRIC_ID);
SimpleMeterRegistry registry = spy(new SimpleMeterRegistry());
MicrometerNodeMetricUpdater updater = new MicrometerNodeMetricUpdater(node, context, enabledMetrics, registry);
for (int i = 0; i < 10; i++) {
updater.updateTimer(metric, null, 100, TimeUnit.MILLISECONDS);
}
// then
Timer timer = registry.find(METRIC_ID.getName()).timer();
assertThat(timer).isNotNull();
assertThat(timer.count()).isEqualTo(10);
HistogramSnapshot snapshot = timer.takeSnapshot();
assertThat(snapshot.histogramCounts()).hasSize(2);
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MicrometerNodeMetricUpdaterTest 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);
MetricIdGenerator generator = mock(MetricIdGenerator.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(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(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));
}
Aggregations