Search in sources :

Example 71 with ByteArrayOutputStream

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());
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 72 with ByteArrayOutputStream

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"));
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 73 with ByteArrayOutputStream

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.");
    }
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Test(org.junit.Test)

Example 74 with ByteArrayOutputStream

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);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream)

Example 75 with ByteArrayOutputStream

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;
    }
}
Also used : ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) IOException(java.io.IOException) UUID(java.util.UUID) Segment(org.apache.jackrabbit.oak.segment.Segment)

Aggregations

ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)92 Test (org.junit.Test)36 DataOutputStream (java.io.DataOutputStream)15 IOException (java.io.IOException)14 HashSet (java.util.HashSet)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)12 Configuration (org.apache.hadoop.conf.Configuration)12 PrintStream (java.io.PrintStream)10 SparkConf (org.apache.spark.SparkConf)10 Edge (uk.gov.gchq.gaffer.data.element.Edge)10 Element (uk.gov.gchq.gaffer.data.element.Element)10 Entity (uk.gov.gchq.gaffer.data.element.Entity)10 Graph (uk.gov.gchq.gaffer.graph.Graph)10 User (uk.gov.gchq.gaffer.user.User)10 File (java.io.File)9 HashMap (java.util.HashMap)8 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)6