Search in sources :

Example 1 with ExponentialBackOffRetryStrategy

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

the class FluencyBuilderForFluentdTest method buildWithComplexConfig.

@Test
void buildWithComplexConfig() throws IOException {
    String tmpdir = System.getProperty("java.io.tmpdir");
    assertThat(tmpdir, is(notNullValue()));
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setFlushAttemptIntervalMillis(200);
    builder.setMaxBufferSize(Long.MAX_VALUE);
    builder.setBufferChunkInitialSize(7 * 1024 * 1024);
    builder.setBufferChunkRetentionSize(13 * 1024 * 1024);
    builder.setBufferChunkRetentionTimeMillis(19 * 1000);
    builder.setJvmHeapBufferMode(true);
    builder.setSenderMaxRetryCount(99);
    builder.setSenderBaseRetryIntervalMillis(20);
    builder.setSenderMaxRetryIntervalMillis(100000);
    builder.setConnectionTimeoutMilli(12345);
    builder.setReadTimeoutMilli(9876);
    builder.setAckResponseMode(true);
    builder.setWaitUntilBufferFlushed(42);
    builder.setWaitUntilFlusherTerminated(24);
    builder.setFileBackupDir(tmpdir);
    try (Fluency fluency = builder.build(Arrays.asList(new InetSocketAddress("333.333.333.333", 11111), new InetSocketAddress("444.444.444.444", 22222)))) {
        assertThat(fluency.getBuffer(), instanceOf(Buffer.class));
        Buffer buffer = fluency.getBuffer();
        assertThat(buffer.getMaxBufferSize(), is(Long.MAX_VALUE));
        assertThat(buffer.getFileBackupDir(), is(tmpdir));
        assertThat(buffer.bufferFormatType(), is("packed_forward"));
        assertThat(buffer.getChunkRetentionTimeMillis(), is(19 * 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));
        Flusher flusher = fluency.getFlusher();
        assertThat(flusher.isTerminated(), is(false));
        assertThat(flusher.getFlushAttemptIntervalMillis(), is(200));
        assertThat(flusher.getWaitUntilBufferFlushed(), is(42));
        assertThat(flusher.getWaitUntilTerminated(), is(24));
        assertThat(flusher.getIngester().getSender(), instanceOf(RetryableSender.class));
        RetryableSender retryableSender = (RetryableSender) flusher.getIngester().getSender();
        assertThat(retryableSender.getRetryStrategy(), instanceOf(ExponentialBackOffRetryStrategy.class));
        ExponentialBackOffRetryStrategy retryStrategy = (ExponentialBackOffRetryStrategy) retryableSender.getRetryStrategy();
        assertThat(retryStrategy.getMaxRetryCount(), is(99));
        assertThat(retryStrategy.getBaseIntervalMillis(), is(20));
        assertThat(retryStrategy.getMaxIntervalMillis(), is(100000));
        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(12345));
            assertThat(sender.getReadTimeoutMilli(), is(9876));
            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(12345));
            assertThat(sender.getReadTimeoutMilli(), is(9876));
            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));
        }
    }
}
Also used : Buffer(org.komamitsu.fluency.buffer.Buffer) Fluency(org.komamitsu.fluency.Fluency) InetSocketAddress(java.net.InetSocketAddress) Flusher(org.komamitsu.fluency.flusher.Flusher) ExponentialBackOffRetryStrategy(org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy) FailureDetector(org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.FailureDetector) MultiSender(org.komamitsu.fluency.fluentd.ingester.sender.MultiSender) RetryableSender(org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender) TCPSender(org.komamitsu.fluency.fluentd.ingester.sender.TCPSender) Test(org.junit.jupiter.api.Test)

Example 2 with ExponentialBackOffRetryStrategy

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

the class FluencyBuilderForFluentd method buildIngester.

private Ingester buildIngester(FluentdSender baseSender) {
    ExponentialBackOffRetryStrategy.Config retryStrategyConfig = new ExponentialBackOffRetryStrategy.Config();
    if (getSenderMaxRetryCount() != null) {
        retryStrategyConfig.setMaxRetryCount(getSenderMaxRetryCount());
    }
    if (getSenderBaseRetryIntervalMillis() != null) {
        retryStrategyConfig.setBaseIntervalMillis(getSenderBaseRetryIntervalMillis());
    }
    if (getSenderMaxRetryIntervalMillis() != null) {
        retryStrategyConfig.setMaxIntervalMillis(getSenderMaxRetryIntervalMillis());
    }
    RetryableSender.Config senderConfig = new RetryableSender.Config();
    if (getErrorHandler() != null) {
        senderConfig.setErrorHandler(getErrorHandler());
    }
    RetryableSender retryableSender = new RetryableSender(senderConfig, baseSender, new ExponentialBackOffRetryStrategy(retryStrategyConfig));
    FluentdIngester.Config ingesterConfig = new FluentdIngester.Config();
    ingesterConfig.setAckResponseMode(isAckResponseMode());
    return new FluentdIngester(ingesterConfig, retryableSender);
}
Also used : FluentdIngester(org.komamitsu.fluency.fluentd.ingester.FluentdIngester) ExponentialBackOffRetryStrategy(org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy) RetryableSender(org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender)

Example 3 with ExponentialBackOffRetryStrategy

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

the class RetryableSenderTest method testSendRetryOver.

@Test
void testSendRetryOver() throws IOException {
    ExponentialBackOffRetryStrategy.Config retryStrategyConfig = new ExponentialBackOffRetryStrategy.Config();
    retryStrategyConfig.setMaxRetryCount(2);
    RetryableSender.Config senderConfig = new RetryableSender.Config();
    RetryableSender sender = new RetryableSender(senderConfig, new FailurableSender(3), new ExponentialBackOffRetryStrategy(retryStrategyConfig));
    FailurableSender baseSender = (FailurableSender) sender.getBaseSender();
    assertThat(baseSender.getRetry(), is(0));
    assertThrows(RetryableSender.RetryOverException.class, () -> sender.send(ByteBuffer.allocate(64)));
}
Also used : ExponentialBackOffRetryStrategy(org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy) Test(org.junit.jupiter.api.Test)

Example 4 with ExponentialBackOffRetryStrategy

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

the class RetryableSenderTest method testSend.

@Test
void testSend() throws IOException {
    ExponentialBackOffRetryStrategy.Config retryStrategyConfig = new ExponentialBackOffRetryStrategy.Config();
    retryStrategyConfig.setMaxRetryCount(3);
    RetryableSender.Config senderConfig = new RetryableSender.Config();
    RetryableSender sender = new RetryableSender(senderConfig, new FailurableSender(3), new ExponentialBackOffRetryStrategy(retryStrategyConfig));
    FailurableSender baseSender = (FailurableSender) sender.getBaseSender();
    assertThat(baseSender.getRetry(), is(0));
    sender.send(ByteBuffer.allocate(64));
    assertThat(baseSender.getRetry(), is(3));
}
Also used : ExponentialBackOffRetryStrategy(org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy) Test(org.junit.jupiter.api.Test)

Example 5 with ExponentialBackOffRetryStrategy

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

the class FluencyBuilderForFluentdTest method buildWithSslAndComplexConfig.

@Test
void buildWithSslAndComplexConfig() throws IOException {
    String tmpdir = System.getProperty("java.io.tmpdir");
    assertThat(tmpdir, is(notNullValue()));
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(true);
    builder.setFlushAttemptIntervalMillis(200);
    builder.setMaxBufferSize(Long.MAX_VALUE);
    builder.setBufferChunkInitialSize(7 * 1024 * 1024);
    builder.setBufferChunkRetentionSize(13 * 1024 * 1024);
    builder.setJvmHeapBufferMode(true);
    builder.setSenderMaxRetryCount(99);
    builder.setSenderBaseRetryIntervalMillis(20);
    builder.setSenderMaxRetryIntervalMillis(100000);
    builder.setConnectionTimeoutMilli(12345);
    builder.setReadTimeoutMilli(9876);
    builder.setAckResponseMode(true);
    builder.setWaitUntilBufferFlushed(42);
    builder.setWaitUntilFlusherTerminated(24);
    builder.setFileBackupDir(tmpdir);
    try (Fluency fluency = builder.build(Arrays.asList(new InetSocketAddress("333.333.333.333", 11111), new InetSocketAddress("444.444.444.444", 22222)))) {
        assertThat(fluency.getFlusher().getIngester().getSender(), instanceOf(RetryableSender.class));
        RetryableSender retryableSender = (RetryableSender) fluency.getFlusher().getIngester().getSender();
        assertThat(retryableSender.getRetryStrategy(), instanceOf(ExponentialBackOffRetryStrategy.class));
        ExponentialBackOffRetryStrategy retryStrategy = (ExponentialBackOffRetryStrategy) retryableSender.getRetryStrategy();
        assertThat(retryStrategy.getMaxRetryCount(), is(99));
        assertThat(retryStrategy.getBaseIntervalMillis(), is(20));
        assertThat(retryStrategy.getMaxIntervalMillis(), is(100000));
        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(12345));
            assertThat(sender.getReadTimeoutMilli(), is(9876));
            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(12345));
            assertThat(sender.getReadTimeoutMilli(), is(9876));
            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));
        }
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) SSLSender(org.komamitsu.fluency.fluentd.ingester.sender.SSLSender) InetSocketAddress(java.net.InetSocketAddress) ExponentialBackOffRetryStrategy(org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy) FailureDetector(org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.FailureDetector) MultiSender(org.komamitsu.fluency.fluentd.ingester.sender.MultiSender) RetryableSender(org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender) Test(org.junit.jupiter.api.Test)

Aggregations

ExponentialBackOffRetryStrategy (org.komamitsu.fluency.fluentd.ingester.sender.retry.ExponentialBackOffRetryStrategy)6 Test (org.junit.jupiter.api.Test)4 RetryableSender (org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender)3 InetSocketAddress (java.net.InetSocketAddress)2 Fluency (org.komamitsu.fluency.Fluency)2 MultiSender (org.komamitsu.fluency.fluentd.ingester.sender.MultiSender)2 FailureDetector (org.komamitsu.fluency.fluentd.ingester.sender.failuredetect.FailureDetector)2 Buffer (org.komamitsu.fluency.buffer.Buffer)1 FluentdIngester (org.komamitsu.fluency.fluentd.ingester.FluentdIngester)1 SSLSender (org.komamitsu.fluency.fluentd.ingester.sender.SSLSender)1 TCPSender (org.komamitsu.fluency.fluentd.ingester.sender.TCPSender)1 Flusher (org.komamitsu.fluency.flusher.Flusher)1