Search in sources :

Example 26 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class CompositeDriverExecutionProfile method entrySet.

@NonNull
@Override
public SortedSet<Map.Entry<String, Object>> entrySet() {
    DriverExecutionProfile primaryProfile = this.primaryProfile;
    DriverExecutionProfile fallbackProfile = this.fallbackProfile;
    if (primaryProfile != null && fallbackProfile != null) {
        SortedSet<Map.Entry<String, Object>> result = new TreeSet<>(Map.Entry.comparingByKey());
        result.addAll(fallbackProfile.entrySet());
        result.addAll(primaryProfile.entrySet());
        return ImmutableSortedSet.copyOf(Map.Entry.comparingByKey(), result);
    } else if (primaryProfile != null) {
        return primaryProfile.entrySet();
    } else {
        assert fallbackProfile != null;
        return fallbackProfile.entrySet();
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) TreeSet(java.util.TreeSet) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 27 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class DriverExecutionProfileCcmIT method should_use_profile_page_size.

@Test
public void should_use_profile_page_size() {
    DriverConfigLoader loader = SessionUtils.configLoaderBuilder().withInt(DefaultDriverOption.REQUEST_PAGE_SIZE, 100).startProfile("smallpages").withInt(DefaultDriverOption.REQUEST_PAGE_SIZE, 10).build();
    try (CqlSession session = SessionUtils.newSession(CCM_RULE, loader)) {
        CqlIdentifier keyspace = SessionUtils.uniqueKeyspaceId();
        DriverExecutionProfile slowProfile = SessionUtils.slowProfile(session);
        SessionUtils.createKeyspace(session, keyspace, slowProfile);
        session.execute(String.format("USE %s", keyspace.asCql(false)));
        // load 500 rows (value beyond page size).
        session.execute(SimpleStatement.builder("CREATE TABLE IF NOT EXISTS test (k int, v int, PRIMARY KEY (k,v))").setExecutionProfile(slowProfile).build());
        PreparedStatement prepared = session.prepare("INSERT INTO test (k, v) values (0, ?)");
        BatchStatementBuilder bs = BatchStatement.builder(DefaultBatchType.UNLOGGED).setExecutionProfile(slowProfile);
        for (int i = 0; i < 500; i++) {
            bs.addStatement(prepared.bind(i));
        }
        session.execute(bs.build());
        String query = "SELECT * FROM test where k=0";
        // Execute query without profile, should use global page size (100)
        CompletionStage<AsyncResultSet> future = session.executeAsync(query);
        AsyncResultSet result = CompletableFutures.getUninterruptibly(future);
        assertThat(result.remaining()).isEqualTo(100);
        result = CompletableFutures.getUninterruptibly(result.fetchNextPage());
        // next fetch should also be 100 pages.
        assertThat(result.remaining()).isEqualTo(100);
        // Execute query with profile, should use profile page size
        future = session.executeAsync(SimpleStatement.builder(query).setExecutionProfileName("smallpages").build());
        result = CompletableFutures.getUninterruptibly(future);
        assertThat(result.remaining()).isEqualTo(10);
        // next fetch should also be 10 pages.
        result = CompletableFutures.getUninterruptibly(result.fetchNextPage());
        assertThat(result.remaining()).isEqualTo(10);
        SessionUtils.dropKeyspace(session, keyspace, slowProfile);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) BatchStatementBuilder(com.datastax.oss.driver.api.core.cql.BatchStatementBuilder) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) CqlSession(com.datastax.oss.driver.api.core.CqlSession) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Test(org.junit.Test)

Example 28 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class ChannelSocketOptionsIT method should_report_socket_options.

@Test
public void should_report_socket_options() {
    Session session = SESSION_RULE.session();
    DriverExecutionProfile config = session.getContext().getConfig().getDefaultProfile();
    assertThat(config.getBoolean(SOCKET_TCP_NODELAY)).isTrue();
    assertThat(config.getBoolean(SOCKET_KEEP_ALIVE)).isFalse();
    assertThat(config.getBoolean(SOCKET_REUSE_ADDRESS)).isFalse();
    assertThat(config.getInt(SOCKET_LINGER_INTERVAL)).isEqualTo(10);
    assertThat(config.getInt(SOCKET_RECEIVE_BUFFER_SIZE)).isEqualTo(123456);
    assertThat(config.getInt(SOCKET_SEND_BUFFER_SIZE)).isEqualTo(123456);
    Node node = session.getMetadata().getNodes().values().iterator().next();
    if (session instanceof SessionWrapper) {
        session = ((SessionWrapper) session).getDelegate();
    }
    DriverChannel channel = ((DefaultSession) session).getChannel(node, "test");
    assertThat(channel).isNotNull();
    assertThat(channel.config()).isInstanceOf(SocketChannelConfig.class);
    SocketChannelConfig socketConfig = (SocketChannelConfig) channel.config();
    assertThat(socketConfig.isTcpNoDelay()).isTrue();
    assertThat(socketConfig.isKeepAlive()).isFalse();
    assertThat(socketConfig.isReuseAddress()).isFalse();
    assertThat(socketConfig.getSoLinger()).isEqualTo(10);
    RecvByteBufAllocator allocator = socketConfig.getRecvByteBufAllocator();
    assertThat(allocator).isInstanceOf(FixedRecvByteBufAllocator.class);
    assertThat(allocator.newHandle().guess()).isEqualTo(123456);
// cannot assert around SO_RCVBUF and SO_SNDBUF, such values are just hints
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) RecvByteBufAllocator(io.netty.channel.RecvByteBufAllocator) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SocketChannelConfig(io.netty.channel.socket.SocketChannelConfig) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) SessionWrapper(com.datastax.oss.driver.internal.core.session.SessionWrapper) Test(org.junit.Test)

Example 29 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphPagingIT method asynchronous_paging_with_options.

@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void asynchronous_paging_with_options(Options options) throws ExecutionException, InterruptedException {
    // given
    DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.ENABLED);
    if (options.sizeInBytes) {
        // Page sizes in bytes are not supported with graph queries
        return;
    }
    // when
    CompletionStage<AsyncGraphResultSet> result = SESSION_RULE.session().executeAsync(ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile));
    // then
    checkAsyncResult(result, options, 0, 1, new ArrayList<>());
    validateMetrics(SESSION_RULE.session());
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 30 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphPagingIT method should_trigger_global_timeout_async.

@Test
public void should_trigger_global_timeout_async() throws InterruptedException {
    // given
    Duration timeout = Duration.ofMillis(100);
    DriverExecutionProfile profile = enableGraphPaging().withDuration(DseDriverOption.GRAPH_TIMEOUT, timeout);
    // when
    try {
        CCM_RULE.getCcmBridge().pause(1);
        CompletionStage<AsyncGraphResultSet> result = SESSION_RULE.session().executeAsync(ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile));
        result.toCompletableFuture().get();
        fail("Expecting DriverTimeoutException");
    } catch (ExecutionException e) {
        assertThat(e.getCause()).hasMessage("Query timed out after " + timeout);
    } finally {
        CCM_RULE.getCcmBridge().resume(1);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Duration(java.time.Duration) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

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