Skip to content

Commit bb73524

Browse files
committed
Use CompositeFuture.join() instead of CompositeFuture.all()
1 parent 01f8ef8 commit bb73524

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/main/java/io/engagingspaces/vertx/dataloader/DataLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public Future<V> load(K key) {
123123
* @return the composite future of the list of values
124124
*/
125125
public CompositeFuture loadMany(List<K> keys) {
126-
return CompositeFuture.all(keys.stream().map(this::load).collect(Collectors.toList()));
126+
return CompositeFuture.join(keys.stream().map(this::load).collect(Collectors.toList()));
127127
}
128128

129129
/**
@@ -135,7 +135,7 @@ public CompositeFuture loadMany(List<K> keys) {
135135
*/
136136
public CompositeFuture dispatch() {
137137
if (!loaderOptions.batchingEnabled() || loaderQueue.size() == 0) {
138-
return CompositeFuture.all(Collections.emptyList());
138+
return CompositeFuture.join(Collections.emptyList());
139139
}
140140
CompositeFuture batch = batchLoadFunction.load(loaderQueue.keySet());
141141
batch.setHandler(rh -> {

src/test/java/io/engagingspaces/vertx/dataloader/DataLoaderTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void setUp() {
6464
public void should_Build_a_really_really_simple_data_loader() {
6565
AtomicBoolean success = new AtomicBoolean();
6666
DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keys ->
67-
CompositeFuture.all(keys.stream()
67+
CompositeFuture.join(keys.stream()
6868
.map(Future::succeededFuture)
6969
.collect(Collectors.toCollection(ArrayList::new))));
7070

@@ -81,7 +81,7 @@ public void should_Build_a_really_really_simple_data_loader() {
8181
public void should_Support_loading_multiple_keys_in_one_call() {
8282
AtomicBoolean success = new AtomicBoolean();
8383
DataLoader<Integer, Integer> identityLoader = new DataLoader<>(keys ->
84-
CompositeFuture.all(keys.stream()
84+
CompositeFuture.join(keys.stream()
8585
.map(Future::succeededFuture)
8686
.collect(Collectors.toCollection(ArrayList::new))));
8787

@@ -321,20 +321,25 @@ public void should_Resolve_to_error_to_indicate_failure() {
321321

322322
@Test
323323
public void should_Represent_failures_and_successes_simultaneously() {
324+
AtomicBoolean success = new AtomicBoolean();
324325
ArrayList<Collection> loadCalls = new ArrayList<>();
325326
DataLoader<Integer, Integer> evenLoader = idLoaderWithErrors(new DataLoaderOptions(), loadCalls);
326327

327328
Future<Integer> future1 = evenLoader.load(1);
328329
Future<Integer> future2 = evenLoader.load(2);
329-
evenLoader.dispatch();
330+
Future<Integer> future3 = evenLoader.load(3);
331+
Future<Integer> future4 = evenLoader.load(4);
332+
CompositeFuture result = evenLoader.dispatch();
333+
result.setHandler(rh -> success.set(true));
330334

331-
await().until(future1::isComplete);
335+
await().untilAtomic(success, is(true));
332336
assertThat(future1.failed(), is(true));
333337
assertThat(future1.cause(), instanceOf(IllegalStateException.class));
334-
335-
await().until(future2::isComplete);
336338
assertThat(future2.result(), equalTo(2));
337-
assertThat(loadCalls, equalTo(Collections.singletonList(Arrays.asList(1, 2))));
339+
assertThat(future3.failed(), is(true));
340+
assertThat(future4.result(), equalTo(4));
341+
342+
assertThat(loadCalls, equalTo(Collections.singletonList(Arrays.asList(1, 2, 3, 4))));
338343
}
339344

340345
@Test
@@ -733,7 +738,7 @@ private static <K, V> DataLoader<K, V> idLoader(DataLoaderOptions options, List<
733738
return new DataLoader<>(keys -> {
734739
loadCalls.add(new ArrayList(keys));
735740
List<Future> futures = keys.stream().map(Future::succeededFuture).collect(Collectors.toList());
736-
return CompositeFuture.all(futures);
741+
return CompositeFuture.join(futures);
737742
}, options);
738743
}
739744

@@ -745,7 +750,7 @@ private static <K, V> DataLoader<K, V> idLoaderAllErrors(
745750
List<Future> futures = keys.stream()
746751
.map(key -> Future.failedFuture(new IllegalStateException("Error")))
747752
.collect(Collectors.toList());
748-
return CompositeFuture.all(futures);
753+
return CompositeFuture.join(futures);
749754
}, options);
750755
}
751756

@@ -758,7 +763,7 @@ private static DataLoader<Integer, Integer> idLoaderWithErrors(
758763
.map(key -> key % 2 == 0 ? Future.succeededFuture(key) :
759764
Future.failedFuture(new IllegalStateException("Error")))
760765
.collect(Collectors.toList());
761-
return CompositeFuture.all(futures);
766+
return CompositeFuture.join(futures);
762767
}, options);
763768
}
764769
}

0 commit comments

Comments
 (0)