Search in sources :

Example 1 with TestableBuffer

use of org.komamitsu.fluency.buffer.TestableBuffer in project fluency by komamitsu.

the class AsyncFlusherTest method testAsyncFlusher.

@Test
public void testAsyncFlusher() throws IOException, InterruptedException {
    TestableBuffer buffer = new TestableBuffer.Config().createInstance();
    MockTCPSender sender = new MockTCPSender(24225);
    AsyncFlusher.Config config = new AsyncFlusher.Config();
    config.setFlushIntervalMillis(500);
    Flusher flusher = config.createInstance(buffer, sender);
    assertEquals(0, buffer.getFlushCount().get());
    flusher.onUpdate();
    assertEquals(0, buffer.getFlushCount().get());
    flusher.flush();
    TimeUnit.MILLISECONDS.sleep(50);
    assertEquals(0, buffer.getFlushCount().get());
    assertEquals(1, buffer.getForceFlushCount().get());
    TimeUnit.SECONDS.sleep(1);
    int flushCount = buffer.getFlushCount().get();
    assertTrue(1 <= flushCount && flushCount <= 3);
    int forceFlushCount = buffer.getForceFlushCount().get();
    assertEquals(1, forceFlushCount);
    assertEquals(0, buffer.getCloseCount().get());
    flusher.close();
    assertEquals(1, buffer.getCloseCount().get());
    assertThat(buffer.getFlushCount().get(), is(greaterThanOrEqualTo(2)));
    assertThat(buffer.getFlushCount().get(), is(lessThanOrEqualTo(3)));
    assertThat(buffer.getForceFlushCount().get(), is(greaterThanOrEqualTo(2)));
    assertThat(buffer.getForceFlushCount().get(), is(lessThanOrEqualTo(3)));
}
Also used : MockTCPSender(org.komamitsu.fluency.sender.MockTCPSender) TestableBuffer(org.komamitsu.fluency.buffer.TestableBuffer) Test(org.junit.Test)

Example 2 with TestableBuffer

use of org.komamitsu.fluency.buffer.TestableBuffer in project fluency by komamitsu.

the class SyncFlusherTest method testSyncFlusher.

@Test
public void testSyncFlusher() throws IOException, InterruptedException {
    TestableBuffer buffer = new TestableBuffer.Config().createInstance();
    MockTCPSender sender = new MockTCPSender(24225);
    SyncFlusher.Config config = new SyncFlusher.Config();
    assertEquals(600, config.getFlushIntervalMillis());
    Flusher flusher = config.createInstance(buffer, sender);
    flusher.flush();
    flusher.flush();
    flusher.flush();
    assertEquals(0, buffer.getFlushCount().get());
    assertEquals(3, buffer.getForceFlushCount().get());
    flusher.onUpdate();
    flusher.onUpdate();
    flusher.onUpdate();
    assertEquals(0, buffer.getFlushCount().get());
    assertEquals(3, buffer.getForceFlushCount().get());
    TimeUnit.SECONDS.sleep(1);
    flusher.onUpdate();
    assertEquals(1, buffer.getFlushCount().get());
    assertEquals(3, buffer.getForceFlushCount().get());
    assertEquals(0, buffer.getCloseCount().get());
    flusher.close();
    assertEquals(1, buffer.getCloseCount().get());
    assertEquals(1, buffer.getFlushCount().get());
    assertEquals(3 + 1, buffer.getForceFlushCount().get());
}
Also used : MockTCPSender(org.komamitsu.fluency.sender.MockTCPSender) TestableBuffer(org.komamitsu.fluency.buffer.TestableBuffer) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 TestableBuffer (org.komamitsu.fluency.buffer.TestableBuffer)2 MockTCPSender (org.komamitsu.fluency.sender.MockTCPSender)2