, V> environmentValues =
@@ -138,6 +136,21 @@ void ifPresentForEnvironment(Class extends EnvironmentType> type,
}
}
+ /**
+ * Applies the passed operation to this setting regardless of current environment.
+ *
+ * This means the operation is applied to all passed setting {@linkplain #environmentValues
+ * values} on a per-environment basis.
+ *
+ * @apiNote The not yet run {@linkplain #fallbacks fallback suppliers} are ignored to avoid an
+ * unnecessary value instantiation.
+ */
+ void apply(SettingOperation operation) throws Exception {
+ for (V v : environmentValues.values()) {
+ operation.accept(v);
+ }
+ }
+
/**
* If the value corresponding to the specified environment type is set, returns it.
*
diff --git a/server/src/main/java/io/spine/server/ServerEnvironment.java b/server/src/main/java/io/spine/server/ServerEnvironment.java
index 86e7091fa15..98e134c4b95 100644
--- a/server/src/main/java/io/spine/server/ServerEnvironment.java
+++ b/server/src/main/java/io/spine/server/ServerEnvironment.java
@@ -442,9 +442,9 @@ public void reset() {
*/
@Override
public void close() throws Exception {
- tracerFactory.ifPresentForEnvironment(Production.class, AutoCloseable::close);
- transportFactory.ifPresentForEnvironment(Production.class, AutoCloseable::close);
- storageFactory.ifPresentForEnvironment(Production.class, AutoCloseable::close);
+ tracerFactory.apply(AutoCloseable::close);
+ transportFactory.apply(AutoCloseable::close);
+ storageFactory.apply(AutoCloseable::close);
}
private static void use(V value, EnvSetting setting, EnvironmentType type) {
diff --git a/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java b/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java
index 0421ed07dbe..47ff19a056e 100644
--- a/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java
+++ b/server/src/main/java/io/spine/server/event/model/StateSubscriberMethod.java
@@ -26,7 +26,7 @@
import io.spine.base.EventMessage;
import io.spine.base.Field;
import io.spine.base.FieldPath;
-import io.spine.base.Production;
+import io.spine.base.Tests;
import io.spine.core.BoundedContext;
import io.spine.core.BoundedContextName;
import io.spine.logging.Logging;
@@ -107,7 +107,7 @@ protected Class extends EventMessage> rawMessageClass() {
private BoundedContextName contextOf(Class> cls) {
Model model = Model.inContextOf(cls);
BoundedContextName name = model.contextName();
- if (Environment.instance().is(Production.class) && name.equals(assumingTests())) {
+ if (!Environment.instance().is(Tests.class) && name.equals(assumingTests())) {
_warn().log(
"The class `%s` belongs to the Bounded Context named `%s`," +
" which is used for testing. As such, it should not be used in production." +
diff --git a/server/src/main/java/io/spine/system/server/SystemSettings.java b/server/src/main/java/io/spine/system/server/SystemSettings.java
index 2e1ff1428ac..0e3e067c930 100644
--- a/server/src/main/java/io/spine/system/server/SystemSettings.java
+++ b/server/src/main/java/io/spine/system/server/SystemSettings.java
@@ -24,7 +24,7 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.spine.annotation.Internal;
import io.spine.base.Environment;
-import io.spine.base.Production;
+import io.spine.base.Tests;
/**
* A configuration of features of a system context.
@@ -61,10 +61,10 @@ public static SystemSettings defaults() {
.disableCommandLog()
.enableAggregateQuerying()
.forgetEvents();
- if (Environment.instance().is(Production.class)) {
- settings.enableParallelPosting();
- } else {
+ if (Environment.instance().is(Tests.class)) {
settings.disableParallelPosting();
+ } else {
+ settings.enableParallelPosting();
}
return settings;
}
diff --git a/server/src/test/java/io/spine/server/EnvSettingTest.java b/server/src/test/java/io/spine/server/EnvSettingTest.java
index cda3694eb55..5335523c2a3 100644
--- a/server/src/test/java/io/spine/server/EnvSettingTest.java
+++ b/server/src/test/java/io/spine/server/EnvSettingTest.java
@@ -170,37 +170,58 @@ void testRetainsDefaultForEnv(Class extends EnvironmentType> type) {
assertThat(storageFactory.value(type)).isSameInstanceAs(actualFactory);
}
}
+ }
- @Test
- @DisplayName("reset the value for all environments")
- void resetTheValues() {
- InMemoryStorageFactory prodStorageFactory = InMemoryStorageFactory.newInstance();
- MemoizingStorageFactory testingStorageFactory = new MemoizingStorageFactory();
- InMemoryStorageFactory localstorageFactory = InMemoryStorageFactory.newInstance();
+ @Test
+ @DisplayName("reset the value for all environments")
+ void resetTheValues() {
+ InMemoryStorageFactory prodStorageFactory = InMemoryStorageFactory.newInstance();
+ MemoizingStorageFactory testingStorageFactory = new MemoizingStorageFactory();
+ InMemoryStorageFactory localStorageFactory = InMemoryStorageFactory.newInstance();
- EnvSetting storageFactory = new EnvSetting<>();
- storageFactory.use(prodStorageFactory, Production.class);
- storageFactory.use(testingStorageFactory, Tests.class);
- storageFactory.use(localstorageFactory, Local.class);
+ EnvSetting storageFactory = new EnvSetting<>();
+ storageFactory.use(prodStorageFactory, Production.class);
+ storageFactory.use(testingStorageFactory, Tests.class);
+ storageFactory.use(localStorageFactory, Local.class);
- storageFactory.reset();
+ storageFactory.reset();
- Stream.of(Production.class, Tests.class, Local.class)
- .map(storageFactory::optionalValue)
- .forEach(s -> assertThat(s).isEmpty());
- }
+ Stream.of(Production.class, Tests.class, Local.class)
+ .map(storageFactory::optionalValue)
+ .forEach(s -> assertThat(s).isEmpty());
+ }
- @Test
- @DisplayName("should run an operation against a value value if it's present")
- void runThrowableConsumer() throws Exception {
- MemoizingStorageFactory storageFactory = new MemoizingStorageFactory();
+ @Test
+ @DisplayName("run an operation against a value if it's present")
+ void runThrowableConsumer() throws Exception {
+ MemoizingStorageFactory storageFactory = new MemoizingStorageFactory();
- EnvSetting storageSetting = new EnvSetting<>();
+ EnvSetting storageSetting = new EnvSetting<>();
- storageSetting.use(storageFactory, Production.class);
- storageSetting.ifPresentForEnvironment(Production.class, AutoCloseable::close);
+ storageSetting.use(storageFactory, Production.class);
+ storageSetting.ifPresentForEnvironment(Production.class, AutoCloseable::close);
+
+ assertThat(storageFactory.isClosed()).isTrue();
+ }
+
+ @Test
+ @DisplayName("run an operation for all present values")
+ void runOperationForAll() throws Exception {
+ MemoizingStorageFactory prodStorageFactory = new MemoizingStorageFactory();
+ MemoizingStorageFactory testingStorageFactory = new MemoizingStorageFactory();
+ MemoizingStorageFactory localStorageFactory = new MemoizingStorageFactory();
+
+ EnvSetting storageSetting = new EnvSetting<>();
+
+ storageSetting.use(prodStorageFactory, Production.class);
+ storageSetting.use(testingStorageFactory, Tests.class);
+ storageSetting.use(localStorageFactory, Local.class);
+
+ storageSetting.apply(AutoCloseable::close);
+
+ assertThat(prodStorageFactory.isClosed()).isTrue();
+ assertThat(testingStorageFactory.isClosed()).isTrue();
+ assertThat(localStorageFactory.isClosed()).isTrue();
- assertThat(storageFactory.isClosed()).isTrue();
- }
}
}
diff --git a/server/src/test/java/io/spine/server/ServerEnvironmentTest.java b/server/src/test/java/io/spine/server/ServerEnvironmentTest.java
index 7f64a070aa9..0f86e2b32bb 100644
--- a/server/src/test/java/io/spine/server/ServerEnvironmentTest.java
+++ b/server/src/test/java/io/spine/server/ServerEnvironmentTest.java
@@ -21,6 +21,7 @@
package io.spine.server;
import io.spine.base.Environment;
+import io.spine.base.EnvironmentType;
import io.spine.base.Production;
import io.spine.base.Tests;
import io.spine.server.delivery.Delivery;
@@ -504,32 +505,33 @@ void resetEnvironment() {
@Test
@DisplayName("close the production transport, tracer and storage factories")
- void testCloses() throws Exception {
- ServerEnvironment serverEnv = ServerEnvironment.instance();
- serverEnv.use(transportFactory, Production.class)
- .use(storageFactory, Production.class)
- .use(tracerFactory, Production.class);
-
- serverEnv.close();
+ void productionCloses() throws Exception {
+ testClosesEnv(Production.class);
+ }
- assertThat(transportFactory.isOpen()).isFalse();
- assertThat(storageFactory.isClosed()).isTrue();
- assertThat(tracerFactory.closed()).isTrue();
+ @Test
+ @DisplayName("close the testing transport, tracer and storage factories")
+ void testCloses() throws Exception {
+ testClosesEnv(Tests.class);
}
@Test
- @DisplayName("leave the testing transport, tracer and storage factories open")
- void testDoesNotClose() throws Exception {
+ @DisplayName("close the custom env transport, tracer and storage factories")
+ void customEnvCloses() throws Exception {
+ testClosesEnv(Local.class);
+ }
+
+ private void testClosesEnv(Class extends EnvironmentType> envType) throws Exception {
ServerEnvironment serverEnv = ServerEnvironment.instance();
- serverEnv.use(transportFactory, Tests.class)
- .use(storageFactory, Tests.class)
- .use(tracerFactory, Tests.class);
+ serverEnv.use(transportFactory, envType)
+ .use(storageFactory, envType)
+ .use(tracerFactory, envType);
serverEnv.close();
- assertThat(tracerFactory.closed()).isFalse();
- assertThat(transportFactory.isOpen()).isTrue();
- assertThat(storageFactory.isClosed()).isFalse();
+ assertThat(transportFactory.isOpen()).isFalse();
+ assertThat(storageFactory.isClosed()).isTrue();
+ assertThat(tracerFactory.closed()).isTrue();
}
}
diff --git a/server/src/test/java/io/spine/system/server/SystemSettingsTest.java b/server/src/test/java/io/spine/system/server/SystemSettingsTest.java
index 3d5dae37bd7..4d5bec4517d 100644
--- a/server/src/test/java/io/spine/system/server/SystemSettingsTest.java
+++ b/server/src/test/java/io/spine/system/server/SystemSettingsTest.java
@@ -23,8 +23,8 @@
import io.spine.base.Environment;
import io.spine.base.Production;
import io.spine.base.Tests;
+import io.spine.server.given.environment.Local;
import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
@@ -67,19 +67,36 @@ void events() {
assertFalse(features.includePersistentEvents());
}
+ @Nested
+ @DisplayName("allow parallel posting of system events")
+ class AllowParallelPosting {
+
+ private final Environment env = Environment.instance();
+
+ @Test
+ @DisplayName("in the `Production` environment")
+ void forProductionEnv() {
+ env.setTo(Production.class);
+ assertTrue(SystemSettings.defaults()
+ .postEventsInParallel());
+ }
+
+ @Test
+ @DisplayName("in a custom environment")
+ void forCustomEnv() {
+ env.setTo(Local.class);
+ assertTrue(SystemSettings.defaults()
+ .postEventsInParallel());
+ }
+ }
+
@Test
- @Disabled
- @DisplayName("allow parallel posting for system events")
- void parallelism() {
+ @DisplayName("disallow parallel posting of system events in the test environment")
+ void disallowParallelPostingForTest() {
Environment env = Environment.instance();
-
assumeTrue(env.is(Tests.class));
assertFalse(SystemSettings.defaults()
.postEventsInParallel());
-
- env.setTo(Production.class);
- assertTrue(SystemSettings.defaults()
- .postEventsInParallel());
}
}
diff --git a/version.gradle.kts b/version.gradle.kts
index f276dd5c548..1ee60589510 100644
--- a/version.gradle.kts
+++ b/version.gradle.kts
@@ -27,4 +27,4 @@
val spineBaseVersion: String by extra("1.5.23")
val spineTimeVersion: String by extra("1.5.21")
-val versionToPublish: String by extra("1.5.24")
+val versionToPublish: String by extra("1.5.25")