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