-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathOrchestratorTest.java
More file actions
77 lines (57 loc) · 2.96 KB
/
OrchestratorTest.java
File metadata and controls
77 lines (57 loc) · 2.96 KB
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
70
71
72
73
74
75
76
77
package org.dataloader.orchestration;
import org.dataloader.DataLoader;
import org.dataloader.DataLoaderOptions;
import org.dataloader.DataLoaderRegistry;
import org.junit.jupiter.api.Test;
import java.util.concurrent.CompletableFuture;
import static org.awaitility.Awaitility.await;
import static org.dataloader.DataLoaderFactory.newDataLoader;
import static org.dataloader.fixtures.TestKit.lowerCaseBatchLoader;
import static org.dataloader.fixtures.TestKit.reverseBatchLoader;
import static org.dataloader.fixtures.TestKit.upperCaseBatchLoader;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
class OrchestratorTest {
DataLoaderOptions cachingAndBatchingOptions = DataLoaderOptions.newOptions().setBatchingEnabled(true).setCachingEnabled(true);
DataLoader<String, String> dlUpper = newDataLoader(upperCaseBatchLoader(), cachingAndBatchingOptions);
DataLoader<String, String> dlLower = newDataLoader(lowerCaseBatchLoader(), cachingAndBatchingOptions);
DataLoader<String, String> dlReverse = newDataLoader(reverseBatchLoader(), cachingAndBatchingOptions);
@Test
void canOrchestrate() {
DataLoaderRegistry registry = DataLoaderRegistry.newRegistry()
.register("upper", dlUpper)
.register("lower", dlLower)
.register("reverse", dlReverse)
.build();
Orchestrator<String, String> orchestrator = Orchestrator.orchestrate(dlUpper);
Step<String, String> step1 = orchestrator.load("aBc", null);
With<String, String> with1 = step1.with(dlLower);
Step<String, String> step2 = with1.thenLoad(key -> key);
With<String, String> with2 = step2.with(dlReverse);
Step<String, String> step3 = with2.thenLoad(key -> key);
CompletableFuture<String> cf = step3.toCompletableFuture();
// because all the dls are dispatched in "perfect order" here they all end up dispatching
// at JUST the right time. A change in order would be different
registry.dispatchAll();
await().until(cf::isDone);
assertThat(cf.join(), equalTo("cba"));
}
@Test
void canOrchestrateWhenNotInPerfectOrder() {
DataLoaderRegistry registry = DataLoaderRegistry.newRegistry()
.register("reverse", dlReverse)
.register("lower", dlLower)
.register("upper", dlUpper)
.build();
Orchestrator<String, String> orchestrator = Orchestrator.orchestrate(dlUpper);
CompletableFuture<String> cf = orchestrator.load("aBc", null)
.with(dlLower).thenLoad(key1 -> key1)
.with(dlReverse).thenLoad(key -> key)
.toCompletableFuture();
registry.dispatchAll();
assertThat(cf.isDone(), equalTo(false));
assertThat(orchestrator.getTracker().getOutstandingLoadCount(),equalTo(2));
await().until(cf::isDone);
assertThat(cf.join(), equalTo("cba"));
}
}