Test that doing lots of inserts and deletes in multiple threads works
()
| 85 | |
| 86 | /** Test that doing lots of inserts and deletes in multiple threads works */ |
| 87 | @Test public void testBigFile() throws Exception { |
| 88 | // For this test we will decrease the size of the Buffer Pool pages |
| 89 | BufferPool.setPageSize(1024); |
| 90 | |
| 91 | // This should create a B+ tree with a packed second tier of internal pages |
| 92 | // and packed third tier of leaf pages |
| 93 | System.out.println("Creating large random B+ tree..."); |
| 94 | List<List<Integer>> tuples = new ArrayList<>(); |
| 95 | BTreeFile bf = BTreeUtility.createRandomBTreeFile(2, 31000, |
| 96 | null, tuples, 0); |
| 97 | |
| 98 | // we will need more room in the buffer pool for this test |
| 99 | Database.resetBufferPool(500); |
| 100 | |
| 101 | BlockingQueue<List<Integer>> insertedTuples = new ArrayBlockingQueue<>(100000); |
| 102 | insertedTuples.addAll(tuples); |
| 103 | assertEquals(31000, insertedTuples.size()); |
| 104 | int size = insertedTuples.size(); |
| 105 | |
| 106 | // now insert some random tuples |
| 107 | System.out.println("Inserting tuples..."); |
| 108 | List<BTreeInserter> insertThreads = new ArrayList<>(); |
| 109 | for(int i = 0; i < 200; i++) { |
| 110 | BTreeInserter bi = startInserter(bf, getRandomTupleData(), insertedTuples); |
| 111 | insertThreads.add(bi); |
| 112 | // The first few inserts will cause pages to split so give them a little |
| 113 | // more time to avoid too many deadlock situations |
| 114 | Thread.sleep(r.nextInt(POLL_INTERVAL)); |
| 115 | } |
| 116 | |
| 117 | for(int i = 0; i < 800; i++) { |
| 118 | BTreeInserter bi = startInserter(bf, getRandomTupleData(), insertedTuples); |
| 119 | insertThreads.add(bi); |
| 120 | } |
| 121 | |
| 122 | // wait for all threads to finish |
| 123 | waitForInserterThreads(insertThreads); |
| 124 | assertTrue(insertedTuples.size() > size); |
| 125 | |
| 126 | // now insert and delete tuples at the same time |
| 127 | System.out.println("Inserting and deleting tuples..."); |
| 128 | List<BTreeDeleter> deleteThreads = new ArrayList<>(); |
| 129 | for(BTreeInserter thread : insertThreads) { |
| 130 | thread.rerun(bf, getRandomTupleData(), insertedTuples); |
| 131 | BTreeDeleter bd = startDeleter(bf, insertedTuples); |
| 132 | deleteThreads.add(bd); |
| 133 | } |
| 134 | |
| 135 | // wait for all threads to finish |
| 136 | waitForInserterThreads(insertThreads); |
| 137 | waitForDeleterThreads(deleteThreads); |
| 138 | int numPages = bf.numPages(); |
| 139 | size = insertedTuples.size(); |
| 140 | |
| 141 | // now delete a bunch of tuples |
| 142 | System.out.println("Deleting tuples..."); |
| 143 | for(int i = 0; i < 10; i++) { |
| 144 | for(BTreeDeleter thread : deleteThreads) { |
nothing calls this directly
no test coverage detected