示例#1
0
        public async void ConnectRetriesOnError()
        {
            int invokationCount = 0;
            var wh = new ManualResetEventSlim();
            var redisConnection = GetMockRedisConnection();

            var tcs = new TaskCompletionSource <object>();

            tcs.TrySetCanceled();

            redisConnection.Setup(m => m.ConnectAsync(It.IsAny <string>(), It.IsAny <TraceSource>())).Returns <string, TraceSource>((connectionString, trace) =>
            {
                if (++invokationCount == 2)
                {
                    wh.Set();
                    return(Task.FromResult(0));
                }
                else
                {
                    return(tcs.Task);
                }
            });

            var redisMessageBus = new RedisMessageBus(GetDependencyResolver(), new RedisScaleoutConfiguration(String.Empty, String.Empty),
                                                      redisConnection.Object, false);

            await redisMessageBus.ConnectWithRetry();

            Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));
            Assert.Equal(RedisMessageBus.State.Connected, redisMessageBus.ConnectionState);
        }
示例#2
0
        public async void ConnectRetriesOnError()
        {
            int invokationCount = 0;
            var wh = new ManualResetEventSlim();
            var redisConnection = GetMockRedisConnection();

            var tcs = new TaskCompletionSource<object>();
            tcs.TrySetCanceled();

            redisConnection.Setup(m => m.ConnectAsync(It.IsAny<string>(), It.IsAny<TraceSource>())).Returns<string, TraceSource>((connectionString, trace) =>
            {
                if (++invokationCount == 2)
                {
                    wh.Set();
                    return Task.FromResult(0);
                }
                else
                {
                    return tcs.Task;
                }
            });

            var redisMessageBus = new RedisMessageBus(GetDependencyResolver(), new RedisScaleoutConfiguration(String.Empty, String.Empty),
            redisConnection.Object, false);

            await redisMessageBus.ConnectWithRetry();

            Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));
            Assert.Equal(RedisMessageBus.State.Connected, redisMessageBus.ConnectionState);
        }
示例#3
0
        public async void ConnectRetriesOnError()
        {
            int invokationCount = 0;
            var wh = new ManualResetEventSlim();
            var redisConnection = GetMockRedisConnection();

            var tcs = new TaskCompletionSource <object>();

            tcs.TrySetCanceled();

            redisConnection.Setup(m => m.ConnectAsync(It.IsAny <string>(), It.IsAny <ILogger>())).Returns <string, ILogger>((connectionString, logger) =>
            {
                if (++invokationCount == 2)
                {
                    wh.Set();
                    return(Task.FromResult(0));
                }
                else
                {
                    //Return cancelled task to insert error
                    return(tcs.Task);
                }
            });

            var redisMessageBus = new RedisMessageBus(new Mock <IStringMinifier>().Object, new TestLoggerFactory(),
                                                      new PerformanceCounterManager(new TestLoggerFactory()), new MessageBusOptionsAccessor(), new RedisOptionsAccessor(), redisConnection.Object, false);

            await redisMessageBus.ConnectWithRetry();

            Assert.True(wh.Wait(TimeSpan.FromSeconds(5)));
            Assert.Equal(RedisMessageBus.State.Connected, redisMessageBus.ConnectionState);
        }
示例#4
0
        public async void ConnectionFailedChangesStateToClosed()
        {
            var redisConnection = GetMockRedisConnection();

            var redisMessageBus = new RedisMessageBus(new Mock <Infrastructure.IStringMinifier>().Object, new TestLoggerFactory(), new Infrastructure.PerformanceCounterManager(new TestLoggerFactory()), new MessageBusOptionsAccessor(), new RedisOptionsAccessor(), redisConnection.Object, false);

            await redisMessageBus.ConnectWithRetry();

            Assert.Equal(RedisMessageBus.State.Connected, redisMessageBus.ConnectionState);

            redisConnection.Raise(mock => mock.ConnectionFailed += null, new Exception("Test exception"));

            Assert.Equal(RedisMessageBus.State.Closed, redisMessageBus.ConnectionState);
        }
示例#5
0
        public async void ConnectionFailedChangesStateToClosed()
        {
            var redisConnection = GetMockRedisConnection();

            var redisMessageBus = new RedisMessageBus(GetDependencyResolver(),
                                                      new RedisScaleoutConfiguration(String.Empty, String.Empty),
                                                      redisConnection.Object, false);

            await redisMessageBus.ConnectWithRetry();

            Assert.Equal(RedisMessageBus.State.Connected, redisMessageBus.ConnectionState);

            redisConnection.Raise(mock => mock.ConnectionFailed += null, new Exception("Test exception"));

            Assert.Equal(RedisMessageBus.State.Closed, redisMessageBus.ConnectionState);
        }
示例#6
0
        public async void ConnectionFailedChangesStateToClosed()
        {
            var redisConnection = GetMockRedisConnection();

            var redisMessageBus = new RedisMessageBus(GetDependencyResolver(),
                new RedisScaleoutConfiguration(String.Empty, String.Empty),
                redisConnection.Object, false);

            await redisMessageBus.ConnectWithRetry();

            Assert.Equal(RedisMessageBus.State.Connected, redisMessageBus.ConnectionState);

            redisConnection.Raise(mock => mock.ConnectionFailed += null, new Exception("Test exception"));

            Assert.Equal(RedisMessageBus.State.Closed, redisMessageBus.ConnectionState);
        }
示例#7
0
        public async void RestoreLatestValueForKeyCalledOnConnectionRestored()
        {
            bool restoreLatestValueForKey = false;

            var redisConnection = GetMockRedisConnection();

            redisConnection.Setup(m => m.RestoreLatestValueForKey(It.IsAny <int>(), It.IsAny <string>())).Returns(() =>
            {
                restoreLatestValueForKey = true;
                return(Task.FromResult <object>(null));
            });

            var redisMessageBus = new RedisMessageBus(new Mock <IStringMinifier>().Object, new TestLoggerFactory(), new PerformanceCounterManager(new TestLoggerFactory()), new MessageBusOptionsAccessor(), new RedisOptionsAccessor(), redisConnection.Object, false);

            await redisMessageBus.ConnectWithRetry();

            redisConnection.Raise(mock => mock.ConnectionRestored += null, new Exception());

            Assert.True(restoreLatestValueForKey, "RestoreLatestValueForKey not invoked");
        }
示例#8
0
        public async Task RestoreLatestValueForKeyCalledOnConnectionRestored()
        {
            bool restoreLatestValueForKey = false;

            var redisConnection = GetMockRedisConnection();

            redisConnection.Setup(m => m.RestoreLatestValueForKey(It.IsAny <int>(), It.IsAny <string>())).Returns(() =>
            {
                restoreLatestValueForKey = true;
                return(TaskAsyncHelper.Empty);
            });

            var redisMessageBus = new RedisMessageBus(GetDependencyResolver(), new RedisScaleoutConfiguration(String.Empty, String.Empty),
                                                      redisConnection.Object, connectAutomatically: false);

            await redisMessageBus.ConnectWithRetry();

            redisConnection.Raise(mock => mock.ConnectionFailed   += null, new Exception());
            redisConnection.Raise(mock => mock.ConnectionRestored += null, new Exception());

            Assert.True(restoreLatestValueForKey, "RestoreLatestValueForKey not invoked");
        }