Search in sources :

Example 21 with RequestHandlerTestHarness

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

the class ContinuousCqlRequestHandlerTest method should_not_cancel_session_if_future_cancelled_but_already_done.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_not_cancel_session_if_future_cancelled_but_already_done(DseProtocolVersion version) {
    RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
    PoolBehavior node1Behavior = builder.customBehavior(node1);
    try (RequestHandlerTestHarness harness = builder.build()) {
        ContinuousCqlRequestHandler handler = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test");
        CompletionStage<ContinuousAsyncResultSet> page1Future = handler.handle();
        // this will complete page 1 future
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, true)));
        // to late
        page1Future.toCompletableFuture().cancel(true);
        assertThat(handler.getState()).isEqualTo(-1);
    }
}
Also used : PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 22 with RequestHandlerTestHarness

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

the class ContinuousCqlRequestHandlerTest method should_invoke_request_tracker.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_invoke_request_tracker(DseProtocolVersion version) {
    try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(new com.datastax.oss.protocol.internal.response.Error(ProtocolConstants.ErrorCode.IS_BOOTSTRAPPING, "mock message"))).withResponse(node2, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
        RequestTracker requestTracker = mock(RequestTracker.class);
        when(harness.getContext().getRequestTracker()).thenReturn(requestTracker);
        CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isSuccess(resultSet -> {
            Iterator<Row> rows = resultSet.currentPage().iterator();
            assertThat(rows.hasNext()).isTrue();
            assertThat(rows.next().getString("message")).isEqualTo("hello, world");
            ExecutionInfo executionInfo = resultSet.getExecutionInfo();
            assertThat(executionInfo.getCoordinator()).isEqualTo(node2);
            assertThat(executionInfo.getErrors()).isNotEmpty();
            assertThat(executionInfo.getIncomingPayload()).isEmpty();
            assertThat(executionInfo.getPagingState()).isNull();
            assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
            assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
            assertThat(executionInfo.getWarnings()).isEmpty();
            verify(requestTracker).onNodeError(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), any(BootstrappingException.class), anyLong(), any(DriverExecutionProfile.class), eq(node1), matches(LOG_PREFIX_PER_REQUEST));
            verify(requestTracker).onNodeSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), matches(LOG_PREFIX_PER_REQUEST));
            verify(requestTracker).onSuccess(eq(UNDEFINED_IDEMPOTENCE_STATEMENT), anyLong(), any(DriverExecutionProfile.class), eq(node2), matches(LOG_PREFIX_PER_REQUEST));
            verifyNoMoreInteractions(requestTracker);
        });
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) RequestTracker(com.datastax.oss.driver.api.core.tracker.RequestTracker) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) Row(com.datastax.oss.driver.api.core.cql.Row) BootstrappingException(com.datastax.oss.driver.api.core.servererrors.BootstrappingException) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 23 with RequestHandlerTestHarness

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

the class ContinuousCqlRequestHandlerTest 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()) {
        CompletionStage<ContinuousAsyncResultSet> resultSetFuture = new ContinuousCqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isSuccess(resultSet -> {
            Iterator<Row> rows = resultSet.currentPage().iterator();
            assertThat(rows.hasNext()).isTrue();
            assertThat(rows.next().getString("message")).isEqualTo("hello, world");
            ExecutionInfo executionInfo = resultSet.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();
        });
    }
}
Also used : RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ContinuousAsyncResultSet(com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 24 with RequestHandlerTestHarness

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

the class ContinuousCqlRequestReactiveProcessorTest method should_create_request_handler.

@Test
public void should_create_request_handler() {
    RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(DSE_V1);
    try (RequestHandlerTestHarness harness = builder.build()) {
        ContinuousCqlRequestReactiveProcessor processor = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor());
        assertThat(processor.process(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test")).isInstanceOf(DefaultContinuousReactiveResultSet.class);
    }
}
Also used : ContinuousCqlRequestAsyncProcessor(com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) Test(org.junit.Test)

Example 25 with RequestHandlerTestHarness

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

the class ContinuousGraphRequestHandlerTest method should_honor_statement_timeout.

@Test
public void should_honor_statement_timeout() throws Exception {
    // given
    GraphBinaryModule binaryModule = createGraphBinaryModule(mockContext);
    Duration defaultTimeout = Duration.ofSeconds(1);
    Duration statementTimeout = Duration.ofSeconds(2);
    RequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphTimeout(defaultTimeout);
    PoolBehavior node1Behavior = builder.customBehavior(node);
    try (RequestHandlerTestHarness harness = builder.build()) {
        DriverExecutionProfile profile = harness.getContext().getConfig().getDefaultProfile();
        when(profile.isDefined(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(true);
        when(profile.getString(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(GraphProtocol.GRAPH_BINARY_1_0.toInternalCode());
        GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setTimeout(statementTimeout);
        // when
        ContinuousGraphRequestHandler handler = new ContinuousGraphRequestHandler(graphStatement, harness.getSession(), harness.getContext(), "test", binaryModule, new GraphSupportChecker());
        // send the initial request
        CompletionStage<AsyncGraphResultSet> page1Future = handler.handle();
        // acknowledge the write, will set the global timeout
        node1Behavior.verifyWrite();
        node1Behavior.setWriteSuccess();
        CapturedTimeout globalTimeout = harness.nextScheduledTimeout();
        assertThat(globalTimeout.getDelay(TimeUnit.NANOSECONDS)).isEqualTo(statementTimeout.toNanos());
        // will trigger the global timeout and complete it exceptionally
        globalTimeout.task().run(globalTimeout);
        assertThat(page1Future.toCompletableFuture()).isCompletedExceptionally();
        assertThatThrownBy(() -> page1Future.toCompletableFuture().get()).hasRootCauseExactlyInstanceOf(DriverTimeoutException.class).hasMessageContaining("Query timed out after " + statementTimeout);
    }
}
Also used : PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) Duration(java.time.Duration) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) CapturedTimeout(com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout) Test(org.junit.Test)

Aggregations

RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)35 Test (org.junit.Test)34 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)27 ContinuousAsyncResultSet (com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet)23 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)14 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)12 Row (com.datastax.oss.driver.api.core.cql.Row)7 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)4 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)4 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)4 CapturedTimeout (com.datastax.oss.driver.internal.core.util.concurrent.CapturingTimer.CapturedTimeout)4 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)3 ContinuousCqlRequestAsyncProcessor (com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor)3 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)3 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)3 CqlRequestAsyncProcessor (com.datastax.oss.driver.internal.core.cql.CqlRequestAsyncProcessor)3 Prepare (com.datastax.oss.protocol.internal.request.Prepare)3 Query (com.datastax.oss.protocol.internal.request.Query)3