Availability avail;
List<Availability> avails;
long now = System.currentTimeMillis();
AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());
avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 1, now);
assert avails.size() == 1 : "Should only be initial unknown avail data";
assert avails.get(0).getAvailabilityType() == UNKNOWN;
assert avails.get(0).getStartTime().equals(1L);
assert avails.get(0).getEndTime().equals(now);
Long startMillis = 60000L;
avail = new Availability(theResource, startMillis, UP);
report.addAvailability(avail);
availabilityManager.mergeAvailabilityReport(report);
// platform: UNKNOWN(0) --> UP(60000) -->
avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 30000L,
startMillis + 10000);
assertEquals("Range should cover both avails", 2, avails.size());
assert avails.get(0).getAvailabilityType() == UNKNOWN;
assert avails.get(0).getStartTime().equals(30000L);
assert avails.get(0).getEndTime().equals(60000L);
assert avails.get(1).getAvailabilityType() == UP;
assert avails.get(1).getStartTime().equals(60000L);
assert avails.get(1).getEndTime().equals(startMillis + 10000);
avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), startMillis,
startMillis + 10000);
assertEquals("Range start on avail start border and extending to future", 1, avails.size());
assert avails.get(0).getAvailabilityType() == UP;
assert avails.get(0).getStartTime().equals(startMillis);
assert avails.get(0).getEndTime().equals(startMillis + 10000);
avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), 1000L,
startMillis - 10000);
assertEquals("Range completely in first avail", 1, avails.size());
assert avails.get(0).getAvailabilityType() == UNKNOWN;
assert avails.get(0).getStartTime().equals(1000L);
assert avails.get(0).getEndTime().equals(startMillis - 10000);
avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), startMillis + 5000,
startMillis + 10000);
assertEquals("Range completely in last avail", 1, avails.size());
assert avails.get(0).getAvailabilityType() == UP;
assert avails.get(0).getStartTime().equals(startMillis + 5000);
assert avails.get(0).getEndTime().equals(startMillis + 10000);
report = new AvailabilityReport(false, theAgent.getName()); // 70000
report.setEnablementReport(true); // simulate a real disable
report.addAvailability(new Availability(theResource, (startMillis + 10000L), DISABLED));
availabilityManager.mergeAvailabilityReport(report);
// UNKNOWN(0) --> UP(60000) --> DISABLED(70000) -->
// before setting other avails, must end disable with enablement report to unknown
report = new AvailabilityReport(false, theAgent.getName()); // 75000
report.setEnablementReport(true);
report.addAvailability(new Availability(theResource, (startMillis + 15000L), UNKNOWN));
availabilityManager.mergeAvailabilityReport(report);
// UNKNOWN(0) --> UP(60000) --> DISABLED(70000) --> UNKNOWN(75000) -->
report = new AvailabilityReport(false, theAgent.getName()); // 80000
report.addAvailability(new Availability(theResource, (startMillis + 20000L), UP));
availabilityManager.mergeAvailabilityReport(report);
// UNKNOWN(0) --> UP(60000) --> DISABLED(70000) --> UNKNOWN(75000) --> UP(80000)
report = new AvailabilityReport(false, theAgent.getName()); // 90000
report.addAvailability(new Availability(theResource, (startMillis + 30000L), DOWN));
availabilityManager.mergeAvailabilityReport(report);
// UNKNOWN(0) --> UP(60000) --> DISABLED(70000) --> UNKNOWN(75000) --> UP(80000) --> DOWN(90000) -->
avails = availabilityManager.getAvailabilitiesForResource(overlord, theResource.getId(), startMillis - 15000,
startMillis + 35000);