Search in sources :

Example 1 with ExponentialBackOffRetryStrategy

use of org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy in project fluency by komamitsu.

the class FluencyTest method testDefaultFluencyWithSslAndComplexConfig.

@Test
public void testDefaultFluencyWithSslAndComplexConfig() throws IOException {
    Fluency fluency = null;
    try {
        String tmpdir = System.getProperty("java.io.tmpdir");
        assertThat(tmpdir, is(notNullValue()));
        Fluency.Config config = new Fluency.Config().setSslEnabled(true).setFlushIntervalMillis(200).setMaxBufferSize(Long.MAX_VALUE).setBufferChunkInitialSize(7 * 1024 * 1024).setBufferChunkRetentionSize(13 * 1024 * 1024).setJvmHeapBufferMode(true).setSenderMaxRetryCount(99).setAckResponseMode(true).setWaitUntilBufferFlushed(42).setWaitUntilFlusherTerminated(24).setFileBackupDir(tmpdir);
        fluency = Fluency.defaultFluency(Arrays.asList(new InetSocketAddress("333.333.333.333", 11111), new InetSocketAddress("444.444.444.444", 22222)), config);
        assertThat(fluency.getFlusher().getSender(), instanceOf(RetryableSender.class));
        RetryableSender retryableSender = (RetryableSender) fluency.getFlusher().getSender();
        assertThat(retryableSender.getRetryStrategy(), instanceOf(ExponentialBackOffRetryStrategy.class));
        ExponentialBackOffRetryStrategy retryStrategy = (ExponentialBackOffRetryStrategy) retryableSender.getRetryStrategy();
        assertThat(retryStrategy.getMaxRetryCount(), is(99));
        assertThat(retryStrategy.getBaseIntervalMillis(), is(400));
        assertThat(retryableSender.getBaseSender(), instanceOf(MultiSender.class));
        MultiSender multiSender = (MultiSender) retryableSender.getBaseSender();
        assertThat(multiSender.getSenders().size(), is(2));
        assertThat(multiSender.getSenders().get(0), instanceOf(SSLSender.class));
        {
            SSLSender sender = (SSLSender) multiSender.getSenders().get(0);
            assertThat(sender.getHost(), is("333.333.333.333"));
            assertThat(sender.getPort(), is(11111));
            assertThat(sender.getConnectionTimeoutMilli(), is(5000));
            assertThat(sender.getReadTimeoutMilli(), is(5000));
            FailureDetector failureDetector = sender.getFailureDetector();
            assertThat(failureDetector.getFailureIntervalMillis(), is(3 * 1000));
            assertThat(failureDetector.getFailureDetectStrategy(), instanceOf(PhiAccrualFailureDetectStrategy.class));
            assertThat(failureDetector.getHeartbeater(), instanceOf(SSLHeartbeater.class));
            assertThat(failureDetector.getHeartbeater().getHost(), is("333.333.333.333"));
            assertThat(failureDetector.getHeartbeater().getPort(), is(11111));
            assertThat(failureDetector.getHeartbeater().getIntervalMillis(), is(1000));
        }
        assertThat(multiSender.getSenders().get(1), instanceOf(SSLSender.class));
        {
            SSLSender sender = (SSLSender) multiSender.getSenders().get(1);
            assertThat(sender.getHost(), is("444.444.444.444"));
            assertThat(sender.getPort(), is(22222));
            assertThat(sender.getConnectionTimeoutMilli(), is(5000));
            assertThat(sender.getReadTimeoutMilli(), is(5000));
            FailureDetector failureDetector = sender.getFailureDetector();
            assertThat(failureDetector.getFailureIntervalMillis(), is(3 * 1000));
            assertThat(failureDetector.getFailureDetectStrategy(), instanceOf(PhiAccrualFailureDetectStrategy.class));
            assertThat(failureDetector.getHeartbeater(), instanceOf(SSLHeartbeater.class));
            assertThat(failureDetector.getHeartbeater().getHost(), is("444.444.444.444"));
            assertThat(failureDetector.getHeartbeater().getPort(), is(22222));
            assertThat(failureDetector.getHeartbeater().getIntervalMillis(), is(1000));
        }
    } finally {
        if (fluency != null) {
            fluency.close();
        }
    }
}
Also used : SSLSender(org.komamitsu.fluency.sender.SSLSender) InetSocketAddress(java.net.InetSocketAddress) ExponentialBackOffRetryStrategy(org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy) FailureDetector(org.komamitsu.fluency.sender.failuredetect.FailureDetector) MultiSender(org.komamitsu.fluency.sender.MultiSender) RetryableSender(org.komamitsu.fluency.sender.RetryableSender) Test(org.junit.Test)

Example 2 with ExponentialBackOffRetryStrategy

use of org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy in project fluency by komamitsu.

the class FluencyTest method testDefaultFluencyWithComplexConfig.

@Test
public void testDefaultFluencyWithComplexConfig() throws IOException {
    Fluency fluency = null;
    try {
        String tmpdir = System.getProperty("java.io.tmpdir");
        assertThat(tmpdir, is(notNullValue()));
        Fluency.Config config = new Fluency.Config().setFlushIntervalMillis(200).setMaxBufferSize(Long.MAX_VALUE).setBufferChunkInitialSize(7 * 1024 * 1024).setBufferChunkRetentionSize(13 * 1024 * 1024).setJvmHeapBufferMode(true).setSenderMaxRetryCount(99).setAckResponseMode(true).setWaitUntilBufferFlushed(42).setWaitUntilFlusherTerminated(24).setFileBackupDir(tmpdir);
        fluency = Fluency.defaultFluency(Arrays.asList(new InetSocketAddress("333.333.333.333", 11111), new InetSocketAddress("444.444.444.444", 22222)), config);
        assertThat(fluency.getBuffer(), instanceOf(PackedForwardBuffer.class));
        PackedForwardBuffer buffer = (PackedForwardBuffer) fluency.getBuffer();
        assertThat(buffer.getMaxBufferSize(), is(Long.MAX_VALUE));
        assertThat(buffer.getFileBackupDir(), is(tmpdir));
        assertThat(buffer.bufferFormatType(), is("packed_forward"));
        assertThat(buffer.getChunkRetentionTimeMillis(), is(1000));
        assertThat(buffer.getChunkExpandRatio(), is(2f));
        assertThat(buffer.getChunkInitialSize(), is(7 * 1024 * 1024));
        assertThat(buffer.getChunkRetentionSize(), is(13 * 1024 * 1024));
        assertThat(buffer.getJvmHeapBufferMode(), is(true));
        assertThat(buffer.isAckResponseMode(), is(true));
        assertThat(fluency.getFlusher(), instanceOf(AsyncFlusher.class));
        AsyncFlusher flusher = (AsyncFlusher) fluency.getFlusher();
        assertThat(flusher.isTerminated(), is(false));
        assertThat(flusher.getFlushIntervalMillis(), is(200));
        assertThat(flusher.getWaitUntilBufferFlushed(), is(42));
        assertThat(flusher.getWaitUntilTerminated(), is(24));
        assertThat(flusher.getSender(), instanceOf(RetryableSender.class));
        RetryableSender retryableSender = (RetryableSender) flusher.getSender();
        assertThat(retryableSender.getRetryStrategy(), instanceOf(ExponentialBackOffRetryStrategy.class));
        ExponentialBackOffRetryStrategy retryStrategy = (ExponentialBackOffRetryStrategy) retryableSender.getRetryStrategy();
        assertThat(retryStrategy.getMaxRetryCount(), is(99));
        assertThat(retryStrategy.getBaseIntervalMillis(), is(400));
        assertThat(retryableSender.getBaseSender(), instanceOf(MultiSender.class));
        MultiSender multiSender = (MultiSender) retryableSender.getBaseSender();
        assertThat(multiSender.getSenders().size(), is(2));
        assertThat(multiSender.getSenders().get(0), instanceOf(TCPSender.class));
        {
            TCPSender sender = (TCPSender) multiSender.getSenders().get(0);
            assertThat(sender.getHost(), is("333.333.333.333"));
            assertThat(sender.getPort(), is(11111));
            assertThat(sender.getConnectionTimeoutMilli(), is(5000));
            assertThat(sender.getReadTimeoutMilli(), is(5000));
            FailureDetector failureDetector = sender.getFailureDetector();
            assertThat(failureDetector.getFailureIntervalMillis(), is(3 * 1000));
            assertThat(failureDetector.getFailureDetectStrategy(), instanceOf(PhiAccrualFailureDetectStrategy.class));
            assertThat(failureDetector.getHeartbeater(), instanceOf(TCPHeartbeater.class));
            assertThat(failureDetector.getHeartbeater().getHost(), is("333.333.333.333"));
            assertThat(failureDetector.getHeartbeater().getPort(), is(11111));
            assertThat(failureDetector.getHeartbeater().getIntervalMillis(), is(1000));
        }
        assertThat(multiSender.getSenders().get(1), instanceOf(TCPSender.class));
        {
            TCPSender sender = (TCPSender) multiSender.getSenders().get(1);
            assertThat(sender.getHost(), is("444.444.444.444"));
            assertThat(sender.getPort(), is(22222));
            assertThat(sender.getConnectionTimeoutMilli(), is(5000));
            assertThat(sender.getReadTimeoutMilli(), is(5000));
            FailureDetector failureDetector = sender.getFailureDetector();
            assertThat(failureDetector.getFailureIntervalMillis(), is(3 * 1000));
            assertThat(failureDetector.getFailureDetectStrategy(), instanceOf(PhiAccrualFailureDetectStrategy.class));
            assertThat(failureDetector.getHeartbeater(), instanceOf(TCPHeartbeater.class));
            assertThat(failureDetector.getHeartbeater().getHost(), is("444.444.444.444"));
            assertThat(failureDetector.getHeartbeater().getPort(), is(22222));
            assertThat(failureDetector.getHeartbeater().getIntervalMillis(), is(1000));
        }
    } finally {
        if (fluency != null) {
            fluency.close();
        }
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) PackedForwardBuffer(org.komamitsu.fluency.buffer.PackedForwardBuffer) ExponentialBackOffRetryStrategy(org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy) FailureDetector(org.komamitsu.fluency.sender.failuredetect.FailureDetector) AsyncFlusher(org.komamitsu.fluency.flusher.AsyncFlusher) MultiSender(org.komamitsu.fluency.sender.MultiSender) RetryableSender(org.komamitsu.fluency.sender.RetryableSender) TCPSender(org.komamitsu.fluency.sender.TCPSender) MockTCPSender(org.komamitsu.fluency.sender.MockTCPSender) Test(org.junit.Test)

Example 3 with ExponentialBackOffRetryStrategy

use of org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy in project fluency by komamitsu.

the class FluencyTest method assertDefaultRetryableSender.

private void assertDefaultRetryableSender(RetryableSender sender, Class<? extends NetworkSender> expectedBaseClass) {
    assertThat(sender.getRetryStrategy(), instanceOf(ExponentialBackOffRetryStrategy.class));
    ExponentialBackOffRetryStrategy retryStrategy = (ExponentialBackOffRetryStrategy) sender.getRetryStrategy();
    assertThat(retryStrategy.getMaxRetryCount(), is(7));
    assertThat(retryStrategy.getBaseIntervalMillis(), is(400));
    assertThat(sender.getBaseSender(), instanceOf(expectedBaseClass));
}
Also used : ExponentialBackOffRetryStrategy(org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy)

Aggregations

ExponentialBackOffRetryStrategy (org.komamitsu.fluency.sender.retry.ExponentialBackOffRetryStrategy)3 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.junit.Test)2 MultiSender (org.komamitsu.fluency.sender.MultiSender)2 RetryableSender (org.komamitsu.fluency.sender.RetryableSender)2 FailureDetector (org.komamitsu.fluency.sender.failuredetect.FailureDetector)2 PackedForwardBuffer (org.komamitsu.fluency.buffer.PackedForwardBuffer)1 AsyncFlusher (org.komamitsu.fluency.flusher.AsyncFlusher)1 MockTCPSender (org.komamitsu.fluency.sender.MockTCPSender)1 SSLSender (org.komamitsu.fluency.sender.SSLSender)1 TCPSender (org.komamitsu.fluency.sender.TCPSender)1