예제 #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));
  }
예제 #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());
  }
예제 #3
0
 public void open() throws DbException, TransactionAbortedException {
   // some code goes here
   if (i_pos != null) {
     i = i_pos;
   } else {
     Catalog gc = Database.getCatalog();
     HeapFile file = (HeapFile) gc.getDbFile(tableid);
     i = file.iterator(tid);
   }
   i.open();
 }
예제 #4
0
 public HeapFileIterator(TransactionId tid, HeapFile file) {
   _transactionId = tid;
   _file = file;
   _currentPageId = 0;
   _numPages = _file.numPages();
   //			System.out.println("numpages "+_numPages);
 }
예제 #5
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();
  }
예제 #6
0
 private Page readPage(int pageNumber)
     throws DbException, TransactionAbortedException, IOException {
   // File == table because we do one file per table
   //	System.out.println("readpage:"+_file.id()+" page:"+pageNumber);
   int tableId = _file.id();
   int pageId = pageNumber;
   //	System.out.println("Page is now "+pageNumber);
   HeapPageId pid = new HeapPageId(tableId, pageId);
   return Database.getBufferPool().getPage(_transactionId, pid, Permissions.READ_ONLY);
 }
예제 #7
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();
  }
예제 #8
0
 /** Unit test for HeapFile.numPages() */
 @Test
 public void numPages() throws Exception {
   assertEquals(1, hf.numPages());
   // assertEquals(1, empty.numPages());
 }
예제 #9
0
 /** Unit test for HeapFile.getTupleDesc() */
 @Test
 public void getTupleDesc() throws Exception {
   assertEquals(td, hf.getTupleDesc());
 }