Search in sources :

Example 66 with DriverExecutionProfile

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

the class GraphPagingIT method synchronous_paging_with_options.

@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void synchronous_paging_with_options(Options options) {
    // given
    DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.ENABLED);
    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(options.expectedRows);
    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());
    assertIfMultiPage(result, options.expectedPages);
    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 67 with DriverExecutionProfile

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

the class GraphPagingIT method asynchronous_options_with_paging_disabled_should_fallback_to_single_page.

@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void asynchronous_options_with_paging_disabled_should_fallback_to_single_page(Options options) throws ExecutionException, InterruptedException {
    // given
    DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.DISABLED);
    if (options.sizeInBytes) {
        // Page sizes in bytes are not supported with graph queries
        return;
    }
    // when
    CompletionStage<AsyncGraphResultSet> result = SESSION_RULE.session().executeAsync(ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile));
    // then
    AsyncGraphResultSet asyncGraphResultSet = result.toCompletableFuture().get();
    for (int i = 1; i <= 100; i++, asyncGraphResultSet.remaining()) {
        GraphNode node = asyncGraphResultSet.one();
        assertThat(node.asString()).isEqualTo("user" + i);
    }
    assertThat(asyncGraphResultSet.remaining()).isEqualTo(0);
    validateMetrics(SESSION_RULE.session());
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 68 with DriverExecutionProfile

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

the class GraphPagingIT method should_cancel_result_set.

@Test
public void should_cancel_result_set() {
    // given
    DriverExecutionProfile profile = enableGraphPaging().withInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_MAX_ENQUEUED_PAGES, 1).withInt(DseDriverOption.GRAPH_CONTINUOUS_PAGING_PAGE_SIZE, 10);
    // when
    GraphStatement statement = ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile);
    MultiPageGraphResultSet results = (MultiPageGraphResultSet) SESSION_RULE.session().execute(statement);
    assertThat(((MultiPageGraphResultSet.RowIterator) results.iterator()).isCancelled()).isFalse();
    assertThat(((CountingIterator) results.iterator()).remaining()).isEqualTo(10);
    results.cancel();
    assertThat(((MultiPageGraphResultSet.RowIterator) results.iterator()).isCancelled()).isTrue();
    assertThat(((CountingIterator) results.iterator()).remaining()).isEqualTo(10);
    for (int i = 0; i < 10; i++) {
        results.one();
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) MultiPageGraphResultSet(com.datastax.dse.driver.internal.core.graph.MultiPageGraphResultSet) CountingIterator(com.datastax.oss.driver.internal.core.util.CountingIterator) Test(org.junit.Test)

Example 69 with DriverExecutionProfile

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

the class GraphPagingIT method asynchronous_paging_with_options_when_auto.

@UseDataProvider(location = ContinuousPagingITBase.class, value = "pagingOptions")
@Test
public void asynchronous_paging_with_options_when_auto(Options options) throws ExecutionException, InterruptedException {
    // given
    DriverExecutionProfile profile = enableGraphPaging(options, PagingEnabledOptions.AUTO);
    if (options.sizeInBytes) {
        // Page sizes in bytes are not supported with graph queries
        return;
    }
    // when
    CompletionStage<AsyncGraphResultSet> result = SESSION_RULE.session().executeAsync(ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile));
    // then
    checkAsyncResult(result, options, 0, 1, new ArrayList<>());
    validateMetrics(SESSION_RULE.session());
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 70 with DriverExecutionProfile

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

the class GraphPagingIT method should_trigger_global_timeout_sync_from_config.

@Test
public void should_trigger_global_timeout_sync_from_config() {
    // given
    Duration timeout = Duration.ofMillis(100);
    DriverExecutionProfile profile = enableGraphPaging().withDuration(DseDriverOption.GRAPH_TIMEOUT, timeout);
    // when
    try {
        CCM_RULE.getCcmBridge().pause(1);
        try {
            SESSION_RULE.session().execute(ScriptGraphStatement.newInstance("g.V().hasLabel('person').values('name')").setGraphName(SESSION_RULE.getGraphName()).setTraversalSource("g").setExecutionProfile(profile));
            fail("Expecting DriverTimeoutException");
        } catch (DriverTimeoutException e) {
            assertThat(e).hasMessage("Query timed out after " + timeout);
        }
    } finally {
        CCM_RULE.getCcmBridge().resume(1);
    }
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverTimeoutException(com.datastax.oss.driver.api.core.DriverTimeoutException) Duration(java.time.Duration) Test(org.junit.Test)

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