예제 #1
0
  /** Test if a record is registered when the controller is temporarily down. */
  @Test
  public void testControllerDownRegistration() {
    System.out.println("testControllerDownRegistration");
    List<String> hosts = new ArrayList();
    hosts.add("uva.nl");

    instance.doInBackground(hosts);
    sleepMillis(120);
    instance.stopTemporarily();
    sleepMillis(1_500);
    assertFalse(instance.isBusyCheckingConnections());
    instance.restart(hosts);
    sleepMillis(1_500);
    assertTrue(
        "The controller is NOT checking connections now", instance.isBusyCheckingConnections());
    OutageListItem lastOutage = instance.getLastOutage();
    assertTrue("No outages were registered", null != lastOutage);
    assertTrue(
        "The actual last outage is " + lastOutage, lastOutage.getOutageCause() == CONTROLLERDOWN);
    instance.exit();
    sleepMillis(1_500);
    if (instance.getSessionData().saveData()) {
      LOGGER.info("Session data is saved at exiting the application.");
    } else {
      LOGGER.error("Session data is NOT saved at exiting the application.");
    }

    LOGGER.info("Load data");
    instance.initWithPreviousSessionData();
    assertTrue(
        "The actual last outage is " + lastOutage, lastOutage.getOutageCause() == CONTROLLERDOWN);
  }
예제 #2
0
 @Before
 public void setUp() {
   System.out.println("setUp");
   instance = new ISPController();
   LOGGER.info("New Controller instance instantiated.");
   setSessionsDataFileNameForTest();
   // copy a test file to the test directory (will be overwritten)
   File resourcesDirectory = new File("src/test/resources");
   File source = new File(resourcesDirectory, "MonitorISPData.bin");
   Path sourcePath = source.toPath();
   // copy the test file to the test directory with the same name as the source
   try {
     Files.copy(sourcePath, getTestHomeDir().resolve(source.getName()), REPLACE_EXISTING);
     LOGGER.info("Fresh test session data copied");
   } catch (IOException ex) {
     LOGGER.error("File copy failed with exception {}", ex);
   }
   // Must load the session data explicit as Homepage is not doing it.
   if (instance.initWithPreviousSessionData()) {
     LOGGER.info("Preset previous session test data are used for initialization.");
   } else {
     LOGGER.info("Preset previous session test data could not be read, defaults are set");
   }
 }