report.addAvailability(avail);
Thread.sleep(1000);
availabilityManager.mergeAvailabilityReport(report);
// the agent should have been updated, but no new rows in availability were added
Agent agent = LookupUtil.getAgentManager().getAgentByName(theAgent.getName());
Date lastReport = new Date(agent.getLastAvailabilityReport());
assert lastReport != null;
assert countAvailabilitiesInDB().equals(allAvailCount);
avail = availabilityManager.getCurrentAvailabilityForResource(overlord, theResource.getId());
// should have returned availability3
// NOTE: availability3 never got an ID assigned, so we can't compare by id
// assert avail.getId() == availability3.getId();
assert avail.getStartTime().equals(availability3.getStartTime());
assert avail.getAvailabilityType() == availability3.getAvailabilityType();
assert Math.abs(avail.getStartTime() - availability3.getStartTime()) < 1000;
assert avail.getEndTime() == null;
assert availability3.getEndTime() == null;
// change start after the start of last (result: add new avail row)
avail = new Availability(theResource, (currentStartTime + 7200000), DOWN);
report = new AvailabilityReport(false, theAgent.getName());
report.addAvailability(avail);
Thread.sleep(1000);
availabilityManager.mergeAvailabilityReport(report);
// the agent should have been updated and a new row in availability was added (resource is now DOWN)
agent = LookupUtil.getAgentManager().getAgentByName(theAgent.getName());
assert new Date(agent.getLastAvailabilityReport()).after(lastReport);
assert countAvailabilitiesInDB().equals(allAvailCount + 1);
assert availabilityManager.getCurrentAvailabilityTypeForResource(overlord, theResource.getId()) == DOWN;
Availability queriedAvail = availabilityManager.getCurrentAvailabilityForResource(overlord,
theResource.getId());
assert queriedAvail.getId() > 0;