Search in sources :

Example 81 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphPagingIT method synchronous_options_with_paging_disabled_should_fallback_to_single_page.

@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void synchronous_options_with_paging_disabled_should_fallback_to_single_page(Options options) {
    // given
    DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.DISABLED);
    if (options.sizeInBytes) {
        // Page sizes in bytes are not supported with graph queries
        return;
    }
    // when
    GraphResultSet result = SESSION_RULE.session().execute(ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile));
    // then
    List<GraphNode> nodes = result.all();
    assertThat(((CountingIterator) result.iterator()).remaining()).isZero();
    assertThat(nodes).hasSize(100);
    for (int i = 1; i <= nodes.size(); i++) {
        GraphNode node = nodes.get(i - 1);
        assertThat(node.asString()).isEqualTo("user" + i);
    }
    assertThat(result.getRequestExecutionInfo()).isNotNull();
    assertThat(result.getRequestExecutionInfo().getCoordinator().getEndPoint().resolve()).isEqualTo(firstCcmNode());
    validateMetrics(SESSION_RULE.session());
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) CountingIterator(com.datastax.oss.driver.internal.core.util.CountingIterator) MultiPageGraphResultSet(com.datastax.dse.driver.internal.core.graph.MultiPageGraphResultSet) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 82 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class ContinuousPagingIT method simple_statement_paging_should_be_resilient_to_schema_change.

/**
 * Validates that continuous paging is resilient to a schema change being made in the middle of
 * producing pages for the driver if the query was a simple statement.
 *
 * <p>Adds a column 'b' after paging the first row in. This column should not be present in the
 * in-flight queries' rows, but should be present for subsequent queries.
 *
 * @test_category queries
 * @jira_ticket JAVA-1653
 * @since 1.2.0
 */
@Test
public void simple_statement_paging_should_be_resilient_to_schema_change() {
    CqlSession session = sessionRule.session();
    SimpleStatement simple = SimpleStatement.newInstance("select * from test_prepare");
    DriverExecutionProfile profile = session.getContext().getConfig().getDefaultProfile().withInt(DseDriverOption.CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES, 1).withInt(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE, 1).withDuration(DseDriverOption.CONTINUOUS_PAGING_TIMEOUT_FIRST_PAGE, Duration.ofSeconds(30)).withDuration(DseDriverOption.CONTINUOUS_PAGING_TIMEOUT_OTHER_PAGES, Duration.ofSeconds(30));
    ContinuousResultSet result = session.executeContinuously(simple.setExecutionProfile(profile));
    Iterator<Row> it = result.iterator();
    // First row should have a non-null values.
    Row row0 = it.next();
    assertThat(row0.getString("k")).isNotNull();
    assertThat(row0.isNull("v")).isFalse();
    // Make schema change to add b, its metadata should NOT be present in subsequent rows.
    CqlSession schemaChangeSession = SessionUtils.newSession(ccmRule, session.getKeyspace().orElseThrow(IllegalStateException::new));
    SimpleStatement statement = SimpleStatement.newInstance("ALTER TABLE test_prepare add b int").setExecutionProfile(sessionRule.slowProfile());
    schemaChangeSession.execute(statement);
    schemaChangeSession.checkSchemaAgreement();
    while (it.hasNext()) {
        // Each row should have a value for k and v, but b should not be present as it was not part
        // of the original metadata.
        Row row = it.next();
        assertThat(row.getString("k")).isNotNull();
        assertThat(row.isNull("v")).isFalse();
        assertThat(row.getColumnDefinitions().contains("b")).isFalse();
    }
    // Subsequent queries should contain b in metadata since its a new query.
    result = session.executeContinuously(simple);
    it = result.iterator();
    while (it.hasNext()) {
        Row row = it.next();
        assertThat(row.getString("k")).isNotNull();
        assertThat(row.isNull("v")).isFalse();
        // b should be null, but present in metadata.
        assertThat(row.isNull("b")).isTrue();
        assertThat(row.getColumnDefinitions().contains("b")).isTrue();
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Row(com.datastax.oss.driver.api.core.cql.Row) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Example 83 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class ContinuousPagingIT method should_execute_prepared_statement_synchronously.

/**
 * Validates {@link ContinuousSession#executeContinuously(Statement)} with a variety of paging
 * options using a prepared statement and ensures in all cases the expected number of rows come
 * back.
 *
 * @test_category queries
 * @jira_ticket JAVA-1322
 * @since 1.2.0
 */
@Test
@UseDataProvider("pagingOptions")
public void should_execute_prepared_statement_synchronously(Options options) {
    CqlSession session = sessionRule.session();
    DriverExecutionProfile profile = options.asProfile(session);
    ContinuousResultSet result = session.executeContinuously(prepared.bind(KEY).setExecutionProfile(profile));
    int i = 0;
    for (Row row : result) {
        assertThat(row.getInt("v")).isEqualTo(i);
        i++;
    }
    assertThat(i).isEqualTo(options.expectedRows);
    validateMetrics(session);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Row(com.datastax.oss.driver.api.core.cql.Row) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 84 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class ContinuousPagingIT method should_cancel_future_when_cancelling_previous_result.

/**
 * Validates that {@link ContinuousAsyncResultSet#cancel()} will cancel a continuous paging
 * session and current tracked {@link CompletionStage} tied to the paging session.
 *
 * <p>Also validates that it is possible to resume the operation using the paging state, as
 * described in the javadocs of {@link ContinuousAsyncResultSet#cancel()}.
 *
 * @test_category queries
 * @jira_ticket JAVA-1322
 * @since 1.2.0
 */
@Test
public void should_cancel_future_when_cancelling_previous_result() {
    CqlSession session = sessionRule.session();
    SimpleStatement statement = SimpleStatement.newInstance("SELECT v from test where k=?", KEY);
    // create options and throttle at a page per second so
    // cancel can go out before the next page is sent.
    // Note that this might not be perfect if there are pauses
    // in the JVM and cancel isn't sent soon enough.
    DriverExecutionProfile profile = session.getContext().getConfig().getDefaultProfile().withInt(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE, 10).withInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND, 1);
    CompletionStage<ContinuousAsyncResultSet> future = session.executeContinuouslyAsync(statement.setExecutionProfile(profile));
    ContinuousAsyncResultSet pagingResult = CompletableFutures.getUninterruptibly(future);
    CompletionStage<?> fetchNextPageFuture = pagingResult.fetchNextPage();
    // Calling cancel on the previous result should cause the current future to be cancelled.
    pagingResult.cancel();
    assertThat(fetchNextPageFuture.toCompletableFuture().isCancelled()).isTrue();
    try {
        // Expect future to be cancelled since the previous result was cancelled.
        CompletableFutures.getUninterruptibly(fetchNextPageFuture);
        fail("Expected a cancellation exception since previous result was cancelled.");
    } catch (CancellationException ce) {
    // expected
    }
    int i = 0;
    for (Row row : pagingResult.currentPage()) {
        assertThat(row.getInt("v")).isEqualTo(i);
        i++;
    }
    // Expect only 10 rows as this is the defined page size.
    assertThat(i).isEqualTo(10);
    // attempt to resume the operation from where we left
    ByteBuffer pagingState = pagingResult.getExecutionInfo().getPagingState();
    future = session.executeContinuouslyAsync(statement.setExecutionProfile(profile.withInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND, 0)).setPagingState(pagingState));
    ContinuousAsyncResultSet pagingResultResumed;
    do {
        pagingResultResumed = CompletableFutures.getUninterruptibly(future);
        for (Row row : pagingResultResumed.currentPage()) {
            assertThat(row.getInt("v")).isEqualTo(i);
            i++;
        }
        if (pagingResultResumed.hasMorePages()) {
            future = pagingResultResumed.fetchNextPage();
        }
    } while (pagingResultResumed.hasMorePages());
    // expect 10 more rows
    assertThat(i).isEqualTo(100);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) CancellationException(java.util.concurrent.CancellationException) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Row(com.datastax.oss.driver.api.core.cql.Row) CqlSession(com.datastax.oss.driver.api.core.CqlSession) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 85 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.

the class GraphSupportCheckerTest method contextGraphPagingEnabled.

private void contextGraphPagingEnabled(InternalDriverContext context, PagingEnabledOptions option) {
    DriverExecutionProfile driverExecutionProfile = mock(DriverExecutionProfile.class);
    when(driverExecutionProfile.getString(DseDriverOption.GRAPH_PAGING_ENABLED)).thenReturn(option.name());
    DriverConfig config = mock(DriverConfig.class);
    when(context.getConfig()).thenReturn(config);
    when(config.getDefaultProfile()).thenReturn(driverExecutionProfile);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig)

Aggregations

DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)140 Test (org.junit.Test)81 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)29 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)20 CqlSession (com.datastax.oss.driver.api.core.CqlSession)19 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)17 Node (com.datastax.oss.driver.api.core.metadata.Node)14 ByteBuffer (java.nio.ByteBuffer)13 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)12 Duration (java.time.Duration)11 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)10 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)10 Row (com.datastax.oss.driver.api.core.cql.Row)9 Test (org.junit.jupiter.api.Test)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 Message (com.datastax.oss.protocol.internal.Message)7 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)6 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)6