Search in sources :

Example 1 with FlatGroup

use of org.springframework.data.cassandra.domain.FlatGroup in project spring-data-cassandra by spring-projects.

the class CassandraBatchTemplateIntegrationTests method shouldUpdatesCollectionOfEntities.

// DATACASS-288
@Test
void shouldUpdatesCollectionOfEntities() {
    FlatGroup walter = new FlatGroup("users", "0x1", "walter");
    FlatGroup mike = new FlatGroup("users", "0x1", "mike");
    template.insert(walter);
    template.insert(mike);
    walter.setEmail("walter@white.com");
    mike.setEmail("mike@sauls.com");
    CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
    batchOperations.update(Arrays.asList(walter, mike)).execute();
    FlatGroup loaded = template.selectOneById(walter, FlatGroup.class);
    assertThat(loaded.getEmail()).isEqualTo(walter.getEmail());
}
Also used : FlatGroup(org.springframework.data.cassandra.domain.FlatGroup) Test(org.junit.jupiter.api.Test)

Example 2 with FlatGroup

use of org.springframework.data.cassandra.domain.FlatGroup in project spring-data-cassandra by spring-projects.

the class ReactiveCassandraBatchTemplateIntegrationTests method shouldUpdateMonoCollectionOfEntities.

// DATACASS-574
@Test
void shouldUpdateMonoCollectionOfEntities() {
    FlatGroup walter = new FlatGroup("users", "0x1", "walter");
    FlatGroup mike = new FlatGroup("users", "0x1", "mike");
    ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
    Mono<FlatGroup> loadedMono = template.insert(walter).then(template.insert(mike)).then(Mono.fromRunnable(() -> {
        walter.setEmail("walter@white.com");
        mike.setEmail("mike@sauls.com");
    })).then(Mono.defer(() -> batchOperations.update(Collections.singletonList(walter)).update(Mono.just(Collections.singletonList(mike))).execute())).then(template.selectOneById(walter, FlatGroup.class));
    // 
    loadedMono.as(// 
    StepVerifier::create).assertNext(loaded -> assertThat(loaded.getEmail()).isEqualTo(walter.getEmail())).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DefaultBridgedReactiveSession(org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) GroupKey(org.springframework.data.cassandra.domain.GroupKey) SchemaTestUtils(org.springframework.data.cassandra.repository.support.SchemaTestUtils) Mono(reactor.core.publisher.Mono) Random(java.util.Random) AbstractKeyspaceCreatingIntegrationTests(org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) FlatGroup(org.springframework.data.cassandra.domain.FlatGroup) Group(org.springframework.data.cassandra.domain.Group) BatchType(com.datastax.oss.driver.api.core.cql.BatchType) ReactiveCqlTemplate(org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) Collections(java.util.Collections) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Row(com.datastax.oss.driver.api.core.cql.Row) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) FlatGroup(org.springframework.data.cassandra.domain.FlatGroup) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 3 with FlatGroup

use of org.springframework.data.cassandra.domain.FlatGroup in project spring-data-cassandra by spring-projects.

the class ReactiveCassandraBatchTemplateIntegrationTests method shouldUpdateMonoOfEntities.

// DATACASS-574
@Test
void shouldUpdateMonoOfEntities() {
    FlatGroup walter = new FlatGroup("users", "0x1", "walter");
    FlatGroup mike = new FlatGroup("users", "0x1", "mike");
    ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
    Mono<FlatGroup> loadedMono = template.insert(walter).then(template.insert(mike)).then(Mono.fromRunnable(() -> {
        walter.setEmail("walter@white.com");
        mike.setEmail("mike@sauls.com");
    })).then(Mono.defer(() -> batchOperations.update(Arrays.asList(walter, mike)).execute())).then(template.selectOneById(walter, FlatGroup.class));
    // 
    loadedMono.as(// 
    StepVerifier::create).assertNext(loaded -> assertThat(loaded.getEmail()).isEqualTo(walter.getEmail())).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DefaultBridgedReactiveSession(org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) GroupKey(org.springframework.data.cassandra.domain.GroupKey) SchemaTestUtils(org.springframework.data.cassandra.repository.support.SchemaTestUtils) Mono(reactor.core.publisher.Mono) Random(java.util.Random) AbstractKeyspaceCreatingIntegrationTests(org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) FlatGroup(org.springframework.data.cassandra.domain.FlatGroup) Group(org.springframework.data.cassandra.domain.Group) BatchType(com.datastax.oss.driver.api.core.cql.BatchType) ReactiveCqlTemplate(org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) Collections(java.util.Collections) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Row(com.datastax.oss.driver.api.core.cql.Row) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) FlatGroup(org.springframework.data.cassandra.domain.FlatGroup) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 FlatGroup (org.springframework.data.cassandra.domain.FlatGroup)3 BatchType (com.datastax.oss.driver.api.core.cql.BatchType)2 Row (com.datastax.oss.driver.api.core.cql.Row)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Random (java.util.Random)2 TimeUnit (java.util.concurrent.TimeUnit)2 Assertions (org.assertj.core.api.Assertions)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ReactiveResultSet (org.springframework.data.cassandra.ReactiveResultSet)2 MappingCassandraConverter (org.springframework.data.cassandra.core.convert.MappingCassandraConverter)2 ReactiveCqlTemplate (org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate)2 WriteOptions (org.springframework.data.cassandra.core.cql.WriteOptions)2 DefaultBridgedReactiveSession (org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession)2 Group (org.springframework.data.cassandra.domain.Group)2 GroupKey (org.springframework.data.cassandra.domain.GroupKey)2 SchemaTestUtils (org.springframework.data.cassandra.repository.support.SchemaTestUtils)2 AbstractKeyspaceCreatingIntegrationTests (org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests)2 Mono (reactor.core.publisher.Mono)2