コード例 #1
0
 public function testCannotAdd()
 {
     $apcMock = $this->getMock('BeaucalLongThrottle\\Apc\\Apc');
     $apcMock->expects($this->any())->method('add')->will($this->returnValue(false));
     $apcAdapter = new ApcAdapter($apcMock, new ApcOptions(), new LockHandleFactory());
     $throttle = new Throttle($apcAdapter, new ThrottleOptions());
     $ttl = new DateTimeUnit(80, 'seconds');
     for ($i = 0; $i < 4; $i++) {
         $this->assertFalse($throttle->takeLock(__FUNCTION__, $ttl));
     }
 }
コード例 #2
0
 public function testClearLock()
 {
     $ttl = new DateTimeUnit(80, 'seconds');
     $handle = $this->throttle->takeLock(__FUNCTION__, $ttl);
     $this->assertInstanceOf('BeaucalLongThrottle\\Lock\\Handle', $handle);
     $badHandle = $this->throttle->takeLock(__FUNCTION__, $ttl);
     $this->assertFalse($badHandle);
     $this->throttle->clearLock($handle);
     $handle = $this->throttle->takeLock(__FUNCTION__, $ttl);
     $this->assertInstanceOf('BeaucalLongThrottle\\Lock\\Handle', $handle);
 }
コード例 #3
0
 /**
  * @expectedException BeaucalLongThrottle\Exception\RuntimeException
  * @expectedExceptionMessage key contained reserved separator
  */
 public function testTakeLockWithSeparator()
 {
     $this->throttle->takeLock('bad::key', new DateTimeUnit(11, 'months'));
 }
コード例 #4
0
 /**
  * @expectedException BeaucalLongThrottle\Exception\OptionException
  * @expectedExceptionMessage regex_counts pattern BAD REGEX is invalid
  */
 public function testRegexCountsInvalidPattern()
 {
     $dbOptions = new ThrottleDbAdapterOptions();
     $dbOptions->setRegexCounts(['BAD REGEX' => 1]);
     $gateway = new TableGateway($dbOptions->getDbTable(), $this->getAdapter());
     $throttleDbAdapter = new ThrottleDbMultipleAdapter($gateway, $dbOptions, new LockHandleFactory());
     $throttleOptions = new ThrottleOptions();
     $throttle = new Throttle($throttleDbAdapter, $throttleOptions);
     $throttle->takeLock('ok', new DateTimeUnit(6, 'days'));
 }