+
+ /**
+ * @small
+ */
+ public function testReleaseWitTTL()
+ {
+ $this->assertFalse($this->instance->isLocked('test'));
+ $this->assertTrue($this->instance->acquire('test', 1, 10));
+ $this->assertTrue($this->instance->isLocked('test'));
+ $this->assertTrue($this->instance->release('test'));
+ $this->assertFalse($this->instance->isLocked('test'));
+ }
+
+ /**
+ * @small
+ */
+ public function testGetLocks()
+ {
+ $this->assertTrue($this->instance->acquire('foo', 1));
+ $this->assertTrue($this->instance->acquire('bar', 1));
+ $this->assertTrue($this->instance->acquire('nice', 1));
+
+ $this->assertTrue($this->instance->isLocked('foo'));
+ $this->assertTrue($this->instance->isLocked('bar'));
+ $this->assertTrue($this->instance->isLocked('nice'));
+
+ $locks = $this->instance->getLocks();
+
+ $this->assertContains('foo', $locks);
+ $this->assertContains('bar', $locks);
+ $this->assertContains('nice', $locks);
+ }
+
+ /**
+ * @small
+ */
+ public function testGetLocksWithPrefix()
+ {
+ $this->assertTrue($this->instance->acquire('foo', 1));
+ $this->assertTrue($this->instance->acquire('test1', 1));
+ $this->assertTrue($this->instance->acquire('test2', 1));
+
+ $this->assertTrue($this->instance->isLocked('foo'));
+ $this->assertTrue($this->instance->isLocked('test1'));
+ $this->assertTrue($this->instance->isLocked('test2'));
+
+ $locks = $this->instance->getLocks('test');
+
+ $this->assertContains('test1', $locks);
+ $this->assertContains('test2', $locks);
+ $this->assertNotContains('foo', $locks);
+ }
+
+ /**
+ * @medium
+ */
+ function testLockTTL()
+ {
+ $this->markTestSkipped('taking too much time without mocking');
+
+ $this->assertFalse($this->instance->isLocked('foo'));
+ $this->assertFalse($this->instance->isLocked('bar'));
+
+ // TODO [nupplaphil] - Because of the Datetime-Utils for the database, we have to wait a FULL second between the checks to invalidate the db-locks/cache
+ $this->assertTrue($this->instance->acquire('foo', 2, 1));
+ $this->assertTrue($this->instance->acquire('bar', 2, 3));
+
+ $this->assertTrue($this->instance->isLocked('foo'));
+ $this->assertTrue($this->instance->isLocked('bar'));
+
+ sleep(2);
+
+ $this->assertFalse($this->instance->isLocked('foo'));
+ $this->assertTrue($this->instance->isLocked('bar'));
+
+ sleep(2);
+
+ $this->assertFalse($this->instance->isLocked('foo'));
+ $this->assertFalse($this->instance->isLocked('bar'));
+ }
+
+ /**
+ * Test if releasing a non-existing lock doesn't throw errors
+ */
+ public function testReleaseLockWithoutLock()
+ {
+ $this->assertFalse($this->instance->isLocked('wrongLock'));
+ $this->assertFalse($this->instance->release('wrongLock'));
+ }