2
2
3
3
import org .junit .jupiter .api .Test ;
4
4
5
- import java .util .ArrayList ;
6
- import java .util .HashMap ;
7
- import java .util .List ;
8
- import java .util .Map ;
5
+ import java .util .*;
9
6
import java .util .concurrent .CompletableFuture ;
10
7
import java .util .concurrent .atomic .AtomicInteger ;
11
8
import java .util .stream .Collectors ;
@@ -50,10 +47,14 @@ public void context_is_passed_to_batch_loader_function() {
50
47
loader .load ("A" );
51
48
loader .load ("B" );
52
49
loader .loadMany (asList ("C" , "D" ));
50
+ Map <String , ?> keysAndContexts = new LinkedHashMap <>();
51
+ keysAndContexts .put ("E" , null );
52
+ keysAndContexts .put ("F" , null );
53
+ loader .loadMany (keysAndContexts );
53
54
54
55
List <String > results = loader .dispatchAndJoin ();
55
56
56
- assertThat (results , equalTo (asList ("A-ctx" , "B-ctx" , "C-ctx" , "D-ctx" )));
57
+ assertThat (results , equalTo (asList ("A-ctx" , "B-ctx" , "C-ctx" , "D-ctx" , "E-ctx" , "F-ctx" )));
57
58
}
58
59
59
60
@ Test
@@ -66,10 +67,14 @@ public void key_contexts_are_passed_to_batch_loader_function() {
66
67
loader .load ("A" , "aCtx" );
67
68
loader .load ("B" , "bCtx" );
68
69
loader .loadMany (asList ("C" , "D" ), asList ("cCtx" , "dCtx" ));
70
+ Map <String , String > keysAndContexts = new LinkedHashMap <>();
71
+ keysAndContexts .put ("E" , "eCtx" );
72
+ keysAndContexts .put ("F" , "fCtx" );
73
+ loader .loadMany (keysAndContexts );
69
74
70
75
List <String > results = loader .dispatchAndJoin ();
71
76
72
- assertThat (results , equalTo (asList ("A-ctx-m:aCtx-l:aCtx" , "B-ctx-m:bCtx-l:bCtx" , "C-ctx-m:cCtx-l:cCtx" , "D-ctx-m:dCtx-l:dCtx" )));
77
+ assertThat (results , equalTo (asList ("A-ctx-m:aCtx-l:aCtx" , "B-ctx-m:bCtx-l:bCtx" , "C-ctx-m:cCtx-l:cCtx" , "D-ctx-m:dCtx-l:dCtx" , "E-ctx-m:eCtx-l:eCtx" , "F-ctx-m:fCtx-l:fCtx" )));
73
78
}
74
79
75
80
@ Test
@@ -82,12 +87,17 @@ public void key_contexts_are_passed_to_batch_loader_function_when_batching_disab
82
87
83
88
CompletableFuture <String > aLoad = loader .load ("A" , "aCtx" );
84
89
CompletableFuture <String > bLoad = loader .load ("B" , "bCtx" );
85
- CompletableFuture <List <String >> canDLoad = loader .loadMany (asList ("C" , "D" ), asList ("cCtx" , "dCtx" ));
90
+ CompletableFuture <List <String >> cAndDLoad = loader .loadMany (asList ("C" , "D" ), asList ("cCtx" , "dCtx" ));
91
+ Map <String , String > keysAndContexts = new LinkedHashMap <>();
92
+ keysAndContexts .put ("E" , "eCtx" );
93
+ keysAndContexts .put ("F" , "fCtx" );
94
+ CompletableFuture <Map <String , String >> eAndFLoad = loader .loadMany (keysAndContexts );
86
95
87
96
List <String > results = new ArrayList <>(asList (aLoad .join (), bLoad .join ()));
88
- results .addAll (canDLoad .join ());
97
+ results .addAll (cAndDLoad .join ());
98
+ results .addAll (eAndFLoad .join ().values ());
89
99
90
- assertThat (results , equalTo (asList ("A-ctx-m:aCtx-l:aCtx" , "B-ctx-m:bCtx-l:bCtx" , "C-ctx-m:cCtx-l:cCtx" , "D-ctx-m:dCtx-l:dCtx" )));
100
+ assertThat (results , equalTo (asList ("A-ctx-m:aCtx-l:aCtx" , "B-ctx-m:bCtx-l:bCtx" , "C-ctx-m:cCtx-l:cCtx" , "D-ctx-m:dCtx-l:dCtx" , "E-ctx-m:eCtx-l:eCtx" , "F-ctx-m:fCtx-l:fCtx" )));
91
101
}
92
102
93
103
@ Test
@@ -101,9 +111,14 @@ public void missing_key_contexts_are_passed_to_batch_loader_function() {
101
111
loader .load ("B" );
102
112
loader .loadMany (asList ("C" , "D" ), singletonList ("cCtx" ));
103
113
114
+ Map <String , String > keysAndContexts = new LinkedHashMap <>();
115
+ keysAndContexts .put ("E" , "eCtx" );
116
+ keysAndContexts .put ("F" , null );
117
+ loader .loadMany (keysAndContexts );
118
+
104
119
List <String > results = loader .dispatchAndJoin ();
105
120
106
- assertThat (results , equalTo (asList ("A-ctx-m:aCtx-l:aCtx" , "B-ctx-m:null-l:null" , "C-ctx-m:cCtx-l:cCtx" , "D-ctx-m:null-l:null" )));
121
+ assertThat (results , equalTo (asList ("A-ctx-m:aCtx-l:aCtx" , "B-ctx-m:null-l:null" , "C-ctx-m:cCtx-l:cCtx" , "D-ctx-m:null-l:null" , "E-ctx-m:eCtx-l:eCtx" , "F-ctx-m:null-l:null" )));
107
122
}
108
123
109
124
@ Test
@@ -125,9 +140,14 @@ public void context_is_passed_to_map_batch_loader_function() {
125
140
loader .load ("B" );
126
141
loader .loadMany (asList ("C" , "D" ), singletonList ("cCtx" ));
127
142
143
+ Map <String , String > keysAndContexts = new LinkedHashMap <>();
144
+ keysAndContexts .put ("E" , "eCtx" );
145
+ keysAndContexts .put ("F" , null );
146
+ loader .loadMany (keysAndContexts );
147
+
128
148
List <String > results = loader .dispatchAndJoin ();
129
149
130
- assertThat (results , equalTo (asList ("A-ctx-aCtx" , "B-ctx-null" , "C-ctx-cCtx" , "D-ctx-null" )));
150
+ assertThat (results , equalTo (asList ("A-ctx-aCtx" , "B-ctx-null" , "C-ctx-cCtx" , "D-ctx-null" , "E-ctx-eCtx" , "F-ctx-null" )));
131
151
}
132
152
133
153
@ Test
@@ -142,9 +162,14 @@ public void null_is_passed_as_context_if_you_do_nothing() {
142
162
loader .load ("B" );
143
163
loader .loadMany (asList ("C" , "D" ));
144
164
165
+ Map <String , String > keysAndContexts = new LinkedHashMap <>();
166
+ keysAndContexts .put ("E" , null );
167
+ keysAndContexts .put ("F" , null );
168
+ loader .loadMany (keysAndContexts );
169
+
145
170
List <String > results = loader .dispatchAndJoin ();
146
171
147
- assertThat (results , equalTo (asList ("A-null" , "B-null" , "C-null" , "D-null" )));
172
+ assertThat (results , equalTo (asList ("A-null" , "B-null" , "C-null" , "D-null" , "E-null" , "F-null" )));
148
173
}
149
174
150
175
@ Test
@@ -160,9 +185,14 @@ public void null_is_passed_as_context_to_map_loader_if_you_do_nothing() {
160
185
loader .load ("B" );
161
186
loader .loadMany (asList ("C" , "D" ));
162
187
188
+ Map <String , String > keysAndContexts = new LinkedHashMap <>();
189
+ keysAndContexts .put ("E" , null );
190
+ keysAndContexts .put ("F" , null );
191
+ loader .loadMany (keysAndContexts );
192
+
163
193
List <String > results = loader .dispatchAndJoin ();
164
194
165
- assertThat (results , equalTo (asList ("A-null" , "B-null" , "C-null" , "D-null" )));
195
+ assertThat (results , equalTo (asList ("A-null" , "B-null" , "C-null" , "D-null" , "E-null" , "F-null" )));
166
196
}
167
197
168
198
@ Test
0 commit comments