Search in sources :

Example 1 with FakeOutputStream

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

the class TargetsCommandTest method testPrintNullDelimitedTargets.

@Test
public void testPrintNullDelimitedTargets() throws UnsupportedEncodingException {
    Iterable<String> targets = ImmutableList.of("//foo:bar", "//foo:baz");
    FakeOutputStream fakeStream = new FakeOutputStream();
    PrintStream printStream = new PrintStream(fakeStream);
    TargetsCommand.printNullDelimitedTargets(targets, printStream);
    printStream.flush();
    assertEquals("//foo:bar\0//foo:baz\0", fakeStream.toString(Charsets.UTF_8.name()));
}
Also used : PrintStream(java.io.PrintStream) FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Test(org.junit.Test)

Example 2 with FakeOutputStream

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

the class ConsoleHandlerTest method logRecordPublishedWithMultipleThreadIdsForSingleCommandId.

@Test
public void logRecordPublishedWithMultipleThreadIdsForSingleCommandId() 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(49153L, "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, " - Another Stream 2", 49153));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2 - Another Stream 2"));
    assertThat(outputStream3.toString("UTF-8"), equalTo(""));
}
Also used : FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Test(org.junit.Test)

Example 3 with FakeOutputStream

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

the class ConsoleHandlerTest method consoleHandlerCanChangeOutputStreamWithoutClosing.

@Test
public void consoleHandlerCanChangeOutputStreamWithoutClosing() throws IOException {
    FakeOutputStream outputStream1 = new FakeOutputStream();
    FakeOutputStream outputStream2 = new FakeOutputStream();
    ConsoleHandler handler = new ConsoleHandler(ConsoleHandler.utf8OutputStreamWriter(outputStream1), new MessageOnlyFormatter(), Level.INFO, state);
    publishAndFlush(handler, new LogRecord(Level.INFO, "Stream 1"));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1"));
    threadIdToCommandId.put(49152L, "commandIdForOutputStream2");
    registerOutputStream("commandIdForOutputStream2", outputStream2);
    assertThat(outputStream1.isClosed(), equalTo(false));
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "Stream 2", 49152));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1"));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
    unregisterOutputStream("commandIdForOutputStream2");
    assertThat(outputStream2.isClosed(), equalTo(false));
    publishAndFlush(handler, new LogRecord(Level.INFO, " - DONE"));
    assertThat(outputStream1.toString("UTF-8"), equalTo("Stream 1 - DONE"));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
}
Also used : LogRecord(java.util.logging.LogRecord) FakeOutputStream(com.facebook.buck.testutil.FakeOutputStream) Test(org.junit.Test)

Example 4 with FakeOutputStream

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

the class ConsoleHandlerTest method previouslyRegisteredOutputStreamCanBeOverridden.

@Test
public void previouslyRegisteredOutputStreamCanBeOverridden() 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");
    registerOutputStream("commandIdForOutputStream2", outputStream2);
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "Stream 2", 49152));
    assertThat(outputStream1.toString("UTF-8"), equalTo(""));
    assertThat(outputStream2.toString("UTF-8"), equalTo("Stream 2"));
    registerOutputStream("commandIdForOutputStream2", outputStream3);
    publishAndFlush(handler, newLogRecordWithThreadId(Level.INFO, "Stream 3", 49152));
    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 5 with FakeOutputStream

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

the class ConsoleHandlerTest method levelOverrideCanBeRemoved.

@Test
public void levelOverrideCanBeRemoved() 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);
    commandIdToLevel.put("commandIdForOutputStream3", Level.FINE);
    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"));
    commandIdToLevel.remove("commandIdForOutputStream3");
    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("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