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

Improve custom environments support #1293

Merged
merged 5 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all 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:1.5.24`
# Dependencies of `io.spine:spine-client:1.5.25`

## 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 **Fri Aug 14 14:46: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).
This report was generated on **Tue Aug 18 15:45:58 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.24`
# Dependencies of `io.spine:spine-core:1.5.25`

## 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 **Fri Aug 14 14:46:46 EEST 2020** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 14 14:46: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).
This report was generated on **Tue Aug 18 15:45:59 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.24`
# Dependencies of `io.spine.tools:spine-model-assembler:1.5.25`

## 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 **Fri Aug 14 14:46:46 EEST 2020** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 14 14:46: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).
This report was generated on **Tue Aug 18 15:46:00 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.24`
# Dependencies of `io.spine.tools:spine-model-verifier:1.5.25`

## 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 **Fri Aug 14 14:46:47 EEST 2020** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 14 14:46: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).
This report was generated on **Tue Aug 18 15:46:00 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.24`
# Dependencies of `io.spine:spine-server:1.5.25`

## 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 **Fri Aug 14 14:46:47 EEST 2020** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 14 14:46: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).
This report was generated on **Tue Aug 18 15:46:01 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.24`
# Dependencies of `io.spine:spine-testutil-client:1.5.25`

## 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 **Fri Aug 14 14:46:47 EEST 2020** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 14 14:46: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).
This report was generated on **Tue Aug 18 15:46: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).




# Dependencies of `io.spine:spine-testutil-core:1.5.24`
# Dependencies of `io.spine:spine-testutil-core:1.5.25`

## 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 **Fri Aug 14 14:46:49 EEST 2020** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 14 14:46: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).
This report was generated on **Tue Aug 18 15:46:05 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.24`
# Dependencies of `io.spine:spine-testutil-server:1.5.25`

## 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 **Fri Aug 14 14:46:50 EEST 2020** using [Gradle-Lic
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.


This report was generated on **Fri Aug 14 14:46:51 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 **Tue Aug 18 15:46: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).
2 changes: 1 addition & 1 deletion 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.24</version>
<version>1.5.25</version>

<inceptionYear>2015</inceptionYear>

Expand Down
17 changes: 15 additions & 2 deletions server/src/main/java/io/spine/server/EnvSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package io.spine.server;

import com.google.common.annotations.VisibleForTesting;
import io.spine.annotation.Internal;
import io.spine.base.EnvironmentType;

import java.util.HashMap;
Expand Down Expand Up @@ -86,7 +85,6 @@
* @param <V>
* the type of value
*/
@Internal
armiol marked this conversation as resolved.
Show resolved Hide resolved
final class EnvSetting<V> {

private final Map<Class<? extends EnvironmentType>, V> environmentValues =
Expand Down Expand Up @@ -138,6 +136,21 @@ void ifPresentForEnvironment(Class<? extends EnvironmentType> type,
}
}

/**
* Applies the passed operation to this setting regardless of current environment.
*
* <p>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<V> operation) throws Exception {
for (V v : environmentValues.values()) {
operation.accept(v);
}
}

/**
* If the value corresponding to the specified environment type is set, returns it.
*
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/java/io/spine/server/ServerEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <V> void use(V value, EnvSetting<V> setting, EnvironmentType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
69 changes: 45 additions & 24 deletions server/src/test/java/io/spine/server/EnvSettingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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> storageFactory = new EnvSetting<>();
storageFactory.use(prodStorageFactory, Production.class);
storageFactory.use(testingStorageFactory, Tests.class);
storageFactory.use(localstorageFactory, Local.class);
EnvSetting<StorageFactory> 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<StorageFactory> storageSetting = new EnvSetting<>();
EnvSetting<StorageFactory> 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<StorageFactory> 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();
}
}
}
38 changes: 20 additions & 18 deletions server/src/test/java/io/spine/server/ServerEnvironmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand Down
Loading