Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion 22 src/test/java/org/dataloader/DataLoaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -826,6 +827,20 @@ public void should_Accept_a_custom_cache_map_implementation() throws ExecutionEx
assertArrayEquals(customMap.stash.keySet().toArray(), emptyList().toArray());
}

@Test
public void should_degrade_gracefully_if_cache_get_throws() {
CacheMap<String, Object> cache = new ThrowingCacheMap();
DataLoaderOptions options = newOptions().setCachingEnabled(true).setCacheMap(cache);
List<Collection<String>> loadCalls = new ArrayList<>();
DataLoader<String, String> identityLoader = idLoader(options, loadCalls);

assertThat(identityLoader.getIfPresent("a"), equalTo(Optional.empty()));

CompletableFuture<String> future = identityLoader.load("a");
identityLoader.dispatch();
assertThat(future.join(), equalTo("a"));
}

@Test
public void batching_disabled_should_dispatch_immediately() {
List<Collection<String>> loadCalls = new ArrayList<>();
Expand Down Expand Up @@ -1097,10 +1112,15 @@ private static DataLoader<Integer, Object> idLoaderOddEvenExceptions(
}, options);
}


private <T> BatchLoader<T, T> keysAsValues() {
return CompletableFuture::completedFuture;
}

private static class ThrowingCacheMap extends CustomCacheMap {
@Override
public CompletableFuture<Object> get(String key) {
throw new RuntimeException("Cache implementation failed.");
}
}
}

Morty Proxy This is a proxified and sanitized view of the page, visit original site.