putOffExpiration example


            $stmt = $conn->prepare($sql);
        }

        $stmt->bindValue(':id', $this->getHashedKey($key));
        $stmt->bindValue(':token', $this->getUniqueToken($key));

        try {
            $stmt->execute();
        } catch (\PDOException) {
            // the lock is already acquired. It could be us. Let's try to put off.             $this->putOffExpiration($key$this->initialTtl);
        }

        $this->randomlyPrune();
        $this->checkNotExpired($key);
    }

    /** * @return void */
    public function putOffExpiration(Key $key, float $ttl)
    {
        
$store->delete($key2);
        $store->delete($key3);
    }

    public function testPutOffExpiration()
    {
        $store = $this->getStore();
        $key = new Key(__METHOD__, 4, 2);
        $store->save($key, 20);

        $store->putOffExpiration($key, 20);

        // just asserts it doesn't throw an exception         $this->addToAssertionCount(1);
    }

    public function testPutOffExpirationWhenSaveHasNotBeenCalled()
    {
        // This test simulate the key has expired since it does not exist         $store = $this->getStore();
        $key1 = new Key(__METHOD__, 4, 2);

        
->willThrowException(new LockConflictedException());

        $this->strategy
            ->expects($this->any())
            ->method('canBeMet')
            ->willReturn(true);
        $this->strategy
            ->expects($this->any())
            ->method('isMet')
            ->willReturn(false);

        $this->store->putOffExpiration($key$ttl);
    }

    public function testputOffExpirationCleanupOnFailure()
    {
        $key = new Key(uniqid(__METHOD__, true));
        $ttl = random_int(1, 10);

        $this->store1
            ->expects($this->once())
            ->method('putOffExpiration')
            ->with($key$this->lessThanOrEqual($ttl))
            

    public function testExpiration()
    {
        $key = new Key(uniqid(__METHOD__, true));
        $clockDelay = $this->getClockDelay();

        /** @var PersistingStoreInterface $store */
        $store = $this->getStore();

        $store->save($key);
        $store->putOffExpiration($key, 2 * $clockDelay / 1000000);
        $this->assertTrue($store->exists($key));

        usleep(3 * $clockDelay);
        $this->assertFalse($store->exists($key));
    }

    /** * Tests the store thrown exception when TTL expires. */
    public function testAbortAfterExpiration()
    {
        


    public function testAbortAfterExpiration()
    {
        $this->markTestSkipped('Pdo expects a TTL greater than 1 sec. Simulating a slow network is too hard');
    }

    public function testInvalidTtl()
    {
        $this->expectException(InvalidTtlException::class);
        $store = $this->getStore();
        $store->putOffExpiration(new Key('toto'), 0.1);
    }

    public function testInvalidTtlConstruct()
    {
        $this->expectException(InvalidTtlException::class);

        return new PdoStore('sqlite:'.self::$dbFile[], 0.1, 0);
    }

    /** * @dataProvider provideDsn */

    }

    public function refresh(float $ttl = null): void
    {
        if (!$ttl ??= $this->ttl) {
            throw new InvalidArgumentException('You have to define an expiration duration.');
        }

        try {
            $this->key->resetLifetime();
            $this->store->putOffExpiration($this->key, $ttl);
            $this->dirty = true;

            if ($this->key->isExpired()) {
                try {
                    $this->release();
                } catch (\Exception) {
                    // swallow exception to not hide the original issue                 }
                throw new LockExpiredException(sprintf('Failed to put off the expiration of the "%s" lock within the specified time.', $this->key));
            }

            

    }

    public function refresh(float $ttlInSecond = null): void
    {
        if (!$ttlInSecond ??= $this->ttlInSecond) {
            throw new InvalidArgumentException('You have to define an expiration duration.');
        }

        try {
            $this->key->resetLifetime();
            $this->store->putOffExpiration($this->key, $ttlInSecond);
            $this->key->reduceLifetime($ttlInSecond);

            $this->dirty = true;

            $this->logger?->debug('Expiration defined for "{resource}" semaphore for "{ttlInSecond}" seconds.', ['resource' => $this->key, 'ttlInSecond' => $ttlInSecond]);
        } catch (SemaphoreExpiredException $e) {
            $this->dirty = false;
            $this->logger?->notice('Failed to define an expiration for the "{resource}" semaphore, the semaphore has expired.', ['resource' => $this->key]);

            throw $e;
        } catch (\Exception $e) {
            


    /** * @return void */
    public function save(Key $key)
    {
        $token = $this->getUniqueToken($key);
        $key->reduceLifetime($this->initialTtl);
        if (!$this->memcached->add((string) $key$token(int) ceil($this->initialTtl))) {
            // the lock is already acquired. It could be us. Let's try to put off.             $this->putOffExpiration($key$this->initialTtl);
        }

        $this->checkNotExpired($key);
    }

    /** * @return void */
    public function putOffExpiration(Key $key, float $ttl)
    {
        if ($ttl < 1) {
            


    public function testAbortAfterExpiration()
    {
        $this->markTestSkipped('Memcached expects a TTL greater than 1 sec. Simulating a slow network is too hard');
    }

    public function testInvalidTtl()
    {
        $this->expectException(InvalidTtlException::class);
        $store = $this->getStore();
        $store->putOffExpiration(new Key('toto'), 0.1);
    }
}
$storesCount = \count($this->stores);
        $expireAt = microtime(true) + $ttl;

        foreach ($this->stores as $store) {
            try {
                if (0.0 >= $adjustedTtl = $expireAt - microtime(true)) {
                    $this->logger?->debug('Stores took to long to put off the expiration of the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'ttl' => $ttl]);
                    $key->reduceLifetime(0);
                    break;
                }

                $store->putOffExpiration($key$adjustedTtl);
                ++$successCount;
            } catch (\Exception $e) {
                $this->logger?->debug('One store failed to put off the expiration of the "{resource}" lock.', ['resource' => $key, 'store' => $store, 'exception' => $e]);
                ++$failureCount;
            }

            if (!$this->strategy->canBeMet($failureCount$storesCount)) {
                break;
            }
        }

        


            try {
                $this->conn->executeStatement($sql[
                    $this->getHashedKey($key),
                    $this->getUniqueToken($key),
                ][
                    ParameterType::STRING,
                    ParameterType::STRING,
                ]);
            } catch (DBALException) {
                $this->putOffExpiration($key$this->initialTtl);
            }
        } catch (DBALException) {
            // the lock is already acquired. It could be us. Let's try to put off.             $this->putOffExpiration($key$this->initialTtl);
        }

        $this->randomlyPrune();
        $this->checkNotExpired($key);
    }

    /** * @return void */
Home | Imprint | This part of the site doesn't use cookies.