Exemplo n.º 1
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());
  }
Exemplo n.º 2
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());
  }