예제 #1
0
 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);
 }
예제 #2
0
 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());
 }
예제 #3
0
        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());
        }
예제 #4
0
        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);
        }
예제 #5
0
 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);
 }
예제 #6
0
        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);
        }
예제 #7
0
 public CountReconnectionSchedule(long delay, CountReconnectionPolicy parent)
 {
     _delay  = delay;
     _parent = parent;
 }
예제 #8
0
 public CountReconnectionSchedule(long delay, CountReconnectionPolicy parent)
 {
     _delay = delay;
     _parent = parent;
 }