MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / testReadPage

Method testReadPage

test/simpledb/systemtest/BTreeScanTest.java:211–285  ·  view source on GitHub ↗

Test that scanning the BTree for predicates does not read all the pages

()

Source from the content-addressed store, hash-verified

209
210 /** Test that scanning the BTree for predicates does not read all the pages */
211 @Test public void testReadPage() throws Exception {
212 // Create the table
213 final int LEAF_PAGES = 30;
214
215 List<List<Integer>> tuples = new ArrayList<>();
216 int keyField = 0;
217 BTreeFile f = BTreeUtility.createBTreeFile(2, LEAF_PAGES*502, null, tuples, keyField);
218 tuples.sort(new TupleComparator(keyField));
219 TupleDesc td = Utility.getTupleDesc(2);
220 InstrumentedBTreeFile table = new InstrumentedBTreeFile(f.getFile(), keyField, td);
221 Database.getCatalog().addTable(table, SystemTestUtil.getUUID());
222
223 // EQUALS
224 TransactionId tid = new TransactionId();
225 List<List<Integer>> tuplesFiltered = new ArrayList<>();
226 IndexPredicate ipred = new IndexPredicate(Op.EQUALS, new IntField(r.nextInt(LEAF_PAGES*502)));
227 Iterator<List<Integer>> it = tuples.iterator();
228 while(it.hasNext()) {
229 List<Integer> tup = it.next();
230 if(tup.get(keyField) == ((IntField) ipred.getField()).getValue()) {
231 tuplesFiltered.add(tup);
232 }
233 }
234
235 Database.resetBufferPool(BufferPool.DEFAULT_PAGES);
236 table.readCount = 0;
237 BTreeScan scan = new BTreeScan(tid, f.getId(), "table", ipred);
238 SystemTestUtil.matchTuples(scan, tuplesFiltered);
239 // root pointer page + root + leaf page (possibly 2 leaf pages)
240 assertTrue(table.readCount == 3 || table.readCount == 4);
241
242 // LESS_THAN
243 tuplesFiltered.clear();
244 ipred = new IndexPredicate(Op.LESS_THAN, new IntField(r.nextInt(LEAF_PAGES*502)));
245 it = tuples.iterator();
246 while(it.hasNext()) {
247 List<Integer> tup = it.next();
248 if(tup.get(keyField) < ((IntField) ipred.getField()).getValue()) {
249 tuplesFiltered.add(tup);
250 }
251 }
252
253 Database.resetBufferPool(BufferPool.DEFAULT_PAGES);
254 table.readCount = 0;
255 scan = new BTreeScan(tid, f.getId(), "table", ipred);
256 SystemTestUtil.matchTuples(scan, tuplesFiltered);
257 // root pointer page + root + leaf pages
258 int leafPageCount = tuplesFiltered.size()/502;
259 if(leafPageCount < LEAF_PAGES)
260 leafPageCount++; // +1 for next key locking
261 assertEquals(leafPageCount + 2, table.readCount);
262
263 // GREATER_THAN
264 tuplesFiltered.clear();
265 ipred = new IndexPredicate(Op.GREATER_THAN_OR_EQ, new IntField(r.nextInt(LEAF_PAGES*502)));
266 it = tuples.iterator();
267 while(it.hasNext()) {
268 List<Integer> tup = it.next();

Callers

nothing calls this directly

Calls 15

createBTreeFileMethod · 0.95
getTupleDescMethod · 0.95
getFileMethod · 0.95
getCatalogMethod · 0.95
getUUIDMethod · 0.95
getFieldMethod · 0.95
resetBufferPoolMethod · 0.95
getIdMethod · 0.95
matchTuplesMethod · 0.95
getBufferPoolMethod · 0.95
getMethod · 0.80
clearMethod · 0.80

Tested by

no test coverage detected