@Test(groups = "pc.itest.avail", priority = 21)
public void testCheckOnlyEligible() throws Exception {
Assert.assertTrue(pluginContainer.isStarted());
Assert.assertTrue(pluginContainer.isRunning());
// Force all the avails to UP to start so we can avoid the scenario in testForceChildrenOfParentUp()
AvailabilityExecutor executor = new ForceAvailabilityExecutor(this.pluginContainer.getInventoryManager());
AvailabilityReport report = executor.call();
Assert.assertNotNull(report);
Assert.assertEquals(report.isChangesOnlyReport(), false, "First report should have been a full report");
List<Datum> availData = report.getResourceAvailability();
for (Datum datum : availData) {
assert datum.getResourceId() != 0 : "resource IDs should be != zero since it should be committed";
Assert.assertEquals(datum.getAvailabilityType(), AvailabilityType.UP, "should be UP at the start");
}
AvailabilityExecutor.Scan scan = executor.getMostRecentScanHistory();
assertScan(scan, true, true, 29, 28, 29, 28, 0, 0);
// don't use a ForceAvailabilityExecutor for this scan, we want to manipulate what gets checked.
// by default new executors always do a full scan to start, we don't want that
executor = new AvailabilityExecutor(this.pluginContainer.getInventoryManager());
executor.sendChangesOnlyReportNextTime();
// Manipulate the scheduled times such that the "1" resources should be checked and the "2"s should not
List<Set<ResourceContainer>> containerSets = new ArrayList<Set<ResourceContainer>>();
containerSets.add(parentContainers1);
containerSets.add(childContainers1);
containerSets.add(grandchildContainers1);
long now = System.currentTimeMillis();
for (Set<ResourceContainer> cs : containerSets) {
for (ResourceContainer c : cs) {
c.setAvailabilityScheduleTime(now);
}
}
containerSets.clear();
containerSets.add(parentContainers2);
containerSets.add(childContainers2);
containerSets.add(grandchildContainers2);
long later = now + 10000000L;
for (Set<ResourceContainer> cs : containerSets) {
for (ResourceContainer c : cs) {
c.setAvailabilityScheduleTime(later);
}
}
// a changes-only report, check half the resources, no changes - should all be UP already. push out scheds for each
report = executor.call();
Assert.assertNotNull(report);
Assert.assertEquals(report.isChangesOnlyReport(), true, "Second report should have been changes-only");
Assert.assertEquals(report.getResourceAvailability().size(), 0, "no changes, everything was already up");
availData = report.getResourceAvailability();
for (Datum datum : availData) {
assert datum.getResourceId() != 0 : "resource IDs should be != zero since it should be committed";
Assert.assertEquals(datum.getAvailabilityType(), AvailabilityType.UP, "should be UP at the start");
}
scan = executor.getMostRecentScanHistory();
assertScan(scan, false, false, 29, 0, 15, 0, 14, 0);
// another quick scan should see no calls, check times should be pushed out at least a minute
report = executor.call();
Assert.assertNotNull(report);
Assert.assertEquals(report.isChangesOnlyReport(), true, "Third report should have been changes-only");
Assert.assertEquals(report.getResourceAvailability().isEmpty(), true, "Nothing changed, should be empty");
scan = executor.getMostRecentScanHistory();
assertScan(scan, false, false, 29, 0, 1, 0, 0, 0);
}