ShellCommandFencer extends Configured implements FenceMethod { static String abbreviate(String cmd, int len) { if (cmd.length() > len && len >= 5) { int firstHalf = (len - 3) / 2; int rem = len - firstHalf - 3; return cmd.substring(0, firstHalf) + "..." + cmd.substring(cmd.length() - rem); } else { return cmd; } }  @Override void checkArgs(String args); @Override boolean tryFence(HAServiceTarget target, String args);  }
@Test public void testCommandAbbreviation() { assertEquals("a...f", ShellCommandFencer.abbreviate("abcdef", 5)); assertEquals("abcdef", ShellCommandFencer.abbreviate("abcdef", 6)); assertEquals("abcdef", ShellCommandFencer.abbreviate("abcdef", 7)); assertEquals("a...g", ShellCommandFencer.abbreviate("abcdefg", 5)); assertEquals("a...h", ShellCommandFencer.abbreviate("abcdefgh", 5)); assertEquals("a...gh", ShellCommandFencer.abbreviate("abcdefgh", 6)); assertEquals("ab...gh", ShellCommandFencer.abbreviate("abcdefgh", 7)); }