Search in sources :

Example 1 with CqlRequestAsyncProcessor

use of com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor in project thingsboard by thingsboard.

the class GuavaDriverContext method buildRequestProcessorRegistry.

@Override
public RequestProcessorRegistry buildRequestProcessorRegistry() {
    // Register the typical request processors, except instead of the normal async processors,
    // use GuavaRequestAsyncProcessor to return ListenableFutures in async methods.
    CqlRequestAsyncProcessor cqlRequestAsyncProcessor = new CqlRequestAsyncProcessor();
    CqlPrepareAsyncProcessor cqlPrepareAsyncProcessor = new CqlPrepareAsyncProcessor();
    CqlRequestSyncProcessor cqlRequestSyncProcessor = new CqlRequestSyncProcessor(cqlRequestAsyncProcessor);
    return new RequestProcessorRegistry(getSessionName(), cqlRequestSyncProcessor, new CqlPrepareSyncProcessor(cqlPrepareAsyncProcessor), new GuavaRequestAsyncProcessor<>(cqlRequestAsyncProcessor, Statement.class, GuavaSession.ASYNC), new GuavaRequestAsyncProcessor<>(cqlPrepareAsyncProcessor, PrepareRequest.class, GuavaSession.ASYNC_PREPARED));
}
Also used : RequestProcessorRegistry(com.datastax.oss.driver.internal.core.session.RequestProcessorRegistry) Statement(com.datastax.oss.driver.api.core.cql.Statement) CqlPrepareSyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlPrepareSyncProcessor) CqlRequestSyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor) CqlPrepareAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlPrepareAsyncProcessor) CqlRequestAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor) PrepareRequest(com.datastax.oss.driver.api.core.cql.PrepareRequest)

Example 2 with CqlRequestAsyncProcessor

use of com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor in project java-driver by datastax.

the class CqlRequestReactiveProcessorTest method should_be_able_to_process_reactive_result_set.

@Test
public void should_be_able_to_process_reactive_result_set() {
    CqlRequestReactiveProcessor processor = new CqlRequestReactiveProcessor(new CqlRequestAsyncProcessor());
    assertThat(processor.canProcess(UNDEFINED_IDEMPOTENCE_STATEMENT, CqlRequestReactiveProcessor.REACTIVE_RESULT_SET)).isTrue();
}
Also used : CqlRequestAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor) Test(org.junit.Test)

Example 3 with CqlRequestAsyncProcessor

use of com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor in project java-driver by datastax.

the class GuavaDriverContext method buildRequestProcessorRegistry.

@Override
public RequestProcessorRegistry buildRequestProcessorRegistry() {
    // Register the typical request processors, except instead of the normal async processors,
    // use GuavaRequestAsyncProcessor to return ListenableFutures in async methods.
    CqlRequestAsyncProcessor cqlRequestAsyncProcessor = new CqlRequestAsyncProcessor();
    CqlPrepareAsyncProcessor cqlPrepareAsyncProcessor = new CqlPrepareAsyncProcessor();
    CqlRequestSyncProcessor cqlRequestSyncProcessor = new CqlRequestSyncProcessor(cqlRequestAsyncProcessor);
    return new RequestProcessorRegistry(getSessionName(), cqlRequestSyncProcessor, new CqlPrepareSyncProcessor(cqlPrepareAsyncProcessor), new GuavaRequestAsyncProcessor<>(cqlRequestAsyncProcessor, Statement.class, GuavaSession.ASYNC), new GuavaRequestAsyncProcessor<>(cqlPrepareAsyncProcessor, PrepareRequest.class, GuavaSession.ASYNC_PREPARED), // Register KeyRequestProcessor for handling KeyRequest and returning Integer.
    new KeyRequestProcessor(cqlRequestAsyncProcessor));
}
Also used : RequestProcessorRegistry(com.datastax.oss.driver.internal.core.session.RequestProcessorRegistry) Statement(com.datastax.oss.driver.api.core.cql.Statement) CqlPrepareSyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlPrepareSyncProcessor) CqlRequestSyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor) CqlPrepareAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlPrepareAsyncProcessor) CqlRequestAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor) PrepareRequest(com.datastax.oss.driver.api.core.cql.PrepareRequest)

Example 4 with CqlRequestAsyncProcessor

use of com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor in project java-driver by datastax.

the class CqlRequestReactiveProcessorTest method should_complete_single_page_result.

@Test
@UseDataProvider(value = "allDseAndOssProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(ProtocolVersion version) {
    try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(singleDseRow())).build()) {
        DefaultSession session = harness.getSession();
        InternalDriverContext context = harness.getContext();
        ReactiveResultSet publisher = new CqlRequestReactiveProcessor(new CqlRequestAsyncProcessor()).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());
    }
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlRequestAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with CqlRequestAsyncProcessor

use of com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor in project java-driver by datastax.

the class CqlRequestReactiveProcessorTest method should_complete_multi_page_result.

@Test
@UseDataProvider(value = "allDseAndOssProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(ProtocolVersion version) {
    RequestHandlerTestHarness.Builder builder = RequestHandlerTestHarness.builder().withProtocolVersion(version);
    PoolBehavior node1Behavior = builder.customBehavior(node1);
    try (RequestHandlerTestHarness harness = builder.build()) {
        DefaultSession session = harness.getSession();
        InternalDriverContext context = harness.getContext();
        // The 2nd page is obtained by an "external" call to session.executeAsync(),
        // so we need to mock that.
        CompletableFuture<AsyncResultSet> page2Future = new CompletableFuture<>();
        when(session.executeAsync(any(Statement.class))).thenAnswer(invocation -> page2Future);
        ExecutionInfo mockInfo = mock(ExecutionInfo.class);
        ReactiveResultSet publisher = new CqlRequestReactiveProcessor(new CqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
        Flowable<ReactiveRow> rowsPublisher = Flowable.fromPublisher(publisher).cache();
        rowsPublisher.subscribe();
        // emulate arrival of page 1
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
        // emulate arrival of page 2 following the call to session.executeAsync()
        page2Future.complete(Conversions.toResultSet(DseTestFixtures.tenDseRows(2, true), mockInfo, harness.getSession(), harness.getContext()));
        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).isSameAs(mockInfo);
        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());
    }
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) Statement(com.datastax.oss.driver.api.core.cql.Statement) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) CqlRequestAsyncProcessor(com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor) CompletableFuture(java.util.concurrent.CompletableFuture) ReactiveResultSet(com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

CqlRequestAsyncProcessor (com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor)8 Test (org.junit.Test)4 Statement (com.datastax.oss.driver.api.core.cql.Statement)3 CqlPrepareAsyncProcessor (com.datastax.oss.driver.internal.core.cql.CqlPrepareAsyncProcessor)3 CqlPrepareSyncProcessor (com.datastax.oss.driver.internal.core.cql.CqlPrepareSyncProcessor)3 CqlRequestSyncProcessor (com.datastax.oss.driver.internal.core.cql.CqlRequestSyncProcessor)3 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)3 ReactiveResultSet (com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet)2 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)2 ContinuousCqlRequestAsyncProcessor (com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor)2 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)2 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)2 PrepareRequest (com.datastax.oss.driver.api.core.cql.PrepareRequest)2 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)2 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)2 RequestProcessorRegistry (com.datastax.oss.driver.internal.core.session.RequestProcessorRegistry)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 ContinuousCqlRequestSyncProcessor (com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestSyncProcessor)1 ContinuousCqlRequestReactiveProcessor (com.datastax.dse.driver.internal.core.cql.continuous.reactive.ContinuousCqlRequestReactiveProcessor)1 CqlRequestReactiveProcessor (com.datastax.dse.driver.internal.core.cql.reactive.CqlRequestReactiveProcessor)1