From 376cbc95025bf1a7d032335666f92e0ce6ef5562 Mon Sep 17 00:00:00 2001 From: Alex Tymchenko Date: Tue, 7 Feb 2023 10:22:04 +0000 Subject: [PATCH 1/4] Bump version to `1.9.0-SNAPSHOT.9`. --- version.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.gradle.kts b/version.gradle.kts index 3f8b9f046e..787f1cf6b9 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -34,7 +34,7 @@ /** * Version of this library. */ -val coreJava = "1.9.0-SNAPSHOT.8" +val coreJava = "1.9.0-SNAPSHOT.9" /** * Versions of the Spine libraries that `core-java` depends on. From dfb51e729b2dbfaa3bed8b9ad2bac5262f9bc88f Mon Sep 17 00:00:00 2001 From: Alex Tymchenko Date: Tue, 7 Feb 2023 10:35:49 +0000 Subject: [PATCH 2/4] Fix a typo. --- .../java/io/spine/server/integration/ThirdPartyContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/io/spine/server/integration/ThirdPartyContext.java b/server/src/main/java/io/spine/server/integration/ThirdPartyContext.java index ea35d42d4e..c5db36c2d4 100644 --- a/server/src/main/java/io/spine/server/integration/ThirdPartyContext.java +++ b/server/src/main/java/io/spine/server/integration/ThirdPartyContext.java @@ -53,7 +53,7 @@ * @implSpec Note that a {@code ThirdPartyContext} sends a request for external messages to * other contexts. The {@code ThirdPartyContext} never consumes external messages itself, * but requires the other Bounded Contexts to send their requests, so that the publishing - * channels are open. Depending of the implementation of + * channels are open. Depending on the implementation of * {@link io.spine.server.transport.TransportFactory transport}, creating * a {@code ThirdPartyContext} may be an expensive operation. Thus, it is recommended that * the instances of this class are reused and {@linkplain #close() closed} when they are From 13790cac287f1de6fa7f7b7d3cede06f40188477 Mon Sep 17 00:00:00 2001 From: Alex Tymchenko Date: Tue, 7 Feb 2023 12:29:52 +0000 Subject: [PATCH 3/4] Ensure the events imported via `ThirdPartyContext` are dispatched in scope of `TenantAwareOperation`. --- .../server/integration/IntegrationBroker.java | 4 ++- .../integration/ThirdPartyContextTest.java | 17 +++++++--- .../integration/given/DocumentRepository.java | 33 +++++++++++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/io/spine/server/integration/IntegrationBroker.java b/server/src/main/java/io/spine/server/integration/IntegrationBroker.java index 4bc486e53a..9b32aeb91f 100644 --- a/server/src/main/java/io/spine/server/integration/IntegrationBroker.java +++ b/server/src/main/java/io/spine/server/integration/IntegrationBroker.java @@ -37,6 +37,7 @@ import io.spine.server.ContextAware; import io.spine.server.ServerEnvironment; import io.spine.server.event.EventDispatcher; +import io.spine.server.tenant.TenantAwareRunner; import io.spine.server.transport.ChannelId; import io.spine.server.transport.Publisher; import io.spine.server.transport.PublisherHub; @@ -245,7 +246,8 @@ void dispatchLocally(Event event) { * Dispatches the given event via the local {@code EventBus} and observes the acknowledgement. */ void dispatchLocally(Event event, StreamObserver ackObserver) { - bus.dispatch(event, ackObserver); + TenantAwareRunner.with(event.tenant()) + .run(() -> bus.dispatch(event, ackObserver)); } /** diff --git a/server/src/test/java/io/spine/server/integration/ThirdPartyContextTest.java b/server/src/test/java/io/spine/server/integration/ThirdPartyContextTest.java index 7a385484dc..92725dfe60 100644 --- a/server/src/test/java/io/spine/server/integration/ThirdPartyContextTest.java +++ b/server/src/test/java/io/spine/server/integration/ThirdPartyContextTest.java @@ -82,9 +82,7 @@ void prepareContext() { @AfterEach void closeContext() throws Exception { context.close(); - ServerEnvironment - .instance() - .reset(); + resetServerEnvironment(); } @Test @@ -213,11 +211,16 @@ void domesticSubscriber() { @Test @DisplayName("in a multitenant environment") void multitenant() { + /* Getting rid of the class-level repositories and bounded contexts. */ + resetServerEnvironment(); + DocumentRepository documentRepository = new DocumentRepository(); - BoundedContextBuilder + BoundedContext boundedContext = BoundedContextBuilder .assumingTests(true) .add(documentRepository) .build(); + assertThat(boundedContext.isMultitenant()) + .isTrue(); UserId johnDoe = userId(); TenantId acmeCorp = TenantId .newBuilder() @@ -248,6 +251,12 @@ void multitenant() { assertThat(cyberdyneDailyReport).isEmpty(); } + private static void resetServerEnvironment() { + ServerEnvironment + .instance() + .reset(); + } + private static void postForSingleTenant(UserId actor, EventMessage event) { try (ThirdPartyContext uploads = ThirdPartyContext.singleTenant("Imports")) { uploads.emittedEvent(event, actor); diff --git a/server/src/test/java/io/spine/server/integration/given/DocumentRepository.java b/server/src/test/java/io/spine/server/integration/given/DocumentRepository.java index 3e2cc88259..4f9c42e0cd 100644 --- a/server/src/test/java/io/spine/server/integration/given/DocumentRepository.java +++ b/server/src/test/java/io/spine/server/integration/given/DocumentRepository.java @@ -32,9 +32,12 @@ import io.spine.server.integration.PaperDocumentScanned; import io.spine.server.route.EventRouting; +import java.util.Optional; +import java.util.Set; + import static io.spine.server.route.EventRoute.withId; -public class DocumentRepository extends AggregateRepository { +public final class DocumentRepository extends AggregateRepository { @Override protected void setupImportRouting(EventRouting routing) { @@ -45,7 +48,31 @@ protected void setupImportRouting(EventRouting routing) { @Override protected void setupEventRouting(EventRouting routing) { super.setupEventRouting(routing); - routing.route(OpenOfficeDocumentUploaded.class, - (message, context) -> withId(message.getId())); + routing.route(OpenOfficeDocumentUploaded.class, (message, context) -> route(message)); + } + + /** + * Routes an external event to the instances of {@link DocumentAggregate}. + * + *

This method includes an explicit call to repository's {@code find(..)} method. + * This is done to ensure that even in multi-tenant environment such a call + * is available, meaning that the {@code TenantId} is present in scope + * of runtime execution context. + * + *

Corresponding tests are available + * in {@link io.spine.server.integration.IntegrationBrokerTest IntegrationBrokerTest}. + * + * @param event + * event to route + * @return set of identifiers + */ + private Set route(OpenOfficeDocumentUploaded event) { + DocumentId id = event.getId(); + Optional aggregate = find(id); + if (!aggregate.isPresent()) { + _debug().log("`Document` aggregate is not found by ID `%s`. " + + "Creating a new instance.", id); + } + return withId(id); } } From f3981b29cf507d6d8450d54f1506de98020f062c Mon Sep 17 00:00:00 2001 From: Alex Tymchenko Date: Tue, 7 Feb 2023 12:40:46 +0000 Subject: [PATCH 4/4] Update the report files. --- license-report.md | 32 ++++++++++++++++---------------- pom.xml | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/license-report.md b/license-report.md index 7e03af0124..c7ce3d1544 100644 --- a/license-report.md +++ b/license-report.md @@ -1,6 +1,6 @@ -# Dependencies of `io.spine:spine-client:1.9.0-SNAPSHOT.8` +# Dependencies of `io.spine:spine-client:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -399,12 +399,12 @@ The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:45 WET 2023** 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 Feb 07 12:37:58 WET 2023** 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.9.0-SNAPSHOT.8` +# Dependencies of `io.spine:spine-core:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2 @@ -763,12 +763,12 @@ This report was generated on **Fri Feb 03 15:42:45 WET 2023** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:45 WET 2023** 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 Feb 07 12:37:58 WET 2023** 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.9.0-SNAPSHOT.8` +# Dependencies of `io.spine.tools:spine-model-assembler:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -1162,12 +1162,12 @@ This report was generated on **Fri Feb 03 15:42:45 WET 2023** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:46 WET 2023** 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 Feb 07 12:37:59 WET 2023** 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.9.0-SNAPSHOT.8` +# Dependencies of `io.spine.tools:spine-model-verifier:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -1627,12 +1627,12 @@ This report was generated on **Fri Feb 03 15:42:46 WET 2023** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:46 WET 2023** 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 Feb 07 12:38:00 WET 2023** 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.9.0-SNAPSHOT.8` +# Dependencies of `io.spine:spine-server:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -2039,12 +2039,12 @@ This report was generated on **Fri Feb 03 15:42:46 WET 2023** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:47 WET 2023** 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 Feb 07 12:38:00 WET 2023** 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.9.0-SNAPSHOT.8` +# Dependencies of `io.spine:spine-testutil-client:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -2493,12 +2493,12 @@ This report was generated on **Fri Feb 03 15:42:47 WET 2023** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:50 WET 2023** 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 Feb 07 12:38:03 WET 2023** 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.9.0-SNAPSHOT.8` +# Dependencies of `io.spine:spine-testutil-core:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -2947,12 +2947,12 @@ This report was generated on **Fri Feb 03 15:42:50 WET 2023** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:52 WET 2023** 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 Feb 07 12:38:05 WET 2023** 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.9.0-SNAPSHOT.8` +# Dependencies of `io.spine:spine-testutil-server:1.9.0-SNAPSHOT.9` ## Runtime 1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4 @@ -3445,4 +3445,4 @@ This report was generated on **Fri Feb 03 15:42:52 WET 2023** using [Gradle-Lice The dependencies distributed under several licenses, are used according their commercial-use-friendly license. -This report was generated on **Fri Feb 03 15:42:56 WET 2023** 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). \ No newline at end of file +This report was generated on **Tue Feb 07 12:38:09 WET 2023** 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). \ No newline at end of file diff --git a/pom.xml b/pom.xml index 10e1fa0b31..021c7db8b5 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject. io.spine spine-core-java -1.9.0-SNAPSHOT.8 +1.9.0-SNAPSHOT.9 2015