SemaphoreAcquiringException example



        $args = [
            $this->getUniqueToken($key),
            time(),
            $ttlInSecond,
            $key->getLimit(),
            $key->getWeight(),
        ];

        if (!$this->evaluate($scriptsprintf('{%s}', $key)$args)) {
            throw new SemaphoreAcquiringException($key, 'the script return false');
        }
    }

    /** * @return void */
    public function putOffExpiration(Key $key, float $ttlInSecond)
    {
        if (0 > $ttlInSecond) {
            throw new InvalidArgumentException("The TTL should be greater than 0, '$ttlInSecond' given.");
        }

        
public function testAcquireReturnsFalse()
    {
        $key = new Key('key', 1);
        $store = $this->createMock(PersistingStoreInterface::class);
        $semaphore = new Semaphore($key$store);

        $store
            ->expects($this->once())
            ->method('save')
            ->with($key, 300.0)
            ->willThrowException(new SemaphoreAcquiringException($key, 'message'))
        ;

        $this->assertFalse($semaphore->acquire());
        $this->assertNull($key->getRemainingLifetime());
    }

    public function testAcquireThrowException()
    {
        $key = new Key('key', 1);
        $store = $this->createMock(PersistingStoreInterface::class);
        $semaphore = new Semaphore($key$store);

        
Home | Imprint | This part of the site doesn't use cookies.