use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraBatchTemplateIntegrationTests method shouldUpdateMonoCollectionOfEntitiesWithTtl.
// DATACASS-574
@Test
void shouldUpdateMonoCollectionOfEntitiesWithTtl() {
walter.setEmail("walter@white.com");
mike.setEmail("mike@sauls.com");
int ttl = 30;
WriteOptions options = WriteOptions.builder().ttl(ttl).build();
ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
Mono<ReactiveResultSet> resultSet = batchOperations.update(Collections.singletonList(walter), options).update(Mono.just(Collections.singletonList(mike)), options).execute().then(template.getReactiveCqlOperations().queryForResultSet("SELECT TTL(email) FROM group;"));
//
resultSet.flatMapMany(ReactiveResultSet::availableRows).as(//
StepVerifier::create).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).verifyComplete();
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraBatchTemplateIntegrationTests method shouldInsertMonoOfEntitiesWithTtl.
// DATACASS-574
@Test
void shouldInsertMonoOfEntitiesWithTtl() {
walter.setEmail("walter@white.com");
mike.setEmail("mike@sauls.com");
int ttl = 30;
WriteOptions options = WriteOptions.builder().ttl(30).build();
ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
Mono<ReactiveResultSet> resultSet = batchOperations.insert(Mono.just(Arrays.asList(walter, mike)), options).execute().then(template.getReactiveCqlOperations().queryForResultSet("SELECT TTL(email) FROM group;"));
//
resultSet.flatMapMany(ReactiveResultSet::availableRows).as(//
StepVerifier::create).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).verifyComplete();
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method updateObjectShouldApplyQueryOptions.
// DATACASS-708
@Test
void updateObjectShouldApplyQueryOptions() {
WriteOptions queryOptions = //
WriteOptions.builder().executionProfile(//
"foo").serialConsistencyLevel(//
DefaultConsistencyLevel.QUORUM).build();
Person person = new Person();
person.id = "foo";
person.set = Collections.emptySet();
person.list = Collections.emptyList();
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, queryOptions);
SimpleStatement statement = update.build();
assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetUpdateWithTtl.
// DATACASS-656
@Test
void shouldCreateSetUpdateWithTtl() {
WriteOptions options = WriteOptions.builder().ttl(Duration.ofMinutes(1)).build();
Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(options);
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz"), personEntity);
assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person USING TTL 60 SET first_name='baz' WHERE foo='bar'");
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method insertShouldApplyQueryOptions.
// DATACASS-708
@Test
void insertShouldApplyQueryOptions() {
Person person = new Person();
person.id = "foo";
WriteOptions queryOptions = //
WriteOptions.builder().executionProfile(//
"foo").serialConsistencyLevel(//
DefaultConsistencyLevel.QUORUM).build();
StatementBuilder<RegularInsert> insert = statementFactory.insert(person, queryOptions);
SimpleStatement statement = insert.build();
assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
Aggregations