@Test
public void testMutativeOperationsWithAutoHaEnabled() throws Exception {

  Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus();
  
  // Turn on auto-HA in the config
  HdfsConfiguration conf = getHAConf();
  conf.setBoolean(DFSConfigKeys.DFS_HA_AUTO_FAILOVER_ENABLED_KEY, true);
  conf.set(DFSConfigKeys.DFS_HA_FENCE_METHODS_KEY, getFencerTrueCommand());
  tool.setConf(conf);
  // Should fail without the forcemanual flag
  assertEquals(-1, runTool("-transitionToActive", "nn1"));
  assertTrue(errOutput.contains("Refusing to manually manage"));
  assertEquals(-1, runTool("-transitionToStandby", "nn1"));
  assertTrue(errOutput.contains("Refusing to manually manage"));
  Mockito.verify(mockProtocol, Mockito.never())
    .transitionToActive(anyReqInfo());
  Mockito.verify(mockProtocol, Mockito.never())
    .transitionToStandby(anyReqInfo());
  // Force flag should bypass the check and change the request source
  // for the RPC
  setupConfirmationOnSystemIn();
  assertEquals(0, runTool("-transitionToActive", "-forcemanual", "nn1"));
  setupConfirmationOnSystemIn();
  assertEquals(0, runTool("-transitionToStandby", "-forcemanual", "nn1"));
  Mockito.verify(mockProtocol, Mockito.times(1)).transitionToActive(
      reqInfoCaptor.capture());
  Mockito.verify(mockProtocol, Mockito.times(1)).transitionToStandby(
      reqInfoCaptor.capture());
  
  // All of the RPCs should have had the "force" source
  for (StateChangeRequestInfo ri : reqInfoCaptor.getAllValues()) {
    assertEquals(RequestSource.REQUEST_BY_USER_FORCED, ri.getSource());
  }
}