示例#1
0
        internal DummyHAService(HAServiceProtocol.HAServiceState state, IPEndPoint address
                                , bool testWithProtoBufRPC)
        {
            this.state = state;
            this.testWithProtoBufRPC = testWithProtoBufRPC;
            if (testWithProtoBufRPC)
            {
                this.address = StartAndGetRPCServerAddress(address);
            }
            else
            {
                this.address = address;
            }
            Configuration conf = new Configuration();

            this.proxy = MakeMock(conf, CommonConfigurationKeys.HaHmRpcTimeoutDefault);
            try
            {
                conf.Set(DummyFenceKey, typeof(DummyHAService.DummyFencer).FullName);
                this.fencer = Org.Mockito.Mockito.Spy(NodeFencer.Create(conf, DummyFenceKey));
            }
            catch (BadFencingConfigurationException e)
            {
                throw new RuntimeException(e);
            }
            lock (instances)
            {
                instances.AddItem(this);
                this.index = instances.Count;
            }
        }
示例#2
0
        public virtual void TestMultipleFencers()
        {
            NodeFencer fencer = SetupFencer(typeof(TestNodeFencer.AlwaysSucceedFencer).FullName
                                            + "(foo)\n" + typeof(TestNodeFencer.AlwaysSucceedFencer).FullName + "(bar)\n");

            Assert.True(fencer.Fence(MockTarget));
            // Only one call, since the first fencer succeeds
            Assert.Equal(1, TestNodeFencer.AlwaysSucceedFencer.fenceCalled
                         );
            Assert.Equal("foo", TestNodeFencer.AlwaysSucceedFencer.callArgs
                         [0]);
        }
示例#3
0
        public virtual void TestSingleFencer()
        {
            NodeFencer fencer = SetupFencer(typeof(TestNodeFencer.AlwaysSucceedFencer).FullName
                                            + "(foo)");

            Assert.True(fencer.Fence(MockTarget));
            Assert.Equal(1, TestNodeFencer.AlwaysSucceedFencer.fenceCalled
                         );
            NUnit.Framework.Assert.AreSame(MockTarget, TestNodeFencer.AlwaysSucceedFencer.fencedSvc
                                           );
            Assert.Equal("foo", TestNodeFencer.AlwaysSucceedFencer.callArgs
                         [0]);
        }
示例#4
0
        public virtual void TestArglessFencer()
        {
            NodeFencer fencer = SetupFencer(typeof(TestNodeFencer.AlwaysSucceedFencer).FullName
                                            );

            Assert.True(fencer.Fence(MockTarget));
            // One call to each, since top fencer fails
            Assert.Equal(1, TestNodeFencer.AlwaysSucceedFencer.fenceCalled
                         );
            NUnit.Framework.Assert.AreSame(MockTarget, TestNodeFencer.AlwaysSucceedFencer.fencedSvc
                                           );
            Assert.Equal(null, TestNodeFencer.AlwaysSucceedFencer.callArgs
                         [0]);
        }
示例#5
0
        public virtual void TestWhitespaceAndCommentsInConfig()
        {
            NodeFencer fencer = SetupFencer("\n" + " # the next one will always fail\n" + " "
                                            + typeof(TestNodeFencer.AlwaysFailFencer).FullName + "(foo) # <- fails\n" + typeof(
                                                TestNodeFencer.AlwaysSucceedFencer).FullName + "(bar) \n");

            Assert.True(fencer.Fence(MockTarget));
            // One call to each, since top fencer fails
            Assert.Equal(1, TestNodeFencer.AlwaysFailFencer.fenceCalled);
            NUnit.Framework.Assert.AreSame(MockTarget, TestNodeFencer.AlwaysFailFencer.fencedSvc
                                           );
            Assert.Equal(1, TestNodeFencer.AlwaysSucceedFencer.fenceCalled
                         );
            NUnit.Framework.Assert.AreSame(MockTarget, TestNodeFencer.AlwaysSucceedFencer.fencedSvc
                                           );
            Assert.Equal("foo", TestNodeFencer.AlwaysFailFencer.callArgs[0
                         ]);
            Assert.Equal("bar", TestNodeFencer.AlwaysSucceedFencer.callArgs
                         [0]);
        }
示例#6
0
        public virtual void TestShortNameSshWithUserPort()
        {
            NodeFencer fencer = SetupFencer("sshfence(user:123)");

            NUnit.Framework.Assert.IsFalse(fencer.Fence(MockTarget));
        }
示例#7
0
        public virtual void TestShortNameShell()
        {
            NodeFencer fencer = SetupFencer(GetFencerTrueCommand());

            Assert.True(fencer.Fence(MockTarget));
        }