MonitoringRunnable implements Runnable { @Override public void run() { this.logger.fine( "Monitoring Task is being invoked." ); if( this.agentInterface.getScopedInstance() == null) { this.logger.fine( "The agent's model has not yet been initialized. Monitoring cannot work yet." ); return; } if( ! this.handlersWereInitialized ) { for( IMonitoringHandler handler : this.handlers ) { String scopedInstancePath = InstanceHelpers.computeInstancePath( this.agentInterface.getScopedInstance()); handler.setAgentId( this.agentInterface.getApplicationName(), scopedInstancePath ); } this.handlersWereInitialized = true; } for( Instance inst : InstanceHelpers.buildHierarchicalList( this.agentInterface.getScopedInstance())) { if( inst.getStatus() != InstanceStatus.DEPLOYED_STARTED ) continue; File dir = InstanceHelpers.findInstanceDirectoryOnAgent( inst ); File measureFile = new File( dir, inst.getComponent().getName() + Constants.FILE_EXT_MEASURES ); if( ! measureFile.exists()) continue; this.logger.fine( "A file with measure rules was found for instance '" + inst + "'." ); String fileContent; try { fileContent = Utils.readFileContent( measureFile ); } catch( IOException e ) { this.logger.warning( "A problem occurred while reading the content for measure rules of instance '"+ inst + "'." ); Utils.logException( this.logger, e ); continue; } File paramFile; Properties params; try { paramFile = new File( dir, inst.getComponent().getName() + Constants.FILE_EXT_MEASURES + ".properties" ); params = Utils.readPropertiesFile( paramFile ); this.logger.fine( "A file with measure parameters (properties) was found for instance '" + inst + "'." ); } catch( IOException e1 ) { params = null; } for( MonitoringHandlerRun bean : extractRuleSections( measureFile, fileContent, params )) { try { IMonitoringHandler handler = findHandlerByName( bean.handlerName ); if( handler == null ) { this.logger.warning( "No handler was found with the ID '" + bean.handlerName + "'. The rule is skipped." ); continue; } handler.reset( inst, bean.eventId, bean.rawRulesText ); Message msg = handler.process(); if( msg != null ) this.agentInterface.getMessagingClient().sendMessageToTheDm( msg ); } catch( IOException e ) { this.logger.warning( "A problem occurred while the agent monitoring was sending a message to the DM. " + e.getMessage()); Utils.logException( this.logger, e ); } } } } MonitoringRunnable( AgentMessagingInterface agentInterface, List<IMonitoringHandler> handlers ); @Override void run();  }
@Test public void testWholeChain_noModelYet() throws Exception { Mockito.verify( this.messagingClient, Mockito.times( 0 )).sendMessageToTheDm( Mockito.any( Message.class )); MonitoringRunnable task = new MonitoringRunnable( this.agentInterface, HANDLERS ); task.run(); Mockito.verify( this.messagingClient, Mockito.times( 0 )).sendMessageToTheDm( Mockito.any( Message.class )); }