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

[2.x] Perform clear-and-replace when applying entity Migration #1419

Merged
merged 7 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -502,12 +502,12 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:53 EET 2021** 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 **Tue Nov 16 17:34:34 EET 2021** 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:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -969,12 +969,12 @@ This report was generated on **Fri Nov 12 16:46:53 EET 2021** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:54 EET 2021** 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 **Tue Nov 16 17:34:35 EET 2021** 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:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine.tools:spine-model-assembler:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -1476,12 +1476,12 @@ This report was generated on **Fri Nov 12 16:46:54 EET 2021** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:55 EET 2021** 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 **Tue Nov 16 17:34:35 EET 2021** 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:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine.tools:spine-model-verifier:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.github.ben-manes.caffeine. **Name** : caffeine. **Version** : 2.8.8.
Expand Down Expand Up @@ -2079,12 +2079,12 @@ This report was generated on **Fri Nov 12 16:46:55 EET 2021** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:55 EET 2021** 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 **Tue Nov 16 17:34:36 EET 2021** 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:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -2594,12 +2594,12 @@ This report was generated on **Fri Nov 12 16:46:55 EET 2021** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:56 EET 2021** 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 **Tue Nov 16 17:34:37 EET 2021** 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-testutil-client:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3153,12 +3153,12 @@ This report was generated on **Fri Nov 12 16:46:56 EET 2021** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:57 EET 2021** 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 **Tue Nov 16 17:34:37 EET 2021** 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-testutil-core:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3712,12 +3712,12 @@ This report was generated on **Fri Nov 12 16:46:57 EET 2021** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:57 EET 2021** 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 **Tue Nov 16 17:34:38 EET 2021** 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-testutil-server:2.0.0-SNAPSHOT.77`
# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.78`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -4315,4 +4315,4 @@ This report was generated on **Fri Nov 12 16:46:57 EET 2021** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Nov 12 16:46:58 EET 2021** 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 **Tue Nov 16 17:34:39 EET 2021** 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).
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>2.0.0-SNAPSHOT.77</version>
<version>2.0.0-SNAPSHOT.78</version>

<inceptionYear>2015</inceptionYear>

Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/io/spine/server/entity/Migration.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ private Operation(E entity, RecordBasedRepository<I, E, S> repository) {

private void updateState(S newState) {
if (!entity.state().equals(newState)) {
tx.builder().mergeFrom(newState);
tx.builder().clear()
.mergeFrom(newState);
Version version = increment(entity.version());
tx.setVersion(version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import io.spine.server.procman.given.delivery.GivenMessage;
import io.spine.server.procman.given.repo.EventDiscardingProcManRepository;
import io.spine.server.procman.given.repo.ProjectCompletion;
import io.spine.server.procman.given.repo.RandomFillProcess;
import io.spine.server.procman.given.repo.RememberingSubscriber;
import io.spine.server.procman.given.repo.SensoryDeprivedPmRepository;
import io.spine.server.procman.given.repo.SetTestProcessId;
Expand Down Expand Up @@ -703,7 +704,7 @@ void performCustomMigrationForMultiple() {
repository.store(pm2);
repository.store(pm3);

// Init filters by the `name` column.
// Query by the `name` column.
Project.Query query =
Project.query()
.name().is(NEW_NAME)
Expand All @@ -720,24 +721,43 @@ void performCustomMigrationForMultiple() {
Iterator<TestProcessManager> foundAfterMigration = repository.find(query);

ImmutableList<TestProcessManager> results = ImmutableList.copyOf(foundAfterMigration);
Project expectedState1 = pm1
.state()
.toBuilder()
.setName(NEW_NAME)
.setIdString(pm1.getIdString())
.build();
Project expectedState2 = pm2
.state()
.toBuilder()
.setName(NEW_NAME)
.setIdString(pm2.getIdString())
.build();
Project expectedState1 = expectedState(pm1, NEW_NAME);
Project expectedState2 = expectedState(pm2, NEW_NAME);
assertThat(results).hasSize(2);
assertThat(results)
.comparingElementsUsing(entityState())
.containsExactly(expectedState1, expectedState2);
}

@Test
@DisplayName("replace the state of the migrated process")
void replaceState() {
ProjectId id = createId(42);
TestProcessManager entity = new TestProcessManager(id);
TestProcessManagerRepository repository = repository();
repository.store(entity);
repository.applyMigration(id, new RandomFillProcess());

Project.Query byNewName =
Project.query()
.name().is(NEW_NAME)
.build();

// Ensure nothing found.
Iterator<TestProcessManager> expectedEmpty = repository.find(byNewName);
assertThat(expectedEmpty.hasNext()).isFalse();

repository.applyMigration(id, new SetTestProcessName());

// Now we should have found a single instance.
Iterator<TestProcessManager> shouldHaveOne = repository.find(byNewName);
Project expectedState = expectedState(entity, NEW_NAME);
ImmutableList<TestProcessManager> actualList = ImmutableList.copyOf(shouldHaveOne);
assertThat(actualList)
.comparingElementsUsing(entityState())
.containsExactly(expectedState);
}

@Test
@DisplayName("update state via migration operation")
void updateState() {
Expand Down Expand Up @@ -868,4 +888,14 @@ private static Correspondence<TestProcessManager, Project> entityState() {
private static boolean hasState(TestProcessManager actual, Project expected) {
return actual.state().equals(expected);
}

private static Project expectedState(TestProcessManager entity, String expectedName) {
return entity
.state()
.toBuilder()
.setId(entity.id())
.setName(expectedName)
.setIdString(entity.getIdString())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2021, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
* disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package io.spine.server.procman.given.repo;

import io.spine.server.procman.ProcessManagerMigration;
import io.spine.test.procman.Project;
import io.spine.test.procman.ProjectId;
import io.spine.test.procman.Task;
import io.spine.test.procman.TaskId;

import static io.spine.base.Identifier.newUuid;
import static io.spine.test.procman.Project.Status.DONE;

/**
* Fills the state of the migrated {@code ProcessManager} with some random values.
*/
public final class RandomFillProcess
extends ProcessManagerMigration<ProjectId, TestProcessManager, Project, Project.Builder> {

@Override
public Project apply(Project project) {
Project newState = project
.toBuilder()
.setId(project.getId())
.setName(newUuid())
.setStatus(DONE)
.addTask(task())
.vBuild();
return newState;
}

private static Task task() {
return Task.newBuilder()
.setTaskId(taskId())
.setTitle(newUuid())
.setDescription(newUuid())
.vBuild();
}

private static TaskId taskId() {
return TaskId.newBuilder()
.setId(newUuid().hashCode())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public final class SetTestProcessName
public Project apply(Project project) {
Project newState = project
.toBuilder()
.clear()
.setId(id())
.setName(NEW_NAME)
.build();
.vBuild();
return newState;
}
}
Loading