Search in sources :

Example 6 with AfterDeleteEvent

use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplateTests method deleteKeysTest.

@Test
public void deleteKeysTest() {
    KeySet keys = KeySet.newBuilder().addKey(Key.of("key1")).addKey(Key.of("key2")).build();
    Mutation mutation = Mutation.delete("custom_test_table", keys);
    List<Mutation> mutations = Collections.singletonList(mutation);
    when(this.mutationFactory.delete(eq(TestEntity.class), same(keys))).thenReturn(mutation);
    verifyBeforeAndAfterEvents(new BeforeDeleteEvent(mutations, null, keys, TestEntity.class), new AfterDeleteEvent(mutations, null, keys, TestEntity.class), () -> this.spannerTemplate.delete(TestEntity.class, keys), x -> x.verify(this.databaseClient, times(1)).write(eq(Collections.singletonList(mutation))));
}
Also used : KeySet(com.google.cloud.spanner.KeySet) AfterDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent) Mutation(com.google.cloud.spanner.Mutation) BeforeDeleteEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent) Test(org.junit.Test)

Aggregations

AfterDeleteEvent (org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterDeleteEvent)6 BeforeDeleteEvent (org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent)6 Mutation (com.google.cloud.spanner.Mutation)4 Test (org.junit.Test)4 KeySet (com.google.cloud.spanner.KeySet)2 Key (com.google.cloud.spanner.Key)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PrimaryKey (org.springframework.cloud.gcp.data.spanner.core.mapping.PrimaryKey)1