SuspendModeTransitioner implements QpidStatusListener, ActiveMQStatusListener { @Override public void onStatusUpdate(QpidStatus oldStatus, QpidStatus newStatus) { if (oldStatus.equals(newStatus)) { return; } switch (newStatus) { case CONNECTED: this.modeManager.resolveSuspendReasonClass(REASON_CLASS_QPID); break; case DOWN: this.modeManager.suspendOperations(REASON_CLASS_QPID, newStatus.toString()); this.resolveReasons(REASON_CLASS_QPID, QpidStatus.FLOW_STOPPED, QpidStatus.MISSING_EXCHANGE, QpidStatus.MISSING_BINDING); break; case FLOW_STOPPED: case MISSING_EXCHANGE: case MISSING_BINDING: this.modeManager.suspendOperations(REASON_CLASS_QPID, newStatus.toString()); this.resolveReasons(REASON_CLASS_QPID, QpidStatus.DOWN); break; default: String msg = String.format("Unknown or unexpected Qpid status received: %s", newStatus); throw new IllegalStateException(msg); } } @Inject  SuspendModeTransitioner(CandlepinModeManager modeManager); @Override void onStatusUpdate(QpidStatus oldStatus, QpidStatus newStatus); @Override void onStatusUpdate(ActiveMQStatus oldStatus, ActiveMQStatus newStatus);  }
@Test public void unchangedStatusUpdateDoesNotTransitionAtAll() { assertMode(Mode.NORMAL); transitioner.onStatusUpdate(QpidStatus.CONNECTED, QpidStatus.CONNECTED); assertMode(Mode.NORMAL); transitioner.onStatusUpdate(ActiveMQStatus.CONNECTED, ActiveMQStatus.CONNECTED); assertMode(Mode.NORMAL); }
@Test public void transitionFromNormalModeToQpidDown() { transitioner.onStatusUpdate(QpidStatus.CONNECTED, QpidStatus.DOWN); assertMode(Mode.SUSPEND, QpidStatus.DOWN); }
@Test public void transitionFromNormalModeToAMQDown() { transitioner.onStatusUpdate(ActiveMQStatus.CONNECTED, ActiveMQStatus.DOWN); assertMode(Mode.SUSPEND, ActiveMQStatus.DOWN); }
@Test public void transitionFromNormalModeToQpidAndAMQDown() throws Exception { transitionFromNormalModeToQpidDown(); transitioner.onStatusUpdate(ActiveMQStatus.CONNECTED, ActiveMQStatus.DOWN); assertMode(Mode.SUSPEND, ActiveMQStatus.DOWN, QpidStatus.DOWN); }
@Test public void transitionToNormalModeWhenQpidComesUp() throws Exception { this.suspendOperations(QpidStatus.DOWN); transitioner.onStatusUpdate(QpidStatus.DOWN, QpidStatus.CONNECTED); assertMode(Mode.NORMAL); }
@Test public void transitionToNormalModeWhenAMQComesUp() throws Exception { this.suspendOperations(ActiveMQStatus.DOWN); transitioner.onStatusUpdate(ActiveMQStatus.DOWN, ActiveMQStatus.CONNECTED); assertMode(Mode.NORMAL); }
@Test public void transitionToNormalModeWhenQpidThenAMQComesUp() throws Exception { this.suspendOperations(ActiveMQStatus.DOWN, QpidStatus.DOWN); transitioner.onStatusUpdate(QpidStatus.DOWN, QpidStatus.CONNECTED); assertMode(Mode.SUSPEND, ActiveMQStatus.DOWN); transitioner.onStatusUpdate(ActiveMQStatus.DOWN, ActiveMQStatus.CONNECTED); assertMode(Mode.NORMAL); }
@Test public void transitionToNormalModeWhenAMQThenQpidComesUp() throws Exception { this.suspendOperations(ActiveMQStatus.DOWN, QpidStatus.DOWN); transitioner.onStatusUpdate(ActiveMQStatus.DOWN, ActiveMQStatus.CONNECTED); assertMode(Mode.SUSPEND, QpidStatus.DOWN); transitioner.onStatusUpdate(QpidStatus.DOWN, QpidStatus.CONNECTED); assertMode(Mode.NORMAL); }
@Test public void transitionToSuspendModeWhenQpidBecomesFlowStopped() throws Exception { transitioner.onStatusUpdate(QpidStatus.CONNECTED, QpidStatus.FLOW_STOPPED); assertMode(Mode.SUSPEND, QpidStatus.FLOW_STOPPED); }
@Test public void remainInSuspendModeWhenQpidComesUpButIsInFlowStopped() { this.suspendOperations(QpidStatus.DOWN); transitioner.onStatusUpdate(QpidStatus.DOWN, QpidStatus.FLOW_STOPPED); assertMode(Mode.SUSPEND, QpidStatus.FLOW_STOPPED); }
@Test public void remainInSuspendModeWhenQpidIsFlowStoppedAndThenGoesDown() { this.suspendOperations(QpidStatus.FLOW_STOPPED); transitioner.onStatusUpdate(QpidStatus.FLOW_STOPPED, QpidStatus.DOWN); assertMode(Mode.SUSPEND, QpidStatus.DOWN); }
@Test public void transitionToSuspendModeWhenAMQGoesDown() throws Exception { transitioner.onStatusUpdate(ActiveMQStatus.CONNECTED, ActiveMQStatus.DOWN); assertMode(Mode.SUSPEND, ActiveMQStatus.DOWN); }
@Test public void transitionToNormalModeWhenAMQComesBackUp() throws Exception { this.suspendOperations(ActiveMQStatus.DOWN); transitioner.onStatusUpdate(ActiveMQStatus.DOWN, ActiveMQStatus.CONNECTED); assertMode(Mode.NORMAL); }
@Test public void remainInSuspendModeWhenAMQComesUpWhileQpidRemainsDown() throws Exception { this.suspendOperations(QpidStatus.DOWN, ActiveMQStatus.DOWN); transitioner.onStatusUpdate(ActiveMQStatus.DOWN, ActiveMQStatus.CONNECTED); assertMode(Mode.SUSPEND, QpidStatus.DOWN); }
@Test public void remainInSuspendModeWhenQpidComesUpWhileAMQRemainsDown() throws Exception { this.suspendOperations(QpidStatus.DOWN, ActiveMQStatus.DOWN); transitioner.onStatusUpdate(QpidStatus.DOWN, QpidStatus.CONNECTED); assertMode(Mode.SUSPEND, ActiveMQStatus.DOWN); }
@Test public void remainInSuspendModeWhenQpidIsFlowStoppedAndAMQComesUp() throws Exception { this.suspendOperations(QpidStatus.FLOW_STOPPED, ActiveMQStatus.DOWN); transitioner.onStatusUpdate(ActiveMQStatus.DOWN, ActiveMQStatus.CONNECTED); assertMode(Mode.SUSPEND, QpidStatus.FLOW_STOPPED); }
@Test public void transitionFromConnectedToMissingExchange() throws Exception { transitioner.onStatusUpdate(QpidStatus.CONNECTED, QpidStatus.MISSING_EXCHANGE); assertMode(Mode.SUSPEND, QpidStatus.MISSING_EXCHANGE); }
@Test public void transitionFromConnectedToMissingBinding() { transitioner.onStatusUpdate(QpidStatus.CONNECTED, QpidStatus.MISSING_BINDING); assertMode(Mode.SUSPEND, QpidStatus.MISSING_BINDING); }
@Test public void transitionFromAMQDownToMissingBinding() { this.suspendOperations(ActiveMQStatus.DOWN); transitioner.onStatusUpdate(QpidStatus.CONNECTED, QpidStatus.MISSING_BINDING); assertMode(Mode.SUSPEND, ActiveMQStatus.DOWN, QpidStatus.MISSING_BINDING); }
@Test public void transitionFromAMQDownToMissingExchange() { this.suspendOperations(ActiveMQStatus.DOWN); transitioner.onStatusUpdate(QpidStatus.CONNECTED, QpidStatus.MISSING_EXCHANGE); assertMode(Mode.SUSPEND, QpidStatus.MISSING_EXCHANGE, ActiveMQStatus.DOWN); }