Search in sources :

Example 21 with Fluency

use of org.komamitsu.fluency.Fluency in project fluency by komamitsu.

the class WithRealFluentd method testWithRealFluentdWithFileBackup.

@Test
void testWithRealFluentdWithFileBackup() throws ExecutionException, TimeoutException, IOException, InterruptedException {
    WithRealFluentd.Config config = getConfig();
    assumeTrue(config != null);
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(config.sslEnabled);
    // Fluency might use a lot of buffer for loaded backup files.
    // So it'd better increase max buffer size
    builder.setMaxBufferSize(512 * 1024 * 1024L);
    builder.setFileBackupDir(System.getProperty("java.io.tmpdir"));
    try (Fluency fluency = new FluencyBuilderForFluentd().build(config.host, config.port)) {
        Map<String, Object> data = new HashMap<>();
        data.put("name", "komamitsu");
        data.put("age", 42);
        data.put("comment", "hello, world");
        ExecutorService executorService = Executors.newCachedThreadPool();
        List<Future<Void>> futures = new ArrayList<>();
        for (int i = 0; i < config.concurrency; i++) {
            futures.add(executorService.submit(new EmitTask(fluency, config.tag, data, config.requests)));
        }
        for (Future<Void> future : futures) {
            future.get(config.waitSeconds, TimeUnit.SECONDS);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Fluency(org.komamitsu.fluency.Fluency) FluencyBuilderForFluentd(org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 22 with Fluency

use of org.komamitsu.fluency.Fluency 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)

Example 23 with Fluency

use of org.komamitsu.fluency.Fluency in project fluency by komamitsu.

the class FluencyBuilderForFluentdTest method build.

@Test
void build() throws IOException {
    try (Fluency fluency = new FluencyBuilderForFluentd().build()) {
        assertBuffer(fluency.getBuffer());
        assertFlusher(fluency.getFlusher());
        assertDefaultFluentdSender((FluentdSender) fluency.getFlusher().getIngester().getSender(), "127.0.0.1", 24224, TCPSender.class);
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) Test(org.junit.jupiter.api.Test)

Example 24 with Fluency

use of org.komamitsu.fluency.Fluency in project fluency by komamitsu.

the class FluencyBuilderForFluentdTest method buildWithCustomPort.

@Test
void buildWithCustomPort() throws IOException {
    try (Fluency fluency = new FluencyBuilderForFluentd().build(54321)) {
        assertBuffer(fluency.getBuffer());
        assertFlusher(fluency.getFlusher());
        assertDefaultFluentdSender((FluentdSender) fluency.getFlusher().getIngester().getSender(), "127.0.0.1", 54321, TCPSender.class);
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) Test(org.junit.jupiter.api.Test)

Example 25 with Fluency

use of org.komamitsu.fluency.Fluency in project fluency by komamitsu.

the class FluencyBuilderForFluentdTest method buildWithSslAndCustomHostAndPort.

@Test
void buildWithSslAndCustomHostAndPort() throws IOException {
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(true);
    try (Fluency fluency = builder.build("192.168.0.99", 54321)) {
        assertBuffer(fluency.getBuffer());
        assertFlusher(fluency.getFlusher());
        assertDefaultFluentdSender((FluentdSender) fluency.getFlusher().getIngester().getSender(), "192.168.0.99", 54321, SSLSender.class);
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) Test(org.junit.jupiter.api.Test)

Aggregations

Fluency (org.komamitsu.fluency.Fluency)27 Test (org.junit.jupiter.api.Test)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 HashMap (java.util.HashMap)7 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 IOException (java.io.IOException)5 Buffer (org.komamitsu.fluency.buffer.Buffer)5 Flusher (org.komamitsu.fluency.flusher.Flusher)5 ArrayList (java.util.ArrayList)4 ExecutorService (java.util.concurrent.ExecutorService)4 TimeoutException (java.util.concurrent.TimeoutException)4 FluencyBuilderForFluentd (org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd)4 MessageUnpacker (org.msgpack.core.MessageUnpacker)4 ImmutableRawValue (org.msgpack.value.ImmutableRawValue)4 StringValue (org.msgpack.value.StringValue)4 Value (org.msgpack.value.Value)4 InetSocketAddress (java.net.InetSocketAddress)3 Future (java.util.concurrent.Future)3 RetryableSender (org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender)3 CountDownLatch (java.util.concurrent.CountDownLatch)2