Monitors

Monitors are processes (threads) that can be defined per test. The monitor will run during the test execution in deferent thread. The monitor can fail the test if it find a problem with the monitored object.

01 package com.aqua.examples;
02 
03 import jsystem.framework.monitor.Monitor;
04 import jsystem.utils.MiscUtils;
05 
06 public class PingMonitor extends Monitor {
07   String host;
08   public PingMonitor(String host) {
09     super("PingMonitor_" + host);
10     this.host = host;
11   }
12 
13   public void run() {
14     while(true){
15       if(!MiscUtils.isPing(host)){
16         report.report("Fail to ping to host: " + host, false);
17         setFail(true);
18       }
19       try {
20         Thread.sleep(5000);
21       catch (InterruptedException ex){
22         return;
23       }
24     }
25   }
26 }

The monitor is activating during the test. To activate a monitor you should use the 'monitors' service.

   monitors.startMonitor(new PingMonitor(linux.getHost()));

What can you learn from the Monitor example?

  1. Monitor should extends the Monitor class (line 06).
  2. As it implement the Java Runnable the Monitor should implement a run method (line 13).
  3. Monitor can use JSystem services like 'report' and 'system' (line 16).
  4. Monitor can fail the test by submitting a fail report (line 16).
  5. On interrupt the monitor should exit (line 22).