Skip to content

Commit 56204a2

Browse files
authored
Merge pull request #1295 from SpineEventEngine/improve-command-filter-rejections-support
Improve support of rejections thrown from the `CommandBus` filters
2 parents 86aaa54 + e4e7f78 commit 56204a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1414
-221
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2020, TeamDev. All rights reserved.
3+
*
4+
* Redistribution and use in source and/or binary forms, with or without
5+
* modification, must retain the above copyright notice and the following
6+
* disclaimer.
7+
*
8+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
10+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
15+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
16+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
17+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
18+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19+
*/
20+
21+
package io.spine.grpc;
22+
23+
import com.google.common.collect.ImmutableList;
24+
import io.grpc.stub.StreamObserver;
25+
26+
import static com.google.common.base.Preconditions.checkNotNull;
27+
28+
/**
29+
* A stream observer which delegates calls to multiple other observers with the same target type.
30+
*
31+
* <p>The observers are called in the exact same order in which they are specified on the object
32+
* construction.
33+
*
34+
* @param <T>
35+
* the observed type
36+
*/
37+
public final class CompositeObserver<T> implements StreamObserver<T> {
38+
39+
private final ImmutableList<StreamObserver<? super T>> observers;
40+
41+
public CompositeObserver(Iterable<StreamObserver<? super T>> observers) {
42+
checkNotNull(observers);
43+
this.observers = ImmutableList.copyOf(observers);
44+
}
45+
46+
@Override
47+
public void onNext(T value) {
48+
observers.forEach(o -> o.onNext(value));
49+
}
50+
51+
@Override
52+
public void onError(Throwable t) {
53+
observers.forEach(o -> o.onError(t));
54+
}
55+
56+
@Override
57+
public void onCompleted() {
58+
observers.forEach(StreamObserver::onCompleted);
59+
}
60+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2020, TeamDev. All rights reserved.
3+
*
4+
* Redistribution and use in source and/or binary forms, with or without
5+
* modification, must retain the above copyright notice and the following
6+
* disclaimer.
7+
*
8+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
9+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
10+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
11+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
12+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
13+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
14+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
15+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
16+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
17+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
18+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19+
*/
20+
21+
package io.spine.grpc;
22+
23+
import com.google.common.collect.ImmutableList;
24+
import com.google.common.testing.NullPointerTester;
25+
import io.grpc.stub.StreamObserver;
26+
import org.junit.jupiter.api.DisplayName;
27+
import org.junit.jupiter.api.Test;
28+
29+
import static com.google.common.truth.Truth.assertThat;
30+
31+
@DisplayName("`CompositeObserver` should")
32+
class CompositeObserverTest {
33+
34+
@Test
35+
@DisplayName("not accept `null` observer list on construction")
36+
void passNullToleranceCheck() {
37+
new NullPointerTester()
38+
.testAllPublicConstructors(CompositeObserver.class);
39+
}
40+
41+
@Test
42+
@DisplayName("delegate `onNext` calls to wrapped observers")
43+
void delegateOnNext() {
44+
MemoizingObserver<String> observer1 = StreamObservers.memoizingObserver();
45+
MemoizingObserver<String> observer2 = StreamObservers.memoizingObserver();
46+
StreamObserver<String> observer =
47+
new CompositeObserver<>(ImmutableList.of(observer1, observer2));
48+
49+
String value = "String value.";
50+
observer.onNext(value);
51+
52+
assertThat(observer1.firstResponse()).isEqualTo(value);
53+
assertThat(observer2.firstResponse()).isEqualTo(value);
54+
}
55+
56+
@Test
57+
@DisplayName("delegate `onError` calls to wrapped observers")
58+
void delegateOnError() {
59+
MemoizingObserver<String> observer1 = StreamObservers.memoizingObserver();
60+
MemoizingObserver<String> observer2 = StreamObservers.memoizingObserver();
61+
StreamObserver<String> observer =
62+
new CompositeObserver<>(ImmutableList.of(observer1, observer2));
63+
64+
RuntimeException error = new RuntimeException("An error.");
65+
observer.onError(error);
66+
67+
assertThat(observer1.getError()).isEqualTo(error);
68+
assertThat(observer2.getError()).isEqualTo(error);
69+
}
70+
71+
@Test
72+
@DisplayName("delegate `onCompleted` calls to wrapped observers")
73+
void delegateOnCompleted() {
74+
MemoizingObserver<String> observer1 = StreamObservers.memoizingObserver();
75+
MemoizingObserver<String> observer2 = StreamObservers.memoizingObserver();
76+
StreamObserver<String> observer =
77+
new CompositeObserver<>(ImmutableList.of(observer1, observer2));
78+
79+
observer.onCompleted();
80+
81+
assertThat(observer1.isCompleted()).isTrue();
82+
assertThat(observer2.isCompleted()).isTrue();
83+
}
84+
}

license-report.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
# Dependencies of `io.spine:spine-client:1.5.25`
3+
# Dependencies of `io.spine:spine-client:1.5.27`
44

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

408408

409-
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).
409+
This report was generated on **Mon Aug 31 12:45:57 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).
410410

411411

412412

413413

414-
# Dependencies of `io.spine:spine-core:1.5.25`
414+
# Dependencies of `io.spine:spine-core:1.5.27`
415415

416416
## Runtime
417417
1. **Group:** com.google.code.findbugs **Name:** jsr305 **Version:** 3.0.2
@@ -777,12 +777,12 @@ This report was generated on **Tue Aug 18 15:45:58 EEST 2020** using [Gradle-Lic
777777
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
778778

779779

780-
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).
780+
This report was generated on **Mon Aug 31 12:45:57 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).
781781

782782

783783

784784

785-
# Dependencies of `io.spine.tools:spine-model-assembler:1.5.25`
785+
# Dependencies of `io.spine.tools:spine-model-assembler:1.5.27`
786786

787787
## Runtime
788788
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1183,12 +1183,12 @@ This report was generated on **Tue Aug 18 15:45:59 EEST 2020** using [Gradle-Lic
11831183
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
11841184

11851185

1186-
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).
1186+
This report was generated on **Mon Aug 31 12: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).
11871187

11881188

11891189

11901190

1191-
# Dependencies of `io.spine.tools:spine-model-verifier:1.5.25`
1191+
# Dependencies of `io.spine.tools:spine-model-verifier:1.5.27`
11921192

11931193
## Runtime
11941194
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -1659,12 +1659,12 @@ This report was generated on **Tue Aug 18 15:46:00 EEST 2020** using [Gradle-Lic
16591659
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
16601660

16611661

1662-
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).
1662+
This report was generated on **Mon Aug 31 12: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).
16631663

16641664

16651665

16661666

1667-
# Dependencies of `io.spine:spine-server:1.5.25`
1667+
# Dependencies of `io.spine:spine-server:1.5.27`
16681668

16691669
## Runtime
16701670
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2082,12 +2082,12 @@ This report was generated on **Tue Aug 18 15:46:00 EEST 2020** using [Gradle-Lic
20822082
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
20832083

20842084

2085-
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).
2085+
This report was generated on **Mon Aug 31 12: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).
20862086

20872087

20882088

20892089

2090-
# Dependencies of `io.spine:spine-testutil-client:1.5.25`
2090+
# Dependencies of `io.spine:spine-testutil-client:1.5.27`
20912091

20922092
## Runtime
20932093
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -2542,12 +2542,12 @@ This report was generated on **Tue Aug 18 15:46:01 EEST 2020** using [Gradle-Lic
25422542
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
25432543

25442544

2545-
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).
2545+
This report was generated on **Mon Aug 31 12: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).
25462546

25472547

25482548

25492549

2550-
# Dependencies of `io.spine:spine-testutil-core:1.5.25`
2550+
# Dependencies of `io.spine:spine-testutil-core:1.5.27`
25512551

25522552
## Runtime
25532553
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -3010,12 +3010,12 @@ This report was generated on **Tue Aug 18 15:46:04 EEST 2020** using [Gradle-Lic
30103010
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
30113011

30123012

3013-
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).
3013+
This report was generated on **Mon Aug 31 12:46:02 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).
30143014

30153015

30163016

30173017

3018-
# Dependencies of `io.spine:spine-testutil-server:1.5.25`
3018+
# Dependencies of `io.spine:spine-testutil-server:1.5.27`
30193019

30203020
## Runtime
30213021
1. **Group:** com.google.android **Name:** annotations **Version:** 4.1.1.4
@@ -3514,4 +3514,4 @@ This report was generated on **Tue Aug 18 15:46:05 EEST 2020** using [Gradle-Lic
35143514
The dependencies distributed under several licenses, are used according their commercial-use-friendly license.
35153515

35163516

3517-
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).
3517+
This report was generated on **Mon Aug 31 12: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).

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ all modules and does not describe the project structure per-subproject.
1212

1313
<groupId>io.spine</groupId>
1414
<artifactId>spine-core-java</artifactId>
15-
<version>1.5.25</version>
15+
<version>1.5.27</version>
1616

1717
<inceptionYear>2015</inceptionYear>
1818

@@ -70,25 +70,25 @@ all modules and does not describe the project structure per-subproject.
7070
<dependency>
7171
<groupId>io.spine</groupId>
7272
<artifactId>spine-base</artifactId>
73-
<version>1.5.23</version>
73+
<version>1.5.29</version>
7474
<scope>compile</scope>
7575
</dependency>
7676
<dependency>
7777
<groupId>io.spine</groupId>
7878
<artifactId>spine-time</artifactId>
79-
<version>1.5.21</version>
79+
<version>1.5.24</version>
8080
<scope>compile</scope>
8181
</dependency>
8282
<dependency>
8383
<groupId>io.spine.tools</groupId>
8484
<artifactId>spine-model-compiler</artifactId>
85-
<version>1.5.23</version>
85+
<version>1.5.29</version>
8686
<scope>compile</scope>
8787
</dependency>
8888
<dependency>
8989
<groupId>io.spine.tools</groupId>
9090
<artifactId>spine-plugin-base</artifactId>
91-
<version>1.5.23</version>
91+
<version>1.5.29</version>
9292
<scope>compile</scope>
9393
</dependency>
9494
<dependency>
@@ -130,25 +130,25 @@ all modules and does not describe the project structure per-subproject.
130130
<dependency>
131131
<groupId>io.spine</groupId>
132132
<artifactId>spine-testlib</artifactId>
133-
<version>1.5.23</version>
133+
<version>1.5.29</version>
134134
<scope>test</scope>
135135
</dependency>
136136
<dependency>
137137
<groupId>io.spine</groupId>
138138
<artifactId>spine-testutil-time</artifactId>
139-
<version>1.5.21</version>
139+
<version>1.5.24</version>
140140
<scope>test</scope>
141141
</dependency>
142142
<dependency>
143143
<groupId>io.spine.tools</groupId>
144144
<artifactId>spine-mute-logging</artifactId>
145-
<version>1.5.23</version>
145+
<version>1.5.29</version>
146146
<scope>test</scope>
147147
</dependency>
148148
<dependency>
149149
<groupId>io.spine.tools</groupId>
150150
<artifactId>spine-plugin-testlib</artifactId>
151-
<version>1.5.23</version>
151+
<version>1.5.29</version>
152152
<scope>test</scope>
153153
</dependency>
154154
<dependency>
@@ -204,12 +204,12 @@ all modules and does not describe the project structure per-subproject.
204204
<dependency>
205205
<groupId>io.spine.tools</groupId>
206206
<artifactId>spine-javadoc-filter</artifactId>
207-
<version>1.5.23</version>
207+
<version>1.5.29</version>
208208
</dependency>
209209
<dependency>
210210
<groupId>io.spine.tools</groupId>
211211
<artifactId>spine-protoc-plugin</artifactId>
212-
<version>1.5.23</version>
212+
<version>1.5.29</version>
213213
</dependency>
214214
<dependency>
215215
<groupId>net.sourceforge.pmd</groupId>

server/src/main/java/io/spine/server/BoundedContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ protected final void init() {
147147
eventBus.registerWith(this);
148148
tenantIndex.registerWith(this);
149149
broker.registerWith(this);
150+
commandBus.initObservers(eventBus);
150151
}
151152

152153
/**

server/src/main/java/io/spine/server/BoundedContextBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public BoundedContextBuilder addCommandDispatcher(CommandDispatcher commandDispa
283283
* <p>The order of appending the filters to the builder is the order of the filters in
284284
* the {@code CommandBus}.
285285
*/
286+
@CanIgnoreReturnValue
286287
public BoundedContextBuilder addCommandFilter(BusFilter<CommandEnvelope> filter) {
287288
checkNotNull(filter);
288289
commandBus.appendFilter(filter);
@@ -321,6 +322,7 @@ public BoundedContextBuilder addEventDispatcher(EventDispatcher eventDispatcher)
321322
* @param filter
322323
* the filter to add
323324
*/
325+
@CanIgnoreReturnValue
324326
public BoundedContextBuilder addEventFilter(BusFilter<EventEnvelope> filter) {
325327
checkNotNull(filter);
326328
eventBus.appendFilter(filter);
@@ -656,7 +658,9 @@ public BoundedContextBuilder testingCopy() {
656658
copy.enrichEventsUsing(enricher);
657659
repositories().forEach(copy::add);
658660
commandDispatchers().forEach(copy::addCommandDispatcher);
661+
commandBus.filters().forEach(copy::addCommandFilter);
659662
eventDispatchers().forEach(copy::addEventDispatcher);
663+
eventBus.filters().forEach(copy::addEventFilter);
660664
return copy;
661665
}
662666
}

server/src/main/java/io/spine/server/CommandService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import java.util.Map;
3737
import java.util.Set;
3838

39-
import static io.spine.server.bus.Buses.reject;
39+
import static io.spine.server.bus.Acks.reject;
4040

4141
/**
4242
* The {@code CommandService} allows client applications to post commands and

0 commit comments

Comments
 (0)