示例#1
0
        public async Task Does_throw_TimeoutException_when_PoolTimeout_exceeded()
        {
            await using IRedisClientsManagerAsync manager = new PooledRedisClientManager(testReadWriteHosts, testReadOnlyHosts,
                                                                                         new RedisClientManagerConfig
            {
                MaxWritePoolSize = 4,
                MaxReadPoolSize  = 4,
                AutoStart        = false,
            });
            ((PooledRedisClientManager)manager).PoolTimeout = 100;

            ((PooledRedisClientManager)manager).Start();

            var masters = 4.Times(i => manager.GetClientAsync());

            try
            {
                await manager.GetClientAsync();

                Assert.Fail("Should throw TimeoutException");
            }
            catch (TimeoutException ex)
            {
                Assert.That(ex.Message, Does.StartWith("Redis Timeout expired."));
            }

            for (int i = 0; i < 4; i++)
            {
                await manager.GetReadOnlyClientAsync();
            }

            try
            {
                await manager.GetReadOnlyClientAsync();

                Assert.Fail("Should throw TimeoutException");
            }
            catch (TimeoutException ex)
            {
                Assert.That(ex.Message, Does.StartWith("Redis Timeout expired."));
            }
        }
示例#2
0
        public async Task Can_have_different_pool_size_and_host_configurations()
        {
            var writeHosts = new[] { "readwrite1" };
            var readHosts  = new[] { "read1", "read2" };

            const int poolSizeMultiplier = 4;

            await using IRedisClientsManagerAsync manager = new PooledRedisClientManager(writeHosts, readHosts,
                                                                                         new RedisClientManagerConfig
            {
                MaxWritePoolSize = writeHosts.Length * poolSizeMultiplier,
                MaxReadPoolSize  = readHosts.Length * poolSizeMultiplier,
                AutoStart        = true,
            }
                                                                                         );
            //A poolsize of 4 will not block getting 4 clients
            await using (var client1 = await manager.GetClientAsync())
                await using (var client2 = await manager.GetClientAsync())
                    await using (var client3 = await manager.GetClientAsync())
                        await using (var client4 = await manager.GetClientAsync())
                        {
                            AssertClientHasHost(client1, writeHosts[0]);
                            AssertClientHasHost(client2, writeHosts[0]);
                            AssertClientHasHost(client3, writeHosts[0]);
                            AssertClientHasHost(client4, writeHosts[0]);
                        }

            //A poolsize of 8 will not block getting 8 clients
            await using (var client1 = await manager.GetReadOnlyClientAsync())
                await using (var client2 = await manager.GetReadOnlyClientAsync())
                    await using (var client3 = await manager.GetReadOnlyClientAsync())
                        await using (var client4 = await manager.GetReadOnlyClientAsync())
                            await using (var client5 = await manager.GetReadOnlyClientAsync())
                                await using (var client6 = await manager.GetReadOnlyClientAsync())
                                    await using (var client7 = await manager.GetReadOnlyClientAsync())
                                        await using (var client8 = await manager.GetReadOnlyClientAsync())
                                        {
                                            AssertClientHasHost(client1, readHosts[0]);
                                            AssertClientHasHost(client2, readHosts[1]);
                                            AssertClientHasHost(client3, readHosts[0]);
                                            AssertClientHasHost(client4, readHosts[1]);
                                            AssertClientHasHost(client5, readHosts[0]);
                                            AssertClientHasHost(client6, readHosts[1]);
                                            AssertClientHasHost(client7, readHosts[0]);
                                            AssertClientHasHost(client8, readHosts[1]);
                                        }
        }