1
1
package com .decathlon .tzatziki .steps ;
2
2
3
+ import com .decathlon .tzatziki .utils .Asserts ;
3
4
import com .decathlon .tzatziki .utils .Comparison ;
4
5
import com .decathlon .tzatziki .utils .Guard ;
5
6
import com .decathlon .tzatziki .utils .Interaction ;
6
7
import io .cucumber .java .Before ;
7
8
import io .cucumber .java .en .Given ;
9
+ import io .cucumber .java .en .Then ;
8
10
import lombok .RequiredArgsConstructor ;
9
11
12
+ import java .util .List ;
13
+ import java .util .concurrent .CompletableFuture ;
14
+ import java .util .concurrent .ExecutorService ;
15
+ import java .util .concurrent .Executors ;
10
16
import java .util .stream .IntStream ;
11
17
18
+ import static com .decathlon .tzatziki .utils .MockFaster .target ;
19
+ import static com .decathlon .tzatziki .utils .Patterns .QUOTED_CONTENT ;
20
+ import static com .decathlon .tzatziki .utils .Unchecked .unchecked ;
21
+ import static io .restassured .RestAssured .given ;
22
+
12
23
@ RequiredArgsConstructor
13
24
public class LocalSteps {
14
25
private final HttpSteps httpSteps ;
26
+ private final ObjectSteps objects ;
15
27
16
28
static {
17
29
Interaction .printResponses = true ;
@@ -32,4 +44,18 @@ public void mockIdEndpointAsSeveralMocks(int startId, int endId) {
32
44
payload: Hello %d
33
45
""" .formatted (idx )));
34
46
}
47
+
48
+ @ Then ("getting (?:on )?" + QUOTED_CONTENT + " four times in parallel returns:$" )
49
+ public void sendInParallel (String path , String content ) {
50
+ ExecutorService executor = Executors .newFixedThreadPool (4 );
51
+
52
+ List <CompletableFuture <Interaction .Response >> responsesAsync = List .of (
53
+ CompletableFuture .supplyAsync (() -> Interaction .Response .fromResponse (Interaction .Request .builder ().build ().send (given (), target (path ), objects )), executor ),
54
+ CompletableFuture .supplyAsync (() -> Interaction .Response .fromResponse (Interaction .Request .builder ().build ().send (given (), target (path ), objects )), executor ),
55
+ CompletableFuture .supplyAsync (() -> Interaction .Response .fromResponse (Interaction .Request .builder ().build ().send (given (), target (path ), objects )), executor ),
56
+ CompletableFuture .supplyAsync (() -> Interaction .Response .fromResponse (Interaction .Request .builder ().build ().send (given (), target (path ), objects )), executor )
57
+ );
58
+
59
+ Asserts .contains (responsesAsync .stream ().map (future -> unchecked (() -> future .get ())).map (response -> response .body .payload ).toList (), objects .resolve (content ));
60
+ }
35
61
}
0 commit comments