Beispiel #1
0
 /**
  * @param Lock\Handle $handle
  */
 public function clearLock(Lock\Handle $handle)
 {
     if (!isset($this->locks[$handle->getToken()])) {
         return;
     }
     $key = $this->locks[$handle->getToken()];
     $this->apc->delete($key);
 }
 public function testGetLockSimulate()
 {
     $key = 'simulate';
     $ttl = new DateTimeUnit(1, 'second');
     $handle = $this->throttle->takeLock($key, $ttl);
     $this->assertInstanceOf('BeaucalLongThrottle\\Lock\\Handle', $handle);
     $keyApc = "beaucal_throttle::{$key}";
     $apc = new ApcExt();
     $this->assertTrue($apc->fetch($keyApc));
     $this->assertFalse($this->throttle->takeLock($key, $ttl));
     /**
      * You'd think you can sleep(1 or 2) then apc_add should work again.
      * But for me apc_add and sleep don't play nice.  So, assume
      * apc_add works and just manually clear to get on with it.
      */
     $apc->delete($keyApc);
     $handle = $this->throttle->takeLock($key, $ttl);
     $this->assertInstanceOf('BeaucalLongThrottle\\Lock\\Handle', $handle);
 }