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);
}
Aggregations