use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetUpdateFromObjectWithTimestamp.
// DATACASS-656
@Test
void shouldCreateSetUpdateFromObjectWithTimestamp() {
WriteOptions options = WriteOptions.builder().timestamp(1234).build();
Person person = new Person();
person.id = "foo";
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, options);
assertThat(update.build(ParameterHandling.INLINE).getQuery()).startsWith("UPDATE person USING TIMESTAMP 1234 SET");
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetUpdateFromObjectWithTtl.
// DATACASS-656
@Test
void shouldCreateSetUpdateFromObjectWithTtl() {
WriteOptions options = WriteOptions.builder().ttl(Duration.ofMinutes(1)).build();
Person person = new Person();
person.id = "foo";
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, options);
assertThat(update.build(ParameterHandling.INLINE).getQuery()).startsWith("UPDATE person USING TTL 60 SET");
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class CassandraBatchTemplateIntegrationTests method shouldInsertCollectionOfEntitiesWithTtl.
// DATACASS-443
@Test
void shouldInsertCollectionOfEntitiesWithTtl() {
walter.setEmail("walter@white.com");
mike.setEmail("mike@sauls.com");
int ttl = 30;
WriteOptions options = WriteOptions.builder().ttl(30).build();
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
batchOperations.insert(Arrays.asList(walter, mike), options).execute();
ResultSet resultSet = template.getCqlOperations().queryForResultSet("SELECT TTL(email) FROM group;");
assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(2);
for (Row row : resultSet) {
assertThat(row.getInt(0)).isBetween(1, ttl);
}
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class CassandraBatchTemplateIntegrationTests method shouldUpdateCollectionOfEntitiesWithTtl.
// DATACASS-443
@Test
void shouldUpdateCollectionOfEntitiesWithTtl() {
walter.setEmail("walter@white.com");
mike.setEmail("mike@sauls.com");
int ttl = 30;
WriteOptions options = WriteOptions.builder().ttl(ttl).build();
CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
batchOperations.update(walter, options).execute();
ResultSet resultSet = template.getCqlOperations().queryForResultSet("SELECT TTL(email), email FROM group");
assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(2);
for (Row row : resultSet) {
if (walter.getEmail().equals(row.getString("email"))) {
assertThat(row.getInt(0)).isBetween(1, ttl);
} else {
assertThat(row.getInt(0)).isZero();
}
}
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraBatchTemplateIntegrationTests method shouldInsertCollectionOfEntitiesWithTtl.
// DATACASS-574
@Test
void shouldInsertCollectionOfEntitiesWithTtl() {
walter.setEmail("walter@white.com");
int ttl = 30;
WriteOptions options = WriteOptions.builder().ttl(30).build();
ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
Mono<ReactiveResultSet> resultSet = batchOperations.insert(walter, options).execute().then(template.getReactiveCqlOperations().queryForResultSet("SELECT TTL(email), email FROM group;"));
//
resultSet.flatMapMany(ReactiveResultSet::availableRows).collectList().as(//
StepVerifier::create).assertNext(rows -> {
for (Row row : rows) {
if (walter.getEmail().equals(row.getString(1))) {
assertThat(row.getInt(0)).isBetween(1, ttl);
} else {
assertThat(row.getInt(0)).isZero();
}
}
}).verifyComplete();
}
Aggregations