Search in sources :

Example 1 with ProgrammaticArguments

use of com.datastax.oss.driver.api.core.session.ProgrammaticArguments 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)

Aggregations

DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)1 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)1 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)1 SchemaChangeListener (com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener)1 ProgrammaticArguments (com.datastax.oss.driver.api.core.session.ProgrammaticArguments)1