use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class DefaultReactiveResultSetIT method should_write_cas.
@Test
public void should_write_cas() {
SimpleStatement statement = SimpleStatement.builder("INSERT INTO test_reactive_write (pk, cc, v) VALUES (?, ?, ?) IF NOT EXISTS").addPositionalValue(0).addPositionalValue(1).addPositionalValue(2).setExecutionProfile(sessionRule.slowProfile()).build();
// execute statement for the first time: the insert should succeed and the server should return
// only one acknowledgement row with just the [applied] column = true
ReactiveResultSet rs = sessionRule.session().executeReactive(statement);
List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results).hasSize(1);
ReactiveRow row = results.get(0);
assertThat(row.getExecutionInfo()).isNotNull();
assertThat(row.getColumnDefinitions()).hasSize(1);
assertThat(row.wasApplied()).isTrue();
assertThat(row.getBoolean("[applied]")).isTrue();
List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
// re-execute same statement: server should return one row with data that failed to be inserted,
// with [applied] = false
rs = sessionRule.session().executeReactive(statement);
results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results).hasSize(1);
row = results.get(0);
assertThat(row.getExecutionInfo()).isNotNull();
assertThat(row.getColumnDefinitions()).hasSize(4);
assertThat(row.wasApplied()).isFalse();
assertThat(row.getBoolean("[applied]")).isFalse();
assertThat(row.getInt("pk")).isEqualTo(0);
assertThat(row.getInt("cc")).isEqualTo(1);
assertThat(row.getInt("v")).isEqualTo(2);
execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
assertThat(execInfos).hasSize(1).containsExactly(row.getExecutionInfo());
colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
assertThat(colDefs).hasSize(1).containsExactly(row.getColumnDefinitions());
wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
assertThat(wasApplied).hasSize(1).containsExactly(row.wasApplied());
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class DefaultReactiveResultSetIT method should_retrieve_all_rows.
@Test
@DataProvider(value = { "1", "10", "100", "999", "1000", "1001", "2000" }, format = "%m [page size %p[0]]")
public void should_retrieve_all_rows(int pageSize) {
DriverExecutionProfile profile = sessionRule.session().getContext().getConfig().getDefaultProfile().withInt(DefaultDriverOption.REQUEST_PAGE_SIZE, pageSize);
SimpleStatement statement = SimpleStatement.builder("SELECT cc, v FROM test_reactive_read WHERE pk = 0").setExecutionProfile(profile).build();
ReactiveResultSet rs = sessionRule.session().executeReactive(statement);
List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results.size()).isEqualTo(1000);
Set<ExecutionInfo> expectedExecInfos = new LinkedHashSet<>();
for (int i = 0; i < results.size(); i++) {
ReactiveRow row = results.get(i);
assertThat(row.getColumnDefinitions()).isNotNull();
assertThat(row.getExecutionInfo()).isNotNull();
assertThat(row.wasApplied()).isTrue();
assertThat(row.getInt("cc")).isEqualTo(i);
assertThat(row.getInt("v")).isEqualTo(i);
expectedExecInfos.add(row.getExecutionInfo());
}
List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
// DSE may send an empty page as it can't always know if it's done paging or not yet.
// See: CASSANDRA-8871. In this case, this page's execution info appears in
// rs.getExecutionInfos(), but is not present in expectedExecInfos since the page did not
// contain any rows.
assertThat(execInfos).containsAll(expectedExecInfos);
List<ColumnDefinitions> colDefs = Flowable.<ColumnDefinitions>fromPublisher(rs.getColumnDefinitions()).toList().blockingGet();
ReactiveRow first = results.get(0);
assertThat(colDefs).hasSize(1).containsExactly(first.getColumnDefinitions());
List<Boolean> wasApplied = Flowable.fromPublisher(rs.wasApplied()).toList().blockingGet();
assertThat(wasApplied).hasSize(1).containsExactly(first.wasApplied());
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandlerRetryTest method should_try_next_node_if_idempotent_and_retry_policy_decides_so.
@Test
@UseDataProvider("failureAndIdempotent")
public void should_try_next_node_if_idempotent_and_retry_policy_decides_so(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement) {
RequestHandlerTestHarness.Builder harnessBuilder = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
harnessBuilder.withResponse(node2, defaultFrameOf(singleRow()));
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.RETRY_NEXT);
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
Iterator<Row> rows = resultSet.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows.next().getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node2);
assertThat(executionInfo.getErrors()).hasSize(1);
assertThat(executionInfo.getErrors().get(0).getKey()).isEqualTo(node1);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.errorMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(DefaultNodeMetric.RETRIES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.retryMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(1)).isEnabled(DefaultNodeMetric.CQL_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(1)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class CqlRequestHandlerRetryTest method should_try_same_node_if_idempotent_and_retry_policy_decides_so.
@Test
@UseDataProvider("failureAndIdempotent")
public void should_try_same_node_if_idempotent_and_retry_policy_decides_so(FailureScenario failureScenario, boolean defaultIdempotence, Statement<?> statement) {
RequestHandlerTestHarness.Builder harnessBuilder = RequestHandlerTestHarness.builder().withDefaultIdempotence(defaultIdempotence);
failureScenario.mockRequestError(harnessBuilder, node1);
harnessBuilder.withResponse(node1, defaultFrameOf(singleRow()));
try (RequestHandlerTestHarness harness = harnessBuilder.build()) {
failureScenario.mockRetryPolicyVerdict(harness.getContext().getRetryPolicy(anyString()), RetryVerdict.RETRY_SAME);
CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(statement, harness.getSession(), harness.getContext(), "test").handle();
assertThatStage(resultSetFuture).isSuccess(resultSet -> {
Iterator<Row> rows = resultSet.currentPage().iterator();
assertThat(rows.hasNext()).isTrue();
assertThat(rows.next().getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = resultSet.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).hasSize(1);
assertThat(executionInfo.getErrors().get(0).getKey()).isEqualTo(node1);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.errorMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(DefaultNodeMetric.RETRIES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1).incrementCounter(failureScenario.retryMetric, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(2)).isEnabled(DefaultNodeMetric.CQL_MESSAGES, DriverExecutionProfile.DEFAULT_NAME);
verify(nodeMetricUpdater1, atMost(2)).updateTimer(eq(DefaultNodeMetric.CQL_MESSAGES), eq(DriverExecutionProfile.DEFAULT_NAME), anyLong(), eq(TimeUnit.NANOSECONDS));
verifyNoMoreInteractions(nodeMetricUpdater1);
});
}
}
use of com.datastax.oss.driver.api.core.cql.ExecutionInfo in project java-driver by datastax.
the class DefaultReactiveGraphResultSetIT method should_retrieve_all_rows.
@Test
@DataProvider(value = { "1", "10", "100", "999", "1000", "1001", "2000" }, format = "%m [page size %p[0]]")
public void should_retrieve_all_rows(int pageSize) {
DriverExecutionProfile profile = sessionRule.session().getContext().getConfig().getDefaultProfile().withInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE, pageSize);
ScriptGraphStatement statement = ScriptGraphStatement.builder("g.V()").setExecutionProfile(profile).build();
ReactiveGraphResultSet rs = sessionRule.session().executeReactive(statement);
List<ReactiveGraphNode> results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results.size()).isEqualTo(1000);
Set<ExecutionInfo> expectedExecInfos = new LinkedHashSet<>();
for (ReactiveGraphNode row : results) {
assertThat(row.getExecutionInfo()).isNotNull();
assertThat(row.isVertex()).isTrue();
expectedExecInfos.add(row.getExecutionInfo());
}
List<ExecutionInfo> execInfos = Flowable.<ExecutionInfo>fromPublisher(rs.getExecutionInfos()).toList().blockingGet();
// DSE may send an empty page as it can't always know if it's done paging or not yet.
// See: CASSANDRA-8871. In this case, this page's execution info appears in
// rs.getExecutionInfos(), but is not present in expectedExecInfos since the page did not
// contain any rows.
assertThat(execInfos).containsAll(expectedExecInfos);
}
Aggregations