NvaMonitor implements AutoCloseable { public synchronized Future<Void> start() throws NvaMonitorException { Preconditions.checkState(!this.isRunning, "Already started"); MonitorConfiguration monitorConfiguration = this.configuration.getMonitors().get(0); Callable<Void> monitor = createMonitorCallable(monitorConfiguration); isRunning = true; Future<Void> task = executorService.submit( monitor ); return task; } NvaMonitor(DaemonConfiguration configuration); synchronized Future<Void> start(); synchronized void stop(); @Override synchronized void close();  }
@Test void testMonitorDoesNotImplementRequiredInterfaces() { List<MonitorConfiguration> monitors = new ArrayList<>(); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$MonitorWithoutValidInterfaces", null)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); Assertions.assertThrows(NvaMonitor.NvaMonitorException.class, () -> nvaMonitor.start()); }
@Test void testScheduledMonitorInvalidClassName() { List<MonitorConfiguration> monitors = new ArrayList<>(); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$InvalidClassName", null)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); Assertions.assertThrows(NvaMonitor.NvaMonitorException.class, () -> nvaMonitor.start()); }
@Test void testScheduledMonitorInvalidConstructor() { List<MonitorConfiguration> monitors = new ArrayList<>(); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$ScheduledMonitorInvalidConstructor", null)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); Assertions.assertThrows(NvaMonitor.NvaMonitorException.class, () -> nvaMonitor.start()); }
@Test void testMonitorExceptionConstructor() { List<MonitorConfiguration> monitors = new ArrayList<>(); Map<String, Object> settings = new HashMap<>(); settings.put("constructorShouldThrowException", "true"); settings.put("initShouldCauseInterrupt", "false"); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$MonitorValidConstructor", settings)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); Assertions.assertThrows(NvaMonitor.NvaMonitorException.class, () -> nvaMonitor.start()); }
@Test void testAbstractMonitor() { List<MonitorConfiguration> monitors = new ArrayList<>(); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$AbstractMonitor", null)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); Assertions.assertThrows(NvaMonitor.NvaMonitorException.class, () -> nvaMonitor.start()); }
@Test void testMonitorValidConstructor() throws NvaMonitor.NvaMonitorException { List<MonitorConfiguration> monitors = new ArrayList<>(); Map<String, Object> settings = new HashMap<>(); settings.put("constructorShouldThrowException", "false"); settings.put("initShouldCauseInterrupt", "false"); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$MonitorValidConstructor", settings)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); nvaMonitor.start(); }
@Test void testScheduledMonitorValidConstructor() throws NvaMonitor.NvaMonitorException, InterruptedException { List<MonitorConfiguration> monitors = new ArrayList<>(); Map<String, Object> settings = new HashMap<>(); settings.put("probeReturnValue", "true"); settings.put("awaitTime", "2000"); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$ScheduledMonitorValidConstructor", settings)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); nvaMonitor.start(); Thread.sleep(10000); }
@Test void testScheduledMonitorExecute() throws NvaMonitor.NvaMonitorException, InterruptedException { List<MonitorConfiguration> monitors = new ArrayList<>(); Map<String, Object> settings = new HashMap<>(); settings.put("probeReturnValue", "false"); settings.put("awaitTime", "2000"); monitors.add( new MonitorConfiguration( "com.microsoft.azure.practices.nvadaemon.NvaMonitorTest$ScheduledMonitorValidConstructor", settings)); DaemonConfiguration daemonConfiguration = new DaemonConfiguration(monitors, null); NvaMonitor nvaMonitor = new NvaMonitor(daemonConfiguration); nvaMonitor.start(); Thread.sleep(10000); }