Search in sources :

Example 21 with ReactiveRow

use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.

the class DefaultReactiveResultSetIT method should_write_batch_cas.

@Test
public void should_write_batch_cas() {
    BatchStatement batch = createCASBatch();
    CqlSession session = sessionRule.session();
    // execute batch for the first time: all inserts should succeed and the server should return
    // only one acknowledgement row with just the [applied] column = true
    ReactiveResultSet rs = session.executeReactive(batch);
    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());
    // delete 5 out of 10 rows
    partiallyDeleteInsertedRows();
    // re-execute same statement: server should return 5 rows for the 5 failed inserts, each one
    // with [applied] = false
    rs = session.executeReactive(batch);
    results = Flowable.fromPublisher(rs).toList().blockingGet();
    assertThat(results).hasSize(5);
    for (int i = 0; i < 5; i++) {
        row = results.get(i);
        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(i);
        assertThat(row.getInt("v")).isEqualTo(i + 1);
    }
    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());
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) EmptyColumnDefinitions(com.datastax.oss.driver.internal.core.cql.EmptyColumnDefinitions) BatchStatement(com.datastax.oss.driver.api.core.cql.BatchStatement) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) 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)

Example 22 with ReactiveRow

use of com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow in project java-driver by datastax.

the class DriverBlockHoundIntegrationIT method should_not_detect_blocking_call_on_asynchronous_execution.

@Test
public void should_not_detect_blocking_call_on_asynchronous_execution() {
    try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
        Flux<ReactiveRow> rows = Flux.range(0, 1000).flatMap(i -> Flux.from(session.executeReactive("SELECT c1, c2 FROM ks.t1")).subscribeOn(Schedulers.parallel()));
        StepVerifier.create(rows).expectNextCount(1000).expectComplete().verify();
    }
}
Also used : ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlSession(com.datastax.oss.driver.api.core.CqlSession) 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