Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how the Migrations with custom state update are applied #1298

Merged
merged 30 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7ad387d
Never allow empty IDs.
yuri-sergiichuk Sep 2, 2020
75b5794
Add custom migration test
yuri-sergiichuk Sep 2, 2020
4380449
Add missing transaction version update to `Migration`
dmitrykuzmin Sep 2, 2020
4263d1f
Enable the custom PM migration test
dmitrykuzmin Sep 2, 2020
d5218a6
Add a test for batch custom migration application
dmitrykuzmin Sep 2, 2020
4fcf821
Add custom migration tests for projection repository
dmitrykuzmin Sep 2, 2020
06274d3
Merge branch 'master' of https://github.com/SpineEventEngine/core-jav…
dmitrykuzmin Sep 2, 2020
9636ca6
Bring back the `[(required) = false]` workaround for PM tests
dmitrykuzmin Sep 2, 2020
effbfaf
Bump versions
dmitrykuzmin Sep 2, 2020
896d157
Fix formatting
dmitrykuzmin Sep 2, 2020
6c130f0
Bring back a test proto comment
dmitrykuzmin Sep 2, 2020
a1fb917
Reorder fields of `Migration.Operation` and mark them as `@LazyInit`
dmitrykuzmin Sep 3, 2020
bb24048
Improve doc of server/src/test/java/io/spine/server/projection/given/…
dmitrykuzmin Sep 3, 2020
e9c6cd4
Improve doc of server/src/test/java/io/spine/server/procman/given/rep…
dmitrykuzmin Sep 3, 2020
adcb6ba
Merge remote-tracking branch 'origin/fix-migrations' into fix-migrations
dmitrykuzmin Sep 3, 2020
9e9c6a4
Make custom migration tests more robust
dmitrykuzmin Sep 3, 2020
7f54a15
Reword a test constant
dmitrykuzmin Sep 3, 2020
f93e2a5
Expand `Migration` doc
dmitrykuzmin Sep 3, 2020
e3a7c76
Merge branch 'master' of https://github.com/SpineEventEngine/core-jav…
dmitrykuzmin Sep 3, 2020
9789df6
Use `Truth8` instead of `Truth` for optionals
dmitrykuzmin Sep 3, 2020
47baf5c
Bump version
dmitrykuzmin Sep 3, 2020
6692fc9
Flip `.equals()`
dmitrykuzmin Sep 3, 2020
9b2e61f
Reword `Migration` doc
dmitrykuzmin Sep 3, 2020
bd252e2
Remove a redundant `see` section
dmitrykuzmin Sep 3, 2020
9c2667a
Use the expected state in column tests
dmitrykuzmin Sep 3, 2020
453e45f
Use the expected entity states for batch migration tests
dmitrykuzmin Sep 3, 2020
7cc8d0d
Improve doc of server/src/main/java/io/spine/server/entity/Migration.…
dmitrykuzmin Sep 3, 2020
2b1c011
Merge remote-tracking branch 'origin/fix-migrations' into fix-migrations
dmitrykuzmin Sep 3, 2020
1168c6a
Use static imports for `Truth8.assertThat(...)`
dmitrykuzmin Sep 3, 2020
2c9e533
Make entity state comparison in migration tests clearer
dmitrykuzmin Sep 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions license-report.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


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

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


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).
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).




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

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


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).
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).




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

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


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).
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).




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

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


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).
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).




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

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


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).
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).




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

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


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).
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).




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

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


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).
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).




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

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


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).
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).
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.

<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>1.5.28</version>
<version>1.5.30</version>

<inceptionYear>2015</inceptionYear>

Expand Down Expand Up @@ -70,7 +70,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-base</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -82,13 +82,13 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-model-compiler</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-base</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -130,7 +130,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-testlib</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -142,13 +142,13 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-mute-logging</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-plugin-testlib</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -204,12 +204,12 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-javadoc-filter</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
</dependency>
<dependency>
<groupId>io.spine.tools</groupId>
<artifactId>spine-protoc-plugin</artifactId>
<version>1.5.29</version>
<version>1.5.31</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
Expand Down
32 changes: 24 additions & 8 deletions server/src/main/java/io/spine/server/entity/Migration.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package io.spine.server.entity;

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

/**
* Applies the migration to a given entity, starting a new migration
* {@linkplain Operation operation}.
* Applies the migration {@linkplain Operation operation} to a given {@code entity}.
*/
final void applyTo(E entity, RecordBasedRepository<I, E, S> repository) {
currentOperation = new Operation<>(entity, repository);
Expand Down Expand Up @@ -195,6 +195,7 @@ final void finishCurrentOperation() {
Transaction<I, E, S, ?> tx = startTransaction(entity);
EntityLifecycleMonitor<I> monitor = configureLifecycleMonitor(id);
tx.setListener(monitor);
currentOperation().tx = tx;
return tx;
}

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

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

@LazyInit
private @MonotonicNonNull Transaction<I, E, S, ?> tx;

@LazyInit
private @MonotonicNonNull Event systemEvent;
dmitrykuzmin marked this conversation as resolved.
Show resolved Hide resolved

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

private void updateState(S newState) {
if (!entity.state().equals(newState)) {
entity.updateState(newState, increment(entity.version()));
tx.builder().mergeFrom(newState);
Version version = increment(entity.version());
tx.setVersion(version);
}
}

private void updateLifecycle() {
if (archive) {
entity.setArchived(true);
tx.setArchived(true);
}
if (delete) {
entity.setDeleted(true);
tx.setDeleted(true);
}
}

Expand Down
8 changes: 3 additions & 5 deletions server/src/test/java/io/spine/client/ClientBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package io.spine.client;

import com.google.common.testing.NullPointerTester;
import com.google.common.truth.Truth8;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.spine.core.TenantId;
Expand All @@ -39,6 +38,7 @@
import java.util.concurrent.TimeUnit;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static io.spine.client.Client.connectTo;
import static io.spine.client.Client.usingChannel;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -175,8 +175,7 @@ class Tenant {
@DisplayName("assuming single-tenant context if not set")
void singleTenant() {
client = builder.build();
Truth8.assertThat(client.tenant())
.isEmpty();
assertThat(client.tenant()).isEmpty();
}

@Test
Expand All @@ -185,8 +184,7 @@ void correctValue() {
TenantId expected = GivenTenantId.generate();
client = builder.forTenant(expected)
.build();
Truth8.assertThat(client.tenant())
.hasValue(expected);
assertThat(client.tenant()).hasValue(expected);
}

@Test
Expand Down
5 changes: 2 additions & 3 deletions server/src/test/java/io/spine/core/CoreMixinsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

package io.spine.core;

import com.google.common.truth.Truth8;
import io.spine.core.given.CoreMixinsTestEnv;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Optional;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;

/**
* Tests of mixins for {@code core} {@code Message}s.
Expand Down Expand Up @@ -87,8 +87,7 @@ void messageIdMixin() {
void originIdMixin() {
Optional<Origin> origin = CoreMixinsTestEnv.event()
.origin();
Truth8.assertThat(origin)
.isPresent();
assertThat(origin).isPresent();
assertThat(origin.get()
.checkFieldsReachable()).isTrue();
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/test/java/io/spine/core/EnrichmentsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import com.google.common.testing.NullPointerTester;
import com.google.common.truth.OptionalSubject;
import com.google.common.truth.Truth8;
import com.google.protobuf.Message;
import com.google.protobuf.StringValue;
import io.spine.base.Identifier;
Expand All @@ -43,6 +42,7 @@
import java.util.Optional;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static io.spine.base.Identifier.newUuid;
import static io.spine.core.Enrichments.containerIn;
import static io.spine.protobuf.AnyPacker.pack;
Expand Down Expand Up @@ -141,7 +141,7 @@ void returnAbsentOnNoEnrichments() {

private static
OptionalSubject assertEnrichment(EventContext ctx, Class<? extends Message> cls) {
return Truth8.assertThat(ctx.find(cls));
return assertThat(ctx.find(cls));
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions server/src/test/java/io/spine/server/BoundedContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.example.ForeignContextConfig;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.truth.Truth8;
import io.spine.annotation.Internal;
import io.spine.core.BoundedContextName;
import io.spine.logging.Logging;
Expand Down Expand Up @@ -67,6 +66,7 @@
import java.util.stream.Stream;

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

context.register(new SecretProjectRepository());

Truth8.assertThat(context.internalAccess()
.findRepository(SecretProject.class))
.isEmpty();
assertThat(context.internalAccess()
.findRepository(SecretProject.class))
.isEmpty();
}

@Test
Expand Down
Loading