-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAddMultithreadingTest.java
69 lines (55 loc) · 2.54 KB
/
AddMultithreadingTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package by.andd3dfx.multithreading;
import by.andd3dfx.multithreading.AddMultithreading.SystemA;
import by.andd3dfx.multithreading.AddMultithreading.SystemB;
import org.junit.Test;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS;
import static org.awaitility.Durations.TWO_SECONDS;
public class AddMultithreadingTest {
@Test
public void checkMultithreadingAbsence() throws ExecutionException, InterruptedException {
var aggregator = new AddMultithreading.Aggregator(
new SystemA("One"),
new SystemB("Two")
);
var future = CompletableFuture.supplyAsync(() -> aggregator.doRequestOld());
await().atLeast(TWO_SECONDS)
.atMost(3, TimeUnit.SECONDS)
.pollInterval(ONE_HUNDRED_MILLISECONDS)
.until(() -> future.isDone());
assertThat(future.get()).isEqualTo("OneTwo");
}
@Test
public void checkMultithreadingPresence() throws ExecutionException, InterruptedException {
var aggregator = new AddMultithreading.Aggregator(
new SystemA("One"),
new SystemB("Two")
);
var future = CompletableFuture.supplyAsync(() -> aggregator.doRequest());
await().atMost(1_200, TimeUnit.MILLISECONDS)
.pollInterval(ONE_HUNDRED_MILLISECONDS)
.until(() -> future.isDone());
assertThat(future.get()).isEqualTo("OneTwo");
}
@Test
public void checkMultithreadingPresenceFor10Requests() throws ExecutionException, InterruptedException {
var aSystems = new SystemA[5];
var bSystems = new SystemB[5];
for (int i = 0; i < aSystems.length; i++) {
aSystems[i] = new SystemA(String.valueOf(i));
}
for (int i = 0; i < bSystems.length; i++) {
bSystems[i] = new SystemB(String.valueOf(i * i));
}
var aggregator = new AddMultithreading.Aggregator(aSystems, bSystems);
var future = CompletableFuture.supplyAsync(() -> aggregator.doRequest10());
await().atMost(1_500, TimeUnit.MILLISECONDS)
.pollInterval(ONE_HUNDRED_MILLISECONDS)
.until(() -> future.isDone());
assertThat(future.get()).isEqualTo("01234014916");
}
}