Beispiel #1
0
        public void FallBackToSequentialScanWhenAllNodesDeadTest()
        {
            var nodes = new BobNodeClientStatusMock[]
            {
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
            };

            var policy = FirstWorkingNodeSelectionPolicy.Factory.Create(nodes);

            int prev = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));

            for (int i = 0; i < 100; i++)
            {
                int expected = (prev + 1) % nodes.Length;

                int cur = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));
                Assert.Equal(expected, cur);

                prev = cur;
            }
        }
Beispiel #2
0
        public void RetrySkipsNotWorkingTest()
        {
            var nodes = new BobNodeClientStatusMock[]
            {
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock()
            };

            var policy = FirstWorkingNodeSelectionPolicy.Factory.Create(nodes);

            int firstAttempt = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));

            Assert.Equal(1, firstAttempt);

            int secondAttempt = policy.SelectNodeIndexOnRetry(firstAttempt, BobOperationKind.Get, default(BobKey));

            Assert.Equal(4, secondAttempt);
        }
Beispiel #3
0
        public void SkipsNonWorkingNodesTest()
        {
            var nodes = new BobNodeClientStatusMock[]
            {
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock()
            };

            var policy = FirstWorkingNodeSelectionPolicy.Factory.Create(nodes);

            int initial = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));

            Assert.Equal(2, initial);
            for (int i = 0; i < 100; i++)
            {
                int cur = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));
                Assert.Equal(initial, cur);
            }
        }
Beispiel #4
0
        public void SimpleFirstNodeSelectionTest()
        {
            var nodes = new BobNodeClientStatusMock[]
            {
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock()
            };

            var policy = FirstWorkingNodeSelectionPolicy.Factory.Create(nodes);

            int initial = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));

            Assert.Equal(0, initial);
            for (int i = 0; i < 100; i++)
            {
                int cur = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));
                Assert.Equal(initial, cur);
            }
        }
Beispiel #5
0
        public void NoRetryWhenAllNodesDeadTest()
        {
            var nodes = new BobNodeClientStatusMock[]
            {
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
            };

            var policy = FirstWorkingNodeSelectionPolicy.Factory.Create(nodes);

            int initial = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));
            int retry   = policy.SelectNodeIndexOnRetry(initial, BobOperationKind.Get, default(BobKey));

            Assert.True(retry < 0);
        }
Beispiel #6
0
        public void SimpleSequenceTest()
        {
            var nodes = new BobNodeClientStatusMock[]
            {
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock()
            };

            var factory = SequentialWorkingNodeSelectionPolicy.CreateFactory(1, 1000);
            var policy  = factory.Create(nodes);

            int initial = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));

            for (int i = 0; i < 1000; i++)
            {
                int cur = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));
                Assert.Equal((initial + i + 1) % nodes.Length, cur);
            }
        }
Beispiel #7
0
        public void RetrySkipsNotWorkingTest()
        {
            var nodes = new BobNodeClientStatusMock[]
            {
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock(),
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock()
                {
                    State = BobNodeClientState.TransientFailure, SequentialErrorCount = 100
                },
                new BobNodeClientStatusMock()
            };

            var factory = SequentialWorkingNodeSelectionPolicy.CreateFactory(1, 1000);
            var policy  = factory.Create(nodes);

            int prev = policy.SelectNodeIndex(BobOperationKind.Get, default(BobKey));

            for (int i = 0; i < 1000; i++)
            {
                int expected = (prev + 1) % nodes.Length;
                while (nodes[expected].State != BobNodeClientState.Ready)
                {
                    expected = (expected + 1) % nodes.Length;
                }

                int cur = policy.SelectNodeIndexOnRetry(prev, BobOperationKind.Get, default(BobKey));
                Assert.Equal(BobNodeClientState.Ready, nodes[cur].State);
                Assert.Equal(expected, cur);

                prev = cur;
            }
        }