/**
  * {@inheritdoc}
  */
 public function release($aggregateId)
 {
     if (!$this->isObtained($aggregateId)) {
         return;
     }
     $this->lock->releaseLock($aggregateId);
     unset($this->lockedAggregateIds[$aggregateId]);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function acquireLock($name, $timeout = null, $ttl = 0)
 {
     $mutex = $this->getOrCreateLock($name);
     if ($this->locker instanceof LockExpirationInterface) {
         $this->locker->setExpiration($ttl);
     }
     return $mutex->acquireLock($timeout);
 }
 public function testItReleasesLockingOnTheLock()
 {
     $this->backend->expects($this->once())->method('acquireLock')->with('test-lock', 23)->willReturn(true);
     $this->backend->expects($this->once())->method('releaseLock')->with('test-lock')->willReturn(true);
     $this->timeout->expects($this->any())->method('getValue')->willReturn(23);
     $lock = new Lock($this->backend, $this->name, $this->timeout);
     $lock->acquire();
     $lock->release();
 }
Example #4
0
 /**
  * @return bool
  */
 public function isLocked()
 {
     return $this->lockImplementor->isLocked($this->name);
 }
 /**
  * @param string $resourceName
  * @return bool
  */
 public function isLocked($resourceName)
 {
     return $this->ninjaMutexLock->isLocked($resourceName);
 }
 public function testAlreadyLocked()
 {
     $this->lock->expects($this->once())->method('acquireLock')->with($this->equalTo('foo'))->will($this->returnValue(false));
     $this->setExpectedException('Simgroep\\EventSourcing\\Repository\\Exception\\ConcurrencyException');
     $this->createManager()->obtain('foo');
 }
Example #7
0
 /**
  * @dataProvider lockImplementorProvider
  * @param LockInterface $lockImplementor
  */
 public function testIfLockIsReleasedAfterLockImplementorIsDestroyed(LockInterface $lockImplementor)
 {
     $name = 'forfiter';
     $duplicateLockImplementor = clone $lockImplementor;
     $duplicateLockImplementor->acquireLock($name, 0);
     unset($duplicateLockImplementor);
     $this->assertTrue($lockImplementor->acquireLock($name, 0));
     $lockImplementor->releaseLock($name);
 }
Example #8
0
 /**
  * @issue https://github.com/arvenil/ninja-mutex/pull/4
  * It's not working for hhvm, see below link to understand limitation
  * https://github.com/facebook/hhvm/blob/af329776c9f740cc1c8c4791f673ba5aa49042ce/hphp/doc/inconsistencies#L40-L45
  *
  * @dataProvider lockImplementorWithBackendProvider
  * @param LockInterface             $lockImplementor
  * @param PermanentServiceInterface $backend
  */
 public function testIfLockDestructorThrowsWhenBackendIsUnavailable(LockInterface $lockImplementor, PermanentServiceInterface $backend)
 {
     $name = "forfiter";
     $this->assertFalse($lockImplementor->isLocked($name));
     $this->assertTrue($lockImplementor->acquireLock($name, 0));
     $this->assertTrue($lockImplementor->isLocked($name));
     // make backend unavailable
     $backend->setAvailable(false);
     try {
         // explicit __destructor() call, should throw UnrecoverableMutexException
         $lockImplementor->__destruct();
     } catch (UnrecoverableMutexException $e) {
         // make backend available again
         $backend->setAvailable(true);
         // release lock
         $this->assertTrue($lockImplementor->releaseLock($name));
         $this->assertFalse($lockImplementor->releaseLock($name));
         $this->assertFalse($lockImplementor->isLocked($name));
         return;
     }
     $this->fail('An expected exception has not been raised.');
 }