Search in sources :

Example 6 with FakeOutputStream

use of com.facebook.buck.testutil.FakeOutputStream in project buck by facebook.

the class ConsoleHandlerTest method setUp.

@Before
public void setUp() {
    outputStream = new FakeOutputStream();
    threadIdToCommandId = new ConcurrentHashMap<>();
    commandIdToConsoleWriter = new ConcurrentHashMap<>();
    commandIdToLevel = new ConcurrentHashMap<>();
    state = new ConsoleHandlerState() {

        @Override
        public Level getLogLevel(String commandId) {
            return commandIdToLevel.get(commandId);
        }

        @Override
        public ConsoleHandlerState.Writer getWriter(String commandId) {
            return commandIdToConsoleWriter.get(commandId);
        }

        @Override
        public Iterable<ConsoleHandlerState.Writer> getAllAvailableWriters() {
            return commandIdToConsoleWriter.values();
        }

        @Override
        public String threadIdToCommandId(long threadId) {
            return threadIdToCommandId.get(threadId);
        }
    };
}
Also used : FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Level(java.util.logging.Level) Before(org.junit.Before)

Example 7 with FakeOutputStream

use of com.facebook.buck.testutil.FakeOutputStream in project buck by facebook.

the class ConsoleHandlerTest method logMessageWithUnregisteredThreadIdGoesToAllConsoles.

@Test
public void logMessageWithUnregisteredThreadIdGoesToAllConsoles() throws IOException {
    FakeOutputStream outputStream1 = new FakeOutputStream();
    FakeOutputStream outputStream2 = new FakeOutputStream();
    FakeOutputStream outputStream3 = new FakeOutputStream();
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream1), new MessageOnlyFormatter(), Level.INFO, state);
    threadIdToCommandId.put(49152L, "commandIdForOutputStream2");
    threadIdToCommandId.put(64738L, "commandIdForOutputStream3");
    registerOutputStream("commandIdForOutputStream2", outputStream2);
    registerOutputStream("commandIdForOutputStream3", outputStream3);
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "What thread is this?", 999999));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo("What thread is this?"));
    assertThat(outputStream3.toString("UTF-8"), equalTo("What thread is this?"));
}
Also used : FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Test(org.junit.Test)

Example 8 with FakeOutputStream

use of com.facebook.buck.testutil.FakeOutputStream in project buck by facebook.

the class ConsoleHandlerTest method logRecordsOnlyGoToRegisteredOutputStream.

@Test
public void logRecordsOnlyGoToRegisteredOutputStream() throws IOException {
    FakeOutputStream outputStream1 = new FakeOutputStream();
    FakeOutputStream outputStream2 = new FakeOutputStream();
    FakeOutputStream outputStream3 = new FakeOutputStream();
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream1), new MessageOnlyFormatter(), Level.INFO, state);
    threadIdToCommandId.put(49152L, "commandIdForOutputStream2");
    threadIdToCommandId.put(64738L, "commandIdForOutputStream3");
    registerOutputStream("commandIdForOutputStream2", outputStream2);
    registerOutputStream("commandIdForOutputStream3", outputStream3);
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "Stream 2", 49152));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
    assertThat(outputStream3.toString("UTF-8"), equalTo(""));
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "Stream 3", 64738));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
    assertThat(outputStream3.toString("UTF-8"), equalTo("Stream 3"));
}
Also used : FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Test(org.junit.Test)

Example 9 with FakeOutputStream

use of com.facebook.buck.testutil.FakeOutputStream in project buck by facebook.

the class ConsoleHandlerTest method levelOverrideAppliesOnlyToRegisteredStream.

@Test
public void levelOverrideAppliesOnlyToRegisteredStream() throws IOException {
    FakeOutputStream outputStream1 = new FakeOutputStream();
    FakeOutputStream outputStream2 = new FakeOutputStream();
    FakeOutputStream outputStream3 = new FakeOutputStream();
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream1), new MessageOnlyFormatter(), Level.INFO, state);
    threadIdToCommandId.put(49152L, "commandIdForOutputStream2");
    threadIdToCommandId.put(64738L, "commandIdForOutputStream3");
    registerOutputStream("commandIdForOutputStream2", outputStream2);
    registerOutputStream("commandIdForOutputStream3", outputStream3);
    publishAndFlush(handler, newLogRecordWithThreadId(Level.FINE, "Shh..", 49152));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo(""));
    assertThat(outputStream3.toString("UTF-8"), equalTo(""));
    publishAndFlush(handler, newLogRecordWithThreadId(Level.FINE, "Shh..", 64738));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo(""));
    assertThat(outputStream3.toString("UTF-8"), equalTo(""));
    commandIdToLevel.put("commandIdForOutputStream3", Level.ALL);
    publishAndFlush(handler, newLogRecordWithThreadId(Level.FINE, "Stream 3", 64738));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo(""));
    assertThat(outputStream3.toString("UTF-8"), equalTo("Stream 3"));
}
Also used : FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Test(org.junit.Test)

Aggregations

FakeOutputStream (com.facebook.buck.testutil.FakeOutputStream)9 Test (org.junit.Test)8 PrintStream (java.io.PrintStream)1 Level (java.util.logging.Level)1 LogRecord (java.util.logging.LogRecord)1 Before (org.junit.Before)1