use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.
the class MockDatabase method populate.
public void populate(MockNetwork network) {
MockVisitor dbCreater = new MockVisitorAdapter() {
@Override
public void visitNode(MockNode node) {
writeNode(node);
}
@Override
public void visitInterface(MockInterface iface) {
writeInterface(iface);
}
@Override
public void visitService(MockService svc) {
writeService(svc);
}
@Override
public void visitPathOutage(MockPathOutage out) {
writePathOutage(out);
}
};
network.visit(dbCreater);
getJdbcTemplate().queryForObject("SELECT setval('nodeNxtId', max(nodeid)) FROM node", Integer.class);
}
use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.
the class MockDatabaseIT method testMultipleDatabases.
public void testMultipleDatabases() throws Exception {
m_secondDb = new MockDatabase(m_db.getTestDatabase() + "_test2");
Querier secondQuerier = new Querier(m_secondDb, "select * from node");
secondQuerier.execute();
Querier querier = new Querier(m_db, "select * from node");
querier.execute();
assertFalse(secondQuerier.getCount() == querier.getCount());
MockNode node = m_network.getNode(1);
m_secondDb.writeNode(node);
secondQuerier = new Querier(m_secondDb, "select * from node");
secondQuerier.execute();
assertEquals(1, secondQuerier.getCount());
}
use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.
the class ProvisionerIT method testImportWithNodeCategoryEvents.
@Test(timeout = 300000)
// Relies on records created in @Before so we need a fresh database
@JUnitTemporaryDatabase
public void testImportWithNodeCategoryEvents() throws Exception {
final int nextNodeId = m_nodeDao.getNextNodeId();
final MockNetwork network = new MockNetwork();
final MockNode node = network.addNode(nextNodeId, "test");
network.addInterface("172.16.1.1");
network.addService("ICMP");
anticipateCreationEvents(node);
m_eventAnticipator.anticipateEvent(getNodeCategoryEvent(nextNodeId, "test"));
m_eventAnticipator.anticipateEvent(new EventBuilder(EventConstants.NODE_UPDATED_EVENT_UEI, "Test").setNodeid(nextNodeId).getEvent());
// we should not get category update events on a re-import now, that happens during the scan phase
//m_eventAnticipator.anticipateEvent(getNodeCategoryEvent(nextNodeId, "test"));
importFromResource("classpath:/requisition_with_node_categories.xml", Boolean.TRUE.toString());
importFromResource("classpath:/requisition_with_node_categories_changed.xml", Boolean.TRUE.toString());
m_eventAnticipator.verifyAnticipated();
}
use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.
the class PollerQueryManagerDaoIT method testInterfaceReparented.
// interfaceReparented: EventConstants.INTERFACE_REPARENTED_EVENT_UEI
@Test
public void testInterfaceReparented() throws Exception {
m_pollerConfig.setNodeOutageProcessingEnabled(true);
MockNode node1 = m_network.getNode(1);
MockNode node2 = m_network.getNode(2);
assertNotNull("Node 1 should have 192.168.1.1", node1.getInterface("192.168.1.1"));
assertNotNull("Node 1 should have 192.168.1.2", node1.getInterface("192.168.1.2"));
assertNull("Node 2 should not yet have 192.168.1.2", node2.getInterface("192.168.1.2"));
assertNotNull("Node 2 should have 192.168.1.3", node2.getInterface("192.168.1.3"));
MockInterface dotTwo = m_network.getInterface(1, "192.168.1.2");
MockInterface dotThree = m_network.getInterface(2, "192.168.1.3");
Event reparentEvent = MockEventUtil.createReparentEvent("Test", "192.168.1.2", 1, 2);
// we are going to reparent to node 2 so when we bring down its only
// current interface we expect an interface down not the whole node.
anticipateDown(dotThree);
startDaemons();
final int waitTime = 2000;
final int verifyTime = 2000;
sleep(waitTime);
// move the reparented interface and send a reparented event
dotTwo.moveTo(node2);
m_db.reparentInterface(dotTwo.getIpAddr(), node1.getNodeId(), node2.getNodeId());
// send the reparent event to the daemons
m_eventMgr.sendEventToListeners(reparentEvent);
sleep(waitTime);
// now bring down the other interface on the new node
// System.err.println("Bring Down:"+node2Iface);
dotThree.bringDown();
verifyAnticipated(verifyTime);
resetAnticipated();
anticipateDown(node2);
// System.err.println("Bring Down:"+reparentedIface);
dotTwo.bringDown();
sleep(waitTime);
verifyAnticipated(verifyTime);
node1 = m_network.getNode(1);
node2 = m_network.getNode(2);
assertNotNull("Node 1 should still have 192.168.1.1", node1.getInterface("192.168.1.1"));
assertNull("Node 1 should no longer have 192.168.1.2", node1.getInterface("192.168.1.2"));
assertNotNull("Node 2 should now have 192.168.1.2", node2.getInterface("192.168.1.2"));
assertNotNull("Node 2 should still have 192.168.1.3", node2.getInterface("192.168.1.3"));
}
use of org.opennms.netmgt.mock.MockNode in project opennms by OpenNMS.
the class PollerQueryManagerDaoIT method testBug1564.
@Test
@Ignore
public void testBug1564() {
// NODE processing = true;
m_pollerConfig.setNodeOutageProcessingEnabled(true);
MockNode node = m_network.getNode(2);
MockService icmpService = m_network.getService(2, "192.168.1.3", "ICMP");
MockService smtpService = m_network.getService(2, "192.168.1.3", "SMTP");
MockService snmpService = m_network.getService(2, "192.168.1.3", "SNMP");
// start the poller
startDaemons();
//
// Bring Down the HTTP service and expect nodeLostService Event
//
resetAnticipated();
anticipateDown(snmpService);
// One service works fine
snmpService.bringDown();
verifyAnticipated(10000);
// Now we simulate the restart, the node
// looses all three at the same time
resetAnticipated();
anticipateDown(node);
icmpService.bringDown();
smtpService.bringDown();
snmpService.bringDown();
verifyAnticipated(10000);
anticipateDown(smtpService);
verifyAnticipated(10000);
anticipateDown(snmpService);
verifyAnticipated(10000);
// This is to simulate a restart,
// where I turn off the node behaviour
m_pollerConfig.setNodeOutageProcessingEnabled(false);
anticipateUp(snmpService);
snmpService.bringUp();
verifyAnticipated(10000);
anticipateUp(smtpService);
smtpService.bringUp();
verifyAnticipated(10000);
// Another restart - let's see if this will work?
m_pollerConfig.setNodeOutageProcessingEnabled(true);
// So everything is down, now
// SNMP will regain and SMTP will regain
// will the node come up?
smtpService.bringDown();
anticipateUp(smtpService);
smtpService.bringUp();
verifyAnticipated(10000, true);
anticipateUp(snmpService);
snmpService.bringUp();
verifyAnticipated(10000);
}
Aggregations