RoboconfConsumer extends DefaultConsumer implements Consumer { @Override public void handleShutdownSignal( String consumerTag, ShutdownSignalException sig ) { if( sig.isInitiatedByApplication()) { this.logger.fine( this.sourceName + ": the connection to the messaging server was shut down." + id( consumerTag )); } else if( sig.getReference() instanceof Channel ) { int nb = ((Channel) sig.getReference()).getChannelNumber(); this.logger.fine( "A RabbitMQ consumer was shut down. Channel #" + nb + ", " + id( consumerTag )); } else { this.logger.fine( "A RabbitMQ consumer was shut down." + id( consumerTag )); } } RoboconfConsumer( String sourceName, Channel channel, RoboconfMessageQueue messageQueue ); @Override void handleDelivery( String consumerTag, Envelope envelope, BasicProperties properties, byte[] body ); @Override void handleShutdownSignal( String consumerTag, ShutdownSignalException sig ); @Override void handleCancelOk( String consumerTag ); @Override void handleCancel( String consumerTag );  }
@Test public void testShutdownSignal() throws Exception { RoboconfMessageQueue messageQueue = new RoboconfMessageQueue(); Channel channel = Mockito.mock( Channel.class ); RoboconfConsumer rc = new RoboconfConsumer( "DM", channel, messageQueue ); final StringHandler logHandler = new StringHandler(); Logger logger = TestUtils.getInternalField( rc, "logger", Logger.class ); logger.setUseParentHandlers( false ); logger.setLevel( Level.FINE ); logger.addHandler( logHandler ); ShutdownSignalException sig = Mockito.mock( ShutdownSignalException.class ); Mockito.when( sig.isInitiatedByApplication()).thenReturn( true ); rc.handleShutdownSignal( "tag", sig ); String log1 = logHandler.getLogs(); Mockito.reset( sig ); Mockito.when( sig.isInitiatedByApplication()).thenReturn( false ); Mockito.when( sig.getReference()).thenReturn( channel ); logHandler.getStringBuilder().setLength( 0 ); rc.handleShutdownSignal( "tag", sig ); String log2 = logHandler.getLogs(); Mockito.reset( sig ); Mockito.when( sig.isInitiatedByApplication()).thenReturn( false ); logHandler.getStringBuilder().setLength( 0 ); rc.handleShutdownSignal( "tag", sig ); String log3 = logHandler.getLogs(); Assert.assertFalse( Utils.isEmptyOrWhitespaces( log1 )); Assert.assertFalse( Utils.isEmptyOrWhitespaces( log2 )); Assert.assertFalse( Utils.isEmptyOrWhitespaces( log3 )); Assert.assertFalse( log1.equals( log2 )); Assert.assertFalse( log1.equals( log3 )); Assert.assertFalse( log3.equals( log2 )); }