Exemplo n.º 1
0
        public async Task AcquireLockAsyncTest()
        {
            var cacheClient = new StackExchangeCacheClient(
                new ProtobufSerializer(), await ConnectionMultiplexer.ConnectAsync("localhost"));

            var tokenSource = new CancellationTokenSource();

            var testLock = await cacheClient.AcquireLockAsync("test:acquire", tokenSource.Token);

            Assert.Equal("1", await cacheClient.Client.GetDatabase().StringGetAsync("test:acquire"));

            await testLock.ReleaseAsync();

            Assert.Null(await cacheClient.GetAsync <string>("test:acquire"));
        }
Exemplo n.º 2
0
        public async Task AcquireLockAsyncTwiceThrowsTimeoutTest()
        {
            var cacheClient = new StackExchangeCacheClient(
                new ProtobufSerializer(),
                await ConnectionMultiplexer.ConnectAsync("localhost"));

            var tokenSource = new CancellationTokenSource();

            var testLock = await cacheClient.AcquireLockAsync(
                "test:redis:acquire:multiple", tokenSource.Token);

            tokenSource.CancelAfter(1000);
            await Assert.ThrowsAnyAsync <OperationCanceledException>(
                () => cacheClient.AcquireLockAsync(
                    "test:redis:acquire:multiple", tokenSource.Token)
                .AsTask());

            await testLock.ReleaseAsync();

            Assert.Null(await cacheClient.GetAsync <string>("test:redis:acquire:multiple"));
        }