use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class CategoryModelIT method test.
@Test
public void test() throws SQLException {
MockService service = m_network.getService(1, "192.168.1.1", "ICMP");
MockService upSmtp = m_network.getService(1, "192.168.1.1", "SMTP");
MockService upSnmp = m_network.getService(1, "192.168.1.1", "SNMP");
// Generate some events for referential integrity
Event[] events = new Event[10];
for (int i = 0; i < events.length; i++) {
events[i] = new Event();
events[i].setTime(new Date());
events[i].setCreationTime(new Date());
events[i].setUei(EventConstants.NODE_LOST_SERVICE_EVENT_UEI);
events[i].setSource(getClass().getSimpleName());
events[i].setNodeid((long) service.getNodeId());
events[i].setInterface(service.getIpAddr());
events[i].setService(service.getSvcName());
m_db.writeEvent(events[i]);
}
long startTime = 0L;
long timeframe = 60L * 60L * 24L * 1000L;
/// 24 HOUR TIMEFRAME
// There are 3 services total
assertEquals(100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(0), new Date(startTime + timeframe)), 0.0000001);
// No downtime yet
assertEquals(100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// Take down one service
assertEquals(0, m_db.countOpenOutagesForService(service));
m_db.createOutage(service, events[0].getDbid(), new Timestamp(0L));
assertEquals(1, m_db.countOpenOutagesForService(service));
/// 24 HOUR TIMEFRAME
// There are 3 services total, one totally down, the other 2 up
assertEquals(48.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(0.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
timeframe = 60L * 60L * 4L * 1000L;
/// 4 HOUR TIMEFRAME
// There are 3 services total, one totally down, the other 2 up
assertEquals(8.0 / 12.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(0.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// Bring the service back up after 2 hours
m_db.resolveOutage(service, events[1].getDbid(), new Timestamp(2L * 60L * 60L * 1000L));
assertEquals(0, m_db.countOpenOutagesForService(service));
timeframe = 60L * 60L * 24L * 1000L;
/// 24 HOUR TIMEFRAME
// There are 3 services total
assertEquals(70.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(22.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// Shift the start time forward 30 minutes so that we only see 30 minutes of downtime
startTime = 30L * 60L * 1000L;
/// 24 HOUR TIMEFRAME
// There are 3 services total
assertEquals(70.5 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(22.5 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
startTime = 0L;
timeframe = 60L * 60L * 4L * 1000L;
/// 4 HOUR TIMEFRAME
// There are 3 services total
assertEquals(10.0 / 12.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(2.0 / 4.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
startTime = 0L;
timeframe = 60L * 60L * 24L * 1000L;
// Take down the service again at the 23 hour mark
assertEquals(0, m_db.countOpenOutagesForService(service));
m_db.createOutage(service, events[2].getDbid(), new Timestamp(23L * 60L * 60L * 1000L));
assertEquals(1, m_db.countOpenOutagesForService(service));
/// 24 HOUR TIMEFRAME
// There are 3 services total, one totally down, the other 2 up
assertEquals(69.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(21.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// Shift the start time forward 60 minutes so that we only see 60 minutes of downtime
// from the first outage and 2 hours from the second outage
startTime = 60L * 60L * 1000L;
/// 24 HOUR TIMEFRAME
// There are 3 services total
assertEquals(69.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(21.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// Bring the service back up after 1.5 hours
m_db.resolveOutage(service, events[3].getDbid(), new Timestamp((24L * 60L * 60L * 1000L) + /* 24 hours */
(30L * 60L * 1000L)));
assertEquals(0, m_db.countOpenOutagesForService(service));
startTime = 0L;
timeframe = 60L * 60L * 24L * 1000L;
/// 24 HOUR TIMEFRAME
// There are 3 services total
assertEquals(69.0 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(21.0 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// Shift the start time forward 60 minutes so that we only see 60 minutes of downtime
// from the first outage and 1.5 hours from the second outage
startTime = 60L * 60L * 1000L;
/// 24 HOUR TIMEFRAME
// There are 3 services total
assertEquals(69.5 / 72.0 * 100.0, CategoryModel.getInterfaceAvailability(service.getNodeId(), service.getIpAddr(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
// One hour of downtime
assertEquals(21.5 / 24.0 * 100.0, CategoryModel.getServiceAvailability(service.getNodeId(), service.getIpAddr(), service.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSmtp.getNodeId(), upSmtp.getIpAddr(), upSmtp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
assertEquals(100.0, CategoryModel.getServiceAvailability(upSnmp.getNodeId(), upSnmp.getIpAddr(), upSnmp.getSvcId(), new Date(startTime), new Date(startTime + timeframe)), 0.0000001);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method anticipateServicesDown.
private void anticipateServicesDown(MockElement node) {
MockVisitor eventCreator = new MockVisitorAdapter() {
@Override
public void visitService(MockService svc) {
anticipateDown(svc);
}
};
node.visit(eventCreator);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method restoresServiceStateOnRestart.
@Test
public void restoresServiceStateOnRestart() {
MockNode node = m_network.getNode(2);
MockService criticalService = m_network.getService(2, "192.168.1.3", "ICMP");
// Bring the critical service down
anticipateDown(node);
criticalService.bringDown();
// Start the poller
startDaemons();
// Verify
verifyAnticipated(10000);
// Stop the poller
stopDaemons();
// Bring the critical service up and expect a nodeUp
// The service should restore the proper state and know that the outage
// was triggered by a node down
anticipateUp(node);
criticalService.bringUp();
// (Re)start the poller
startDaemons();
// Verify
verifyAnticipated(10000);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method testServiceDeleted.
// serviceDeleted: EventConstants.SERVICE_DELETED_EVENT_UEI
@Test
public void testServiceDeleted() {
MockService svc = m_network.getService(1, "192.168.1.1", "SMTP");
testElementDeleted(svc);
}
use of org.opennms.netmgt.mock.MockService in project opennms by OpenNMS.
the class PollerIT method bringDownCritSvcs.
private void bringDownCritSvcs(MockElement element) {
MockVisitor markCritSvcDown = new MockVisitorAdapter() {
@Override
public void visitService(MockService svc) {
if ("ICMP".equals(svc.getSvcName())) {
svc.bringDown();
}
}
};
element.visit(markCritSvcDown);
}
Aggregations