use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class ContinuousPagingReactiveIT method should_execute_reactively.
@Test
@UseDataProvider("pagingOptions")
public void should_execute_reactively(Options options) {
CqlSession session = sessionRule.session();
SimpleStatement statement = SimpleStatement.newInstance("SELECT v from test where k=?", KEY);
DriverExecutionProfile profile = options.asProfile(session);
ContinuousReactiveResultSet rs = session.executeContinuouslyReactive(statement.setExecutionProfile(profile));
List<ReactiveRow> results = Flowable.fromPublisher(rs).toList().blockingGet();
assertThat(results).hasSize(options.expectedRows);
Set<ExecutionInfo> expectedExecInfos = new LinkedHashSet<>();
for (int i = 0; i < results.size(); i++) {
ReactiveRow row = results.get(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());
validateMetrics(session);
}
use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class DeleteReactiveIT method should_delete_entity_reactive.
@Test
public void should_delete_entity_reactive() {
UUID id = FLAMETHROWER.getId();
assertThat(Flowable.fromPublisher(dao.findByIdReactive(id)).blockingSingle()).isNotNull();
ReactiveResultSet rs = dao.deleteEntityReactive(FLAMETHROWER);
ReactiveRow row = Flowable.fromPublisher(rs).singleElement().blockingGet();
assertThat(row).isNull();
assertThat(Flowable.fromPublisher(dao.findByIdReactive(id)).singleElement().blockingGet()).isNull();
}
use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class DeleteReactiveIT method should_delete_with_condition_reactive.
@Test
public void should_delete_with_condition_reactive() {
UUID id = FLAMETHROWER.getId();
assertThat(Flowable.fromPublisher(dao.findByIdReactive(id)).blockingSingle()).isNotNull();
{
ReactiveResultSet rs = dao.deleteIfDescriptionMatchesReactive(id, "foo");
ReactiveRow row = Flowable.fromPublisher(rs).blockingSingle();
assertThat(row.wasApplied()).isFalse();
assertThat(Flowable.fromPublisher(rs.wasApplied()).blockingSingle()).isFalse();
assertThat(row.getString("description")).isEqualTo(FLAMETHROWER.getDescription());
}
{
ReactiveResultSet rs = dao.deleteIfDescriptionMatchesReactive(id, FLAMETHROWER.getDescription());
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();
}
use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.
the class InsertReactiveIT method should_insert_entity_if_not_exists_reactive.
@Test
public void should_insert_entity_if_not_exists_reactive() {
UUID id = FLAMETHROWER.getId();
assertThat(Flowable.fromPublisher(dao.findByIdReactive(id)).singleElement().blockingGet()).isNull();
{
ReactiveResultSet rs = dao.saveIfNotExistsReactive(FLAMETHROWER);
ReactiveRow row = Flowable.fromPublisher(rs).blockingSingle();
assertThat(row.wasApplied()).isTrue();
assertThat(Flowable.fromPublisher(rs.wasApplied()).blockingSingle()).isTrue();
}
assertThat(Flowable.fromPublisher(dao.findByIdReactive(id)).blockingSingle()).isNotNull().isEqualTo(FLAMETHROWER);
{
ReactiveResultSet rs = dao.saveIfNotExistsReactive(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 UpdateReactiveIT method should_not_update_entity_if_condition_is_not_met_reactive.
@Test
public void should_not_update_entity_if_condition_is_not_met_reactive() {
Flowable.fromPublisher(dao.updateReactive(new Product(FLAMETHROWER.getId(), "Description for length 10", new Dimensions(10, 1, 1)))).blockingSubscribe();
assertThat(Flowable.fromPublisher(dao.findByIdReactive(FLAMETHROWER.getId())).blockingSingle()).isNotNull().extracting("description").isEqualTo("Description for length 10");
ReactiveResultSet rs = dao.updateIfLengthReactive(new Product(FLAMETHROWER.getId(), "Other description", new Dimensions(1, 1, 1)), 20);
ReactiveRow row = Flowable.fromPublisher(rs).blockingSingle();
assertThat(row.wasApplied()).isFalse();
assertThat(row.getColumnDefinitions().contains("dimensions")).isTrue();
assertThat(Single.fromPublisher(rs.getColumnDefinitions()).blockingGet().contains("dimensions")).isTrue();
assertThat(Single.fromPublisher(rs.wasApplied()).blockingGet()).isFalse();
}
Aggregations