コード例 #1
0
        public void SSHRecoverRegularConnection()
        {
            var maker = new dummyConnectionMaker();

            using (var c = new SSHRecoveringConnection(() => maker.Execute()))
            {
                Assert.AreEqual(0, dummyConnection.DisposedCalled);
                c.ExecuteLinuxCommand("ls");
                Assert.AreEqual(2, dummyConnection.CalledExecuteLinuxCommand);
            }
            Assert.AreEqual(1, dummyConnection.DisposedCalled);
        }
コード例 #2
0
        public void SSHRecoverFailsConnectionSSHConnectionDroppedException()
        {
            var maker = new dummyConnectionMaker(failExecuteCommandForNTimes: 1, genException: () => new SSHConnectionDroppedException());

            using (var c = new SSHRecoveringConnection(() => maker.Execute()))
            {
                c.RetryWaitPeriod = TimeSpan.FromMilliseconds(5);
                c.ExecuteLinuxCommand("ls");
                Assert.AreEqual(3, dummyConnection.CalledExecuteLinuxCommand);
            }
            Assert.AreEqual(2, dummyConnection.DisposedCalled);
        }
コード例 #3
0
        public void SSHRecoverNoRecover()
        {
            var maker = new dummyConnectionMaker(failExecuteCommandForNTimes: 1);

            using (var c = new SSHRecoveringConnection(() => maker.Execute()))
            {
                c.RetryWaitPeriod = TimeSpan.FromMilliseconds(1);
                using (var blocker = c.EnterNoRecoverRegion())
                {
                    c.ExecuteLinuxCommand("ls");
                }
            }
            Assert.AreEqual(1, dummyConnection.DisposedCalled);
            Assert.AreEqual(1, dummyConnection.CTorCalls);
        }
コード例 #4
0
        public void SSHRecoverMakeSureCommandRetriedOnException()
        {
            var maker = new dummyConnectionMaker(failExecuteCommandForNTimes: 1);

            using (var c = new SSHRecoveringConnection(() => maker.Execute()))
            {
                c.RetryWaitPeriod = TimeSpan.FromMilliseconds(5);
                try
                {
                    c.ExecuteLinuxCommand("ls");
                }
                catch { }
                Assert.AreEqual(2, dummyConnection.ListOfCommands.Count());
                Assert.AreEqual("ls", dummyConnection.ListOfCommands[0]);
            }
            Assert.AreEqual(2, dummyConnection.DisposedCalled);
        }