public static void transitionToActive(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.transitionToActive(reqInfo); } catch (RemoteException e) { throw e.unwrapRemoteException(ServiceFailedException.class); } }
@Override public TransitionToActiveResponseProto transitionToActive( RpcController controller, TransitionToActiveRequestProto request) throws ServiceException { try { server.transitionToActive(convert(request.getReqInfo())); return TRANSITION_TO_ACTIVE_RESP; } catch(IOException e) { throw new ServiceException(e); } }
public static void transitionToActive(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.transitionToActive(reqInfo); } catch (RemoteException e) { throw e.unwrapRemoteException(ServiceFailedException.class); } }
public static void transitionToActive(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.transitionToActive(reqInfo); } catch (RemoteException e) { throw e.unwrapRemoteException(ServiceFailedException.class); } }
public static void transitionToActive(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.transitionToActive(reqInfo); } catch (RemoteException e) { throw e.unwrapRemoteException(ServiceFailedException.class); } }
public static void transitionToActive(HAServiceProtocol svc, StateChangeRequestInfo reqInfo) throws IOException { try { svc.transitionToActive(reqInfo); } catch (RemoteException e) { throw e.unwrapRemoteException(ServiceFailedException.class); } }
@Override public TransitionToActiveResponseProto transitionToActive( RpcController controller, TransitionToActiveRequestProto request) throws ServiceException { try { server.transitionToActive(convert(request.getReqInfo())); return TRANSITION_TO_ACTIVE_RESP; } catch(IOException e) { throw new ServiceException(e); } }
@Override public TransitionToActiveResponseProto transitionToActive( RpcController controller, TransitionToActiveRequestProto request) throws ServiceException { try { server.transitionToActive(convert(request.getReqInfo())); return TRANSITION_TO_ACTIVE_RESP; } catch(IOException e) { throw new ServiceException(e); } }
@Override public TransitionToActiveResponseProto transitionToActive( RpcController controller, TransitionToActiveRequestProto request) throws ServiceException { try { server.transitionToActive(convert(request.getReqInfo())); return TRANSITION_TO_ACTIVE_RESP; } catch(IOException e) { throw new ServiceException(e); } }
@Override public TransitionToActiveResponseProto transitionToActive( RpcController controller, TransitionToActiveRequestProto request) throws ServiceException { try { server.transitionToActive(convert(request.getReqInfo())); return TRANSITION_TO_ACTIVE_RESP; } catch(IOException e) { throw new ServiceException(e); } }
@Test public void testTransitionToActive() throws Exception { Mockito.doReturn(STANDBY_READY_RESULT).when(mockProtocol).getServiceStatus(); assertEquals(0, runTool("-transitionToActive", "nn1")); Mockito.verify(mockProtocol).transitionToActive( reqInfoCaptor.capture()); assertEquals(RequestSource.REQUEST_BY_USER, reqInfoCaptor.getValue().getSource()); }
@Test public void testFailbackToFaultyServiceFails() throws Exception { DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc1.proxy).transitionToActive(anyReqInfo()); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); try { doFailover(svc1, svc2, false, false); fail("Failover to already active service"); } catch (FailoverFailedException ffe) { // Expected } assertEquals(HAServiceState.STANDBY, svc1.state); assertEquals(HAServiceState.STANDBY, svc2.state); }
@Test public void testFailbackToFaultyServiceFails() throws Exception { DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc1.proxy).transitionToActive(anyReqInfo()); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); try { doFailover(svc1, svc2, false, false); fail("Failover to already active service"); } catch (FailoverFailedException ffe) { // Expected } assertEquals(HAServiceState.STANDBY, svc1.state); assertEquals(HAServiceState.STANDBY, svc2.state); }
@Test public void testFailoverToFaultyServiceFailsbackOK() throws Exception { DummyHAService svc1 = spy(new DummyHAService(HAServiceState.ACTIVE, svc1Addr)); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); try { doFailover(svc1, svc2, false, false); fail("Failover to already active service"); } catch (FailoverFailedException ffe) { // Expected } // svc1 went standby then back to active verify(svc1.proxy).transitionToStandby(anyReqInfo()); verify(svc1.proxy).transitionToActive(anyReqInfo()); assertEquals(HAServiceState.ACTIVE, svc1.state); assertEquals(HAServiceState.STANDBY, svc2.state); }
@Test public void testFailoverToFaultyServiceFailsbackOK() throws Exception { DummyHAService svc1 = spy(new DummyHAService(HAServiceState.ACTIVE, svc1Addr)); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); try { doFailover(svc1, svc2, false, false); fail("Failover to already active service"); } catch (FailoverFailedException ffe) { // Expected } // svc1 went standby then back to active verify(svc1.proxy).transitionToStandby(anyReqInfo()); verify(svc1.proxy).transitionToActive(anyReqInfo()); assertEquals(HAServiceState.ACTIVE, svc1.state); assertEquals(HAServiceState.STANDBY, svc2.state); }
@Test public void testFailureToFenceOnFailbackFailsTheFailback() throws Exception { DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new IOException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysFailFencer.class.getName()); AlwaysFailFencer.fenceCalled = 0; try { doFailover(svc1, svc2, false, false); fail("Failed over to service that won't transition to active"); } catch (FailoverFailedException ffe) { // Expected } // We did not fence svc1 because it cooperated and we didn't force it, // we failed to failover so we fenced svc2, we failed to fence svc2 // so we did not failback to svc1, ie it's still standby. assertEquals(HAServiceState.STANDBY, svc1.state); assertEquals(1, AlwaysFailFencer.fenceCalled); assertSame(svc2, AlwaysFailFencer.fencedSvc); }
@Test public void testWeDontFailbackIfActiveWasFenced() throws Exception { DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); try { doFailover(svc1, svc2, true, false); fail("Failed over to service that won't transition to active"); } catch (FailoverFailedException ffe) { // Expected } // We failed to failover and did not failback because we fenced // svc1 (we forced it), therefore svc1 and svc2 should be standby. assertEquals(HAServiceState.STANDBY, svc1.state); assertEquals(HAServiceState.STANDBY, svc2.state); }
@Test public void testWeDontFailbackIfActiveWasFenced() throws Exception { DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); try { doFailover(svc1, svc2, true, false); fail("Failed over to service that won't transition to active"); } catch (FailoverFailedException ffe) { // Expected } // We failed to failover and did not failback because we fenced // svc1 (we forced it), therefore svc1 and svc2 should be standby. assertEquals(HAServiceState.STANDBY, svc1.state); assertEquals(HAServiceState.STANDBY, svc2.state); }
@Test public void testWeFenceOnFailbackIfTransitionToActiveFails() throws Exception { DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); AlwaysSucceedFencer.fenceCalled = 0; try { doFailover(svc1, svc2, false, false); fail("Failed over to service that won't transition to active"); } catch (FailoverFailedException ffe) { // Expected } // We failed to failover. We did not fence svc1 because it cooperated // and we didn't force it, so we failed back to svc1 and fenced svc2. // Note svc2 still thinks it's active, that's OK, we fenced it. assertEquals(HAServiceState.ACTIVE, svc1.state); assertEquals(1, AlwaysSucceedFencer.fenceCalled); assertSame(svc2, AlwaysSucceedFencer.fencedSvc); }
@Test public void testWeFenceOnFailbackIfTransitionToActiveFails() throws Exception { DummyHAService svc1 = new DummyHAService(HAServiceState.ACTIVE, svc1Addr); DummyHAService svc2 = new DummyHAService(HAServiceState.STANDBY, svc2Addr); Mockito.doThrow(new ServiceFailedException("Failed!")) .when(svc2.proxy).transitionToActive(anyReqInfo()); svc1.fencer = svc2.fencer = setupFencer(AlwaysSucceedFencer.class.getName()); AlwaysSucceedFencer.fenceCalled = 0; try { doFailover(svc1, svc2, false, false); fail("Failed over to service that won't transition to active"); } catch (FailoverFailedException ffe) { // Expected } // We failed to failover. We did not fence svc1 because it cooperated // and we didn't force it, so we failed back to svc1 and fenced svc2. // Note svc2 still thinks it's active, that's OK, we fenced it. assertEquals(HAServiceState.ACTIVE, svc1.state); assertEquals(1, AlwaysSucceedFencer.fenceCalled); assertSame(svc2, AlwaysSucceedFencer.fencedSvc); }