-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from samuelAndalon/feat/cache-map-get-values
feat: make cache map values accesible for read only purposes
- Loading branch information
Showing
7 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.dataloader; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static org.dataloader.DataLoaderFactory.newDataLoader; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Tests for cacheMap functionality.. | ||
*/ | ||
public class DataLoaderCacheMapTest { | ||
|
||
private <T> BatchLoader<T, T> keysAsValues() { | ||
return CompletableFuture::completedFuture; | ||
} | ||
|
||
@Test | ||
public void should_provide_all_futures_from_cache() { | ||
DataLoader<Integer, Integer> dataLoader = newDataLoader(keysAsValues()); | ||
|
||
dataLoader.load(1); | ||
dataLoader.load(2); | ||
dataLoader.load(1); | ||
|
||
Collection<CompletableFuture<Integer>> futures = dataLoader.getCacheMap().getAll(); | ||
assertThat(futures.size(), equalTo(2)); | ||
} | ||
|
||
@Test | ||
public void should_access_to_future_dependants() { | ||
DataLoader<Integer, Integer> dataLoader = newDataLoader(keysAsValues()); | ||
|
||
dataLoader.load(1).handle((v, t) -> t); | ||
dataLoader.load(2).handle((v, t) -> t); | ||
dataLoader.load(1).handle((v, t) -> t); | ||
|
||
Collection<CompletableFuture<Integer>> futures = dataLoader.getCacheMap().getAll(); | ||
|
||
List<CompletableFuture<Integer>> futuresList = new ArrayList<>(futures); | ||
assertThat(futuresList.get(0).getNumberOfDependents(), equalTo(2)); | ||
assertThat(futuresList.get(1).getNumberOfDependents(), equalTo(1)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters