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);
}
};
}
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?"));
}
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"));
}
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"));
}
Aggregations