Skip to content

Commit b04dfa0

Browse files
author
samvazquez
committed
feat: getters for futureCache and cacheMap
1 parent 908a4a3 commit b04dfa0

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

src/main/java/org/dataloader/CacheMap.java

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.dataloader.impl.DefaultCacheMap;
2121

2222
import java.util.Collection;
23-
import java.util.Collections;
2423
import java.util.concurrent.CompletableFuture;
2524

2625
/**

src/main/java/org/dataloader/DataLoader.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.time.Duration;
2727
import java.time.Instant;
2828
import java.util.ArrayList;
29-
import java.util.Collection;
3029
import java.util.Collections;
3130
import java.util.List;
3231
import java.util.Optional;
@@ -453,14 +452,6 @@ public Duration getTimeSinceDispatch() {
453452
return Duration.between(helper.getLastDispatchTime(), helper.now());
454453
}
455454

456-
/**
457-
* This returns a read-only collection of CompletableFutures of the cache map.
458-
* @return read-only collection of CompletableFutures
459-
*/
460-
public Collection<CompletableFuture<V>> getCacheFutures() {
461-
return Collections.unmodifiableCollection(futureCache.getAll());
462-
}
463-
464455
/**
465456
* Requests to load the data with the specified key asynchronously, and returns a future of the resulting value.
466457
* <p>
@@ -760,4 +751,21 @@ public Statistics getStatistics() {
760751
return stats.getStatistics();
761752
}
762753

754+
/**
755+
* Gets the cacheMap associated with this data loader passed in via {@link DataLoaderOptions#cacheMap()}
756+
* @return the cacheMap of this data loader
757+
*/
758+
public CacheMap<Object, V> getCacheMap() {
759+
return futureCache;
760+
}
761+
762+
763+
/**
764+
* Gets the valueCache associated with this data loader passed in via {@link DataLoaderOptions#valueCache()}
765+
* @return the valueCache of this data loader
766+
*/
767+
public ValueCache<K, V> getValueCache() {
768+
return valueCache;
769+
}
770+
763771
}

src/test/java/org/dataloader/DataLoaderCacheMapTest.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void should_provide_all_futures_from_cache() {
2828
dataLoader.load(2);
2929
dataLoader.load(1);
3030

31-
Collection<CompletableFuture<Integer>> futures = dataLoader.getCacheFutures();
31+
Collection<CompletableFuture<Integer>> futures = dataLoader.getCacheMap().getAll();
3232
assertThat(futures.size(), equalTo(2));
3333
}
3434

@@ -40,21 +40,10 @@ public void should_access_to_future_dependants() {
4040
dataLoader.load(2).handle((v, t) -> t);
4141
dataLoader.load(1).handle((v, t) -> t);
4242

43-
Collection<CompletableFuture<Integer>> futures = dataLoader.getCacheFutures();
43+
Collection<CompletableFuture<Integer>> futures = dataLoader.getCacheMap().getAll();
4444

4545
List<CompletableFuture<Integer>> futuresList = new ArrayList<>(futures);
4646
assertThat(futuresList.get(0).getNumberOfDependents(), equalTo(2));
4747
assertThat(futuresList.get(1).getNumberOfDependents(), equalTo(1));
4848
}
49-
50-
@Test(expected = UnsupportedOperationException.class)
51-
public void should_throw_exception__on_mutation_attempt() {
52-
DataLoader<Integer, Integer> dataLoader = newDataLoader(keysAsValues());
53-
54-
dataLoader.load(1).handle((v, t) -> t);
55-
56-
Collection<CompletableFuture<Integer>> futures = dataLoader.getCacheFutures();
57-
58-
futures.add(CompletableFuture.completedFuture(2));
59-
}
6049
}

0 commit comments

Comments
 (0)