Skip to content

Commit 9d1f4cc

Browse files
authored
Merge pull request #1298 from SpineEventEngine/fix-migrations
Fix how the `Migration`s with custom state update are applied
2 parents eac102c + 2c9e533 commit 9d1f4cc

26 files changed

+533
-141
lines changed

license-report.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
# Dependencies of `io.spine:spine-client:1.5.28`
3+
# Dependencies of `io.spine:spine-client:1.5.30`
44

55
## Runtime
66
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -406,12 +406,12 @@
406406
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
407407

408408

409-
This report was generated on **Tue Sep 01 23:59:03 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
409+
This report was generated on **Thu Sep 03 20:06:46 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
410410

411411

412412

413413

414-
# Dependencies of `io.spine:spine-core:1.5.28`
414+
# Dependencies of `io.spine:spine-core:1.5.30`
415415

416416
## Runtime
417417
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -777,12 +777,12 @@ This report was generated on **Tue Sep 01 23:59:03 EEST 2020** using [Gradle-Lic
777777
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
778778

779779

780-
This report was generated on **Tue Sep 01 23:59:03 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
780+
This report was generated on **Thu Sep 03 20:06:46 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
781781

782782

783783

784784

785-
# Dependencies of `io.spine.tools:spine-model-assembler:1.5.28`
785+
# Dependencies of `io.spine.tools:spine-model-assembler:1.5.30`
786786

787787
## Runtime
788788
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1183,12 +1183,12 @@ This report was generated on **Tue Sep 01 23:59:03 EEST 2020** using [Gradle-Lic
11831183
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
11841184

11851185

1186-
This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
1186+
This report was generated on **Thu Sep 03 20:06:46 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
11871187

11881188

11891189

11901190

1191-
# Dependencies of `io.spine.tools:spine-model-verifier:1.5.28`
1191+
# Dependencies of `io.spine.tools:spine-model-verifier:1.5.30`
11921192

11931193
## Runtime
11941194
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1659,12 +1659,12 @@ This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-Lic
16591659
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
16601660

16611661

1662-
This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
1662+
This report was generated on **Thu Sep 03 20:06:47 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
16631663

16641664

16651665

16661666

1667-
# Dependencies of `io.spine:spine-server:1.5.28`
1667+
# Dependencies of `io.spine:spine-server:1.5.30`
16681668

16691669
## Runtime
16701670
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2082,12 +2082,12 @@ This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-Lic
20822082
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
20832083

20842084

2085-
This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2085+
This report was generated on **Thu Sep 03 20:06:47 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
20862086

20872087

20882088

20892089

2090-
# Dependencies of `io.spine:spine-testutil-client:1.5.28`
2090+
# Dependencies of `io.spine:spine-testutil-client:1.5.30`
20912091

20922092
## Runtime
20932093
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2542,12 +2542,12 @@ This report was generated on **Tue Sep 01 23:59:04 EEST 2020** using [Gradle-Lic
25422542
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
25432543

25442544

2545-
This report was generated on **Tue Sep 01 23:59:06 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
2545+
This report was generated on **Thu Sep 03 20:06:49 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
25462546

25472547

25482548

25492549

2550-
# Dependencies of `io.spine:spine-testutil-core:1.5.28`
2550+
# Dependencies of `io.spine:spine-testutil-core:1.5.30`
25512551

25522552
## Runtime
25532553
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -3010,12 +3010,12 @@ This report was generated on **Tue Sep 01 23:59:06 EEST 2020** using [Gradle-Lic
30103010
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
30113011

30123012

3013-
This report was generated on **Tue Sep 01 23:59:07 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
3013+
This report was generated on **Thu Sep 03 20:06:50 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
30143014

30153015

30163016

30173017

3018-
# Dependencies of `io.spine:spine-testutil-server:1.5.28`
3018+
# Dependencies of `io.spine:spine-testutil-server:1.5.30`
30193019

30203020
## Runtime
30213021
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -3514,4 +3514,4 @@ This report was generated on **Tue Sep 01 23:59:07 EEST 2020** using [Gradle-Lic
35143514
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
35153515

35163516

3517-
This report was generated on **Tue Sep 01 23:59:08 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
3517+
This report was generated on **Thu Sep 03 20:06:52 EEST 2020** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.
1212

1313
<groupId>io.spine</groupId>
1414
<artifactId>spine-core-java</artifactId>
15-
<version>1.5.28</version>
15+
<version>1.5.30</version>
1616

1717
<inceptionYear>2015</inceptionYear>
1818

@@ -70,7 +70,7 @@ all modules and does not describe the project structure per-subproject.
7070
<dependency>
7171
<groupId>io.spine</groupId>
7272
<artifactId>spine-base</artifactId>
73-
<version>1.5.29</version>
73+
<version>1.5.31</version>
7474
<scope>compile</scope>
7575
</dependency>
7676
<dependency>
@@ -82,13 +82,13 @@ all modules and does not describe the project structure per-subproject.
8282
<dependency>
8383
<groupId>io.spine.tools</groupId>
8484
<artifactId>spine-model-compiler</artifactId>
85-
<version>1.5.29</version>
85+
<version>1.5.31</version>
8686
<scope>compile</scope>
8787
</dependency>
8888
<dependency>
8989
<groupId>io.spine.tools</groupId>
9090
<artifactId>spine-plugin-base</artifactId>
91-
<version>1.5.29</version>
91+
<version>1.5.31</version>
9292
<scope>compile</scope>
9393
</dependency>
9494
<dependency>
@@ -130,7 +130,7 @@ all modules and does not describe the project structure per-subproject.
130130
<dependency>
131131
<groupId>io.spine</groupId>
132132
<artifactId>spine-testlib</artifactId>
133-
<version>1.5.29</version>
133+
<version>1.5.31</version>
134134
<scope>test</scope>
135135
</dependency>
136136
<dependency>
@@ -142,13 +142,13 @@ all modules and does not describe the project structure per-subproject.
142142
<dependency>
143143
<groupId>io.spine.tools</groupId>
144144
<artifactId>spine-mute-logging</artifactId>
145-
<version>1.5.29</version>
145+
<version>1.5.31</version>
146146
<scope>test</scope>
147147
</dependency>
148148
<dependency>
149149
<groupId>io.spine.tools</groupId>
150150
<artifactId>spine-plugin-testlib</artifactId>
151-
<version>1.5.29</version>
151+
<version>1.5.31</version>
152152
<scope>test</scope>
153153
</dependency>
154154
<dependency>
@@ -204,12 +204,12 @@ all modules and does not describe the project structure per-subproject.
204204
<dependency>
205205
<groupId>io.spine.tools</groupId>
206206
<artifactId>spine-javadoc-filter</artifactId>
207-
<version>1.5.29</version>
207+
<version>1.5.31</version>
208208
</dependency>
209209
<dependency>
210210
<groupId>io.spine.tools</groupId>
211211
<artifactId>spine-protoc-plugin</artifactId>
212-
<version>1.5.29</version>
212+
<version>1.5.31</version>
213213
</dependency>
214214
<dependency>
215215
<groupId>net.sourceforge.pmd</groupId>

server/src/main/java/io/spine/server/entity/Migration.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package io.spine.server.entity;
2222

23+
import com.google.errorprone.annotations.concurrent.LazyInit;
2324
import io.spine.annotation.Experimental;
2425
import io.spine.annotation.Internal;
2526
import io.spine.base.EntityState;
@@ -56,7 +57,7 @@
5657
*
5758
* <p>To create a user-defined {@code Migration} in real life scenarios, consider inheriting from
5859
* {@link io.spine.server.projection.ProjectionMigration ProjectionMigration} and
59-
* {@link io.spine.server.procman.ProcessManagerMigration ProjectionMigration} types.
60+
* {@link io.spine.server.procman.ProcessManagerMigration ProcessManagerMigration} types.
6061
*
6162
* @param <I>
6263
* the entity ID type
@@ -75,8 +76,7 @@ public abstract class Migration<I, E extends TransactionalEntity<I, S, ?>, S ext
7576
private @Nullable Operation<I, S, E> currentOperation;
7677

7778
/**
78-
* Applies the migration to a given entity, starting a new migration
79-
* {@linkplain Operation operation}.
79+
* Applies the migration {@linkplain Operation operation} to a given {@code entity}.
8080
*/
8181
final void applyTo(E entity, RecordBasedRepository<I, E, S> repository) {
8282
currentOperation = new Operation<>(entity, repository);
@@ -195,6 +195,7 @@ final void finishCurrentOperation() {
195195
Transaction<I, E, S, ?> tx = startTransaction(entity);
196196
EntityLifecycleMonitor<I> monitor = configureLifecycleMonitor(id);
197197
tx.setListener(monitor);
198+
currentOperation().tx = tx;
198199
return tx;
199200
}
200201

@@ -227,8 +228,17 @@ private Operation<I, S, E> currentOperation() {
227228
}
228229

229230
/**
230-
* A migration operation on an entity instance.
231-
*/
231+
* A migration operation on a single entity.
232+
*
233+
* <p>The operation is performed in scope of an active {@link Transaction}.
234+
*
235+
* <p>All entity state and meta-data changes are propagated to the transaction and remain in
236+
* pending state until the transaction is {@linkplain Transaction#commit() committed}, which is
237+
* the last step of a migration operation.
238+
*
239+
* <p>On a transaction commit, all changes are propagated to the actual entity passed to
240+
* {@link Migration#applyTo(TransactionalEntity, RecordBasedRepository)}, modifying it in-place.
241+
* */
232242
private static class Operation<I,
233243
S extends EntityState,
234244
E extends TransactionalEntity<I, S, ?>> {
@@ -240,6 +250,10 @@ private static class Operation<I,
240250
private final E entity;
241251
private final RecordBasedRepository<I, E, S> repository;
242252

253+
@LazyInit
254+
private @MonotonicNonNull Transaction<I, E, S, ?> tx;
255+
256+
@LazyInit
243257
private @MonotonicNonNull Event systemEvent;
244258

245259
private Operation(E entity, RecordBasedRepository<I, E, S> repository) {
@@ -249,16 +263,18 @@ private Operation(E entity, RecordBasedRepository<I, E, S> repository) {
249263

250264
private void updateState(S newState) {
251265
if (!entity.state().equals(newState)) {
252-
entity.updateState(newState, increment(entity.version()));
266+
tx.builder().mergeFrom(newState);
267+
Version version = increment(entity.version());
268+
tx.setVersion(version);
253269
}
254270
}
255271

256272
private void updateLifecycle() {
257273
if (archive) {
258-
entity.setArchived(true);
274+
tx.setArchived(true);
259275
}
260276
if (delete) {
261-
entity.setDeleted(true);
277+
tx.setDeleted(true);
262278
}
263279
}
264280

server/src/test/java/io/spine/client/ClientBuilderTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package io.spine.client;
2222

2323
import com.google.common.testing.NullPointerTester;
24-
import com.google.common.truth.Truth8;
2524
import io.grpc.ManagedChannel;
2625
import io.grpc.ManagedChannelBuilder;
2726
import io.spine.core.TenantId;
@@ -39,6 +38,7 @@
3938
import java.util.concurrent.TimeUnit;
4039

4140
import static com.google.common.truth.Truth.assertThat;
41+
import static com.google.common.truth.Truth8.assertThat;
4242
import static io.spine.client.Client.connectTo;
4343
import static io.spine.client.Client.usingChannel;
4444
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -175,8 +175,7 @@ class Tenant {
175175
@DisplayName("assuming single-tenant context if not set")
176176
void singleTenant() {
177177
client = builder.build();
178-
Truth8.assertThat(client.tenant())
179-
.isEmpty();
178+
assertThat(client.tenant()).isEmpty();
180179
}
181180

182181
@Test
@@ -185,8 +184,7 @@ void correctValue() {
185184
TenantId expected = GivenTenantId.generate();
186185
client = builder.forTenant(expected)
187186
.build();
188-
Truth8.assertThat(client.tenant())
189-
.hasValue(expected);
187+
assertThat(client.tenant()).hasValue(expected);
190188
}
191189

192190
@Test

server/src/test/java/io/spine/core/CoreMixinsTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
package io.spine.core;
2222

23-
import com.google.common.truth.Truth8;
2423
import io.spine.core.given.CoreMixinsTestEnv;
2524
import org.junit.jupiter.api.DisplayName;
2625
import org.junit.jupiter.api.Test;
2726

2827
import java.util.Optional;
2928

3029
import static com.google.common.truth.Truth.assertThat;
30+
import static com.google.common.truth.Truth8.assertThat;
3131

3232
/**
3333
* Tests of mixins for {@code core} {@code Message}s.
@@ -87,8 +87,7 @@ void messageIdMixin() {
8787
void originIdMixin() {
8888
Optional<Origin> origin = CoreMixinsTestEnv.event()
8989
.origin();
90-
Truth8.assertThat(origin)
91-
.isPresent();
90+
assertThat(origin).isPresent();
9291
assertThat(origin.get()
9392
.checkFieldsReachable()).isTrue();
9493
}

server/src/test/java/io/spine/core/EnrichmentsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import com.google.common.testing.NullPointerTester;
2424
import com.google.common.truth.OptionalSubject;
25-
import com.google.common.truth.Truth8;
2625
import com.google.protobuf.Message;
2726
import com.google.protobuf.StringValue;
2827
import io.spine.base.Identifier;
@@ -43,6 +42,7 @@
4342
import java.util.Optional;
4443

4544
import static com.google.common.truth.Truth.assertThat;
45+
import static com.google.common.truth.Truth8.assertThat;
4646
import static io.spine.base.Identifier.newUuid;
4747
import static io.spine.core.Enrichments.containerIn;
4848
import static io.spine.protobuf.AnyPacker.pack;
@@ -141,7 +141,7 @@ void returnAbsentOnNoEnrichments() {
141141

142142
private static
143143
OptionalSubject assertEnrichment(EventContext ctx, Class<? extends Message> cls) {
144-
return Truth8.assertThat(ctx.find(cls));
144+
return assertThat(ctx.find(cls));
145145
}
146146

147147
@Test

server/src/test/java/io/spine/server/BoundedContextTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.example.ForeignContextConfig;
2424
import com.google.common.collect.ImmutableSet;
2525
import com.google.common.collect.Sets;
26-
import com.google.common.truth.Truth8;
2726
import io.spine.annotation.Internal;
2827
import io.spine.core.BoundedContextName;
2928
import io.spine.logging.Logging;
@@ -67,6 +66,7 @@
6766
import java.util.stream.Stream;
6867

6968
import static com.google.common.truth.Truth.assertThat;
69+
import static com.google.common.truth.Truth8.assertThat;
7070
import static io.spine.core.BoundedContextNames.newName;
7171
import static io.spine.testing.TestValues.randomString;
7272
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -379,9 +379,9 @@ void notExposeInvisibleAggregates() {
379379

380380
context.register(new SecretProjectRepository());
381381

382-
Truth8.assertThat(context.internalAccess()
383-
.findRepository(SecretProject.class))
384-
.isEmpty();
382+
assertThat(context.internalAccess()
383+
.findRepository(SecretProject.class))
384+
.isEmpty();
385385
}
386386

387387
@Test

0 commit comments

Comments
 (0)