File tree Expand file tree Collapse file tree 3 files changed +18
-19
lines changed
chapter-5-quarkus-kafka-streams/src/test/java/org/acme
chapter-5-spring-kafka-streams/src/test/java/org/acme Expand file tree Collapse file tree 3 files changed +18
-19
lines changed Original file line number Diff line number Diff line change 11package org .acme .rest ;
22
3+ import static org .assertj .core .api .Assertions .assertThat ;
34import static org .awaitility .Awaitility .await ;
45
56import java .net .URI ;
@@ -31,10 +32,17 @@ void testPricesEventStream() {
3132
3233 List <Double > received = new CopyOnWriteArrayList <>();
3334
34- SseEventSource source = SseEventSource .target (target ).build ();
35- source .register (inboundSseEvent -> received .add (Double .valueOf (inboundSseEvent .readData ())));
36- source .open ();
37- await ().atMost (Duration .ofSeconds (20 )).until (() -> received .size () == 3 );
38- source .close ();
35+ try (SseEventSource source = SseEventSource .target (target ).build ()) {
36+ source .register (inboundSseEvent -> received .add (Double .valueOf (inboundSseEvent .readData ())));
37+ source .open ();
38+
39+ await ()
40+ .atMost (Duration .ofSeconds (20 ))
41+ .until (() -> received .size () == 3 );
42+ }
43+
44+ assertThat (received )
45+ .hasSize (3 )
46+ .allMatch (value -> (value >= 0 ) && (value < 100 ));
3947 }
4048}
Original file line number Diff line number Diff line change 44
55import java .time .Duration ;
66import java .util .List ;
7- import java .util .function .Predicate ;
87
98import org .junit .jupiter .api .Test ;
109
1312class PriceGeneratorTests {
1413 PriceGenerator priceGenerator = new PriceGenerator ();
1514
16- private static final Predicate <Integer > VALUE_TEST =
17- value -> (value >= 0 ) && (value < 100 );
18-
1915 @ Test
2016 public void generatesProperly () {
2117 List <Integer > prices = this .priceGenerator .generate ()
2218 .select ().first (2 )
2319 .subscribe ().withSubscriber (AssertSubscriber .create (2 ))
2420 .assertSubscribed ()
25- .awaitNextItem (Duration .ofSeconds (7 )) // Needs to be a second or 2 more than the timing of actual events
26- .awaitNextItem (Duration .ofSeconds (7 ))
21+ .awaitNextItem (Duration .ofSeconds (8 )) // Needs to be a few seconds more than the timing of actual events
22+ .awaitNextItem (Duration .ofSeconds (8 ))
2723 .awaitCompletion (Duration .ofSeconds (15 ))
2824 .assertCompleted ()
2925 .getItems ();
3026
3127 assertThat (prices )
3228 .hasSize (2 )
33- .allMatch (VALUE_TEST );
29+ .allMatch (value -> ( value >= 0 ) && ( value < 100 ) );
3430 }
3531}
Original file line number Diff line number Diff line change @@ -36,12 +36,7 @@ void sseWorks() {
3636
3737 assertThat (emittedPrices )
3838 .isNotNull ()
39- .hasSize (3 );
40-
41- emittedPrices .forEach (price ->
42- assertThat (price )
43- .isNotNull ()
44- .isGreaterThan (0 )
45- );
39+ .hasSize (3 )
40+ .allMatch (value -> (value >= 0 ) && (value < 100 ));
4641 }
4742}
You can’t perform that action at this time.
0 commit comments