public void BringUpIfDown_Should_Allow_Multiple_Concurrent_Calls() { var policy = new CountReconnectionPolicy(100); var host = new Host(Address, policy); var counter = 0; host.Up += _ => Interlocked.Increment(ref counter); host.SetDown(); TestHelper.ParallelInvoke(() => { host.BringUpIfDown(); }, 100); //Should fire event only once Assert.AreEqual(1, counter); }
public void BringUpIfDown_Resets_Attempt_Reconnection_Flag() { var policy = new CountReconnectionPolicy(long.MaxValue); var host = new Host(Address, policy); host.SetDown(); Assert.True(host.SetAttemptingReconnection()); //Next times it should be false Assert.False(host.SetAttemptingReconnection()); Assert.False(host.SetAttemptingReconnection()); Assert.False(host.SetAttemptingReconnection()); host.BringUpIfDown(); //next time should be allowed Assert.True(host.SetAttemptingReconnection()); }
public void BringUpIfDown_Resets_Attempt_Reconnection_Flag() { var policy = new CountReconnectionPolicy(long.MaxValue); var host = new Host(Address, policy); host.SetDown(); Assert.True(host.SetAttemptingReconnection()); //Next times it should be false Assert.False(host.SetAttemptingReconnection()); Assert.False(host.SetAttemptingReconnection()); Assert.False(host.SetAttemptingReconnection()); host.BringUpIfDown(); //next time should be allowed Assert.True(host.SetAttemptingReconnection()); }
public void BringUpIfDown_Should_Allow_Multiple_Concurrent_Calls() { var policy = new CountReconnectionPolicy(100); var host = new Host(Address, policy); var counter = 0; host.Up += _ => Interlocked.Increment(ref counter); host.SetDown(); TestHelper.ParallelInvoke(() => { host.BringUpIfDown(); }, 100); //Should fire event only once Assert.AreEqual(1, counter); }
public void SetDown_Should_Get_The_Next_Delay_Once_The_Time_Passes() { var policy = new CountReconnectionPolicy(3000); var host = new Host(Address, policy); TestHelper.ParallelInvoke(() => { host.SetDown(); }, 5); //Should call the Schedule#NextDelayMs() Assert.AreEqual(1, policy.CallsCount); //SetDown should do nothing as the time has not passed host.SetDown(); Assert.AreEqual(1, policy.CallsCount); Thread.Sleep(3000); Assert.True(host.IsConsiderablyUp); //The nextUpTime passed TestHelper.ParallelInvoke(() => { host.SetDown(); }, 5); Assert.AreEqual(2, policy.CallsCount); }
public void SetDown_Should_Get_The_Next_Delay_Once_The_Time_Passes() { var policy = new CountReconnectionPolicy(3000); var host = new Host(Address, policy); TestHelper.ParallelInvoke(() => { host.SetDown(); }, 5); //Should call the Schedule#NextDelayMs() Assert.AreEqual(1, policy.CallsCount); //SetDown should do nothing as the time has not passed host.SetDown(); Assert.AreEqual(1, policy.CallsCount); Thread.Sleep(3000); Assert.True(host.IsConsiderablyUp); //The nextUpTime passed TestHelper.ParallelInvoke(() => { host.SetDown(); }, 5); Assert.AreEqual(2, policy.CallsCount); }
public CountReconnectionSchedule(long delay, CountReconnectionPolicy parent) { _delay = delay; _parent = parent; }
public CountReconnectionSchedule(long delay, CountReconnectionPolicy parent) { _delay = delay; _parent = parent; }