use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphSupportCheckerTest method statementGraphPagingEnabled.
private void statementGraphPagingEnabled(GraphStatement graphStatement, PagingEnabledOptions option) {
DriverExecutionProfile driverExecutionProfile = mock(DriverExecutionProfile.class);
when(driverExecutionProfile.getString(DseDriverOption.GRAPH_PAGING_ENABLED)).thenReturn(option.name());
when(graphStatement.getExecutionProfile()).thenReturn(driverExecutionProfile);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_script_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_script_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
ScriptGraphStatement graphStatement = ScriptGraphStatement.newInstance("mockQuery").setQueryParam("p1", 1L).setQueryParam("p2", Uuids.random());
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(Query.class);
Query q = ((Query) m);
assertThat(q.query).isEqualTo("mockQuery");
assertThat(q.options.positionalValues).containsExactly(serialize(graphStatement.getQueryParams(), graphProtocol, module));
assertThat(q.options.namedValues).isEmpty();
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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.DriverExecutionProfile in project java-driver by datastax.
the class ReconnectionPolicyInfoFinderTest method should_find_an_info_about_constant_reconnection_policy.
@Test
public void should_find_an_info_about_constant_reconnection_policy() {
// given
DriverExecutionProfile driverExecutionProfile = mock(DriverExecutionProfile.class);
when(driverExecutionProfile.getDuration(DefaultDriverOption.RECONNECTION_BASE_DELAY)).thenReturn(Duration.ofMillis(100));
ReconnectionPolicy constantReconnectionPolicy = mock(ConstantReconnectionPolicy.class);
// when
ReconnectionPolicyInfo reconnectionPolicyInfo = new ReconnectionPolicyInfoFinder().getReconnectionPolicyInfo(constantReconnectionPolicy, driverExecutionProfile);
// then
assertThat(reconnectionPolicyInfo.getOptions()).contains(MapEntry.entry("delayMs", 100L));
assertThat(reconnectionPolicyInfo.getType()).contains("ConstantReconnectionPolicy");
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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;
}
Aggregations