use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class DefaultSchemaQueriesFactoryTest method buildFactory.
private DefaultSchemaQueriesFactory buildFactory() {
final DriverExecutionProfile mockProfile = mock(DriverExecutionProfile.class);
final DriverConfig mockConfig = mock(DriverConfig.class);
when(mockConfig.getDefaultProfile()).thenReturn(mockProfile);
final InternalDriverContext mockInternalCtx = mock(InternalDriverContext.class);
when(mockInternalCtx.getConfig()).thenReturn(mockConfig);
return new DefaultSchemaQueriesFactory(mockInternalCtx);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class DefaultSchemaQueriesFactory method newInstance.
protected SchemaQueries newInstance(Node node, DriverChannel channel) {
DriverExecutionProfile config = context.getConfig().getDefaultProfile();
Version dseVersion = (Version) node.getExtras().get(DseNodeProperties.DSE_VERSION);
if (dseVersion != null) {
dseVersion = dseVersion.nextStable();
LOG.debug("[{}] Sending schema queries to {} with DSE version {}", logPrefix, node, dseVersion);
// 4.8 is the oldest version supported, which uses C* 2.1 schema
if (dseVersion.compareTo(Version.V5_0_0) < 0) {
return new Cassandra21SchemaQueries(channel, node, config, logPrefix);
} else if (dseVersion.compareTo(Version.V6_7_0) < 0) {
// 5.0 - 6.7 uses C* 3.0 schema
return new Cassandra3SchemaQueries(channel, node, config, logPrefix);
} else if (dseVersion.compareTo(Version.V6_8_0) < 0) {
// 6.7 uses C* 4.0 schema
return new Cassandra4SchemaQueries(channel, node, config, logPrefix);
} else {
// 6.8+ uses DSE 6.8 schema (C* 4.0 schema with graph metadata) (JAVA-1898)
return new Dse68SchemaQueries(channel, node, config, logPrefix);
}
} else {
Version cassandraVersion = node.getCassandraVersion();
if (cassandraVersion == null) {
LOG.warn("[{}] Cassandra version missing for {}, defaulting to {}", logPrefix, node, Version.V3_0_0);
cassandraVersion = Version.V3_0_0;
} else {
cassandraVersion = cassandraVersion.nextStable();
}
LOG.debug("[{}] Sending schema queries to {} with version {}", logPrefix, node, cassandraVersion);
if (cassandraVersion.compareTo(Version.V2_2_0) < 0) {
return new Cassandra21SchemaQueries(channel, node, config, logPrefix);
} else if (cassandraVersion.compareTo(Version.V3_0_0) < 0) {
return new Cassandra22SchemaQueries(channel, node, config, logPrefix);
} else if (cassandraVersion.compareTo(Version.V4_0_0) < 0) {
return new Cassandra3SchemaQueries(channel, node, config, logPrefix);
} else {
return new Cassandra4SchemaQueries(channel, node, config, logPrefix);
}
}
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class ContinuousPagingIT method should_execute_asynchronously.
/**
* Validates {@link ContinuousSession#executeContinuouslyAsync(Statement)} with a variety of
* paging options and ensures in all cases the expected number of rows come back and the expected
* number of pages are received.
*
* @test_category queries
* @jira_ticket JAVA-1322
* @since 1.2.0
*/
@Test
@UseDataProvider("pagingOptions")
public void should_execute_asynchronously(Options options) {
CqlSession session = sessionRule.session();
SimpleStatement statement = SimpleStatement.newInstance("SELECT v from test where k=?", KEY);
DriverExecutionProfile profile = options.asProfile(session);
PageStatistics stats = CompletableFutures.getUninterruptibly(session.executeContinuouslyAsync(statement.setExecutionProfile(profile)).thenCompose(new AsyncContinuousPagingFunction()));
assertThat(stats.rows).isEqualTo(options.expectedRows);
assertThat(stats.pages).isEqualTo(options.expectedPages);
validateMetrics(session);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class ContinuousPagingIT method should_cancel_with_synchronous_paging.
/**
* Validates that {@link ContinuousResultSet#cancel()} will cancel a continuous paging session by
* setting maxPagesPerSecond to 1 and sending a cancel immediately and ensuring the total number
* of rows iterated over is equal to the size of pageSize.
*
* <p>Also validates that it is possible to resume the operation using the paging state, as
* described in the javadocs of {@link ContinuousResultSet#cancel()}.
*
* @test_category queries
* @jira_ticket JAVA-1322
* @since 1.2.0
*/
@Test
public void should_cancel_with_synchronous_paging() {
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_MAX_ENQUEUED_PAGES, 1).withInt(DseDriverOption.CONTINUOUS_PAGING_PAGE_SIZE, 10).withInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND, 1);
ContinuousResultSet pagingResult = session.executeContinuously(statement.setExecutionProfile(profile));
pagingResult.cancel();
int i = 0;
for (Row row : pagingResult) {
assertThat(row.getInt("v")).isEqualTo(i);
i++;
}
// Expect only 10 rows as paging was cancelled immediately.
assertThat(i).isEqualTo(10);
// attempt to resume the operation from where we left
ByteBuffer pagingState = pagingResult.getExecutionInfo().getPagingState();
ContinuousResultSet pagingResultResumed = session.executeContinuously(statement.setExecutionProfile(profile.withInt(DseDriverOption.CONTINUOUS_PAGING_MAX_PAGES_PER_SECOND, 0)).setPagingState(pagingState));
for (Row row : pagingResultResumed) {
assertThat(row.getInt("v")).isEqualTo(i);
i++;
}
assertThat(i).isEqualTo(100);
}
use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile in project java-driver by datastax.
the class ContinuousPagingIT method prepared_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 prepared.
*
* <p>Drops column 'v' after paging the first row in. This column should still be present in the
* in-flight queries' rows, but it's value should be null. The column should not be present in
* subsequent queries.
*
* @test_category queries
* @jira_ticket JAVA-1653
* @since 1.2.0
*/
@Test
public void prepared_statement_paging_should_be_resilient_to_schema_change() {
CqlSession session = sessionRule.session();
// Create table and prepare select * query against it.
session.execute(SimpleStatement.newInstance("CREATE TABLE test_prep (k text PRIMARY KEY, v int)").setExecutionProfile(SessionUtils.slowProfile(session)));
for (int i = 0; i < 100; i++) {
session.execute(String.format("INSERT INTO test_prep (k, v) VALUES ('foo', %d)", i));
}
PreparedStatement prepared = session.prepare("SELECT * FROM test_prep WHERE k = ?");
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(prepared.bind("foo").setExecutionProfile(profile));
Iterator<Row> it = result.iterator();
// First row should have a non-null value for v.
Row row0 = it.next();
assertThat(row0.getString("k")).isNotNull();
assertThat(row0.isNull("v")).isFalse();
// Make schema change to drop v, its metadata should be present, values will be null.
CqlSession schemaChangeSession = SessionUtils.newSession(ccmRule, session.getKeyspace().orElseThrow(IllegalStateException::new));
schemaChangeSession.execute(SimpleStatement.newInstance("ALTER TABLE test_prep DROP v;").setExecutionProfile(SessionUtils.slowProfile(schemaChangeSession)));
while (it.hasNext()) {
// Each row should have a value for k, v should still be present, but null since column was
// dropped.
Row row = it.next();
assertThat(row.getString("k")).isNotNull();
if (ccmRule.getDseVersion().orElseThrow(IllegalStateException::new).compareTo(Objects.requireNonNull(Version.parse("6.0.0"))) >= 0) {
// DSE 6 only, v should be null here since dropped.
// Not reliable for 5.1 since we may have gotten page queued before schema changed.
assertThat(row.isNull("v")).isTrue();
}
assertThat(row.getColumnDefinitions().contains("v")).isTrue();
}
// Subsequent queries should lack v from metadata as it was dropped.
prepared = session.prepare("SELECT * FROM test_prep WHERE k = ?");
result = session.executeContinuously(prepared.bind("foo").setExecutionProfile(profile));
it = result.iterator();
while (it.hasNext()) {
Row row = it.next();
assertThat(row.getString("k")).isNotNull();
assertThat(row.getColumnDefinitions().contains("v")).isFalse();
}
}
Aggregations