Skip to content

Verify a throwing CacheMap#get does not break DataLoader #147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 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.");
}
}
}

Loading