예제 #1
0
  /** Test rolling without compression, file option left blank, no stop/start */
  @Test
  public void noCompression_FileBlank_NoRestart_1() throws Exception {
    String testId = "test1";
    initRFA(rfa1, null);
    initTRBP(
        rfa1,
        tbrp1,
        randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}",
        currentTime);

    // compute the current filename
    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), false);

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

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

    int i = 0;
    for (String fn : expectedFilenameList) {
      assertTrue(
          Compare.compare(
              fn, CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-" + testId + "." + i++));
    }
  }
예제 #2
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++));
    }
  }
예제 #3
0
  /** With compression, file option set, no stop/restart, */
  @Test
  public void withCompression_FileSet_NoRestart_6() throws Exception {

    String testId = "test6";

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

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

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

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

    massageExpectedFilesToCorresponToCurrentTarget("test6.log");

    int i = 0;
    for (String fn : expectedFilenameList) {
      assertTrue(
          Compare.compare(
              fn,
              CoreTestConstants.TEST_SRC_PREFIX
                  + "witness/rolling/tbr-"
                  + testId
                  + "."
                  + i
                  + addGZIfNotLast(i)));
      i++;
    }
  }
예제 #4
0
  @Test
  public void withMissingTargetDir() throws Exception {
    String testId = "missingTargetDir";

    initRFA(rfa1, testId2FileName(testId));
    int secondDiff = RandomUtil.getPositiveInt();
    String randomTargetDir = CoreTestConstants.OUTPUT_DIR_PREFIX + secondDiff + '/';

    System.out.println("randomOutputDir" + randomOutputDir);
    System.out.println("randomTargetDir" + randomTargetDir);

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

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

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

    for (int i = 0; i < 3; i++) {
      rfa1.doAppend("Hello---" + i);
      addExpectedFileNamedIfItsTime_ByDate(randomTargetDir, testId, false);
      incCurrentTime(500);
      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
    }
    massageExpectedFilesToCorresponToCurrentTarget("missingTargetDir.log");
    int i = 0;
    for (String fn : expectedFilenameList) {
      System.out.println("expectedFile=" + fn);
      assertTrue(
          Compare.compare(
              fn, CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-test5." + i++));
    }
  }
예제 #5
0
  /** With compression, file option left blank, no stop/restart */
  @Test
  public void withCompression_FileBlank_NoRestart_2() throws Exception {
    String testId = "test2";
    initRFA(rfa1, null);
    initTRBP(
        rfa1,
        tbrp1,
        randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + "}.gz",
        currentTime);

    addExpectedFileName_ByDate(randomOutputDir, testId, getDateOfCurrentPeriodsStart(), true);
    incCurrentTime(1100);
    tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);

    for (int i = 0; i < 3; i++) {
      // when i == 2, file name should not have .gz extension
      addExpectedFileNamedIfItsTime_ByDate(randomOutputDir, testId, i != 2);
      rfa1.doAppend("Hello---" + i);
      incCurrentTime(500);
      tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime);
      waitForCompression(tbrp1);
    }

    int i = 0;
    for (String fn : expectedFilenameList) {
      assertTrue(
          Compare.compare(
              fn,
              CoreTestConstants.TEST_SRC_PREFIX
                  + "witness/rolling/tbr-"
                  + testId
                  + "."
                  + i
                  + addGZIfNotLast(i)));
      i++;
    }
  }
예제 #6
0
 public void check(List<String> expectedFilenameList) throws IOException {
   int lastIndex = expectedFilenameList.size() - 1;
   String lastFile = expectedFilenameList.get(lastIndex);
   String witnessFileName = CoreTestConstants.TEST_SRC_PREFIX + "witness/rolling/tbr-" + testId;
   assertTrue(Compare.compare(lastFile, witnessFileName));
 }