use of org.apache.commons.io.output.ByteArrayOutputStream in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testDebugMode.
@Test
public void testDebugMode() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
Exception ex = new Exception("Test exception.");
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex, Level.DEBUG);
LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex, Level.DEBUG);
LoggingEvent event3 = getLoggingEventForTest("Test Exception.", ex, Level.DEBUG);
appender.append(event1);
appender.append(event2);
appender.append(event3);
String logging = os.toString("UTF8");
// 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
Matcher m = initPattern.matcher(logging);
// everything should get logged with a DEBUG logger, so we should't find the StackTraceKey pattern.
assertFalse(m.matches());
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testCacheExceeded.
@Test
public void testCacheExceeded() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
final int HISTORY_SIZE = 100;
final int TEST_TOTAL = HISTORY_SIZE * 4;
appender.setHistorySize(HISTORY_SIZE);
for (int i = 0; i < TEST_TOTAL; i++) {
Exception ex = new Exception("Test exception." + i);
LoggingEvent event = getLoggingEventForTest("Test Exception.", ex);
appender.append(event);
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
appender.append(event1);
}
String logging = os.toString("UTF8");
assertEquals(TEST_TOTAL, StringUtils.countMatches(logging, "StackTraceKey.init"));
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testDuplicatedLogMessages.
@Test
public void testDuplicatedLogMessages() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
Exception ex = new Exception("Test exception.");
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event3 = getLoggingEventForTest("Test Exception.", ex);
appender.append(event1);
appender.append(event2);
appender.append(event3);
String logging = os.toString("UTF8");
// 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
Matcher m = initPattern.matcher(logging);
if (m.matches()) {
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(3, StringUtils.countMatches(logging, stackTraceKey));
} else {
fail("Didn't find proper logging pattern.");
}
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project SSM by Intel-bigdata.
the class ActionStatus method init.
public void init() {
finished = false;
startTime = Time.monotonicNow();
successful = false;
resultOs = new ByteArrayOutputStream(64 * 1024);
psResultOs = new PrintStream(resultOs, false);
logOs = new ByteArrayOutputStream(64 * 1024);
psLogOs = new PrintStream(logOs, false);
}
use of org.apache.commons.io.output.ByteArrayOutputStream in project jackrabbit-oak by apache.
the class DefaultStandbySegmentReader method readSegment.
@Override
public byte[] readSegment(String segmentId) {
UUID uuid = UUID.fromString(segmentId);
long msb = uuid.getMostSignificantBits();
long lsb = uuid.getLeastSignificantBits();
Segment segment = readSegmentWithRetry(store, store.getSegmentIdProvider().newSegmentId(msb, lsb));
if (segment == null) {
return null;
}
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
segment.writeTo(stream);
return stream.toByteArray();
} catch (IOException e) {
log.warn("Error while reading segment content", e);
return null;
}
}
Aggregations