(int columns, int sourceRows, int destinationRows)
| 18 | |
| 19 | public 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 { |
no test coverage detected