Unit test for BufferPool.deleteTuple()
()
| 92 | * Unit test for BufferPool.deleteTuple() |
| 93 | */ |
| 94 | @Test public void deleteTuple() throws Exception { |
| 95 | |
| 96 | // heap file should have ~10 pages |
| 97 | HeapFile hf = SystemTestUtil.createRandomHeapFile(2, 504*10, null, null); |
| 98 | DbFileIterator it = hf.iterator(tid); |
| 99 | it.open(); |
| 100 | |
| 101 | List<Tuple> tuples = new ArrayList<>(); |
| 102 | while(it.hasNext()) { |
| 103 | tuples.add(it.next()); |
| 104 | } |
| 105 | |
| 106 | // clear the cache |
| 107 | Database.resetBufferPool(BufferPool.DEFAULT_PAGES); |
| 108 | |
| 109 | // delete 504 tuples from the first page |
| 110 | for (int i = 0; i < 504; ++i) { |
| 111 | Tuple t = tuples.get(i); |
| 112 | Database.getBufferPool().deleteTuple(tid, t); |
| 113 | HeapPage p = (HeapPage) Database.getBufferPool().getPage(tid, t.getRecordId().getPageId(), Permissions.READ_ONLY); |
| 114 | assertEquals(i+1, p.getNumEmptySlots()); |
| 115 | } |
| 116 | |
| 117 | // delete 504 tuples from the second page |
| 118 | for (int i = 0; i < 504; ++i) { |
| 119 | Tuple t = tuples.get(i+504); |
| 120 | Database.getBufferPool().deleteTuple(tid, t); |
| 121 | HeapPage p = (HeapPage) Database.getBufferPool().getPage(tid, t.getRecordId().getPageId(), Permissions.READ_ONLY); |
| 122 | assertEquals(i+1, p.getNumEmptySlots()); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | @Test public void handleManyDirtyPages() throws Exception { |
| 127 | HeapFileDuplicates hfd = new HeapFileDuplicates(empty.getFile(), empty.getTupleDesc(), 10); |
nothing calls this directly
no test coverage detected