예제 #1
0
 public void testPollDuration() throws Exception {
   TimeBase.setSimulated(TimeBase.nowMs());
   V3LcapMessage src = this.makePollMessage(6 * Constants.WEEK);
   InputStream srcStream = src.getInputStream();
   V3LcapMessage copy = new V3LcapMessage(srcStream, tempDir, theDaemon);
   assertEqualMessages(src, copy);
   assertEquals(6 * Constants.WEEK, copy.getDuration());
 }
예제 #2
0
  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 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();
  }
예제 #4
0
  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;
  }
예제 #5
0
  // remove task-ending chunk, past task deadline, s.b. Timeout error.
  public void testRemoveChunkTaskEndTimeout() {
    final List finished = new ArrayList();
    StepTask t1 =
        task(
            100,
            200,
            100,
            new TaskCallback() {
              public void taskEvent(SchedulableTask task, Schedule.EventType event) {
                if (log.isDebug2()) {
                  log.debug2("testRemoveChunkTaskEndTimeout callback");
                }
                if (event == Schedule.EventType.FINISH) {
                  finished.add(task);
                }
              }
            });
    Schedule s = sched(ListUtil.list(t1));
    fact.setResult(s);
    assertTrue(tr.addToSchedule(t1));

    Schedule.Chunk chunk = (Schedule.Chunk) s.getEvents().get(0);
    assertTrue(tr.getCurrentSchedule().getEvents().contains(chunk));
    chunk.setTaskEnd();
    TimeBase.setSimulated(201);
    tr.removeChunk(chunk);
    assertFalse(tr.getCurrentSchedule().getEvents().contains(chunk));
    assertSame(t1, finished.get(0));
    assertNotNull(t1.e);
    assertTrue(t1.e.toString(), t1.e instanceof SchedService.Timeout);
    assertEmpty(tr.getAcceptedTasks());
  }
예제 #6
0
 public void testRunStepsWithOverrunDisallowed() {
   StepTask t1 = task(100, 300, 100, null, new MyMockStepper(15, -10));
   //    t1.setOverrunAllowed(true);
   StepTask t2 = task(150, 250, 100, null, new MyMockStepper(10, -10));
   Schedule s = sched(ListUtil.list(t1, t2));
   fact.setResults(s, s);
   assertTrue(tr.addToSchedule(t1));
   assertTrue(tr.addToSchedule(t2));
   TimeBase.setSimulated(101);
   Interrupter intr = null;
   try {
     intr = interruptMeIn(TIMEOUT_SHOULDNT, true);
     while (tr.findTaskToRun()) {
       tr.runSteps(new MutableBoolean(true), null);
     }
     intr.cancel();
   } catch (Exception e) {
     log.error("runSteps threw:", e);
   } finally {
     if (intr.did()) {
       fail("runSteps looped");
     }
   }
   assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(removedTasks));
   assertTrue(t1.e.toString(), t1.e instanceof SchedService.Overrun);
 }
예제 #7
0
 public void testRunStepsWithOverrunAllowed() {
   StepTask t1 = task(100, 500, 30, null, new MyMockStepper(15, -10));
   t1.setOverrunAllowed(true);
   StepTask t2 = task(150, 250, 100, null, new MyMockStepper(10, -10));
   newTr(
       new MyMockTaskRunner(
           new TaskRunner.SchedulerFactory() {
             public Scheduler createScheduler() {
               return new SortScheduler();
             }
           }));
   assertTrue(tr.addToSchedule(t1));
   assertTrue(tr.addToSchedule(t2));
   TimeBase.setSimulated(101);
   assertTrue(tr.findTaskToRun());
   Interrupter intr = null;
   try {
     intr = interruptMeIn(TIMEOUT_SHOULDNT, true);
     while (tr.findTaskToRun()) {
       tr.runSteps(new MutableBoolean(true), null);
     }
     intr.cancel();
   } catch (Exception e) {
     log.error("runSteps threw:", e);
   } finally {
     if (intr.did()) {
       fail("runSteps looped");
     }
   }
   assertNull(t1.e);
   assertTrue(t1.hasOverrun());
 }
예제 #8
0
  public void testStepperThrows() {
    final List finished = new ArrayList();
    TaskCallback cb =
        new TaskCallback() {
          public void taskEvent(SchedulableTask task, Schedule.EventType event) {
            if (event == Schedule.EventType.FINISH) {
              finished.add(task);
            }
          }
        };

    MyMockStepper stepper = new MyMockStepper(10, -10);
    stepper.setWhenToThrow(5);
    StepTask t1 = task(100, 200, 100, cb, stepper);
    Schedule s = sched(ListUtil.list(t1));
    fact.setResult(s);
    assertTrue(tr.addToSchedule(t1));
    TimeBase.setSimulated(101);
    assertTrue(tr.findTaskToRun());
    Interrupter intr = null;
    try {
      intr = interruptMeIn(TIMEOUT_SHOULDNT, true);
      tr.runSteps(new MutableBoolean(true), null);
      intr.cancel();
    } catch (Exception e) {
      log.error("runSteps threw:", e);
    } finally {
      if (intr.did()) {
        fail("runSteps looped");
      }
    }
    assertSame(t1, finished.get(0));
    assertTrue(t1.e instanceof ExpectedRuntimeException);
    assertEquals(5, stepper.nSteps);
  }
예제 #9
0
 public int computeStep(int metric) {
   int work = 0;
   if (nSteps == whenToThrow) {
     throw new ExpectedRuntimeException("Hash step throw test");
   }
   if (nSteps-- > 0) {
     if (eachStepTime > 0) {
       Deadline time = Deadline.in(eachStepTime);
       while (!time.expired()) {
         try {
           Thread.sleep(1);
         } catch (InterruptedException e) {
           throw new RuntimeException(e.toString());
         }
         work++;
       }
     } else {
       work = -eachStepTime;
       TimeBase.step(work);
       try {
         Thread.sleep(1);
       } catch (InterruptedException e) {
         throw new RuntimeException(e.toString());
       }
     }
   }
   return work;
 }
예제 #10
0
 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());
 }
예제 #11
0
  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());
  }
예제 #12
0
 public void setUp() throws Exception {
   super.setUp();
   log.setLevel(Logger.LEVEL_DEBUG);
   if (dig == null) {
     dig = MessageDigest.getInstance(hashAlgorithm);
   }
   mau = new MockArchivalUnit(new MockPlugin());
   cus = new MockCachedUrlSet(mau, null);
   cus.setHashItSource(Collections.EMPTY_LIST);
   TimeBase.setSimulated();
 }
예제 #13
0
 public void setUp() throws Exception {
   super.setUp();
   TimeBase.setSimulated();
   ConfigurationUtil.setFromArgs(SortScheduler.PARAM_OVERHEAD_LOAD, "0");
   removedChunks = new ArrayList();
   removedTasks = new ArrayList();
   fact = new SchedFact(null);
   tr = new MyMockTaskRunner(fact);
   tr.initService(getMockLockssDaemon());
   tr.startService();
 }
예제 #14
0
  protected void setUp() throws Exception {
    super.setUp();
    TimeBase.setSimulated();

    initRequiredServices();

    testau.setPlugin(new MockPlugin());

    initTestPeerIDs();
    initTestMsg();
    initTestPolls();
  }
예제 #15
0
 /**
  * tearDown method for test case
  *
  * @throws Exception if removePoll failed
  */
 public void tearDown() throws Exception {
   pollmanager.stopService();
   theDaemon.getLockssRepository(testau).stopService();
   theDaemon.getHashService().stopService();
   theDaemon.getDatagramRouterManager().stopService();
   theDaemon.getRouterManager().stopService();
   theDaemon.getSystemMetrics().stopService();
   TimeBase.setReal();
   for (int i = 0; i < testV1msg.length; i++) {
     if (testV1msg[i] != null) pollmanager.removePoll(testV1msg[i].getKey());
   }
   super.tearDown();
 }
예제 #16
0
 // 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));
 }
예제 #17
0
  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());
  }
예제 #18
0
 private V3LcapMessage makePollMessage(long duration) {
   V3LcapMessage msg =
       new V3LcapMessage(
           "ArchivalID_2",
           "key",
           "Plug42",
           m_testBytes,
           m_testBytes,
           V3LcapMessage.MSG_POLL,
           TimeBase.nowMs() + duration,
           m_testID,
           tempDir,
           theDaemon);
   return msg;
 }
예제 #19
0
  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);
  }
예제 #20
0
  // one task to drop, succeeds after dropping it
  public void testAddToScheduleOkAfterDrops() {
    log.debug("testAddToScheduleOkAfterDrops()");
    ConfigurationUtil.addFromArgs(
        TaskRunner.PARAM_DROP_TASK_MAX, "10", TaskRunner.PARAM_MIN_CLEANUP_INTERVAL, "0");
    StepTask t1 = task(100, 200, 50);
    StepTask t2 = task(100, 200, 100);
    Schedule sched1 = sched(ListUtil.list(t1));
    Schedule sched2 = sched(ListUtil.list(t2));
    fact.setResults(ListUtil.list(sched1, null, null, sched2, sched2));
    TimeBase.step(101);
    assertTrue(tr.addToSchedule(t1));
    assertIsomorphic(ListUtil.list(t1), fact.scheduler.tasks);
    assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getAcceptedTasks()));
    assertForegroundStat(1, TaskRunner.STAT_ACCEPTED);
    assertForegroundStat(0, TaskRunner.STAT_REFUSED);
    assertForegroundStat(1, TaskRunner.STAT_WAITING);
    assertForegroundStat(0, TaskRunner.STAT_DROPPED);

    assertTrue(tr.addToSchedule(t2));
    assertEquals(
        ListUtil.list(
            ListUtil.list(t1),
            ListUtil.list(t1, t2),
            ListUtil.list(t1),
            Collections.EMPTY_SET,
            ListUtil.list(t1, t2)),
        fact.createArgs);
    assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(fact.scheduler.tasks));
    assertTrue(t1.isDropped());
    assertEquals(sched2, tr.getCurrentSchedule());
    assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(tr.getAcceptedTasks()));
    assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getOverrunTasks()));
    assertForegroundStat(2, TaskRunner.STAT_ACCEPTED);
    assertForegroundStat(0, TaskRunner.STAT_REFUSED);
    assertForegroundStat(1, TaskRunner.STAT_WAITING);
    assertForegroundStat(1, TaskRunner.STAT_DROPPED);

    t2.cancel();
    assertForegroundStat(2, TaskRunner.STAT_ACCEPTED);
    assertForegroundStat(0, TaskRunner.STAT_REFUSED);
    assertForegroundStat(0, TaskRunner.STAT_WAITING);
    assertForegroundStat(1, TaskRunner.STAT_DROPPED);
    assertForegroundStat(1, TaskRunner.STAT_CANCELLED);
  }
예제 #21
0
 /*
  * 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);
 }
예제 #22
0
 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);
 }
예제 #23
0
 // test resched with overrun task doesn't lose task.
 public void testRunStepsWithOverrunAllowedPlusResched() {
   StepTask t1 = task(100, 500, 30, null, new MyMockStepper(15, -10));
   t1.setOverrunAllowed(true);
   StepTask t2 = task(150, 250, 100, null, new MyMockStepper(10, -10));
   newTr(
       new MyMockTaskRunner(
           new TaskRunner.SchedulerFactory() {
             public Scheduler createScheduler() {
               return new SortScheduler();
             }
           }));
   assertTrue(tr.addToSchedule(t1));
   assertEmpty(tr.getOverrunTasks());
   TimeBase.setSimulated(101);
   assertTrue(tr.findTaskToRun());
   t1.timeUsed = 1000;
   assertTrue(t1.hasOverrun());
   assertEmpty(tr.getOverrunTasks());
   assertTrue(tr.addToSchedule(t2));
   assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getOverrunTasks()));
 }
  public void testStorePollHistories() throws Exception {
    TimeBase.setSimulated(123321);
    MockCachedUrlSetSpec mspec = new MockCachedUrlSetSpec("http://www.example.com", null);
    CachedUrlSet mcus = new MockCachedUrlSet(mau, mspec);
    NodeStateImpl nodeState = new NodeStateImpl(mcus, -1, null, null, repository);
    List histories =
        ListUtil.list(
            createPollHistoryBean(3),
            createPollHistoryBean(3),
            createPollHistoryBean(3),
            createPollHistoryBean(3),
            createPollHistoryBean(3));

    /*
     * CASTOR: [summary] Rewrite test in non-Castor way
     * This is obviously not an appropriate way of writing this test,
     * Right now it creates sample data in Castor format, from legacy
     * code back when Castor was the built-in serialization engine.
     * TODO: Rewrite test in non-Castor way
     */
    // nodeState.setPollHistoryBeanList(histories);
    nodeState.setPollHistoryList(NodeHistoryBean.fromBeanListToList(histories));

    repository.storePollHistories(nodeState);
    String filePath = LockssRepositoryImpl.mapAuToFileLocation(tempDirPath, mau);
    filePath =
        LockssRepositoryImpl.mapUrlToFileLocation(
            filePath, "http://www.example.com/" + HistoryRepositoryImpl.HISTORY_FILE_NAME);
    File xmlFile = new File(filePath);
    assertTrue(xmlFile.exists());

    nodeState.setPollHistoryList(new ArrayList());
    repository.loadPollHistories(nodeState);
    List loadedHistory = nodeState.getPollHistoryList();
    assertEquals(histories.size(), loadedHistory.size());
    // CASTOR: some Castor-tailored stuff here
    // PollHistoryBean expect1 = (PollHistoryBean)histories.get(0);
    // PollHistoryBean elem1 = (PollHistoryBean)loadedHistory.get(0);
    PollHistory expect1 = (PollHistory) histories.get(0);
    PollHistory elem1 = (PollHistory) loadedHistory.get(0);
    assertEquals(expect1.type, elem1.type);
    assertEquals(expect1.lwrBound, elem1.lwrBound);
    assertEquals(expect1.uprBound, elem1.uprBound);
    assertEquals(expect1.status, elem1.status);
    assertEquals(expect1.startTime, elem1.startTime);
    assertEquals(expect1.duration, elem1.duration);
    // CASTOR: some Castor-tailored stuff here
    // List expectBeans = (List)expect1.getVoteBeans();
    // List elemBeans = (List)elem1.getVoteBeans();
    Iterator expectIter = (Iterator) expect1.getVotes();
    Iterator elemIter = (Iterator) elem1.getVotes();
    while (expectIter.hasNext() && elemIter.hasNext()) {
      Vote expectVote = (Vote) expectIter.next();
      Vote elemVote = (Vote) elemIter.next();
      assertEquals(
          expectVote.getVoterIdentity().getIdString(), elemVote.getVoterIdentity().getIdString());
      assertEquals(expectVote.isAgreeVote(), elemVote.isAgreeVote());
      assertEquals(expectVote.getChallengeString(), elemVote.getChallengeString());
      assertEquals(expectVote.getVerifierString(), elemVote.getVerifierString());
      assertEquals(expectVote.getHashString(), elemVote.getHashString());
    }
    assertFalse(expectIter.hasNext());
    assertFalse(expectIter.hasNext());
    TimeBase.setReal();
  }
예제 #25
0
  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());
  }
예제 #26
0
 public void tearDown() throws Exception {
   TimeBase.setReal();
   super.tearDown();
 }
예제 #27
0
 public void setUp() throws Exception {
   super.setUp();
   TimeBase.setSimulated();
 }
예제 #28
0
 public void tearDown() throws Exception {
   TimeBase.setReal();
   tr.stopService();
   super.tearDown();
 }
예제 #29
0
  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);
  }