use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class DeleteReactiveIT method should_delete_if_exists_reactive.
@Test
public void should_delete_if_exists_reactive() {
UUID id = FLAMETHROWER.getId();
assertThat(Flowable.fromPublisher(dao.findByIdReactive(id)).blockingSingle()).isNotNull();
{
ReactiveResultSet rs = dao.deleteIfExistsReactive(FLAMETHROWER);
ReactiveRow row = Flowable.fromPublisher(rs).blockingSingle();
assertThat(row.wasApplied()).isTrue();
assertThat(Flowable.fromPublisher(rs.wasApplied()).blockingSingle()).isTrue();
}
assertThat(Flowable.fromPublisher(dao.findByIdReactive(id)).singleElement().blockingGet()).isNull();
{
ReactiveResultSet rs = dao.deleteIfExistsReactive(FLAMETHROWER);
ReactiveRow row = Flowable.fromPublisher(rs).singleElement().blockingGet();
assertThat(row.wasApplied()).isFalse();
assertThat(Flowable.fromPublisher(rs.wasApplied()).blockingSingle()).isFalse();
}
}
use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class ContinuousCqlRequestReactiveProcessorTest method should_complete_single_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version) {
try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
List<ReactiveRow> rows = Flowable.fromPublisher(publisher).toList().blockingGet();
assertThat(rows).hasSize(1);
ReactiveRow row = rows.get(0);
assertThat(row.getString("message")).isEqualTo("hello, world");
ExecutionInfo executionInfo = row.getExecutionInfo();
assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
assertThat(executionInfo.getErrors()).isEmpty();
assertThat(executionInfo.getIncomingPayload()).isEmpty();
assertThat(executionInfo.getPagingState()).isNull();
assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(executionInfo.getWarnings()).isEmpty();
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(executionInfo);
Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(row.getColumnDefinitions());
Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(row.wasApplied());
}
}
use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class ContinuousCqlRequestReactiveProcessorTest method should_complete_multi_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(DseProtocolVersion version) {
RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (RequestHandlerTestHarness harness = builder.build()) {
DefaultSession session = harness.getSession();
InternalDriverContext context = harness.getContext();
ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
Flowable<ReactiveRow> rowsPublisher = Flowable.fromPublisher(publisher).cache();
rowsPublisher.subscribe();
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, true)));
List<ReactiveRow> rows = rowsPublisher.toList().blockingGet();
assertThat(rows).hasSize(20);
ReactiveRow first = rows.get(0);
ExecutionInfo firstExecutionInfo = first.getExecutionInfo();
assertThat(firstExecutionInfo.getCoordinator()).isEqualTo(node1);
assertThat(firstExecutionInfo.getErrors()).isEmpty();
assertThat(firstExecutionInfo.getIncomingPayload()).isEmpty();
assertThat(firstExecutionInfo.getPagingState()).isNotNull();
assertThat(firstExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(firstExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(firstExecutionInfo.getWarnings()).isEmpty();
ReactiveRow inSecondPage = rows.get(10);
ExecutionInfo secondExecutionInfo = inSecondPage.getExecutionInfo();
assertThat(secondExecutionInfo.getCoordinator()).isEqualTo(node1);
assertThat(secondExecutionInfo.getErrors()).isEmpty();
assertThat(secondExecutionInfo.getIncomingPayload()).isEmpty();
assertThat(secondExecutionInfo.getPagingState()).isNull();
assertThat(secondExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
assertThat(secondExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
assertThat(secondExecutionInfo.getWarnings()).isEmpty();
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(firstExecutionInfo, secondExecutionInfo);
Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(first.getColumnDefinitions());
Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(first.wasApplied());
}
}
use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class ReactiveResultSetSubscriptionTest method should_report_error_on_intermediary_page.
@Test
public void should_report_error_on_intermediary_page() {
CompletableFuture<AsyncResultSet> future1 = new CompletableFuture<>();
CompletableFuture<AsyncResultSet> future2 = new CompletableFuture<>();
MockAsyncResultSet page1 = new MockAsyncResultSet(3, future2);
TestSubscriber<ReactiveRow> mainSubscriber = new TestSubscriber<>();
TestSubscriber<ColumnDefinitions> colDefsSubscriber = new TestSubscriber<>();
TestSubscriber<ExecutionInfo> execInfosSubscriber = new TestSubscriber<>();
TestSubscriber<Boolean> wasAppliedSubscriber = new TestSubscriber<>();
ReactiveResultSetSubscription<AsyncResultSet> subscription = new ReactiveResultSetSubscription<>(mainSubscriber, colDefsSubscriber, execInfosSubscriber, wasAppliedSubscriber);
mainSubscriber.onSubscribe(subscription);
subscription.start(() -> future1);
future1.complete(page1);
future2.completeExceptionally(new UnavailableException(null, null, 0, 0));
mainSubscriber.awaitTermination();
assertThat(mainSubscriber.getElements()).extracting("row").isEqualTo(page1.currentPage());
assertThat(mainSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
// colDefsSubscriber completed normally when page1 arrived
assertThat(colDefsSubscriber.getError()).isNull();
assertThat(colDefsSubscriber.getElements()).hasSize(1).containsExactly(page1.getColumnDefinitions());
// execInfosSubscriber completed with error, but should have emitted 1 item for page1
assertThat(execInfosSubscriber.getElements()).hasSize(1).containsExactly(page1.getExecutionInfo());
assertThat(execInfosSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
// colDefsSubscriber completed normally when page1 arrived
assertThat(wasAppliedSubscriber.getElements()).hasSize(1).containsExactly(true);
assertThat(wasAppliedSubscriber.getError()).isNull();
}
use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class ReactiveResultSetSubscriptionTest method should_report_error_on_first_page.
@Test
public void should_report_error_on_first_page() {
CompletableFuture<AsyncResultSet> future1 = new CompletableFuture<>();
TestSubscriber<ReactiveRow> mainSubscriber = new TestSubscriber<>();
TestSubscriber<ColumnDefinitions> colDefsSubscriber = new TestSubscriber<>();
TestSubscriber<ExecutionInfo> execInfosSubscriber = new TestSubscriber<>();
TestSubscriber<Boolean> wasAppliedSubscriber = new TestSubscriber<>();
ReactiveResultSetSubscription<AsyncResultSet> subscription = new ReactiveResultSetSubscription<>(mainSubscriber, colDefsSubscriber, execInfosSubscriber, wasAppliedSubscriber);
mainSubscriber.onSubscribe(subscription);
subscription.start(() -> future1);
future1.completeExceptionally(new UnavailableException(null, null, 0, 0));
mainSubscriber.awaitTermination();
assertThat(mainSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
assertThat(colDefsSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
assertThat(execInfosSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
assertThat(wasAppliedSubscriber.getError()).isNotNull().isInstanceOf(UnavailableException.class);
}
Aggregations