InMemoryStore example

->expects($this->once())
            ->method('exists')
            ->with($key)
            ->willReturn(true);

        $lock->release();
    }

    public function testSuccessReleaseLog()
    {
        $key = new Key((string) random_int(100, 1000));
        $store = new InMemoryStore();
        $logger = new class() extends AbstractLogger {
            private array $logs = [];

            public function log($level$message, array $context = []): void
            {
                $this->logs[] = [
                    $level,
                    (string) $message,
                    $context,
                ];
            }

            
#[AsSchedule('dummy')] class DummySchedule implements ScheduleProviderInterface
{
    public static array $recurringMessages;

    public function getSchedule(): Schedule
    {
        return (new Schedule())
            ->add(...self::$recurringMessages)
            ->stateful(new ArrayAdapter())
            ->lock(new Lock(new Key('dummy')new InMemoryStore()))
        ;
    }
}
case str_starts_with($connection, 'postgres+advisory://'):
            case str_starts_with($connection, 'postgresql+advisory://'):
                return new DoctrineDbalPostgreSqlStore($connection);

            case str_starts_with($connection, 'pgsql+advisory:'):
                return new PostgreSqlStore(preg_replace('/^([^:+]+)\+advisory/', '$1', $connection));

            case str_starts_with($connection, 'zookeeper://'):
                return new ZookeeperStore(ZookeeperStore::createConnection($connection));

            case 'in-memory' === $connection:
                return new InMemoryStore();
        }

        throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection));
    }
}
use Symfony\Component\Lock\Store\InMemoryStore;

/** * @author Jérémy Derussé <jeremy@derusse.com> */
class InMemoryStoreTest extends AbstractStoreTestCase
{
    use SharedLockStoreTestTrait;

    public function getStore(): PersistingStoreInterface
    {
        return new InMemoryStore();
    }
}
if (!\in_array($driver['pgsql', 'postgres', 'postgresql'])) {
            throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
        }

        return sprintf('%s:%s', $driver$rest);
    }

    private function getInternalStore(): SharedLockStoreInterface
    {
        $namespace = spl_object_hash($this->conn);

        return self::$storeRegistry[$namespace] ??= new InMemoryStore();
    }
}
$cache->get('cache', fn () => [$now, 0], \INF);

        $this->assertTrue($checkpoint->acquire($startedAt = $now->modify('1 min')));
        $this->assertEquals($now$checkpoint->time());
        $this->assertEquals(0, $checkpoint->index());
        $this->assertEquals([$now, 0, $startedAt]$cache->get('cache', fn () => []));
    }

    public function testWithLockInitStateOnFirstAcquiring()
    {
        $lock = new Lock(new Key('lock')new InMemoryStore());
        $checkpoint = new Checkpoint('dummy', $lock);
        $now = new \DateTimeImmutable('2020-02-20 20:20:20Z');

        $this->assertTrue($checkpoint->acquire($now));
        $this->assertEquals($now$checkpoint->time());
        $this->assertEquals($now$checkpoint->from());
        $this->assertEquals(-1, $checkpoint->index());
        $this->assertTrue($lock->isAcquired());
    }

    public function testWithLockLoadStateOnAcquiring()
    {
private function checkDriver(): void
    {
        if ('pgsql' !== $driver = $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
            throw new InvalidArgumentException(sprintf('The adapter "%s" does not support the "%s" driver.', __CLASS__, $driver));
        }
    }

    private function getInternalStore(): SharedLockStoreInterface
    {
        $namespace = spl_object_hash($this->getConnection());

        return self::$storeRegistry[$namespace] ??= new InMemoryStore();
    }
}
Home | Imprint | This part of the site doesn't use cookies.