@Test public void testSendPingAgent_normal_rootsAreDeployed() throws Exception { TestApplication app = new TestApplication(); ManagedApplication ma = new ManagedApplication( app ); Mockito.verifyZeroInteractions( this.messagingMngr ); app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); app.getTomcatVm().setStatus( InstanceStatus.PROBLEM ); for( Instance i : app.getRootInstances()) Assert.assertEquals( 0, this.mngr.pingAgent( ma, i, "TEST " + i.getName())); int inv = app.getRootInstances().size(); ArgumentCaptor<Message> argMsg = ArgumentCaptor.forClass( Message.class ); ArgumentCaptor<ManagedApplication> argApp = ArgumentCaptor.forClass( ManagedApplication.class ); Mockito.verify( this.messagingMngr, Mockito.times( inv )).sendMessageDirectly( argApp.capture(), Mockito.any( Instance.class ), argMsg.capture()); List<Message> sentMessages = argMsg.getAllValues(); Assert.assertEquals( app.getRootInstances().size(), sentMessages.size()); int index = 0; for( Instance i : app.getRootInstances()) { Message message = sentMessages.get( index++ ); Assert.assertTrue( message instanceof MsgEcho ); MsgEcho echo = (MsgEcho) message; Assert.assertEquals( "PING:TEST " + i.getName(), echo.getContent()); } for( ManagedApplication t : argApp.getAllValues()) { Assert.assertEquals( ma, t ); } }
@Override public int pingAgent( ManagedApplication app, Instance scopedInstance, String message ) { int result; MsgEcho ping = new MsgEcho( "PING:" + message ); try { if( scopedInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) { this.messagingMngr.sendMessageDirectly( app, scopedInstance, ping ); this.logger.fine( "Sent PING request message=" + message + " to application=" + app + ", agent=" + scopedInstance ); result = 0; } else { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". The agent was not started." ); result = 1; } } catch( IOException e ) { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". An error occurred with the messaging." ); Utils.logException( this.logger, e ); result = 2; } return result; }
DebugMngrImpl implements IDebugMngr { @Override public int pingAgent( ManagedApplication app, Instance scopedInstance, String message ) { int result; MsgEcho ping = new MsgEcho( "PING:" + message ); try { if( scopedInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) { this.messagingMngr.sendMessageDirectly( app, scopedInstance, ping ); this.logger.fine( "Sent PING request message=" + message + " to application=" + app + ", agent=" + scopedInstance ); result = 0; } else { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". The agent was not started." ); result = 1; } } catch( IOException e ) { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". An error occurred with the messaging." ); Utils.logException( this.logger, e ); result = 2; } return result; } }
DebugMngrImpl implements IDebugMngr { @Override public int pingAgent( ManagedApplication app, Instance scopedInstance, String message ) { int result; MsgEcho ping = new MsgEcho( "PING:" + message ); try { if( scopedInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) { this.messagingMngr.sendMessageDirectly( app, scopedInstance, ping ); this.logger.fine( "Sent PING request message=" + message + " to application=" + app + ", agent=" + scopedInstance ); result = 0; } else { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". The agent was not started." ); result = 1; } } catch( IOException e ) { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". An error occurred with the messaging." ); Utils.logException( this.logger, e ); result = 2; } return result; } DebugMngrImpl( IMessagingMngr messagingMngr, INotificationMngr notificationMngr ); }
DebugMngrImpl implements IDebugMngr { @Override public int pingAgent( ManagedApplication app, Instance scopedInstance, String message ) { int result; MsgEcho ping = new MsgEcho( "PING:" + message ); try { if( scopedInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) { this.messagingMngr.sendMessageDirectly( app, scopedInstance, ping ); this.logger.fine( "Sent PING request message=" + message + " to application=" + app + ", agent=" + scopedInstance ); result = 0; } else { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". The agent was not started." ); result = 1; } } catch( IOException e ) { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". An error occurred with the messaging." ); Utils.logException( this.logger, e ); result = 2; } return result; } DebugMngrImpl( IMessagingMngr messagingMngr, INotificationMngr notificationMngr ); @Override boolean pingMessageQueue( String message ); @Override int pingAgent( ManagedApplication app, Instance scopedInstance, String message ); @Override void notifyMsgEchoReceived( MsgEcho message ); }
DebugMngrImpl implements IDebugMngr { @Override public int pingAgent( ManagedApplication app, Instance scopedInstance, String message ) { int result; MsgEcho ping = new MsgEcho( "PING:" + message ); try { if( scopedInstance.getStatus() != InstanceStatus.NOT_DEPLOYED ) { this.messagingMngr.sendMessageDirectly( app, scopedInstance, ping ); this.logger.fine( "Sent PING request message=" + message + " to application=" + app + ", agent=" + scopedInstance ); result = 0; } else { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". The agent was not started." ); result = 1; } } catch( IOException e ) { this.logger.fine( "No PING request was sent to application=" + app + ", agent=" + scopedInstance + ". An error occurred with the messaging." ); Utils.logException( this.logger, e ); result = 2; } return result; } DebugMngrImpl( IMessagingMngr messagingMngr, INotificationMngr notificationMngr ); @Override boolean pingMessageQueue( String message ); @Override int pingAgent( ManagedApplication app, Instance scopedInstance, String message ); @Override void notifyMsgEchoReceived( MsgEcho message );  }