public void MarkBadRequest_RunTwice() { SL.Config(TestCommandKey, TestGroupKey, TestDomain); CommandComponents.ConfigSet.InitTestHealthSnapshotInterval(); for (int i = 1; i <= DefaultConfigSet.CircuitBreakerRequestCountThreshold; i++) { using (SL instance = new SL(TestCommandKey)) { instance.StartExecution(); instance.MarkBadRequest(); ScenarioTestHelper.SleepHealthSnapshotInverval(); Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution(); Assert.AreEqual(i, counts[CommandExecutionEventEnum.BadRequest]); instance.MarkBadRequest(); ScenarioTestHelper.SleepHealthSnapshotInverval(); counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution(); Assert.AreEqual(i, counts[CommandExecutionEventEnum.BadRequest]); } } }
public void Execution_SimulateReal() { CountdownEvent waitHandle = new CountdownEvent(DefaultConfigSet.CommandMaxConcurrentCount); for (int i = 0; i < DefaultConfigSet.CommandMaxConcurrentCount; i++) { Task.Factory.StartNew( j => { for (int k = 0; k < 10; k++) { using (SL instance = new SL(TestCommandKey)) { instance.StartExecution(); Assert.AreNotEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount); Thread.Sleep(1000); int v = (int)j; if (v % 3 == 0) { instance.MarkFailure(); } else if (v % 5 == 0) { instance.MarkBadRequest(); } else { instance.MarkSuccess(); } Assert.AreNotEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount); } } }, i) .ContinueWith( t => { var ex = t.Exception; waitHandle.Signal(); }); } bool success = waitHandle.Wait(180 * 1000); Assert.IsTrue(success); Assert.AreEqual(DefaultConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount); }
public void MarkBadRequest_WithInstance() { SL.Config(TestCommandKey, TestGroupKey, TestDomain); CommandComponents.ConfigSet.InitTestHealthSnapshotInterval(); object instance = SL.CreateInstance(TestCommandKey); Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount); SL.StartExecution(instance); Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount); SL.MarkBadRequest(instance); Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount - 1, TestSemaphore.CurrentCount); ScenarioTestHelper.SleepHealthSnapshotInverval(); Dictionary <CommandExecutionEventEnum, int> counts = CommandComponents.Metrics.ToConcrete().GetExecutionEventDistribution(); Assert.AreEqual(1, counts[CommandExecutionEventEnum.BadRequest]); SL.EndExecution(instance); Assert.AreEqual(CommandComponents.ConfigSet.CommandMaxConcurrentCount, TestSemaphore.CurrentCount); }
public static void MarkBadRequest(object instance) { SemaphoreIsolation isolationInstance = ConvertInstance(instance); isolationInstance.MarkBadRequest(); }
public void MarkBadRequest_WithEmptyInstance() { SL.MarkBadRequest(null); }