use of org.folio.inventory.common.WaitForAllFutures in project mod-inventory by folio-org.
the class ExternalItemCollectionExamples method allItemsCanBePaged.
@Test
public void allItemsCanBePaged() throws InterruptedException, ExecutionException, TimeoutException {
WaitForAllFutures<Item> allAdded = new WaitForAllFutures<>();
collection.add(smallAngryPlanet, allAdded.notifySuccess(), v -> {
});
collection.add(nod, allAdded.notifySuccess(), v -> {
});
collection.add(uprooted, allAdded.notifySuccess(), v -> {
});
collection.add(temeraire, allAdded.notifySuccess(), v -> {
});
collection.add(interestingTimes, allAdded.notifySuccess(), v -> {
});
allAdded.waitForCompletion();
CompletableFuture<MultipleRecords<Item>> firstPageFuture = new CompletableFuture<>();
CompletableFuture<MultipleRecords<Item>> secondPageFuture = new CompletableFuture<>();
collection.findAll(new PagingParameters(3, 0), succeed(firstPageFuture), fail(secondPageFuture));
collection.findAll(new PagingParameters(3, 3), succeed(secondPageFuture), fail(secondPageFuture));
MultipleRecords<Item> firstPage = getOnCompletion(firstPageFuture);
MultipleRecords<Item> secondPage = getOnCompletion(secondPageFuture);
assertThat(firstPage.records.size(), is(3));
assertThat(secondPage.records.size(), is(2));
assertThat(firstPage.totalRecords, is(5));
assertThat(secondPage.totalRecords, is(5));
}
use of org.folio.inventory.common.WaitForAllFutures in project mod-inventory by folio-org.
the class ExternalInstanceCollectionExamples method allInstancesCanBePaged.
@Test
public void allInstancesCanBePaged() throws InterruptedException, ExecutionException, TimeoutException {
WaitForAllFutures<Instance> allAdded = new WaitForAllFutures<>();
collection.add(smallAngryPlanet(), allAdded.notifySuccess(), v -> {
});
collection.add(nod(), allAdded.notifySuccess(), v -> {
});
collection.add(uprooted(), allAdded.notifySuccess(), v -> {
});
collection.add(temeraire(), allAdded.notifySuccess(), v -> {
});
collection.add(interestingTimes(), allAdded.notifySuccess(), v -> {
});
allAdded.waitForCompletion();
CompletableFuture<MultipleRecords<Instance>> firstPageFuture = new CompletableFuture<MultipleRecords<Instance>>();
CompletableFuture<MultipleRecords<Instance>> secondPageFuture = new CompletableFuture<MultipleRecords<Instance>>();
collection.findAll(new PagingParameters(3, 0), succeed(firstPageFuture), fail(firstPageFuture));
collection.findAll(new PagingParameters(3, 3), succeed(secondPageFuture), fail(secondPageFuture));
MultipleRecords<Instance> firstPage = getOnCompletion(firstPageFuture);
MultipleRecords<Instance> secondPage = getOnCompletion(secondPageFuture);
List<Instance> firstPageInstances = firstPage.records;
List<Instance> secondPageInstances = secondPage.records;
assertThat(firstPageInstances.size(), is(3));
assertThat(secondPageInstances.size(), is(2));
assertThat(firstPage.totalRecords, is(5));
assertThat(secondPage.totalRecords, is(5));
}
Aggregations