1818
1919import org .awaitility .Duration ;
2020import org .dataloader .fixtures .CustomCacheMap ;
21+ import org .dataloader .fixtures .CustomValueCache ;
2122import org .dataloader .fixtures .JsonObject ;
2223import org .dataloader .fixtures .User ;
2324import org .dataloader .fixtures .UserManager ;
7071import static org .hamcrest .Matchers .equalTo ;
7172import static org .hamcrest .Matchers .instanceOf ;
7273import static org .hamcrest .Matchers .is ;
74+ import static org .hamcrest .Matchers .not ;
75+ import static org .hamcrest .Matchers .sameInstance ;
7376import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
7477import static org .junit .jupiter .api .Assertions .assertEquals ;
7578import static org .junit .jupiter .api .Assertions .assertNotNull ;
@@ -1009,16 +1012,27 @@ public void should_degrade_gracefully_if_cache_get_throws(TestDataLoaderFactory
10091012 @ MethodSource ("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get" )
10101013 public void batching_disabled_should_dispatch_immediately (TestDataLoaderFactory factory ) {
10111014 List <Collection <String >> loadCalls = new ArrayList <>();
1012- DataLoaderOptions options = newOptions ().setBatchingEnabled (false ).build ();
1015+
1016+ CacheMap <String , String > cacheMap = CacheMap .simpleMap ();
1017+ CustomValueCache valueCache = new CustomValueCache ();
1018+
1019+ DataLoaderOptions options = newOptions ().setBatchingEnabled (false )
1020+ .setCacheMap (cacheMap ).setValueCache (valueCache ).build ();
10131021 DataLoader <String , String > identityLoader = factory .idLoader (options , loadCalls );
10141022
10151023 CompletableFuture <String > fa = identityLoader .load ("A" );
10161024 CompletableFuture <String > fb = identityLoader .load ("B" );
10171025
1026+ assertThat (cacheMap .size (), equalTo (2 ));
1027+ assertThat (valueCache .asMap ().size (), equalTo (2 ));
1028+
10181029 // caching is on still
10191030 CompletableFuture <String > fa1 = identityLoader .load ("A" );
10201031 CompletableFuture <String > fb1 = identityLoader .load ("B" );
10211032
1033+ assertThat (fa , sameInstance (fa1 ));
1034+ assertThat (fb , sameInstance (fb1 ));
1035+
10221036 List <String > values = CompletableFutureKit .allOf (asList (fa , fb , fa1 , fb1 )).join ();
10231037
10241038 assertThat (fa .join (), equalTo ("A" ));
@@ -1038,16 +1052,27 @@ public void batching_disabled_should_dispatch_immediately(TestDataLoaderFactory
10381052 @ MethodSource ("org.dataloader.fixtures.parameterized.TestDataLoaderFactories#get" )
10391053 public void batching_disabled_and_caching_disabled_should_dispatch_immediately_and_forget (TestDataLoaderFactory factory ) {
10401054 List <Collection <String >> loadCalls = new ArrayList <>();
1041- DataLoaderOptions options = newOptions ().setBatchingEnabled (false ).setCachingEnabled (false ).build ();
1055+
1056+ CacheMap <String , String > cacheMap = CacheMap .simpleMap ();
1057+ CustomValueCache valueCache = new CustomValueCache ();
1058+
1059+ DataLoaderOptions options = newOptions ().setBatchingEnabled (false ).setCachingEnabled (false )
1060+ .setCacheMap (cacheMap ).setValueCache (valueCache ).build ();
10421061 DataLoader <String , String > identityLoader = factory .idLoader (options , loadCalls );
10431062
10441063 CompletableFuture <String > fa = identityLoader .load ("A" );
10451064 CompletableFuture <String > fb = identityLoader .load ("B" );
10461065
1047- // caching is off
1066+ // caching is off - it should not go to the Value cache nor the future cache
1067+ assertThat (cacheMap .size (), equalTo (0 ));
1068+ assertThat (valueCache .asMap ().size (), equalTo (0 ));
1069+
10481070 CompletableFuture <String > fa1 = identityLoader .load ("A" );
10491071 CompletableFuture <String > fb1 = identityLoader .load ("B" );
10501072
1073+ assertThat (fa , not (sameInstance (fa1 )));
1074+ assertThat (fb , not (sameInstance (fb1 )));
1075+
10511076 List <String > values = CompletableFutureKit .allOf (asList (fa , fb , fa1 , fb1 )).join ();
10521077
10531078 assertThat (fa .join (), equalTo ("A" ));
0 commit comments