public void testScheduleOurHash() { V1Poll p = testV1polls[0]; p.m_pollstate = V1Poll.PS_WAIT_HASH; // no time has elapsed - so we should be able to schedule our hash assertTrue(p.scheduleOurHash()); // half the time has elapsed so we should be able to schedule our hash TimeBase.step(p.m_deadline.getRemainingTime() / 2); assertTrue(p.scheduleOurHash()); // all of the time has elapsed we should not be able to schedule our hash TimeBase.step(p.m_deadline.getRemainingTime() - 1000); assertFalse(p.scheduleOurHash()); p.m_pollstate = V1Poll.PS_COMPLETE; }
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()); }
// test completion & callback public void testDone() throws Exception { HashQueue q = new HashQueue(); final List cookieList = new LinkedList(); final List eList = new LinkedList(); HashService.Callback cb = new HashService.Callback() { public void hashingFinished( CachedUrlSet urlset, long timeUsed, Object cookie, CachedUrlSetHasher hasher, Exception e) { cookieList.add(cookie); eList.add(e); } }; HashQueue.Request r1, r2, r3, r4, r5; r1 = req(2000, 0, 100, cb); r2 = req(10000, 0, 200, cb); r3 = req(20000, 0, 0, cb); r4 = req(50000, 0, 1, cb); assertTrue(q.insert(r1)); assertTrue(q.insert(r2)); assertTrue(q.insert(r4)); assertEquals(0, cookieList.size()); q.removeCompleted(); assertEquals(0, cookieList.size()); // make r1 timeout r1.deadline.expire(); q.removeCompleted(); List exp = ListUtil.list(r1); assertEquals(exp, cookieList); assertEquals(exp, q.getCompletedSnapshot()); // make r2 timeout TimeBase.step(11000); // r3 is finished assertTrue(q.insert(r3)); Exception r4e = new Exception(); // make r4 error r4.e = r4e; q.removeCompleted(); // check that they all finished, and in the right order Object exp2[] = {r1, r2, r3, r4}; assertIsomorphic(exp2, cookieList); assertIsomorphic(exp2, q.getCompletedSnapshot()); // check their exceptions assertTrue(eList.get(0) instanceof HashService.Timeout); assertTrue(eList.get(1) instanceof HashService.Timeout); assertSame(null, eList.get(2)); assertSame(r4e, eList.get(3)); }