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);
}
}
}
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));
}
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations