use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class NoopMetricsFactoryTest method should_log_warning_when_metrics_enabled.
@Test
public void should_log_warning_when_metrics_enabled() {
// given
InternalDriverContext context = mock(InternalDriverContext.class);
DriverConfig config = mock(DriverConfig.class);
DriverExecutionProfile profile = mock(DriverExecutionProfile.class);
when(context.getSessionName()).thenReturn("MockSession");
when(context.getConfig()).thenReturn(config);
when(config.getDefaultProfile()).thenReturn(profile);
when(profile.getStringList(DefaultDriverOption.METRICS_SESSION_ENABLED)).thenReturn(Collections.singletonList(DefaultSessionMetric.CQL_REQUESTS.getPath()));
LoggerTest.LoggerSetup logger = LoggerTest.setupTestLogger(NoopMetricsFactory.class, Level.WARN);
// when
new NoopMetricsFactory(context);
// then
verify(logger.appender, times(1)).doAppend(logger.loggingEventCaptor.capture());
assertThat(logger.loggingEventCaptor.getValue().getMessage()).isNotNull();
assertThat(logger.loggingEventCaptor.getValue().getFormattedMessage()).contains("[MockSession] Some session-level or node-level metrics were enabled");
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MockedDriverContextFactory method defaultDriverContext.
public static DefaultDriverContext defaultDriverContext(Optional<DriverExecutionProfile> profileOption) {
/* If the caller provided a profile use that, otherwise make a new one */
final DriverExecutionProfile profile = profileOption.orElseGet(() -> {
DriverExecutionProfile blankProfile = mock(DriverExecutionProfile.class);
when(blankProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")).thenReturn("none");
when(blankProfile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(Duration.ofMinutes(5));
when(blankProfile.isDefined(DefaultDriverOption.METRICS_FACTORY_CLASS)).thenReturn(true);
when(blankProfile.getString(DefaultDriverOption.METRICS_FACTORY_CLASS)).thenReturn("DefaultMetricsFactory");
return blankProfile;
});
/* Setup machinery to connect the input DriverExecutionProfile to the config loader */
final DriverConfig driverConfig = mock(DriverConfig.class);
final DriverConfigLoader configLoader = mock(DriverConfigLoader.class);
when(configLoader.getInitialConfig()).thenReturn(driverConfig);
when(driverConfig.getDefaultProfile()).thenReturn(profile);
ProgrammaticArguments args = ProgrammaticArguments.builder().withNodeStateListener(mock(NodeStateListener.class)).withSchemaChangeListener(mock(SchemaChangeListener.class)).withRequestTracker(mock(RequestTracker.class)).withLocalDatacenters(Maps.newHashMap()).withNodeDistanceEvaluators(Maps.newHashMap()).build();
return new DefaultDriverContext(configLoader, args);
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class ChannelFactoryTestBase method setup.
@Before
public void setup() throws InterruptedException {
MockitoAnnotations.initMocks(this);
serverGroup = new DefaultEventLoopGroup(1);
clientGroup = new DefaultEventLoopGroup(1);
when(context.getConfig()).thenReturn(driverConfig);
when(driverConfig.getDefaultProfile()).thenReturn(defaultProfile);
when(defaultProfile.isDefined(DefaultDriverOption.AUTH_PROVIDER_CLASS)).thenReturn(false);
when(defaultProfile.getDuration(DefaultDriverOption.CONNECTION_INIT_QUERY_TIMEOUT)).thenReturn(Duration.ofMillis(TIMEOUT_MILLIS));
when(defaultProfile.getDuration(DefaultDriverOption.CONNECTION_SET_KEYSPACE_TIMEOUT)).thenReturn(Duration.ofMillis(TIMEOUT_MILLIS));
when(defaultProfile.getInt(DefaultDriverOption.CONNECTION_MAX_REQUESTS)).thenReturn(1);
when(defaultProfile.getDuration(DefaultDriverOption.HEARTBEAT_INTERVAL)).thenReturn(Duration.ofSeconds(30));
when(defaultProfile.getDuration(DefaultDriverOption.CONNECTION_CONNECT_TIMEOUT)).thenReturn(Duration.ofSeconds(5));
when(context.getProtocolVersionRegistry()).thenReturn(protocolVersionRegistry);
when(context.getNettyOptions()).thenReturn(nettyOptions);
when(nettyOptions.ioEventLoopGroup()).thenReturn(clientGroup);
when(nettyOptions.channelClass()).thenAnswer((Answer<Object>) i -> LocalChannel.class);
when(nettyOptions.allocator()).thenReturn(ByteBufAllocator.DEFAULT);
when(context.getFrameCodec()).thenReturn(FrameCodec.defaultClient(new ByteBufPrimitiveCodec(ByteBufAllocator.DEFAULT), Compressor.none()));
when(context.getSslHandlerFactory()).thenReturn(Optional.empty());
when(context.getEventBus()).thenReturn(eventBus);
when(context.getWriteCoalescer()).thenReturn(new PassThroughWriteCoalescer(null));
when(context.getCompressor()).thenReturn(compressor);
// Start local server
ServerBootstrap serverBootstrap = new ServerBootstrap().group(serverGroup).channel(LocalServerChannel.class).localAddress(SERVER_ADDRESS.resolve()).childHandler(new ServerInitializer());
ChannelFuture channelFuture = serverBootstrap.bind().sync();
serverAcceptChannel = (LocalServerChannel) channelFuture.sync().channel();
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MapBasedDriverConfigLoaderTest method should_reflect_changes_in_real_time.
@Test
public void should_reflect_changes_in_real_time() {
OptionsMap source = new OptionsMap();
source.put(MockTypedOptions.INT1, 1);
DriverConfigLoader loader = DriverConfigLoader.fromMap(source);
DriverConfig config = loader.getInitialConfig();
assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(1);
source.put(MockTypedOptions.INT1, 2);
assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(2);
}
use of com.datastax.oss.driver.api.core.config.DriverConfig in project java-driver by datastax.
the class MapBasedDriverConfigTest method should_inherit_option_in_profile.
@Test
public void should_inherit_option_in_profile() {
OptionsMap source = new OptionsMap();
source.put(MockTypedOptions.INT1, 42);
// need to add an unrelated option to create the profile
source.put("profile1", MockTypedOptions.INT2, 1);
DriverConfig config = DriverConfigLoader.fromMap(source).getInitialConfig();
assertThat(config).hasIntOption(MockOptions.INT1, 42).hasIntOption("profile1", MockOptions.INT1, 42);
}
Aggregations