public function test_getDbLock_shouldGetLock() { $db = Db::get(); $this->assertTrue(Db::getDbLock('MyLock')); // same session still has lock $this->assertTrue(Db::getDbLock('MyLock')); Db::setDatabaseObject(null); // different session, should not be able to acquire lock $this->assertFalse(Db::getDbLock('MyLock', 1)); // different session cannot release lock $this->assertFalse(Db::releaseDbLock('MyLock')); Db::destroyDatabaseObject(); // release lock again by using previous session Db::setDatabaseObject($db); $this->assertTrue(Db::releaseDbLock('MyLock')); Db::destroyDatabaseObject(); }
protected function acquireArchiveTableLock($dbLockName) { if (Db::getDbLock($dbLockName, $maxRetries = 30) === false) { throw new Exception("Cannot get named lock {$dbLockName}."); } }
protected function acquireArchiveTableLock() { $dbLockName = $this->getArchiveLockName(); if (Db::getDbLock($dbLockName, $maxRetries = 30) === false) { throw new Exception("allocateNewArchiveId: Cannot get named lock {$dbLockName}."); } }