📄 pollablestest.java
字号:
verifyAnticipated(); anticipateUp(mDot1); anticipateDown(mDot1Smtp); mDot1.bringUp(); mDot1Smtp.bringDown(); pDot1Icmp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); } public void testSvcOutage() { anticipateDown(mDot1Smtp); mDot1Smtp.bringDown(); pDot1Smtp.doPoll(); pDot1Smtp.processStatusChange(new Date()); verifyAnticipated(); anticipateUp(mDot1Smtp); mDot1Smtp.bringUp(); pDot1Smtp.doPoll(); pDot1Smtp.processStatusChange(new Date()); verifyAnticipated(); } public void testIfOutage() { anticipateDown(mDot1); mDot1.bringDown(); pDot1Smtp.doPoll(); pDot1.processStatusChange(new Date()); verifyAnticipated(); anticipateUp(mDot1); mDot1.bringUp(); pDot1Icmp.doPoll(); pDot1.processStatusChange(new Date()); verifyAnticipated(); } public void testCause() { anticipateDown(mDot1Smtp); mDot1Smtp.bringDown(); pDot1Smtp.doPoll(); pDot1.processStatusChange(new Date()); verifyAnticipated(); anticipateDown(mDot1); mDot1.bringDown(); pDot1Icmp.doPoll(); pDot1.processStatusChange(new Date()); verifyAnticipated(); PollEvent cause = pDot1.getCause(); assertNotNull(cause); assertEquals(cause, pDot1.getCause()); assertEquals(cause, pDot1Icmp.getCause()); assertFalse(cause.equals(pDot1Smtp.getCause())); } public void testIndependentOutageEventsUpTogether() throws Exception { anticipateDown(mDot1Smtp); mDot1Smtp.bringDown(); pDot1Smtp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); anticipateDown(mNode1); mNode1.bringDown(); pDot1Icmp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); anticipateUp(mDot1Smtp); anticipateUp(mNode1); mNode1.bringUp(); pDot1Icmp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); } public void testIndependentOutageEventsUpSeparately() throws Exception { anticipateDown(mDot1Smtp); mDot1Smtp.bringDown(); pDot1Smtp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); anticipateDown(mNode1); mNode1.bringDown(); pDot1Icmp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); anticipateUp(mNode1); m_outageAnticipator.deanticipateOutageClosed(mDot1Smtp, mNode1.createUpEvent()); mNode1.bringUp(); mDot1Smtp.bringDown(); pDot1Icmp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); anticipateUp(mDot1Smtp); mDot1Smtp.bringUp(); pDot1Smtp.doPoll(); m_network.processStatusChange(new Date()); verifyAnticipated(); } public void testDowntimeInterval() { // HERE ARE the calls to setup the downtime model// m_pollerConfig.addDowntime(100L, 0L, 500L, false);// m_pollerConfig.addDowntime(200L, 500L, 1500L, false);// m_pollerConfig.addDowntime(500L, 1500L, -1L, true); Package pkg = m_pollerConfig.getPackage("TestPackage"); PollableServiceConfig pollConfig = new PollableServiceConfig(pDot1Smtp, m_pollerConfig, m_pollerConfig, pkg, m_timer); m_timer.setCurrentTime(1000L); pDot1Smtp.updateStatus(PollStatus.STATUS_DOWN); assertEquals(1000, pDot1Smtp.getStatusChangeTime()); assertDown(pDot1Smtp); pDot1.resetStatusChanged(); assertEquals(100L, pollConfig.getInterval()); m_timer.setCurrentTime(1234L); assertEquals(100L, pollConfig.getInterval()); m_timer.setCurrentTime(1500L); assertEquals(200L, pollConfig.getInterval()); m_timer.setCurrentTime(1700L); assertEquals(200L, pollConfig.getInterval()); m_timer.setCurrentTime(2500L); assertEquals(-1L, pollConfig.getInterval()); //assertTrue(pDot1Smtp.isDeleted()); } public void testSchedule() { pDot1Smtp.getSchedule().schedule(); m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(0); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); mDot1Smtp.bringDown(); m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(1000); assertDown(pDot1Smtp); assertChanged(pDot1Smtp); pDot1Smtp.resetStatusChanged(); // test scheduling for downTime model for(int downFor = 100; downFor < 500; downFor += 100) { m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(1000+downFor); } for(int downFor = 500; downFor < 1500; downFor += 200) { m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(1000+downFor); } mDot1Smtp.bringUp(); m_scheduler.next(); assertPoll(mDot1Smtp); assertUp(pDot1Smtp); assertChanged(pDot1Smtp); pDot1Smtp.recalculateStatus(); } public void testScheduleAdjust() { // change SMTP so it is only polled every 10 secs rather than 1 sec m_pollerConfig.setPollInterval(m_pollerConfig.getPackage("TestPackage"), "SMTP", 10000L); pDot1Icmp.getSchedule().schedule(); pDot1Smtp.getSchedule().schedule(); // get the immediate polls out of the way m_scheduler.next(); m_scheduler.next(); assertTime(0); assertPoll(mDot1Icmp); assertPoll(mDot1Smtp); assertUp(pDot1Smtp); assertUp(pDot1Icmp); assertUnchanged(pDot1Smtp); assertUnchanged(pDot1Icmp); // not we should come to the poll for icmp m_scheduler.next(); // icmp should be polled but not smtp and they both should be up assertTime(1000); assertPoll(mDot1Icmp); assertNoPoll(mDot1Smtp); assertUp(pDot1Smtp); assertUp(pDot1Icmp); assertUnchanged(pDot1Smtp); assertUnchanged(pDot1Icmp); // now bring down both services mDot1.bringDown(); // we come to the next icmp poll still not time to poll smtp m_scheduler.next(); // no need to poll smtp because icmp reports itself down assertTime(2000); assertPoll(mDot1Icmp); assertNoPoll(mDot1Smtp); assertUp(pDot1Smtp); // TODO: i wonder if this matters... its really down (the outage does get created) assertDown(pDot1Icmp); assertUnchanged(pDot1Smtp); assertChanged(pDot1Icmp); // now we bring icmp back up but not smtp. it is still not time for a scheduled smtp poll mDot1Icmp.bringUp(); // we come to the next icmp poll in only 100ms according to the downtime model m_scheduler.next(); // since icmp came up we do an unscheduled poll of smtp and find its down assertTime(2100); assertPoll(mDot1Icmp); assertPoll(mDot1Smtp); assertDown(pDot1Smtp); assertUp(pDot1Icmp); assertChanged(pDot1Smtp); assertChanged(pDot1Icmp); // since smtp is now down, the schedule for smtp should be adjusted according // to the downtime model so we expect the next poll for it in only 100ms m_scheduler.next(); // this time we should poll only smtp and find it still down assertTime(2200); assertNoPoll(mDot1Icmp); assertPoll(mDot1Smtp); assertDown(pDot1Smtp); assertUp(pDot1Icmp); assertUnchanged(pDot1Smtp); assertUnchanged(pDot1Icmp); mDot1Smtp.bringUp(); // another downtime model poll of smtp m_scheduler.next(); assertTime(2300); assertNoPoll(mDot1Icmp); assertPoll(mDot1Smtp); assertUp(pDot1Smtp); assertUp(pDot1Icmp); assertChanged(pDot1Smtp); assertUnchanged(pDot1Icmp); // now the next one should be the next scheduled icmp poll m_scheduler.next(); assertTime(3100); assertPoll(mDot1Icmp); assertNoPoll(mDot1Smtp); assertUp(pDot1Smtp); assertUp(pDot1Icmp); assertUnchanged(pDot1Smtp); assertUnchanged(pDot1Icmp); } public void testComputeScheduledOutageTime() { Package pkg = m_pollerConfig.getPackage("TestPackage"); m_pollerConfig.addScheduledOutage(pkg, "first", 3000, 5000, "192.168.1.1"); PollableServiceConfig pollConfig = new PollableServiceConfig(pDot1Smtp, m_pollerConfig, m_pollerConfig, pkg, m_timer); m_timer.setCurrentTime(2000L); assertFalse(pollConfig.scheduledSuspension()); m_timer.setCurrentTime(4000L); assertTrue(pollConfig.scheduledSuspension()); } public void testScheduledOutage() { m_pollerConfig.addScheduledOutage(m_pollerConfig.getPackage("TestPackage"), "first", 3000, 5000, "192.168.1.1"); pDot1Smtp.getSchedule().schedule(); m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(0); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(1000); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(2000); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); m_scheduler.next(); assertNoPoll(mDot1Smtp); assertTime(3000); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); m_scheduler.next(); assertNoPoll(mDot1Smtp); assertTime(4000); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); m_scheduler.next(); assertNoPoll(mDot1Smtp); assertTime(5000); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); m_scheduler.next(); assertPoll(mDot1Smtp); assertTime(6000); assertUp(pDot1Smtp); assertUnchanged(pDot1Smtp); } public void testMidnightOutageBug1122() throws ParseException { m_pollerConfig.addScheduledOutage(m_pollerConfig.getPackage("TestPackage"), "first", "monday", "23:59:57", "23:59:59", "192.168.1.1"); m_pollerConfig.addScheduledOutage(m_pollerConfig.getPackage("TestPackage"), "second", "tuesday", "00:00:00", "00:00:02", "192.168.1.1"); Date start = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss").parse("21-FEB-2005 23:59:56"); long startTime = start.getTime();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -