@Override public void log(Request request, Response response) { long currentTime = currentTimeMillisProvider.getCurrentTimeMillis(); HttpRequestEvent event = createHttpRequestEvent(request, response, traceTokenManager, currentTime); fileAppender.doAppend(event); eventClient.post(event); }
public void run() { while (!isDone()) { counter++; rfa.doAppend(id + " " + counter); if ((counter % 64 == 0) && withInducedDelay) { try { Thread.sleep(10); } catch (InterruptedException e) { } } } } }
@Override public void publish(LogRecord record) { if (!isLoggable(record)) { return; } String message; try { message = getFormatter().format(record); } catch (Exception e) { // catch any exception to assure logging always works reportError(null, e, FORMAT_FAILURE); return; } try { fileAppender.doAppend(message); } catch (Exception e) { // catch any exception to assure logging always works reportError(null, e, WRITE_FAILURE); } }
rfa.doAppend(sb.toString()); addExpectedFileNamedIfItsTime_ByDate(fileNamePatternStr); incCurrentTime(singleTickDuration);
private long logOverMultiplePeriods(ConfigParameters cp) { buildRollingFileAppender(cp); final int ticksPerPeriod = 216; int runLength = cp.simulatedNumberOfPeriods * ticksPerPeriod; int startInactivityIndex = cp.startInactivity * ticksPerPeriod; int endInactivityIndex = startInactivityIndex + cp.numInactivityPeriods * ticksPerPeriod; long tickDuration = cp.periodDurationInMillis / ticksPerPeriod; for (int i = 0; i <= runLength; i++) { if (i < startInactivityIndex || i > endInactivityIndex) { Date currentDate = new Date(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime()); StringBuilder sb = new StringBuilder("Hello"); String currentDateStr = currentDate.toString(); String iAsString = Integer.toString(i); sb.append(currentDateStr); SpacePadder.spacePad(sb, 66 + (3 - iAsString.length() - currentDateStr.length())); sb.append(iAsString); rfa.doAppend(sb.toString()); } tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime() + tickDuration); add(tbrp.compressionFuture); add(tbrp.cleanUpFuture); waitForJobsToComplete(); } rfa.stop(); return tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime(); } }
private void secondPhase(String testId, String file, String stem, String compressionSuffix, int runLength, String prefix) { rfa1.stop(); if (stem != null) { File f = new File(file); f.setLastModified(currentTime); } StatusManager sm = context.getStatusManager(); sm.add(new InfoStatus("Time when rfa1 is stopped: " + new Date(currentTime), this)); sm.add(new InfoStatus("currentTime%1000=" + (currentTime % 1000), this)); initRollingFileAppender(rfa2, file); initPolicies(rfa2, tbrp2, randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + ", GMT}-%i.txt" + compressionSuffix, sizeThreshold, currentTime); for (int i = runLength; i < runLength * 2; i++) { incCurrentTime(100); tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); String msg = prefix + i; rfa2.doAppend(msg); addExpectedFileNamedIfItsTime(randomOutputDir, testId, msg, compressionSuffix); } }
@Test public void testFileNameWithParenthesis() { // if ')' is not escaped, the test throws // java.lang.IllegalStateException: FileNamePattern [.../program(x86)/toto-%d.log] does not contain a valid DateToken rfa.setContext(context); tbrp .setFileNamePattern(randomOutputDir + "program(x86)/toto-%d.log"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); rfa.doAppend("hello"); }
private 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 + ", GMT}"; 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(400); tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); add(tbrp2.compressionFuture); add(tbrp2.cleanUpFuture); } rfa2.stop(); }
void generic(String testName, String fileName, String filenamePattern, List<String> expectedFilenameList) throws InterruptedException, IOException { rfa.setName("ROLLING"); initRFA(randomOutputDir + fileName); sizeBasedTriggeringPolicy.setMaxFileSize(new FileSize(100)); fwrp.setMinIndex(0); fwrp.setFileNamePattern(randomOutputDir + filenamePattern); rfa.triggeringPolicy = sizeBasedTriggeringPolicy; rfa.rollingPolicy = fwrp; fwrp.start(); sizeBasedTriggeringPolicy.start(); rfa.start(); int runLength = 40; String prefix = "hello"; for (int i = 0; i < runLength; i++){ Thread.sleep(10); rfa.doAppend(prefix + i); } rfa.stop(); existenceCheck(expectedFilenameList); reverseSortedContentCheck(randomOutputDir, runLength, prefix); }
rfa1.doAppend(msg); addExpectedFileNamedIfItsTime(randomOutputDir, testId, msg, compressionSuffix); incCurrentTime(20);
private void genericTest(String testId, String patternPrefix, String compressionSuffix, boolean fileOptionIsSet, int waitDuration) throws IOException { String fileName = fileOptionIsSet ? testId2FileName(testId) : null; initRFA(rfa1, fileName); String fileNamePatternStr = randomOutputDir + patternPrefix + "-%d{" + DATE_PATTERN_WITH_SECONDS + ", GMT}" + 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); add(tbrp1.compressionFuture); add(tbrp1.cleanUpFuture); } rfa1.stop(); waitForJobsToComplete(); if (waitDuration != NO_RESTART) { doRestart(testId, patternPrefix, fileOptionIsSet, waitDuration); } waitForJobsToComplete(); massageExpectedFilesToCorresponToCurrentTarget(fileName, fileOptionIsSet); StatusPrinter.print(context); rolloverChecker.check(expectedFilenameList); }