use of com.datastax.oss.driver.api.core.cql.PagingState in project java-driver by datastax.
the class PagingStateIT method should_inject_in_simple_statement_with_custom_codecs.
@Test
public void should_inject_in_simple_statement_with_custom_codecs() {
try (CqlSession session = (CqlSession) SessionUtils.baseBuilder().addTypeCodecs(new IntWrapperCodec()).addContactEndPoints(CCM_RULE.getContactPoints()).withKeyspace(SESSION_RULE.keyspace()).build()) {
SimpleStatement statement = SimpleStatement.newInstance("SELECT * FROM foo WHERE k = ?", new IntWrapper(1)).setPageSize(15);
ResultSet resultSet = session.execute(statement);
assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(15);
assertThat(resultSet.isFullyFetched()).isFalse();
PagingState pagingState = resultSet.getExecutionInfo().getSafePagingState();
// setPagingState() cannot find the custom codec.
try {
@SuppressWarnings("unused") SimpleStatement ignored = statement.setPagingState(pagingState);
fail("Expected a CodecNotFoundException");
} catch (CodecNotFoundException e) {
// expected
}
resultSet = session.execute(statement.setPagingState(pagingState, session));
assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(5);
assertThat(resultSet.isFullyFetched()).isTrue();
}
}
use of com.datastax.oss.driver.api.core.cql.PagingState in project java-driver by datastax.
the class PagingStateIT method should_fail.
private void should_fail(String query1, int value1, String query2, int value2) {
CqlSession session = SESSION_RULE.session();
BoundStatement boundStatement1 = session.prepare(SimpleStatement.newInstance(query1).setPageSize(15)).bind(value1);
ResultSet resultSet = session.execute(boundStatement1);
PagingState pagingState = resultSet.getExecutionInfo().getSafePagingState();
@SuppressWarnings("ResultOfMethodCallIgnored") Throwable t = catchThrowable(() -> session.prepare(SimpleStatement.newInstance(query2).setPageSize(15)).bind(value2).setPagingState(pagingState));
assertThat(t).isInstanceOf(IllegalArgumentException.class);
}
use of com.datastax.oss.driver.api.core.cql.PagingState in project java-driver by datastax.
the class PagingStateIT method should_extract_and_reuse.
private void should_extract_and_reuse(UnaryOperator<PagingState> transformation) {
CqlSession session = SESSION_RULE.session();
BoundStatement boundStatement = session.prepare(SimpleStatement.newInstance("SELECT * FROM foo WHERE k = ?").setPageSize(15)).bind(1);
ResultSet resultSet = session.execute(boundStatement);
assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(15);
assertThat(resultSet.isFullyFetched()).isFalse();
PagingState pagingState = transformation.apply(resultSet.getExecutionInfo().getSafePagingState());
assertThat(pagingState.matches(boundStatement)).isTrue();
resultSet = session.execute(boundStatement.setPagingState(pagingState));
assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(5);
assertThat(resultSet.isFullyFetched()).isTrue();
}
Aggregations