Exemplo n.º 1
0
  @Test
  public void noCompression_FileSet_StopRestart_WithLongWait_4B() throws Exception {
    String testId = "test4B";
    initRFA(rfa1, testId2FileName(testId));
    initTRBP(
        rfa1,
        tbrp1,
        randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}",
        currentTime);

    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);

    incCurrentTime(1100);
    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);

    for (int i = 0; i <= 2; i++) {
      rfa1.doAppend("Hello---" + i);
      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
      incCurrentTime(500);
      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
    }

    rfa1.stop();

    // change the timestamp of the currently actively file
    File activeFile = new File(rfa1.getFile());
    activeFile.setLastModified(currentTime);

    incCurrentTime(2000);

    initRFA(rfa2, randomOutputDir + "test4B.log");
    initTRBP(
        rfa2,
        tbrp2,
        randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}",
        currentTime);

    for (int i = 0; i <= 2; i++) {
      rfa2.doAppend("World---" + i);
      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
      incCurrentTime(100);
      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
    }

    massageExpectedFilesToCorresponToCurrentTarget("test4B.log");

    int i = 0;
    for (String fn : expectedFilenameList) {
      assertTrue(
          Compare.compare(
              fn, CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-test4B." + i++));
    }
  }
Exemplo n.º 2
0
  /** No compression, file option left blank, with stop/restart, */
  @Test
  public void noCompression_FileBlank_StopRestart_3() throws Exception {
    String testId = "test3";

    initRFA(rfa1, null);
    initTRBP(
        rfa1,
        tbrp1,
        randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}",
        currentTime);

    // a new file is created by virtue of rfa.start();
    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);

    incCurrentTime(1100);
    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);

    for (int i = 0; i <= 2; i++) {
      rfa1.doAppend("Hello---" + i);
      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
      incCurrentTime(500);
      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
    }

    rfa1.stop();

    initRFA(rfa2, null);
    initTRBP(
        rfa2,
        tbrp2,
        randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}",
        tbrp1.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime());

    for (int i = 0; i <= 2; i++) {
      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, false);
      rfa2.doAppend("World---" + i);
      incCurrentTime(100);
      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
    }

    int i = 0;
    for (String fn : expectedFilenameList) {
      assertTrue(
          Compare.compare(
              fn, CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-" + testId + "." + i++));
    }
  }
Exemplo n.º 3
0
  void genericTest(
      String testId,
      String patternPrefix,
      String compressionSuffix,
      boolean fileOptionIsSet,
      int waitDuration)
      throws IOException {
    boolean withCompression = compressionSuffix.length() > 0;
    String fileName = fileOptionIsSet ? testId2FileName(testId) : null;
    initRFA(rfa1, fileName);

    String fileNamePatternStr =
        randomOutputDir
            + patternPrefix
            + "-%d{"
            + DATE_PATTERN_WITH_SECONDS
            + "}"
            + compressionSuffix;

    initTRBP(rfa1, tbrp1, fileNamePatternStr, currentTime);

    // compute the current filename
    addExpectedFileName_ByDate(fileNamePatternStr, getMillisOfCurrentPeriodsStart());

    incCurrentTime(1100);
    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);

    for (int i = 0; i < 3; i++) {
      rfa1.doAppend("Hello---" + i);
      addExpectedFileNamedIfItsTime_ByDate(fileNamePatternStr);
      incCurrentTime(500);
      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
      if (withCompression) waitForCompression(tbrp1);
    }
    rfa1.stop();

    if (waitDuration != NO_RESTART) {
      doRestart(testId, patternPrefix, fileOptionIsSet, waitDuration);
    }

    massageExpectedFilesToCorresponToCurrentTarget(fileName, fileOptionIsSet);

    StatusPrinter.print(context);

    rolloverChecker.check(expectedFilenameList);
  }
Exemplo n.º 4
0
  void doRestart(String testId, String patternPart, boolean fileOptionIsSet, int waitDuration) {
    // change the timestamp of the currently actively file
    File activeFile = new File(rfa1.getFile());
    activeFile.setLastModified(currentTime);

    incCurrentTime(waitDuration);

    String filePatternStr =
        randomOutputDir + patternPart + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}";

    String fileName = fileOptionIsSet ? testId2FileName(testId) : null;
    initRFA(rfa2, fileName);
    initTRBP(rfa2, tbrp2, filePatternStr, currentTime);
    for (int i = 0; i < 3; i++) {
      rfa2.doAppend("World---" + i);
      addExpectedFileNamedIfItsTime_ByDate(filePatternStr);
      incCurrentTime(100);
      tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
    }
    rfa2.stop();
  }
 @After
 public void tearDown() throws Exception {
   rfa.stop();
 }