From 1efbae36eec613073d532f20ee38bc6d06d1fa27 Mon Sep 17 00:00:00 2001 From: "yevhenii.nadtochii" Date: Thu, 6 Jan 2022 18:15:11 +0200 Subject: [PATCH] Extract the test into a separate test class --- .../io/spine/server/aggregate/Aggregate.java | 2 +- .../aggregate/AggregateTransaction.java | 2 +- .../aggregate/AggregateCachingTest.java | 87 +++++++++++++++++++ .../spine/server/aggregate/AggregateTest.java | 36 -------- 4 files changed, 89 insertions(+), 38 deletions(-) create mode 100644 server/src/test/java/io/spine/server/aggregate/AggregateCachingTest.java diff --git a/server/src/main/java/io/spine/server/aggregate/Aggregate.java b/server/src/main/java/io/spine/server/aggregate/Aggregate.java index eff795762b7..ec5b5b61787 100644 --- a/server/src/main/java/io/spine/server/aggregate/Aggregate.java +++ b/server/src/main/java/io/spine/server/aggregate/Aggregate.java @@ -349,7 +349,7 @@ final BatchDispatchOutcome apply(List events, int snapshotTrigger) { System.out.println("Batch size: " + events.size()); uncommittedHistory.startTracking(snapshotTrigger); System.out.println("Uncommitted size before: " + uncommittedHistory.events().list().size()); - var result = play(versionedEvents); + var result = play((List)versionedEvents); System.out.println("Batch successful ? " + result.getSuccessful()); uncommittedHistory.stopTracking(); System.out.println("Uncommitted size after: " + uncommittedHistory.events().list().size()); diff --git a/server/src/main/java/io/spine/server/aggregate/AggregateTransaction.java b/server/src/main/java/io/spine/server/aggregate/AggregateTransaction.java index 60d415b15fd..c1bdbcb8901 100644 --- a/server/src/main/java/io/spine/server/aggregate/AggregateTransaction.java +++ b/server/src/main/java/io/spine/server/aggregate/AggregateTransaction.java @@ -41,7 +41,7 @@ * * @param the type of aggregate IDs * @param the type of aggregate state - * @param the type of a {@code ValidatingBuilder} for the aggregate state + * @param the type of {@code ValidatingBuilder} for the aggregate state */ @Internal public class AggregateTransaction(EmployeeAgg.class); + BoundedContextBuilder.assumingTests() + .add(repository) + .build(); + + serverEnv.delivery().deliverMessagesFrom(shardIndex); + serverEnv.reset(); + + var storedEvents = repository.aggregateStorage() + .read(jack) + .orElseThrow() + .getEventList(); + assertThat(storedEvents.size()).isEqualTo(3); + } +} diff --git a/server/src/test/java/io/spine/server/aggregate/AggregateTest.java b/server/src/test/java/io/spine/server/aggregate/AggregateTest.java index 109eab37d44..0bfbf776ef2 100644 --- a/server/src/test/java/io/spine/server/aggregate/AggregateTest.java +++ b/server/src/test/java/io/spine/server/aggregate/AggregateTest.java @@ -457,42 +457,6 @@ void restoreSnapshot() { assertEquals(aggregate, anotherAggregate); } - @Test - @DisplayName("store events only if they were successfully applied") - void storeEventsOnlyIfApplied() { - var jack = newEmployee(); - var shardIndex = DeliveryStrategy.newIndex(0, 1); - var inboxStorage = PreparedInboxStorage.withCommands( - shardIndex, - TypeUrl.of(Employee.class), - command(employ(jack, 250)), - command(decreaseSalary(jack, 15)), - command(decreaseSalary(jack, 500)), - command(increaseSalary(jack, 500)) - ); - - var serverEnv = ServerEnvironment.instance(); - serverEnv.reset(); - ServerEnvironment.when(Tests.class).use(PreparedStorageFactory.with(inboxStorage)); - - var repository = new DefaultAggregateRepository<>(EmployeeAgg.class); - BoundedContextBuilder.assumingTests() - .add(repository) - .build(); - - serverEnv.delivery().deliverMessagesFrom(shardIndex); - serverEnv.reset(); - - var storedEvents = repository.aggregateStorage() - .read(jack) - .orElseThrow() - .getEventList(); - var singleEvent = storedEvents.get(0).enclosedMessage(); - - assertThat(storedEvents.size()).isEqualTo(1); - assertThat(singleEvent.getClass()).isEqualTo(NewEmployed.class); - } - @Nested @DisplayName("after dispatch, return event records") class ReturnEventRecords {