Generic unit test structure to grab an additional lock in a new thread. @param tid the transaction Id @param pid the first page to lock over @param perm the type of lock desired @param expected true if we expect the acquisition to succeed; false otherwise
(TransactionId tid, PageId pid, Permissions perm,
boolean expected)
| 90 | * false otherwise |
| 91 | */ |
| 92 | public void grabLock(TransactionId tid, PageId pid, Permissions perm, |
| 93 | boolean expected) throws Exception { |
| 94 | |
| 95 | TestUtil.LockGrabber t = new TestUtil.LockGrabber(tid, pid, perm); |
| 96 | t.start(); |
| 97 | |
| 98 | // if we don't have the lock after TIMEOUT, we assume blocking. |
| 99 | Thread.sleep(TIMEOUT); |
| 100 | assertEquals(expected, t.acquired()); |
| 101 | |
| 102 | // TODO(ghuo): yes, stop() is evil, but this is unit test cleanup |
| 103 | t.stop(); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Unit test for BufferPool.getPage() assuming locking. |
no test coverage detected