NodeFencer { public boolean fence(HAServiceTarget fromSvc) { return fence(fromSvc, null); } NodeFencer(Configuration conf, String spec); static NodeFencer create(Configuration conf, String confKey); boolean fence(HAServiceTarget fromSvc); boolean fence(HAServiceTarget fromSvc, HAServiceTarget toSvc);  }
@Test public void testSingleFencer() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer( AlwaysSucceedFencer.class.getName() + "(foo)"); assertTrue(fencer.fence(MOCK_TARGET)); assertEquals(1, AlwaysSucceedFencer.fenceCalled); assertSame(MOCK_TARGET, AlwaysSucceedFencer.fencedSvc); assertEquals("foo", AlwaysSucceedFencer.callArgs.get(0)); }
@Test public void testMultipleFencers() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer( AlwaysSucceedFencer.class.getName() + "(foo)\n" + AlwaysSucceedFencer.class.getName() + "(bar)\n"); assertTrue(fencer.fence(MOCK_TARGET)); assertEquals(1, AlwaysSucceedFencer.fenceCalled); assertEquals("foo", AlwaysSucceedFencer.callArgs.get(0)); }
@Test public void testWhitespaceAndCommentsInConfig() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer( "\n" + " # the next one will always fail\n" + " " + AlwaysFailFencer.class.getName() + "(foo) # <- fails\n" + AlwaysSucceedFencer.class.getName() + "(bar) \n"); assertTrue(fencer.fence(MOCK_TARGET)); assertEquals(1, AlwaysFailFencer.fenceCalled); assertSame(MOCK_TARGET, AlwaysFailFencer.fencedSvc); assertEquals(1, AlwaysSucceedFencer.fenceCalled); assertSame(MOCK_TARGET, AlwaysSucceedFencer.fencedSvc); assertEquals("foo", AlwaysFailFencer.callArgs.get(0)); assertEquals("bar", AlwaysSucceedFencer.callArgs.get(0)); }
@Test public void testArglessFencer() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer( AlwaysSucceedFencer.class.getName()); assertTrue(fencer.fence(MOCK_TARGET)); assertEquals(1, AlwaysSucceedFencer.fenceCalled); assertSame(MOCK_TARGET, AlwaysSucceedFencer.fencedSvc); assertEquals(null, AlwaysSucceedFencer.callArgs.get(0)); }
@Test public void testShortNameShell() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer(getFencerTrueCommand()); assertTrue(fencer.fence(MOCK_TARGET)); }
@Test public void testShortNameSsh() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer("sshfence"); assertFalse(fencer.fence(MOCK_TARGET)); }
@Test public void testShortNameSshWithUser() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer("sshfence(user)"); assertFalse(fencer.fence(MOCK_TARGET)); }
@Test public void testShortNameSshWithPort() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer("sshfence(:123)"); assertFalse(fencer.fence(MOCK_TARGET)); }
@Test public void testShortNameSshWithUserPort() throws BadFencingConfigurationException { NodeFencer fencer = setupFencer("sshfence(user:123)"); assertFalse(fencer.fence(MOCK_TARGET)); }