Search in sources :

Example 11 with ReactiveRow

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 12 with ReactiveRow

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();
}
Also used : ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) MappedReactiveResultSet(com.datastax.dse.driver.api.mapper.reactive.MappedReactiveResultSet) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with ReactiveRow

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();
}
Also used : ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) MappedReactiveResultSet(com.datastax.dse.driver.api.mapper.reactive.MappedReactiveResultSet) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with ReactiveRow

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();
    }
}
Also used : ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) MappedReactiveResultSet(com.datastax.dse.driver.api.mapper.reactive.MappedReactiveResultSet) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) UUID(java.util.UUID) Test(org.junit.Test)

Example 15 with ReactiveRow

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();
}
Also used : ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) MappedReactiveResultSet(com.datastax.dse.driver.api.mapper.reactive.MappedReactiveResultSet) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) Test(org.junit.Test)

Aggregations

ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)22 Test (org.junit.Test)21 ReactiveResultSet (com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet)13 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)12 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)11 MappedReactiveResultSet (com.datastax.dse.driver.api.mapper.reactive.MappedReactiveResultSet)7 UUID (java.util.UUID)7 CqlSession (com.datastax.oss.driver.api.core.CqlSession)5 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 EmptyColumnDefinitions (com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions)4 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)4 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)4 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)3 UnavailableException (com.datastax.oss.driver.api.core.servererrors.UnavailableException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ContinuousReactiveResultSet (com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet)2 ContinuousCqlRequestAsyncProcessor (com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor)2 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)2