public void testGetAvailabilities() throws Exception {
beginTx();
try {
List<AvailabilityPoint> availPoints;
Availability avail;
setupResource();
// platform: UNKNOWN(0) -->
commitAndClose();
AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());
availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(), 1,
System.currentTimeMillis(), 3, false);
assert availPoints.size() == 3 : "There is no avail data, but should still get 3 availability points";
assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
assert availPoints.get(1).getAvailabilityType() == UNKNOWN;
assert availPoints.get(2).getAvailabilityType() == UNKNOWN;
Long startMillis = 60000L;
avail = new Availability(theResource, startMillis, UP);
report.addAvailability(avail);
availabilityManager.mergeAvailabilityReport(report);
// platform: UNKNOWN(0) --> UP(60000) -->
// our avail data point is right on the start edge
availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(), startMillis,
startMillis + 10000, 3, false);
assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
assert availPoints.get(0).getAvailabilityType() == UP;
assert availPoints.get(1).getAvailabilityType() == UP;
assert availPoints.get(2).getAvailabilityType() == UP;
// our avail data point is right on the end edge
availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
startMillis - 3, startMillis, 3, false);
assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
assert !availPoints.get(0).isKnown() : availPoints;
assert availPoints.get(1).getAvailabilityType() == UNKNOWN;
assert !availPoints.get(1).isKnown() : availPoints;
assert availPoints.get(2).getAvailabilityType() == UNKNOWN;
assert !availPoints.get(2).isKnown() : availPoints;
availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
startMillis - 20000, startMillis + 10000, 3, false);
assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
assert !availPoints.get(0).isKnown() : availPoints;
assert availPoints.get(1).getAvailabilityType() == UNKNOWN;
assert !availPoints.get(1).isKnown() : availPoints;
assert availPoints.get(2).getAvailabilityType() == UP : availPoints;
availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
startMillis - 10000, startMillis + 20000, 3, false);
assert availPoints.size() == 3 : "There is 1 avail data, but should still get 3 availability points";
assert availPoints.get(0).getAvailabilityType() == UNKNOWN;
assert !availPoints.get(0).isKnown() : availPoints;
assert availPoints.get(1).getAvailabilityType() == UP;
assert availPoints.get(1).isKnown() : availPoints;
assert availPoints.get(2).getAvailabilityType() == UP;
availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
startMillis - 20000, startMillis + 20000, 10, false);
assert availPoints.size() == 10 : "There is 1 avail data, but should still get 10 availability points";
assert availPoints.get(0).getAvailabilityType() == UNKNOWN : availPoints;
assert !availPoints.get(0).isKnown() : availPoints;
assert availPoints.get(1).getAvailabilityType() == UNKNOWN : availPoints;
assert !availPoints.get(1).isKnown() : availPoints;
assert availPoints.get(2).getAvailabilityType() == UNKNOWN : availPoints;
assert !availPoints.get(2).isKnown() : availPoints;
assert availPoints.get(3).getAvailabilityType() == UNKNOWN : availPoints;
assert !availPoints.get(3).isKnown() : availPoints;
assert availPoints.get(4).getAvailabilityType() == UNKNOWN : availPoints;
assert !availPoints.get(4).isKnown() : availPoints;
assert availPoints.get(5).getAvailabilityType() == UP : availPoints;
assert availPoints.get(5).isKnown() : availPoints;
assert availPoints.get(6).getAvailabilityType() == UP : availPoints;
assert availPoints.get(7).getAvailabilityType() == UP : availPoints;
assert availPoints.get(8).getAvailabilityType() == UP : availPoints;
assert availPoints.get(9).getAvailabilityType() == UP : availPoints;
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) -->
availPoints = availabilityManager.findAvailabilitiesForResource(overlord, theResource.getId(),
startMillis - 15000, startMillis + 35000, 5, false); // 45000 - 95000