summaryrefslogtreecommitdiffstats
path: root/tests/lib/lock/lockingprovider.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/lock/lockingprovider.php')
-rw-r--r--tests/lib/lock/lockingprovider.php77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/lib/lock/lockingprovider.php b/tests/lib/lock/lockingprovider.php
index 08d879da8bb..efd6e1939f2 100644
--- a/tests/lib/lock/lockingprovider.php
+++ b/tests/lib/lock/lockingprovider.php
@@ -107,6 +107,30 @@ abstract class LockingProvider extends TestCase {
$this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE));
}
+ public function testReleaseAll() {
+ $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->releaseAll();
+
+ $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED));
+ $this->assertFalse($this->instance->isLocked('bar', 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);
+
+ $this->instance->releaseAll();
+
+ $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED));
+
+ $this->instance->releaseLock('foo', ILockingProvider::LOCK_SHARED);
+ }
+
/**
* @expectedException \OCP\Lock\LockedException
@@ -134,4 +158,57 @@ abstract class LockingProvider extends TestCase {
$this->assertEquals('foo', $e->getPath());
}
}
+
+ public function testChangeLockToExclusive() {
+ $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED);
+ $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE);
+ $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED));
+ $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE));
+ }
+
+ public function testChangeLockToShared() {
+ $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE);
+ $this->instance->changeLock('foo', ILockingProvider::LOCK_SHARED);
+ $this->assertFalse($this->instance->isLocked('foo', ILockingProvider::LOCK_EXCLUSIVE));
+ $this->assertTrue($this->instance->isLocked('foo', ILockingProvider::LOCK_SHARED));
+ }
+
+ /**
+ * @expectedException \OCP\Lock\LockedException
+ */
+ public function testChangeLockToExclusiveDoubleShared() {
+ $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED);
+ $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED);
+ $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE);
+ }
+
+ /**
+ * @expectedException \OCP\Lock\LockedException
+ */
+ public function testChangeLockToExclusiveNoShared() {
+ $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE);
+ }
+
+ /**
+ * @expectedException \OCP\Lock\LockedException
+ */
+ public function testChangeLockToExclusiveFromExclusive() {
+ $this->instance->acquireLock('foo', ILockingProvider::LOCK_EXCLUSIVE);
+ $this->instance->changeLock('foo', ILockingProvider::LOCK_EXCLUSIVE);
+ }
+
+ /**
+ * @expectedException \OCP\Lock\LockedException
+ */
+ public function testChangeLockToSharedNoExclusive() {
+ $this->instance->changeLock('foo', ILockingProvider::LOCK_SHARED);
+ }
+
+ /**
+ * @expectedException \OCP\Lock\LockedException
+ */
+ public function testChangeLockToSharedFromShared() {
+ $this->instance->acquireLock('foo', ILockingProvider::LOCK_SHARED);
+ $this->instance->changeLock('foo', ILockingProvider::LOCK_SHARED);
+ }
}