Ejemplo n.º 1
0
  /** Unit test for HeapFile.readPage() */
  @Test
  public void readPage() throws Exception {
    HeapPageId pid = new HeapPageId(hf.getId(), 0);
    HeapPage page = (HeapPage) hf.readPage(pid);

    // NOTE(ghuo): we try not to dig too deeply into the Page API here; we
    // rely on HeapPageTest for that. perform some basic checks.
    assertEquals(484, page.getNumEmptySlots());
    assertTrue(page.isSlotUsed(1));
    assertFalse(page.isSlotUsed(20));
  }
Ejemplo n.º 2
0
  /** Unit test for HeapFile.getId() */
  @Test
  public void getId() throws Exception {
    int id = hf.getId();

    // NOTE(ghuo): the value could be anything. test determinism, at least.
    assertEquals(id, hf.getId());
    assertEquals(id, hf.getId());

    HeapFile other = SystemTestUtil.createRandomHeapFile(1, 1, null, null);
    assertTrue(id != other.getId());
  }
Ejemplo n.º 3
0
  @Test
  public void testIteratorClose() throws Exception {
    // make more than 1 page. Previous closed iterator would start fetching
    // from page 1.
    HeapFile twoPageFile = SystemTestUtil.createRandomHeapFile(2, 520, null, null);

    DbFileIterator it = twoPageFile.iterator(tid);
    it.open();
    assertTrue(it.hasNext());
    it.close();
    try {
      it.next();
      fail("expected exception");
    } catch (NoSuchElementException e) {
    }
    // close twice is harmless
    it.close();
  }
Ejemplo n.º 4
0
  @Test
  public void testIteratorBasic() throws Exception {
    HeapFile smallFile = SystemTestUtil.createRandomHeapFile(2, 3, null, null);

    DbFileIterator it = smallFile.iterator(tid);
    // Not open yet
    assertFalse(it.hasNext());
    try {
      it.next();
      fail("expected exception");
    } catch (NoSuchElementException e) {
    }

    it.open();
    int count = 0;
    while (it.hasNext()) {
      System.out.println(count);
      assertNotNull(it.next());
      count += 1;
    }
    assertEquals(3, count);
    it.close();
  }
Ejemplo n.º 5
0
 /** Unit test for HeapFile.numPages() */
 @Test
 public void numPages() throws Exception {
   assertEquals(1, hf.numPages());
   // assertEquals(1, empty.numPages());
 }
Ejemplo n.º 6
0
 /** Unit test for HeapFile.getTupleDesc() */
 @Test
 public void getTupleDesc() throws Exception {
   assertEquals(td, hf.getTupleDesc());
 }