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; } }
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); }
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); } }
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); } }
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); }
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); } }
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; } }