File tree 3 files changed +19
-23
lines changed
3 files changed +19
-23
lines changed Original file line number Diff line number Diff line change 20
20
import org .dataloader .impl .DefaultCacheMap ;
21
21
22
22
import java .util .Collection ;
23
- import java .util .Collections ;
24
23
import java .util .concurrent .CompletableFuture ;
25
24
26
25
/**
Original file line number Diff line number Diff line change 26
26
import java .time .Duration ;
27
27
import java .time .Instant ;
28
28
import java .util .ArrayList ;
29
- import java .util .Collection ;
30
29
import java .util .Collections ;
31
30
import java .util .List ;
32
31
import java .util .Optional ;
@@ -453,14 +452,6 @@ public Duration getTimeSinceDispatch() {
453
452
return Duration .between (helper .getLastDispatchTime (), helper .now ());
454
453
}
455
454
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
-
464
455
/**
465
456
* Requests to load the data with the specified key asynchronously, and returns a future of the resulting value.
466
457
* <p>
@@ -760,4 +751,21 @@ public Statistics getStatistics() {
760
751
return stats .getStatistics ();
761
752
}
762
753
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
+
763
771
}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public void should_provide_all_futures_from_cache() {
28
28
dataLoader .load (2 );
29
29
dataLoader .load (1 );
30
30
31
- Collection <CompletableFuture <Integer >> futures = dataLoader .getCacheFutures ();
31
+ Collection <CompletableFuture <Integer >> futures = dataLoader .getCacheMap (). getAll ();
32
32
assertThat (futures .size (), equalTo (2 ));
33
33
}
34
34
@@ -40,21 +40,10 @@ public void should_access_to_future_dependants() {
40
40
dataLoader .load (2 ).handle ((v , t ) -> t );
41
41
dataLoader .load (1 ).handle ((v , t ) -> t );
42
42
43
- Collection <CompletableFuture <Integer >> futures = dataLoader .getCacheFutures ();
43
+ Collection <CompletableFuture <Integer >> futures = dataLoader .getCacheMap (). getAll ();
44
44
45
45
List <CompletableFuture <Integer >> futuresList = new ArrayList <>(futures );
46
46
assertThat (futuresList .get (0 ).getNumberOfDependents (), equalTo (2 ));
47
47
assertThat (futuresList .get (1 ).getNumberOfDependents (), equalTo (1 ));
48
48
}
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
- }
60
49
}
You can’t perform that action at this time.
0 commit comments