Search in sources :

Example 86 with DriverExecutionProfile

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);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile)

Example 87 with 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();
}
Also used : Message(com.datastax.oss.protocol.internal.Message) Query(com.datastax.oss.protocol.internal.request.Query) RawBytesQuery(com.datastax.dse.protocol.internal.request.RawBytesQuery) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 88 with DriverExecutionProfile

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;
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) SessionStateForNode(com.datastax.dse.driver.internal.core.insights.schema.SessionStateForNode) Node(com.datastax.oss.driver.api.core.metadata.Node) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) InsightMetadata(com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata) EndPoint(com.datastax.oss.driver.api.core.metadata.EndPoint) MetadataManager(com.datastax.oss.driver.internal.core.metadata.MetadataManager) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) ControlConnection(com.datastax.oss.driver.internal.core.control.ControlConnection) DefaultNode(com.datastax.oss.driver.internal.core.metadata.DefaultNode) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig)

Example 89 with DriverExecutionProfile

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");
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) ExponentialReconnectionPolicy(com.datastax.oss.driver.internal.core.connection.ExponentialReconnectionPolicy) ReconnectionPolicy(com.datastax.oss.driver.api.core.connection.ReconnectionPolicy) ConstantReconnectionPolicy(com.datastax.oss.driver.internal.core.connection.ConstantReconnectionPolicy) ReconnectionPolicyInfo(com.datastax.dse.driver.internal.core.insights.schema.ReconnectionPolicyInfo) Test(org.junit.Test)

Example 90 with DriverExecutionProfile

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

Aggregations

DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)140 Test (org.junit.Test)81 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)29 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)20 CqlSession (com.datastax.oss.driver.api.core.CqlSession)19 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)17 Node (com.datastax.oss.driver.api.core.metadata.Node)14 ByteBuffer (java.nio.ByteBuffer)13 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)12 Duration (java.time.Duration)11 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)10 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)10 Row (com.datastax.oss.driver.api.core.cql.Row)9 Test (org.junit.jupiter.api.Test)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 Message (com.datastax.oss.protocol.internal.Message)7 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)6 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)6