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()); }
public void testLastContentChange() { TimeBase.setSimulated(10); AuState aus = new AuState(mau, historyRepo); aus.newCrawlStarted(); TimeBase.step(10); aus.contentChanged(); assertEquals(20, aus.getLastContentChange()); TimeBase.step(10); aus.contentChanged(); assertEquals(20, aus.getLastContentChange()); TimeBase.step(10); aus.newCrawlFinished(1, "foo"); TimeBase.step(10); aus.contentChanged(); assertEquals(50, aus.getLastContentChange()); }
public void testTreeWalkFinished() { AuState auState = makeAuState(mau, -1, -1, -1, -1, 123, null, 1, -1.0, 1.0, historyRepo); assertEquals(123, auState.getLastTreeWalkTime()); TimeBase.setSimulated(456); auState.setLastTreeWalkTime(); assertEquals(456, auState.getLastTreeWalkTime()); }
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()); }
/* * Abbreviate the verbose constructor */ private AuState makeAuState( ArchivalUnit au, long lastCrawlTime, long lastCrawlAttempt, long lastTopLevelPoll, long lastPollStart, long lastTreeWalk, HashSet crawlUrls, int clockssSubscriptionStatus, double v3Agreement, double highestV3Agreement, HistoryRepository historyRepo) { return new AuState( au, lastCrawlTime, lastCrawlAttempt, -1, null, lastTopLevelPoll, lastPollStart, -1, null, 0, lastTreeWalk, crawlUrls, null, clockssSubscriptionStatus, v3Agreement, highestV3Agreement, SubstanceChecker.State.Unknown, null, // substanceFeatureVersion null, // metadataFeatureVersion -1, // lastMetadataIndex TimeBase.nowMs(), // lastContentChange -1, -1, -1, -1, // numWillingRepairers -1, // numCurrentSuspectVersions 0, null, historyRepo); }
public void tearDown() throws Exception { TimeBase.setReal(); super.tearDown(); }
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()); }