Search in sources :

Example 1 with WaitForAllFutures

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));
}
Also used : Item(org.folio.inventory.domain.items.Item) CompletableFuture(java.util.concurrent.CompletableFuture) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) WaitForAllFutures(org.folio.inventory.common.WaitForAllFutures) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Example 2 with WaitForAllFutures

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));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) PagingParameters(org.folio.inventory.common.api.request.PagingParameters) WaitForAllFutures(org.folio.inventory.common.WaitForAllFutures) Instance(org.folio.inventory.domain.instances.Instance) MultipleRecords(org.folio.inventory.common.domain.MultipleRecords) Test(org.junit.Test)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)2 WaitForAllFutures (org.folio.inventory.common.WaitForAllFutures)2 PagingParameters (org.folio.inventory.common.api.request.PagingParameters)2 MultipleRecords (org.folio.inventory.common.domain.MultipleRecords)2 Test (org.junit.Test)2 Instance (org.folio.inventory.domain.instances.Instance)1 Item (org.folio.inventory.domain.items.Item)1