Search in sources :

Example 6 with DriverConfig

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");
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest) Test(org.junit.Test) LoggerTest(com.datastax.oss.driver.internal.core.util.LoggerTest)

Example 7 with DriverConfig

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);
}
Also used : SchemaChangeListener(com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) ProgrammaticArguments(com.datastax.oss.driver.api.core.session.ProgrammaticArguments)

Example 8 with DriverConfig

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();
}
Also used : LocalServerChannel(io.netty.channel.local.LocalServerChannel) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) CompletableFuture(java.util.concurrent.CompletableFuture) NettyOptions(com.datastax.oss.driver.internal.core.context.NettyOptions) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) NodeMetricUpdater(com.datastax.oss.driver.internal.core.metrics.NodeMetricUpdater) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) Compressor(com.datastax.oss.protocol.internal.Compressor) DefaultDriverOption(com.datastax.oss.driver.api.core.config.DefaultDriverOption) Message(com.datastax.oss.protocol.internal.Message) ByteBuf(io.netty.buffer.ByteBuf) ProtocolVersionRegistry(com.datastax.oss.driver.internal.core.ProtocolVersionRegistry) LocalChannel(io.netty.channel.local.LocalChannel) EventBus(com.datastax.oss.driver.internal.core.context.EventBus) ByteBufPrimitiveCodec(com.datastax.oss.driver.internal.core.protocol.ByteBufPrimitiveCodec) Duration(java.time.Duration) After(org.junit.After) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) ProtocolVersion(com.datastax.oss.driver.api.core.ProtocolVersion) Ready(com.datastax.oss.protocol.internal.response.Ready) Before(org.junit.Before) ChannelInitializer(io.netty.channel.ChannelInitializer) FrameCodec(com.datastax.oss.protocol.internal.FrameCodec) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Mockito.when(org.mockito.Mockito.when) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Assertions.fail(org.assertj.core.api.Assertions.fail) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) TestResponses(com.datastax.oss.driver.internal.core.TestResponses) Frame(com.datastax.oss.protocol.internal.Frame) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Optional(java.util.Optional) Startup(com.datastax.oss.protocol.internal.request.Startup) Options(com.datastax.oss.protocol.internal.request.Options) Collections(java.util.Collections) Exchanger(java.util.concurrent.Exchanger) ChannelFuture(io.netty.channel.ChannelFuture) LocalChannel(io.netty.channel.local.LocalChannel) ByteBufPrimitiveCodec(com.datastax.oss.driver.internal.core.protocol.ByteBufPrimitiveCodec) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Before(org.junit.Before)

Example 9 with DriverConfig

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);
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DefaultDriverConfigLoader(com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Test(org.junit.Test)

Example 10 with DriverConfig

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);
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Aggregations

DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)46 Test (org.junit.Test)31 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)22 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)16 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)10 Node (com.datastax.oss.driver.api.core.metadata.Node)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 OptionsMap (com.datastax.oss.driver.api.core.config.OptionsMap)7 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 DriverContext (com.datastax.oss.driver.api.core.context.DriverContext)4 MetricIdGenerator (com.datastax.oss.driver.internal.core.metrics.MetricIdGenerator)4 DseNodeMetric (com.datastax.dse.driver.api.core.metrics.DseNodeMetric)3 DefaultDriverOption (com.datastax.oss.driver.api.core.config.DefaultDriverOption)3 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 Duration (java.time.Duration)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)2 DriverOption (com.datastax.oss.driver.api.core.config.DriverOption)2