use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method deleteObjectTest.
@Test
public void deleteObjectTest() {
Mutation mutation = Mutation.delete("custom_test_table", Key.of("key"));
List<Mutation> mutations = Collections.singletonList(mutation);
TestEntity entity = new TestEntity();
when(this.mutationFactory.delete(entity)).thenReturn(mutation);
verifyBeforeAndAfterEvents(new BeforeDeleteEvent(mutations, Collections.singletonList(entity), null, null), new AfterDeleteEvent(mutations, Collections.singletonList(entity), null, null), () -> this.spannerTemplate.delete(entity), x -> x.verify(this.databaseClient, times(1)).write(eq(Collections.singletonList(mutation))));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method deleteAllObjectTest.
@Test
public void deleteAllObjectTest() {
Mutation mutation = Mutation.delete("custom_test_table", Key.of("key"));
TestEntity entity = new TestEntity();
List entities = Arrays.asList(entity, entity, entity);
List<Mutation> mutations = Arrays.asList(mutation, mutation, mutation);
when(this.mutationFactory.delete(entity)).thenReturn(mutation);
verifyBeforeAndAfterEvents(new BeforeDeleteEvent(mutations, entities, null, null), new AfterDeleteEvent(mutations, entities, null, null), () -> this.spannerTemplate.deleteAll(Arrays.asList(entity, entity, entity)), x -> x.verify(this.databaseClient, times(1)).write(eq(mutations)));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplate method applyDeleteMutations.
private void applyDeleteMutations(Iterable<?> objects, List<Mutation> mutations) {
maybeEmitEvent(new BeforeDeleteEvent(mutations, objects, null, null));
applyMutations(mutations);
maybeEmitEvent(new AfterDeleteEvent(mutations, objects, null, null));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent in project spring-cloud-gcp by spring-cloud.
the class SpannerTemplateTests method deleteByKeyTest.
@Test
public void deleteByKeyTest() {
Key key = Key.of("key");
Mutation mutation = Mutation.delete("custom_test_table", key);
KeySet keys = KeySet.newBuilder().addKey(key).build();
List<Mutation> mutations = Collections.singletonList(mutation);
when(this.mutationFactory.delete(eq(TestEntity.class), same(key))).thenReturn(mutation);
verifyBeforeAndAfterEvents(new BeforeDeleteEvent(mutations, null, keys, TestEntity.class), new AfterDeleteEvent(mutations, null, keys, TestEntity.class), () -> this.spannerTemplate.delete(TestEntity.class, key), x -> x.verify(this.databaseClient, times(1)).write(eq(Collections.singletonList(mutation))));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.event.BeforeDeleteEvent 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))));
}
Aggregations