use of org.opennms.web.rest.v1.AvailCalculator in project opennms by OpenNMS.
the class RemotePollerAvailabilityRestServiceIT method testGetAvailability.
@Test
public void testGetAvailability() {
final long endMillis = System.currentTimeMillis();
final long startMillis = endMillis - 12000;
final long totalTime = endMillis - startMillis;
m_transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
final TimeChunker timeChunker = new TimeChunker(totalTime, new Date(startMillis), new Date(endMillis));
// increment the time segment
timeChunker.getNextSegment();
final Collection<OnmsLocationSpecificStatus> allStatusChanges = m_locationMonitorDao.getStatusChangesForApplicationBetween(new Date(startMillis), new Date(endMillis), "IPv6");
final AvailCalculator calc = new AvailCalculator(timeChunker);
for (final OnmsLocationSpecificStatus statusChange : allStatusChanges) {
calc.onStatusChange(statusChange);
}
final Collection<OnmsMonitoredService> svcs = m_monServiceDao.findByApplication(m_applicationDao.findByName("IPv6"));
final double avail = calc.getAvailabilityFor(svcs, 0);
assertEquals(0.8333, avail, 0.0333);
}
});
}
Aggregations