MessagingMngrImpl implements IMessagingMngr { @Override public void sendStoredMessages( ManagedApplication ma, Instance instance ) { if( messagingIsReady()) { Instance scopedInstance = InstanceHelpers.findScopedInstance( instance ); if( scopedInstance.getStatus() == InstanceStatus.DEPLOYED_STARTED ) { List<Message> messages = ma.removeAwaitingMessages( instance ); if( messages.isEmpty()) return; String path = InstanceHelpers.computeInstancePath( scopedInstance ); this.logger.fine( "Forcing the sending of " + messages.size() + " awaiting message(s) for " + path + "." ); for( Message msg : messages ) { try { sendMessageDirectly( ma, scopedInstance, msg ); } catch( IOException e ) { ma.storeAwaitingMessage( scopedInstance, msg ); this.logger.severe( "Error while sending a stored message. A retry is planned. " + e.getMessage()); Utils.logException( this.logger, e ); } } } } }  void setMessagingClient( RCDm messagingClient ); @Override void sendMessageSafely( ManagedApplication ma, Instance instance, Message message ); @Override void sendMessageDirectly( ManagedApplication ma, Instance scopedInstance, Message message ); @Override void sendStoredMessages( ManagedApplication ma, Instance instance ); @Override void sendMessageToTheDm( Message message ); @Override IDmClient getMessagingClient(); @Override void checkMessagingConfiguration();  }
@Test public void testSendStoredMessages_NoMessageToSend() throws Exception { TestApplication app = new TestApplication(); ManagedApplication ma = new ManagedApplication( app ); app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); Mockito.when( this.msgClient.isConnected()).thenReturn( true ); Mockito.verifyZeroInteractions( this.msgClient ); this.mngr.sendStoredMessages( ma, app.getMySqlVm()); Mockito.verify( this.msgClient, Mockito.times( 1 )).isConnected(); Mockito.verify( this.msgClient, Mockito.times( 0 )).sendMessageToAgent( Mockito.any( Application.class ), Mockito.any( Instance.class ), Mockito.any( Message.class )); }