### Question:
MemoryPagesStore { public synchronized List<Page> getPages( Long tableId, int partNumber, int totalParts, List<Integer> columnIndexes, long expectedRows, OptionalLong limit, OptionalDouble sampleRatio) { if (!contains(tableId)) { throw new PrestoException(MISSING_DATA, "Failed to find table on a worker."); } TableData tableData = tables.get(tableId); if (tableData.getRows() < expectedRows) { throw new PrestoException(MISSING_DATA, format("Expected to find [%s] rows on a worker, but found [%s].", expectedRows, tableData.getRows())); } ImmutableList.Builder<Page> partitionedPages = ImmutableList.builder(); boolean done = false; long totalRows = 0; for (int i = partNumber; i < tableData.getPages().size() && !done; i += totalParts) { if (sampleRatio.isPresent() && ThreadLocalRandom.current().nextDouble() >= sampleRatio.getAsDouble()) { continue; } Page page = tableData.getPages().get(i); totalRows += page.getPositionCount(); if (limit.isPresent() && totalRows > limit.getAsLong()) { page = page.getRegion(0, (int) (page.getPositionCount() - (totalRows - limit.getAsLong()))); done = true; } partitionedPages.add(getColumns(page, columnIndexes)); } return partitionedPages.build(); } @Inject  MemoryPagesStore(MemoryConfig config); synchronized void initialize(long tableId); synchronized void add(Long tableId, Page page); synchronized List<Page> getPages(
            Long tableId,
            int partNumber,
            int totalParts,
            List<Integer> columnIndexes,
            long expectedRows,
            OptionalLong limit,
            OptionalDouble sampleRatio); synchronized boolean contains(Long tableId); synchronized void cleanUp(Set<Long> activeTableIds);  }### Answer:
@Test public void testCreateEmptyTable() { createTable(0L, 0L); assertEquals(pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 0, OptionalLong.empty(), OptionalDouble.empty()), ImmutableList.of()); }
@Test public void testInsertPage() { createTable(0L, 0L); insertToTable(0L, 0L); assertEquals(pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), POSITIONS_PER_PAGE, OptionalLong.empty(), OptionalDouble.empty()).size(), 1); }
@Test public void testInsertPageWithoutCreate() { insertToTable(0L, 0L); assertEquals(pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), POSITIONS_PER_PAGE, OptionalLong.empty(), OptionalDouble.empty()).size(), 1); }
@Test(expectedExceptions = PrestoException.class) public void testReadFromUnknownTable() { pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 0, OptionalLong.empty(), OptionalDouble.empty()); }
@Test(expectedExceptions = PrestoException.class) public void testTryToReadFromEmptyTable() { createTable(0L, 0L); assertEquals(pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 0, OptionalLong.empty(), OptionalDouble.empty()), ImmutableList.of()); pagesStore.getPages(0L, 0, 1, ImmutableList.of(0), 42, OptionalLong.empty(), OptionalDouble.empty()); }