Example #1
0
  @Test
  public void testTruncates() {
    expect(wrappedLog.log(MESSAGES)).andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("1", "2", "3", "4", "5", "a"))).andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("1", "2", "3", "4", "5", "a", "b"))).andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("1", "2", "3", "4", "5", "a", "b", "c"))).andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("1", "2", "3", "4", "5", "a", "b", "c", "d")))
        .andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("1", "2", "3", "4", "5", "a", "b", "c", "d", "e")))
        .andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("1", "2", "3", "4", "5", "a", "b", "c", "d", "e", "f")))
        .andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("2", "3", "4", "5", "a", "b", "c", "d", "e", "f", "g")))
        .andReturn(FALSE);
    expect(wrappedLog.log(Arrays.asList("3", "4", "5", "a", "b", "c", "d", "e", "f", "g", "h")))
        .andReturn(TRUE);

    replay(wrappedLog);

    bufferedLog.log(MESSAGES);
    bufferedLog.log("a");
    bufferedLog.log("b");
    bufferedLog.log("c");
    bufferedLog.log("d");
    bufferedLog.log("e");
    bufferedLog.log("f");
    bufferedLog.log("g");
    bufferedLog.log("h");
  }
Example #2
0
  @Test
  public void testFlush() {
    expect(wrappedLog.log(Arrays.asList("a", "b", "c"))).andReturn(TRUE);

    replay(wrappedLog);
    bufferedLog.log("a");
    bufferedLog.log("b");
    bufferedLog.log("c");
    bufferedLog.flush();
  }
Example #3
0
  @Test
  public void testBufferRetries() {
    List<String> bufferAppended = ImmutableList.<String>builder().addAll(MESSAGES).add("6").build();

    expect(wrappedLog.log(MESSAGES)).andReturn(FALSE);
    expect(wrappedLog.log(bufferAppended)).andReturn(TRUE);

    replay(wrappedLog);
    bufferedLog.log(MESSAGES);
    bufferedLog.log("6");
  }
Example #4
0
  @Test
  public void testBuffers() {
    expect(wrappedLog.log(MESSAGES)).andReturn(TRUE);

    replay(wrappedLog);
    bufferedLog.log(MESSAGES);
  }
Example #5
0
  @Before
  @SuppressWarnings("unchecked") // Due to createMock.
  public void setUp() {
    wrappedLog = createMock(Log.class);

    bufferedLog =
        BufferedLog.<String, Boolean>builder()
            .buffer(wrappedLog)
            .withRetryFilter(RETRY_FILTER)
            .withChunkLength(BUFFER_SIZE)
            .withMaxBuffer(MAX_BUFFER_SIZE)
            .withFlushInterval(Amount.of(10000, Time.SECONDS))
            .withExecutorService(MoreExecutors.sameThreadExecutor())
            .build();
  }
Example #6
0
 @After
 public void runTest() {
   verify(wrappedLog);
   assertThat(bufferedLog.getBacklog(), is(0));
 }