Esempio n. 1
0
 /**
  * @issue https://github.com/arvenil/ninja-mutex/pull/4
  */
 public function testIfMutexDestructorThrowsWhenBackendIsUnavailable()
 {
     $lockImplementor = new MockLock();
     $mutex = new Mutex('forfiter', $lockImplementor);
     $this->assertFalse($mutex->isAcquired());
     $this->assertTrue($mutex->acquireLock());
     $this->assertTrue($mutex->isAcquired());
     $this->assertTrue($mutex->acquireLock());
     $this->assertTrue($mutex->isAcquired());
     // make backend unavailable
     $lockImplementor->setAvailable(false);
     try {
         // explicit __destructor() call, should throw UnrecoverableMutexException
         $mutex->__destruct();
     } catch (UnrecoverableMutexException $e) {
         // make backend available again
         $lockImplementor->setAvailable(true);
         // release lock
         $this->assertTrue($mutex->releaseLock());
         $this->assertFalse($mutex->releaseLock());
         return;
     }
     $this->fail('An expected exception has not been raised.');
 }
 /**
  * @return void
  */
 public function release()
 {
     $this->lock->releaseLock();
 }
Esempio n. 3
0
 /**
  * @expectedException NinjaMutex\MutexException
  */
 public function testIfMutexDestructorThrowsWhenBackendIsUnavailable()
 {
     $predisMock = new MockPredisClient();
     $lockImplementor = new PredisRedisLock($predisMock);
     $mutex = new Mutex('forfiter', $lockImplementor);
     $this->assertFalse($mutex->isAcquired());
     $mutex->acquireLock();
     $this->assertTrue($mutex->isAcquired());
     $mutex->acquireLock();
     $this->assertTrue($mutex->isAcquired());
     // make backend unavailable
     $predisMock->setAvailable(false);
     // explicit dtor call, should throw MutexException
     $mutex->__destruct();
 }
Esempio n. 4
0
 /**
  * @issue https://github.com/arvenil/ninja-mutex/pull/1
  *
  * @dataProvider lockImplementorProvider
  * @param LockInterface $lockImplementor
  */
 public function testIfMutexIsReusableAfterSeveralAcquireReleaseCycles(LockInterface $lockImplementor)
 {
     $firstMutex = new Mutex('forfiter', $lockImplementor);
     $firstMutex->acquireLock();
     $firstMutex->releaseLock();
     $firstMutex->acquireLock();
     $firstMutex->releaseLock();
     $secondMutex = new Mutex('forfiter', $lockImplementor);
     $this->assertTrue($secondMutex->acquireLock());
     // cleanup
     $secondMutex->releaseLock();
 }