diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-08-26 03:56:37 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-08-26 03:56:37 +0200 |
commit | 534b2e407a80405c636b1ebd4486d01b9d3147bd (patch) | |
tree | 540fc589d148d8962b057b4914fbc59539251414 /tests | |
parent | b45ae1b32e41951a879bdbbdbbe0cb04dd86cda1 (diff) | |
parent | 6f6a5f6c2981cd046abc0530c4b6a222e67f17a7 (diff) | |
download | nextcloud-server-534b2e407a80405c636b1ebd4486d01b9d3147bd.tar.gz nextcloud-server-534b2e407a80405c636b1ebd4486d01b9d3147bd.zip |
Merge pull request #17662 from owncloud/locking-db
Database backend for locking
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/lock/dblockingprovider.php | 43 | ||||
-rw-r--r-- | tests/lib/lock/lockingprovider.php | 30 |
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/lib/lock/dblockingprovider.php b/tests/lib/lock/dblockingprovider.php new file mode 100644 index 00000000000..fd6550d9c47 --- /dev/null +++ b/tests/lib/lock/dblockingprovider.php @@ -0,0 +1,43 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace Test\Lock; + +class DBLockingProvider extends LockingProvider { + + /** + * @var \OCP\IDBConnection + */ + private $connection; + + /** + * @return \OCP\Lock\ILockingProvider + */ + protected function getInstance() { + $this->connection = \OC::$server->getDatabaseConnection(); + return new \OC\Lock\DBLockingProvider($this->connection, \OC::$server->getLogger()); + } + + public function tearDown() { + $this->connection->executeQuery('DELETE FROM `*PREFIX*file_locks`'); + parent::tearDown(); + } +} diff --git a/tests/lib/lock/lockingprovider.php b/tests/lib/lock/lockingprovider.php index efd6e1939f2..ca72c1bb7f3 100644 --- a/tests/lib/lock/lockingprovider.php +++ b/tests/lib/lock/lockingprovider.php @@ -120,6 +120,36 @@ abstract class LockingProvider extends TestCase { $this->assertFalse($this->instance->isLocked('asd', ILockingProvider::LOCK_EXCLUSIVE)); } + public function testReleaseAllAfterChange() { + $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); + $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); + $this->instance->acquireLock('bar', ILockingProvider::LOCK_SHARED); + $this->instance->acquireLock('asd', ILockingProvider::LOCK_EXCLUSIVE); + + $this->instance->changeLock('bar', ILockingProvider::LOCK_EXCLUSIVE); + + $this->instance->releaseAll(); + + $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); + $this->assertFalse($this->instance->isLocked('bar', ILockingProvider::LOCK_SHARED)); + $this->assertFalse($this->instance->isLocked('bar', ILockingProvider::LOCK_EXCLUSIVE)); + $this->assertFalse($this->instance->isLocked('asd', ILockingProvider::LOCK_EXCLUSIVE)); + } + + public function testReleaseAllAfterUnlock() { + $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); + $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); + $this->instance->acquireLock('bar', ILockingProvider::LOCK_SHARED); + $this->instance->acquireLock('asd', ILockingProvider::LOCK_EXCLUSIVE); + + $this->instance->releaseLock('bar', ILockingProvider::LOCK_SHARED); + + $this->instance->releaseAll(); + + $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED)); + $this->assertFalse($this->instance->isLocked('asd', ILockingProvider::LOCK_EXCLUSIVE)); + } + public function testReleaseAfterReleaseAll() { $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED); |