Search in sources :

Example 1 with Page

use of com.cinchapi.concourse.lang.paginate.Page in project concourse by cinchapi.

the class ResultPaginationTest method testGetCclPage.

@Test
public void testGetCclPage() {
    List<Long> records = Lists.newArrayList();
    for (long i = 0; i < 100; ++i) {
        client.add("foo", i, i);
        records.add(i);
    }
    Page page = Page.sized(15);
    Map<Long, Map<String, Set<Object>>> data = null;
    while (data == null || !data.isEmpty()) {
        data = client.get("foo >= 50", page);
        for (long record : data.keySet()) {
            Assert.assertTrue(record >= page.skip() + 50 && record <= (page.limit() + page.skip() + 50));
        }
        records.removeAll(data.keySet());
        page = page.next();
    }
}
Also used : Page(com.cinchapi.concourse.lang.paginate.Page) Map(java.util.Map) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Example 2 with Page

use of com.cinchapi.concourse.lang.paginate.Page in project concourse by cinchapi.

the class PaginationTest method testPaginateSortedMap.

@Test
public void testPaginateSortedMap() {
    SortableTable<Set<TObject>> table = SortableTable.multiValued(Maps.newLinkedHashMap());
    table.put(1L, ImmutableMap.of("name", ImmutableSet.of(Convert.javaToThrift("a"))));
    table.put(2L, ImmutableMap.of("name", ImmutableSet.of(Convert.javaToThrift("b"))));
    table.put(3L, ImmutableMap.of("name", ImmutableSet.of(Convert.javaToThrift("c"))));
    table.put(4L, ImmutableMap.of("name", ImmutableSet.of(Convert.javaToThrift("d"))));
    table.put(5L, ImmutableMap.of("name", ImmutableSet.of(Convert.javaToThrift("e"))));
    table.put(6L, ImmutableMap.of("name", ImmutableSet.of(Convert.javaToThrift("z"))));
    table.sort(Sorting.byValues(Order.by("name").largestFirst(), null));
    Page page = Page.sized(2).go(2);
    Map<Long, Map<String, Set<TObject>>> expected = table.entrySet().stream().skip(page.skip()).limit(page.limit()).collect(Collectors.toMap(Entry::getKey, Entry::getValue, (a, b) -> b, LinkedHashMap::new));
    Map<Long, Map<String, Set<TObject>>> actual = Paging.page(table, page);
    Assert.assertEquals(expected, actual);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Page(com.cinchapi.concourse.lang.paginate.Page) Order(com.cinchapi.concourse.lang.sort.Order) Sorting(com.cinchapi.concourse.server.query.sort.Sorting) ImmutableMap(com.google.common.collect.ImmutableMap) TestData(com.cinchapi.concourse.util.TestData) Set(java.util.Set) Random(java.util.Random) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Lists(com.google.common.collect.Lists) TObject(com.cinchapi.concourse.thrift.TObject) Convert(com.cinchapi.concourse.util.Convert) Map(java.util.Map) Entry(java.util.Map.Entry) Assert(org.junit.Assert) SortableTable(com.cinchapi.concourse.data.sort.SortableTable) TObject(com.cinchapi.concourse.thrift.TObject) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Page(com.cinchapi.concourse.lang.paginate.Page) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Page

use of com.cinchapi.concourse.lang.paginate.Page in project concourse by cinchapi.

the class ResultPaginationTest method testSelectRecordsPage.

@Test
public void testSelectRecordsPage() {
    List<Long> records = Lists.newArrayList();
    for (long i = 0; i < 100; ++i) {
        client.add("foo", i, i);
        records.add(i);
    }
    List<Long> $records = Lists.newArrayList(records);
    Page page = Page.sized(15);
    Map<Long, Map<String, Set<Object>>> data = null;
    while (data == null || !data.isEmpty()) {
        data = client.select($records, page);
        for (long record : data.keySet()) {
            Assert.assertTrue(record >= page.skip() && record <= (page.limit() + page.skip()));
        }
        records.removeAll(data.keySet());
        page = page.next();
    }
    Assert.assertTrue(records.isEmpty());
}
Also used : Page(com.cinchapi.concourse.lang.paginate.Page) Map(java.util.Map) ConcourseIntegrationTest(com.cinchapi.concourse.test.ConcourseIntegrationTest) Test(org.junit.Test)

Aggregations

Page (com.cinchapi.concourse.lang.paginate.Page)3 Map (java.util.Map)3 Test (org.junit.Test)3 ConcourseIntegrationTest (com.cinchapi.concourse.test.ConcourseIntegrationTest)2 SortableTable (com.cinchapi.concourse.data.sort.SortableTable)1 Order (com.cinchapi.concourse.lang.sort.Order)1 Sorting (com.cinchapi.concourse.server.query.sort.Sorting)1 TObject (com.cinchapi.concourse.thrift.TObject)1 Convert (com.cinchapi.concourse.util.Convert)1 TestData (com.cinchapi.concourse.util.TestData)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Random (java.util.Random)1 Set (java.util.Set)1