/** * @param event * */ public void anticipateNotification(MockNotification mn) { MockUtil.println("Anticipating notification: " + mn); m_anticipated.add(mn); }
/** * <p>println</p> * * @param string a {@link java.lang.String} object. */ public static void println(String string) { if (MockUtil.printEnabled()) System.err.println(string); }
public MockNotificationStrategy(){ MockUtil.println("Created a "+ MockNotificationStrategy.class.getName()); }
/** * <p>printEvents</p> * * @param prefix a {@link java.lang.String} object. * @param events a {@link java.util.Collection} object. */ public static void printEvents(String prefix, Collection<Event> events) { if (!MockUtil.printEnabled()) { return; } for (Event event : events) { printEvent(prefix, event); } }
/** * @param event */ public synchronized void notificationReceived(MockNotification mn) { int i = m_anticipated.indexOf(mn); if (i != -1) { MockNotification notification = m_anticipated.get(i); long receivedTime = mn.getExpectedTime(); long expectedTime = notification.getExpectedTime(); long difference = expectedTime - receivedTime; if (Math.abs(difference) < m_expectedDiff) { MockUtil.println("Received expected notification: " + mn); m_anticipated.remove(mn); notifyAll(); } else { MockNotification[] n = new MockNotification[] { notification, mn }; if (difference > 0) { MockUtil.println("Received early notification: " + mn); m_earlyArrival.add(n); } else { MockUtil.println("Received late notification: " + mn); m_lateBloomers.add(n); } } } else { MockUtil.println("Received unexpected notification: " + mn); m_unanticipated.add(mn); } }
/** * <p>printEvent</p> * * @param prefix a {@link java.lang.String} object. * @param event a {@link org.opennms.netmgt.xml.event.Event} object. */ public static void printEvent(String prefix, Event event) { if (!MockUtil.printEnabled()) { return; } if (prefix == null) { prefix = "Event"; } LOG.info("{}: {}/{}/{}/{}", prefix, event.getUei(), event.getNodeid(), event.getInterface(), event.getService()); }
@After public void tearDown() throws Exception { MockUtil.println("------------ End Test --------------------------"); // MockLogAppender.assertNoWarningsOrGreater(); }
@Override protected void tearDown() throws Exception { MockUtil.println("------------ End Test "+getName()+" --------------------------"); super.tearDown(); }
@After public void tearDown() throws Exception { MockUtil.println("------------ End Test --------------------------"); // MockLogAppender.assertNoWarningsOrGreater(); }
@After public void runTest() throws Throwable { try { if (!m_allowWarnings) { MockLogAppender.assertNoWarningsOrGreater(); } } finally { MockUtil.println("------------ End Test "+this+" --------------------------"); } }
@After public void tearDown() throws Exception { sleep(200); MockUtil.println("------------ End Test --------------------------"); }
@After public void tearDown() throws Exception { m_eventMgr.finishProcessingEvents(); MockUtil.println("------------ End Test --------------------------"); }
@Override public void run() { try { pNode1.withTreeLock(r, 500); fail("Expected LockUnavailable"); } catch (LockUnavailable e) { MockUtil.println("Received expected exception "+e); } } };
/** * Tears down the test. * * @throws Exception the exception */ @After public void tearDown() throws Exception { MockUtil.println("------------ End Test --------------------------"); MockLogAppender.assertNoWarningsOrGreater(); }
@Override public int send(List<Argument> arguments) { MockUtil.println("Message sent with arguments:"+arguments); MockNotification notification = new MockNotification(); Iterator<Argument> it = arguments.iterator(); while (it.hasNext()) { Argument arg = it.next(); if (arg.getSwitch().equals(NotificationManager.PARAM_SUBJECT)) { notification.setSubject(arg.getValue()); } else if (arg.getSwitch().equals(NotificationManager.PARAM_EMAIL)) { notification.setEmail(arg.getValue()); } else if (arg.getSwitch().equals(NotificationManager.PARAM_TEXT_MSG)) { notification.setTextMsg(arg.getValue()); } } notification.setExpectedTime(System.currentTimeMillis()); NotificationAnticipator anticipator = getAnticipator(); if (anticipator != null) { anticipator.notificationReceived(notification); } else { throw new NullPointerException("anticipator is null"); } return 0; }
@Override protected void tearDown() throws Exception { m_proxy.stop(); /* * Future calls to setUp() fail due to the port still being in use * if I don't have the sleep: * * OpenJDK Runtime Environment (build 1.8.0_45-b13) on Amazon Linux AMI release 2015.03 * * I hate it when resources don't get fully deallocated. */ Thread.sleep(5); MockLogAppender.assertNoWarningsOrGreater(); MockUtil.println("------------ End Test "+getName()+" --------------------------"); }
@Override protected void setUp() throws Exception { super.setUp(); MockUtil.println("------------ Begin Test "+getName()+" --------------------------"); MockLogAppender.setupLogging(); MockDatabase m_db = new MockDatabase(); // m_db.populate(m_network); DataSourceFactory.setInstance(m_db); }
@Override public void visitService(MockService svc) { if (anticipatesClose(svc)) { // Decrease the open ones.. leave the total the same m_expectedOpenCount++; for (Outage outage : m_db.getOpenOutages(svc)) { MockUtil.println("Deanticipating outage closed: "+outage); removeFromOutageList(m_pendingCloses, regainService, outage); } } } };
private void testElementDownUp(MockElement element) { startDaemons(); resetAnticipated(); anticipateDown(element); MockUtil.println("Bringing down element: " + element); element.bringDown(); MockUtil.println("Finished bringing down element: " + element); verifyAnticipated(5000); sleep(2000); resetAnticipated(); anticipateUp(element); MockUtil.println("Bringing up element: " + element); element.bringUp(); MockUtil.println("Finished bringing up element: " + element); verifyAnticipated(8000); }
private void testElementDownUp(MockElement element) { startDaemons(); resetAnticipated(); anticipateDown(element); MockUtil.println("Bringing down element: " + element); element.bringDown(); MockUtil.println("Finished bringing down element: " + element); verifyAnticipated(5000); sleep(2000); resetAnticipated(); anticipateUp(element); MockUtil.println("Bringing up element: " + element); element.bringUp(); MockUtil.println("Finished bringing up element: " + element); verifyAnticipated(8000); }