@Test public void testScan() throws IOException { KijiDataRequestBuilder builder = KijiDataRequest.builder(); builder.addColumns().withMaxVersions(5).add("info", "name"); builder .addColumns() .withMaxVersions(5) .withPageSize(2) .add("info", "location") .addFamily("jobs"); KijiDataRequest dataRequest = builder.build(); KijiRowScanner scanner = mTableReader.getScanner(dataRequest); try { Iterator<KijiRowData> rowDataIterator = scanner.iterator(); assertTrue(rowDataIterator.hasNext()); KijiRowData garrettInput = rowDataIterator.next(); CharSequence name = garrettInput.getMostRecentValue("info", "name"); // Page over location column. List<CharSequence> locations = new ArrayList<CharSequence>(); KijiPager locationPager = garrettInput.getPager("info", "location"); assertTrue("Our pager always has a first page.", locationPager.hasNext()); for (CharSequence location : locationPager.next().<CharSequence>getValues("info", "location").values()) { locations.add(location); } LOG.debug("The size of our locations list is [{}].", locations.size()); assertEquals(2, locations.size()); // Read the second page of locations (2 cells). assertTrue("Our pager should have a second page.", locationPager.hasNext()); for (CharSequence location : locationPager.next().<CharSequence>getValues("info", "location").values()) { LOG.debug("Adding location [{}].", location); locations.add(location); } LOG.debug("The size of our locations list is [{}].", locations.size()); assertEquals(4, locations.size()); // Read the last page of locations (1 cell). assertTrue("Our pager should have a third page", locationPager.hasNext()); for (CharSequence location : locationPager.next().<CharSequence>getValues("info", "location").values()) { locations.add(location); } LOG.debug("This size of our locations list is [{}].", locations.size()); assertEquals(5, locations.size()); assertFalse("Our page should not have a fifth page.", locationPager.hasNext()); // Page over jobs column. KijiPager jobsPager = garrettInput.getPager("jobs"); assertTrue("Our pagers always have a first page.", jobsPager.hasNext()); List<CharSequence> jobs = new ArrayList<CharSequence>(); for (Map.Entry<String, CharSequence> employment : jobsPager.next().<CharSequence>getMostRecentValues("jobs").entrySet()) { jobs.add(employment.getValue().toString() + " @ " + employment.getKey()); } assertEquals(2, jobs.size()); // Read the second page of jobs. assertTrue(jobsPager.hasNext()); for (Map.Entry<String, CharSequence> employment : jobsPager.next().<CharSequence>getMostRecentValues("jobs").entrySet()) { jobs.add(employment.getValue().toString() + " @ " + employment.getKey()); } assertEquals(4, jobs.size()); // We should try to get the next page assertTrue(jobsPager.hasNext()); // But it should be empty. assertTrue(jobsPager.next().getValues("jobs").isEmpty()); } finally { scanner.close(); } }
@After public void teardown() throws Exception { mTableReader.close(); mUserTable.close(); mKiji.release(); }