Skip to content

Commit

Permalink
Merge pull request #172 from AlexandreCarlton/fix-publisher-dataloade…
Browse files Browse the repository at this point in the history
…r-with-value-cache

Allow ValueCache to work with Publisher DataLoader
  • Loading branch information
bbakerman authored Jan 5, 2025
2 parents 04db8d2 + 9a20334 commit 205aaa5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/dataloader/DataLoaderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ CompletableFuture<List<V>> invokeLoader(List<K> keys, List<Object> keyContexts,
missedKeyIndexes.add(i);
missedKeys.add(keys.get(i));
missedKeyContexts.add(keyContexts.get(i));
missedQueuedFutures.add(queuedFutures.get(i));
} else {
queuedFutures.get(i).complete(cacheGet.get());
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/test/java/org/dataloader/DataLoaderValueCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class DataLoaderValueCacheTest {

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void test_by_default_we_have_no_value_caching(TestDataLoaderFactory factory) {
List<Collection<String>> loadCalls = new ArrayList<>();
DataLoaderOptions options = newOptions();
Expand Down Expand Up @@ -68,7 +68,7 @@ public void test_by_default_we_have_no_value_caching(TestDataLoaderFactory facto
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void should_accept_a_remote_value_store_for_caching(TestDataLoaderFactory factory) {
CustomValueCache customValueCache = new CustomValueCache();
List<Collection<String>> loadCalls = new ArrayList<>();
Expand Down Expand Up @@ -113,7 +113,7 @@ public void should_accept_a_remote_value_store_for_caching(TestDataLoaderFactory
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void can_use_caffeine_for_caching(TestDataLoaderFactory factory) {
//
// Mostly to prove that some other CACHE library could be used
Expand Down Expand Up @@ -154,7 +154,7 @@ public void can_use_caffeine_for_caching(TestDataLoaderFactory factory) {
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void will_invoke_loader_if_CACHE_GET_call_throws_exception(TestDataLoaderFactory factory) {
CustomValueCache customValueCache = new CustomValueCache() {

Expand Down Expand Up @@ -185,7 +185,7 @@ public CompletableFuture<Object> get(String key) {
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void will_still_work_if_CACHE_SET_call_throws_exception(TestDataLoaderFactory factory) {
CustomValueCache customValueCache = new CustomValueCache() {
@Override
Expand Down Expand Up @@ -214,7 +214,7 @@ public CompletableFuture<Object> set(String key, Object value) {
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void caching_can_take_some_time_complete(TestDataLoaderFactory factory) {
CustomValueCache customValueCache = new CustomValueCache() {

Expand Down Expand Up @@ -256,7 +256,7 @@ public CompletableFuture<Object> get(String key) {
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void batch_caching_works_as_expected(TestDataLoaderFactory factory) {
CustomValueCache customValueCache = new CustomValueCache() {

Expand Down Expand Up @@ -303,7 +303,7 @@ public CompletableFuture<List<Try<Object>>> getValues(List<String> keys) {
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void assertions_will_be_thrown_if_the_cache_does_not_follow_contract(TestDataLoaderFactory factory) {
CustomValueCache customValueCache = new CustomValueCache() {

Expand Down Expand Up @@ -346,7 +346,7 @@ private boolean isAssertionException(CompletableFuture<String> fA) {


@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void if_caching_is_off_its_never_hit(TestDataLoaderFactory factory) {
AtomicInteger getCalls = new AtomicInteger();
CustomValueCache customValueCache = new CustomValueCache() {
Expand Down Expand Up @@ -380,7 +380,7 @@ public CompletableFuture<Object> get(String key) {
}

@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void if_everything_is_cached_no_batching_happens(TestDataLoaderFactory factory) {
AtomicInteger getCalls = new AtomicInteger();
AtomicInteger setCalls = new AtomicInteger();
Expand Down Expand Up @@ -423,7 +423,7 @@ public CompletableFuture<List<Object>> setValues(List<String> keys, List<Object>


@ParameterizedTest
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#getWithoutPublisher")
@MethodSource("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get")
public void if_batching_is_off_it_still_can_cache(TestDataLoaderFactory factory) {
AtomicInteger getCalls = new AtomicInteger();
AtomicInteger setCalls = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.stream.Stream;

public class TestDataLoaderFactories {

public static Stream<Arguments> get() {
return Stream.of(
Arguments.of(Named.of("List DataLoader", new ListDataLoaderFactory())),
Expand All @@ -14,12 +15,4 @@ public static Stream<Arguments> get() {
Arguments.of(Named.of("Mapped Publisher DataLoader", new MappedPublisherDataLoaderFactory()))
);
}

// TODO: Remove in favour of #get when ValueCache supports Publisher Factories.
public static Stream<Arguments> getWithoutPublisher() {
return Stream.of(
Arguments.of(Named.of("List DataLoader", new ListDataLoaderFactory())),
Arguments.of(Named.of("Mapped DataLoader", new MappedDataLoaderFactory()))
);
}
}

0 comments on commit 205aaa5

Please sign in to comment.