public void testPollDuration() throws Exception { MyAuState aus = new MyAuState(mau, historyRepo); assertEquals(0, aus.getPollDuration()); aus.setPollDuration(1000); assertEquals(1000, aus.getPollDuration()); aus.setPollDuration(2000); assertEquals(1500, aus.getPollDuration()); }
MyAuState simulateStoreLoad() throws CloneNotSupportedException { MyAuState ret = (MyAuState) this.clone(); ret.previousCrawlState = null; return ret; }
public void testV3Agreement() throws Exception { MyAuState aus = new MyAuState(mau, historyRepo); assertEquals(-1.0, aus.getV3Agreement()); assertEquals(-1.0, aus.getHighestV3Agreement()); assertNull(historyRepo.theAuState); aus.setV3Agreement(0.0); assertEquals(0.0, aus.getV3Agreement()); assertEquals(0.0, aus.getHighestV3Agreement()); assertNotNull(historyRepo.theAuState); aus.setV3Agreement(0.5); assertEquals(0.5, aus.getV3Agreement()); assertEquals(0.5, aus.getHighestV3Agreement()); aus.setV3Agreement(0.3); assertEquals(0.3, aus.getV3Agreement()); assertEquals(0.5, aus.getHighestV3Agreement()); }
public void testPollTimeAndResult() throws Exception { MyAuState aus = new MyAuState(mau, historyRepo); assertEquals(-1, aus.getLastTopLevelPollTime()); assertEquals(-1, aus.getLastPollStart()); assertEquals(-1, aus.getLastPollResult()); assertEquals(null, aus.getLastPollResultMsg()); assertEquals(-1, aus.getLastPoPPoll()); assertEquals(-1, aus.getLastPoPPollResult()); assertEquals(null, aus.getLastPoPPollResultMsg()); assertEquals(-1, aus.getLastLocalHashScan()); assertEquals(-1, aus.getLastTimePollCompleted()); assertEquals(0, aus.getPollDuration()); assertNull(historyRepo.theAuState); TimeBase.setSimulated(t1); aus.pollStarted(); // running poll assertEquals(t1, aus.getLastPollStart()); // These haven't been updated yet assertEquals(-1, aus.getLastTopLevelPollTime()); assertEquals(-1, aus.getLastPollResult()); assertEquals(0, aus.getPollDuration()); assertEquals(-1, aus.getLastTimePollCompleted()); assertNotNull(historyRepo.theAuState); TimeBase.setSimulated(t2); aus.pollFinished(V3Poller.POLLER_STATUS_ERROR, PollVariant.PoR); assertEquals(-1, aus.getLastTopLevelPollTime()); assertEquals(t1, aus.getLastPollStart()); assertEquals(V3Poller.POLLER_STATUS_ERROR, aus.getLastPollResult()); assertEquals("Error", aus.getLastPollResultMsg()); assertEquals(t2, aus.getPollDuration()); assertEquals(-1, aus.getLastPoPPoll()); assertEquals(-1, aus.getLastPoPPollResult()); assertEquals(null, aus.getLastPoPPollResultMsg()); assertEquals(-1, aus.getLastLocalHashScan()); assertEquals(-1, aus.getLastTimePollCompleted()); TimeBase.setSimulated(t3); aus.pollFinished(V3Poller.POLLER_STATUS_COMPLETE, PollVariant.PoR); assertEquals(t3, aus.getLastTopLevelPollTime()); assertEquals(t1, aus.getLastPollStart()); assertEquals(V3Poller.POLLER_STATUS_COMPLETE, aus.getLastPollResult()); assertEquals("Complete", aus.getLastPollResultMsg()); assertEquals((t3 + t2) / 2, aus.getPollDuration()); assertEquals(-1, aus.getLastPoPPoll()); assertEquals(-1, aus.getLastPoPPollResult()); assertEquals(null, aus.getLastPoPPollResultMsg()); assertEquals(-1, aus.getLastLocalHashScan()); assertEquals(t3, aus.getLastTimePollCompleted()); TimeBase.setSimulated(t4); aus.pollFinished(V3Poller.POLLER_STATUS_NO_QUORUM, PollVariant.PoP); assertEquals(t3, aus.getLastTopLevelPollTime()); assertEquals(t1, aus.getLastPollStart()); assertEquals(V3Poller.POLLER_STATUS_COMPLETE, aus.getLastPollResult()); assertEquals("Complete", aus.getLastPollResultMsg()); assertEquals((t3 + t2) / 2, aus.getPollDuration()); assertEquals(-1, aus.getLastPoPPoll()); assertEquals(V3Poller.POLLER_STATUS_NO_QUORUM, aus.getLastPoPPollResult()); assertEquals(-1, aus.getLastLocalHashScan()); assertEquals("No Quorum", aus.getLastPoPPollResultMsg()); assertEquals(t3, aus.getLastTimePollCompleted()); TimeBase.setSimulated(t5); aus.pollFinished(V3Poller.POLLER_STATUS_COMPLETE, PollVariant.PoP); assertEquals(t3, aus.getLastTopLevelPollTime()); assertEquals(t1, aus.getLastPollStart()); assertEquals(V3Poller.POLLER_STATUS_COMPLETE, aus.getLastPollResult()); assertEquals("Complete", aus.getLastPollResultMsg()); assertEquals((t3 + t2) / 2, aus.getPollDuration()); assertEquals(t5, aus.getLastPoPPoll()); assertEquals(V3Poller.POLLER_STATUS_COMPLETE, aus.getLastPoPPollResult()); assertEquals("Complete", aus.getLastPoPPollResultMsg()); assertEquals(-1, aus.getLastLocalHashScan()); assertEquals(t5, aus.getLastTimePollCompleted()); aus.pollFinished(V3Poller.POLLER_STATUS_NO_QUORUM, PollVariant.PoP); TimeBase.setSimulated(t6); aus.pollFinished(V3Poller.POLLER_STATUS_COMPLETE, PollVariant.Local); assertEquals(t3, aus.getLastTopLevelPollTime()); assertEquals(t1, aus.getLastPollStart()); assertEquals(V3Poller.POLLER_STATUS_COMPLETE, aus.getLastPollResult()); assertEquals("Complete", aus.getLastPollResultMsg()); assertEquals((t3 + t2) / 2, aus.getPollDuration()); assertEquals(t5, aus.getLastPoPPoll()); assertEquals(V3Poller.POLLER_STATUS_NO_QUORUM, aus.getLastPoPPollResult()); assertEquals("No Quorum", aus.getLastPoPPollResultMsg()); assertEquals(t6, aus.getLastLocalHashScan()); assertEquals(t5, aus.getLastTimePollCompleted()); aus = aus.simulateStoreLoad(); assertEquals(t3, aus.getLastTopLevelPollTime()); assertEquals(t1, aus.getLastPollStart()); assertEquals(V3Poller.POLLER_STATUS_COMPLETE, aus.getLastPollResult()); TimeBase.setSimulated(t7); aus.pollStarted(); assertEquals(t3, aus.getLastTopLevelPollTime()); assertEquals(t7, aus.getLastPollStart()); assertEquals(V3Poller.POLLER_STATUS_COMPLETE, aus.getLastPollResult()); }
public void testDaemonCrashedDuringCrawl() throws Exception { MyAuState aus = new MyAuState(mau, historyRepo); assertEquals(-1, aus.getLastCrawlTime()); assertEquals(-1, aus.getLastCrawlAttempt()); assertEquals(-1, aus.getLastCrawlResult()); assertFalse(aus.isCrawlActive()); assertNull(historyRepo.theAuState); TimeBase.setSimulated(t1); aus.newCrawlStarted(); // these should now reflect the previoud crawl, not the active one assertEquals(-1, aus.getLastCrawlTime()); assertEquals(-1, aus.getLastCrawlAttempt()); assertEquals(-1, aus.getLastCrawlResult()); assertTrue(aus.isCrawlActive()); assertNotNull(historyRepo.theAuState); TimeBase.setSimulated(t2); aus = aus.simulateStoreLoad(); assertEquals(-1, aus.getLastCrawlTime()); assertEquals(t1, aus.getLastCrawlAttempt()); assertEquals(Crawler.STATUS_RUNNING_AT_CRASH, aus.getLastCrawlResult()); assertFalse(aus.isCrawlActive()); TimeBase.setSimulated(t3); aus.newCrawlStarted(); assertEquals(-1, aus.getLastCrawlTime()); assertEquals(t1, aus.getLastCrawlAttempt()); assertEquals(Crawler.STATUS_RUNNING_AT_CRASH, aus.getLastCrawlResult()); TimeBase.setSimulated(t4); aus.newCrawlFinished(Crawler.STATUS_SUCCESSFUL, "Plorg"); assertEquals(t4, aus.getLastCrawlTime()); assertEquals(t3, aus.getLastCrawlAttempt()); assertEquals(Crawler.STATUS_SUCCESSFUL, aus.getLastCrawlResult()); }
public void testCrawlStarted() throws Exception { MyAuState aus = new MyAuState(mau, historyRepo); assertEquals(-1, aus.getLastCrawlTime()); assertEquals(-1, aus.getLastCrawlAttempt()); assertEquals(-1, aus.getLastCrawlResult()); assertFalse(aus.isCrawlActive()); assertFalse(aus.hasCrawled()); assertNull(historyRepo.theAuState); assertEquals(0, historyRepo.getAuStateStoreCount()); TimeBase.setSimulated(t1); aus.newCrawlStarted(); // these should now reflect the previoud crawl, not the active one assertEquals(-1, aus.getLastCrawlTime()); assertEquals(-1, aus.getLastCrawlAttempt()); assertEquals(-1, aus.getLastCrawlResult()); assertTrue(aus.isCrawlActive()); assertFalse(aus.hasCrawled()); assertNotNull(historyRepo.theAuState); assertEquals(1, historyRepo.getAuStateStoreCount()); TimeBase.setSimulated(t2); aus.newCrawlFinished(Crawler.STATUS_ERROR, "Plorg"); assertEquals(-1, aus.getLastCrawlTime()); assertEquals(t1, aus.getLastCrawlAttempt()); assertEquals(Crawler.STATUS_ERROR, aus.getLastCrawlResult()); assertEquals("Plorg", aus.getLastCrawlResultMsg()); assertFalse(aus.isCrawlActive()); assertFalse(aus.hasCrawled()); assertEquals(2, historyRepo.getAuStateStoreCount()); TimeBase.setSimulated(t3); aus.newCrawlFinished(Crawler.STATUS_SUCCESSFUL, "Syrah"); assertEquals(t3, aus.getLastCrawlTime()); assertEquals(t1, aus.getLastCrawlAttempt()); assertEquals(Crawler.STATUS_SUCCESSFUL, aus.getLastCrawlResult()); assertEquals("Syrah", aus.getLastCrawlResultMsg()); assertFalse(aus.isCrawlActive()); assertTrue(aus.hasCrawled()); assertEquals(3, historyRepo.getAuStateStoreCount()); aus = aus.simulateStoreLoad(); assertEquals(t3, aus.getLastCrawlTime()); assertEquals(t1, aus.getLastCrawlAttempt()); assertEquals(Crawler.STATUS_SUCCESSFUL, aus.getLastCrawlResult()); assertEquals("Syrah", aus.getLastCrawlResultMsg()); assertFalse(aus.isCrawlActive()); assertTrue(aus.hasCrawled()); TimeBase.setSimulated(t4); aus.newCrawlStarted(); assertEquals(t3, aus.getLastCrawlTime()); assertEquals(t1, aus.getLastCrawlAttempt()); assertEquals(Crawler.STATUS_SUCCESSFUL, aus.getLastCrawlResult()); assertEquals("Syrah", aus.getLastCrawlResultMsg()); assertTrue(aus.hasCrawled()); }