public void testStoreNodeState() throws Exception { TimeBase.setSimulated(100); CachedUrlSet mcus = new MockCachedUrlSet(mau, new RangeCachedUrlSetSpec("http://www.example.com")); CrawlState crawl = new CrawlState(1, 2, 123); List polls = new ArrayList(2); PollState poll1 = new PollState(1, "sdf", "jkl", 2, 123, Deadline.at(456), false); PollState poll2 = new PollState(2, "abc", "def", 3, 321, Deadline.at(654), false); polls.add(poll1); polls.add(poll2); NodeState nodeState = new NodeStateImpl(mcus, 123321, crawl, polls, repository); ((NodeStateImpl) nodeState).setState(NodeState.DAMAGE_AT_OR_BELOW); repository.storeNodeState(nodeState); String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau); filePath = LockssRepositoryImpl.mapUrlToFileLocation( filePath, "http://www.example.com/" + HistoryRepositoryImpl.NODE_FILE_NAME); File xmlFile = new File(filePath); assertTrue(xmlFile.exists()); nodeState = null; nodeState = repository.loadNodeState(mcus); assertSame(mcus, nodeState.getCachedUrlSet()); assertEquals(123321, nodeState.getAverageHashDuration()); assertEquals(1, nodeState.getCrawlState().getType()); assertEquals(2, nodeState.getCrawlState().getStatus()); assertEquals(123, nodeState.getCrawlState().getStartTime()); assertEquals(NodeState.DAMAGE_AT_OR_BELOW, nodeState.getState()); Iterator pollIt = nodeState.getActivePolls(); assertTrue(pollIt.hasNext()); PollState loadedPoll = (PollState) pollIt.next(); assertEquals(1, loadedPoll.getType()); assertEquals("sdf", loadedPoll.getLwrBound()); assertEquals("jkl", loadedPoll.getUprBound()); assertEquals(2, loadedPoll.getStatus()); assertEquals(123, loadedPoll.getStartTime()); assertEquals(456, loadedPoll.getDeadline().getExpirationTime()); assertTrue(pollIt.hasNext()); loadedPoll = (PollState) pollIt.next(); assertEquals(2, loadedPoll.getType()); assertEquals("abc", loadedPoll.getLwrBound()); assertEquals("def", loadedPoll.getUprBound()); assertEquals(3, loadedPoll.getStatus()); assertEquals(321, loadedPoll.getStartTime()); assertEquals(654, loadedPoll.getDeadline().getExpirationTime()); assertFalse(pollIt.hasNext()); TimeBase.setReal(); }
public void testFindOverrunTaskToRun() { assertFalse(tr.findTaskToRun()); StepTask t1 = task(100, 200, 100); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); assertFalse(tr.findTaskToRun()); assertEquals(Deadline.at(100), tr.runningDeadline); StepTask t2 = task(0, 300, 50); tr.addOverrunner(t2); assertTrue(tr.findTaskToRun()); assertEquals(t2, tr.runningTask); assertEquals(Deadline.at(100), tr.runningDeadline); assertNull(tr.runningChunk); }
public void testFindChunkTaskToRun() { assertFalse(tr.findTaskToRun()); StepTask t1 = task(100, 200, 100); StepTask t2 = task(100, 300, 50); Schedule s = sched(ListUtil.list(t1, t2)); fact.setResults(s, s); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); assertFalse(tr.findTaskToRun()); assertEquals(Deadline.at(100), tr.runningDeadline); TimeBase.setSimulated(101); assertTrue(tr.findTaskToRun()); assertEquals(t1, tr.runningTask); assertEquals(t1.getLatestFinish(), tr.runningDeadline); assertEquals(s.getEvents().get(0), tr.runningChunk); }
public void testFindRunnableChunk() { assertFalse(tr.findTaskToRun()); StepTask t1 = task(100, 200, 100); StepTask t2 = task(10, 300, 50); Schedule.Chunk c1 = new Schedule.Chunk(t1, Deadline.at(100), Deadline.at(200), 100); Schedule.Chunk c2 = new Schedule.Chunk(t2, Deadline.at(200), Deadline.at(300), 100); Schedule s = new Schedule(ListUtil.list(c1, c2)); fact.setResults(s, s); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); assertFalse(tr.findTaskToRun()); assertEquals(Deadline.at(100), tr.runningDeadline); TimeBase.setSimulated(11); assertTrue(tr.findTaskToRun()); assertEquals(t2, tr.runningTask); assertEquals(c2, tr.runningChunk); assertEquals(Deadline.at(100), tr.runningDeadline); assertEquals(s.getEvents().get(1), tr.runningChunk); }
static StepperTask taskBetween(long minStart, long deadline, int duration, Stepper stepper) { return new StepperTask( Deadline.at(minStart), Deadline.at(deadline), duration, null, null, stepper); }
BackgroundTask btask(long start, long end, double loadFactor, TaskCallback cb) { return new BackgroundTask(Deadline.at(start), Deadline.at(end), loadFactor, cb); }
StepTask task(long start, long end, long duration, TaskCallback cb, Stepper stepper) { return new StepperTask(Deadline.at(start), Deadline.at(end), duration, cb, null, stepper); }
StepTask task(long start, long end, long duration, TaskCallback cb) { return new StepperTask( Deadline.at(start), Deadline.at(end), duration, cb, null, new MyMockStepper()); }
public void testBackground() { final List rec = new ArrayList(); TaskCallback cb = new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { rec.add(new BERec(Deadline.in(0), (BackgroundTask) task, event)); } }; assertFalse(tr.findTaskToRun()); BackgroundTask t1 = btask(100, 200, .1, cb); BackgroundTask t2 = btask(100, 300, .2, cb); BackgroundTask t3 = btask(150, 200, .4, cb); Schedule s = sched( ListUtil.list( bEvent(t1, Schedule.EventType.START), bEvent(t2, Schedule.EventType.START), bEvent(t3, Schedule.EventType.START), bEvent(t1, Schedule.EventType.FINISH), bEvent(t3, Schedule.EventType.FINISH), bEvent(t2, Schedule.EventType.FINISH))); fact.setResults(ListUtil.list(s, s, s)); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); assertTrue(tr.addToSchedule(t3)); assertEquals(3, tr.getAcceptedTasks().size()); assertIsomorphic(ListUtil.list(t1, t2, t3), tr.getAcceptedTasks()); assertFalse(tr.findTaskToRun()); assertEquals(0, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); assertEquals(Deadline.at(100), tr.runningDeadline); TimeBase.setSimulated(101); assertFalse(tr.findTaskToRun()); assertEquals(2, rec.size()); assertEquals(.3, tr.getBackgroundLoadFactor(), .005); TimeBase.setSimulated(151); assertFalse(tr.findTaskToRun()); assertEquals(3, rec.size()); assertEquals(.7, tr.getBackgroundLoadFactor(), .005); assertEquals(3, tr.getAcceptedTasks().size()); TimeBase.setSimulated(201); assertFalse(tr.findTaskToRun()); assertEquals(5, rec.size()); assertEquals(.2, tr.getBackgroundLoadFactor(), .005); assertEquals(1, tr.getAcceptedTasks().size()); t2.taskIsFinished(); TimeBase.setSimulated(202); assertFalse(tr.findTaskToRun()); assertEquals(6, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); assertEquals(0, tr.getAcceptedTasks().size()); TimeBase.setSimulated(301); assertFalse(tr.findTaskToRun()); assertEquals(6, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); List exp = ListUtil.list( new BERec(101, t1, Schedule.EventType.START), new BERec(101, t2, Schedule.EventType.START), new BERec(151, t3, Schedule.EventType.START), new BERec(201, t1, Schedule.EventType.FINISH), new BERec(201, t3, Schedule.EventType.FINISH), new BERec(201, t2, Schedule.EventType.FINISH)); assertEquals(exp, rec); }
BERec(long when, BackgroundTask task, Schedule.EventType event) { this.when = Deadline.at(when); this.task = task; this.event = event; }