File tree Expand file tree Collapse file tree 3 files changed +19
-23
lines changed Expand file tree Collapse file tree 3 files changed +19
-23
lines changed Original file line number Diff line number Diff line change 2020import org .dataloader .impl .DefaultCacheMap ;
2121
2222import java .util .Collection ;
23- import java .util .Collections ;
2423import java .util .concurrent .CompletableFuture ;
2524
2625/**
Original file line number Diff line number Diff line change 2626import java .time .Duration ;
2727import java .time .Instant ;
2828import java .util .ArrayList ;
29- import java .util .Collection ;
3029import java .util .Collections ;
3130import java .util .List ;
3231import 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments