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

Method validateInsert

test/simpledb/systemtest/InsertTest.java:20–58  ·  view source on GitHub ↗
(int columns, int sourceRows, int destinationRows)

Source from the content-addressed store, hash-verified

18
19public class InsertTest extends SimpleDbTestBase {
20 private void validateInsert(int columns, int sourceRows, int destinationRows)
21 throws DbException, IOException, TransactionAbortedException {
22 // Create the two tables
23 List<List<Integer>> sourceTuples = new ArrayList<>();
24 HeapFile source = SystemTestUtil.createRandomHeapFile(
25 columns, sourceRows, null, sourceTuples);
26 assert sourceTuples.size() == sourceRows;
27 List<List<Integer>> destinationTuples = new ArrayList<>();
28 HeapFile destination = SystemTestUtil.createRandomHeapFile(
29 columns, destinationRows, null, destinationTuples);
30 assert destinationTuples.size() == destinationRows;
31
32 // Insert source into destination
33 TransactionId tid = new TransactionId();
34 SeqScan ss = new SeqScan(tid, source.getId(), "");
35 Insert insOp = new Insert(tid, ss, destination.getId());
36
37// Query q = new Query(insOp, tid);
38 insOp.open();
39 boolean hasResult = false;
40 while (insOp.hasNext()) {
41 Tuple tup = insOp.next();
42 assertFalse(hasResult);
43 hasResult = true;
44 assertEquals(SystemTestUtil.SINGLE_INT_DESCRIPTOR, tup.getTupleDesc());
45 assertEquals(sourceRows, ((IntField) tup.getField(0)).getValue());
46 }
47 assertTrue(hasResult);
48 insOp.close();
49
50 // As part of the same transaction, scan the table
51 sourceTuples.addAll(destinationTuples);
52 SystemTestUtil.matchTuples(destination, tid, sourceTuples);
53
54 // As part of a different transaction, scan the table
55 Database.getBufferPool().transactionComplete(tid);
56 Database.getBufferPool().flushAllPages();
57 SystemTestUtil.matchTuples(destination, sourceTuples);
58 }
59
60 @Test public void testEmptyToEmpty()
61 throws IOException, DbException, TransactionAbortedException {

Callers 4

testEmptyToEmptyMethod · 0.95
testEmptyToOneMethod · 0.95
testOneToEmptyMethod · 0.95
testOneToOneMethod · 0.95

Calls 13

createRandomHeapFileMethod · 0.95
getIdMethod · 0.95
openMethod · 0.95
getTupleDescMethod · 0.95
getFieldMethod · 0.95
closeMethod · 0.95
matchTuplesMethod · 0.95
getBufferPoolMethod · 0.95
flushAllPagesMethod · 0.80
hasNextMethod · 0.65
nextMethod · 0.65
getValueMethod · 0.45

Tested by

no test coverage detected