Search in sources :

Example 16 with Fluency

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

the class FluencyBuilderForAwsS3Test method buildWithCustomConfig.

@Test
void buildWithCustomConfig() {
    FluencyBuilderForAwsS3 builder = builderWithCustomConfig;
    AwsS3Sender sender = mock(AwsS3Sender.class);
    doReturn(sender).when(builder).createSender(any(AwsS3Sender.Config.class));
    builder.setFormatType(FluencyBuilderForAwsS3.FormatType.JSONL);
    Fluency fluency = builder.build();
    assertEquals(fluency, this.fluency);
    ArgumentCaptor<AwsS3Sender.Config> configArgumentCaptor = ArgumentCaptor.forClass(AwsS3Sender.Config.class);
    verify(builder, times(1)).createSender(configArgumentCaptor.capture());
    AwsS3Sender.Config senderConfig = configArgumentCaptor.getValue();
    assertEquals("https://foo.bar.org", senderConfig.getEndpoint());
    assertEquals(Region.US_EAST_1.toString(), senderConfig.getRegion());
    assertEquals("ACCESSKEYID", senderConfig.getAwsAccessKeyId());
    assertEquals("SECRETACCESSKEY", senderConfig.getAwsSecretAccessKey());
    assertEquals(4, senderConfig.getRetryMax());
    assertEquals(543, senderConfig.getRetryIntervalMs());
    assertEquals(65432, senderConfig.getMaxRetryIntervalMs());
    assertEquals(1.234f, senderConfig.getRetryFactor());
    assertEquals(99 * 1024, senderConfig.getWorkBufSize());
    assertFalse(senderConfig.isCompressionEnabled());
    ArgumentCaptor<RecordFormatter> recordFormatterArgumentCaptor = ArgumentCaptor.forClass(RecordFormatter.class);
    ArgumentCaptor<Ingester> ingesterArgumentCaptor = ArgumentCaptor.forClass(Ingester.class);
    verify(builder, times(1)).buildFromIngester(recordFormatterArgumentCaptor.capture(), ingesterArgumentCaptor.capture());
    RecordFormatter recordFormatter = recordFormatterArgumentCaptor.getValue();
    assertTrue(recordFormatter instanceof JsonlRecordFormatter);
    AwsS3Ingester ingester = (AwsS3Ingester) ingesterArgumentCaptor.getValue();
    assertEquals(sender, ingester.getSender());
    DefaultS3DestinationDecider destinationDecider = (DefaultS3DestinationDecider) ingester.getS3DestinationDecider();
    assertEquals("mydata", destinationDecider.getKeyPrefix());
    assertEquals(".zzz", destinationDecider.getKeySuffix());
    assertEquals(ZoneId.of("JST", SHORT_IDS), destinationDecider.getZoneId());
    ArgumentCaptor<Buffer.Config> bufferConfigArgumentCaptor = ArgumentCaptor.forClass(Buffer.Config.class);
    ArgumentCaptor<Flusher.Config> flusherConfigArgumentCaptor = ArgumentCaptor.forClass(Flusher.Config.class);
    verify(builder, times(1)).createFluency(eq(recordFormatter), eq(ingester), bufferConfigArgumentCaptor.capture(), flusherConfigArgumentCaptor.capture());
    Buffer.Config bufferConfig = bufferConfigArgumentCaptor.getValue();
    assertEquals(42 * 1024 * 1024, bufferConfig.getMaxBufferSize());
    assertEquals(2 * 1024 * 1024, bufferConfig.getChunkInitialSize());
    assertEquals(9 * 1024 * 1024, bufferConfig.getChunkRetentionSize());
    assertEquals(1234, bufferConfig.getChunkRetentionTimeMillis());
}
Also used : Buffer(org.komamitsu.fluency.buffer.Buffer) AwsS3Sender(org.komamitsu.fluency.aws.s3.ingester.sender.AwsS3Sender) Fluency(org.komamitsu.fluency.Fluency) JsonlRecordFormatter(org.komamitsu.fluency.aws.s3.recordformat.JsonlRecordFormatter) AwsS3RecordFormatter(org.komamitsu.fluency.aws.s3.recordformat.AwsS3RecordFormatter) RecordFormatter(org.komamitsu.fluency.recordformat.RecordFormatter) MessagePackRecordFormatter(org.komamitsu.fluency.aws.s3.recordformat.MessagePackRecordFormatter) CsvRecordFormatter(org.komamitsu.fluency.aws.s3.recordformat.CsvRecordFormatter) DefaultS3DestinationDecider(org.komamitsu.fluency.aws.s3.ingester.DefaultS3DestinationDecider) Flusher(org.komamitsu.fluency.flusher.Flusher) Ingester(org.komamitsu.fluency.ingester.Ingester) AwsS3Ingester(org.komamitsu.fluency.aws.s3.ingester.AwsS3Ingester) JsonlRecordFormatter(org.komamitsu.fluency.aws.s3.recordformat.JsonlRecordFormatter) AwsS3Ingester(org.komamitsu.fluency.aws.s3.ingester.AwsS3Ingester) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with Fluency

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

the class WithRealFluentd method testWithRealMultipleFluentd.

@Test
void testWithRealMultipleFluentd() throws IOException, InterruptedException, TimeoutException, ExecutionException {
    WithRealFluentd.Config config = getConfig();
    assumeTrue(config != null);
    assumeTrue(config.anotherPort != null);
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(config.sslEnabled);
    builder.setAckResponseMode(true);
    try (Fluency fluency = builder.build(Arrays.asList(new InetSocketAddress(config.host, config.port), new InetSocketAddress(config.host, config.anotherPort)))) {
        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) InetSocketAddress(java.net.InetSocketAddress) 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 18 with Fluency

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

the class FluencyBuilderForTreasureDataTest method build.

@Test
void build() throws IOException, NoSuchFieldException, IllegalAccessException {
    try (Fluency fluency = new FluencyBuilderForTreasureData().build(APIKEY)) {
        assertBuffer(fluency.getBuffer());
        assertFlusher(fluency.getFlusher());
        assertDefaultFluentdSender((TreasureDataSender) fluency.getFlusher().getIngester().getSender(), "api-import.treasuredata.com", true);
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) Test(org.junit.jupiter.api.Test)

Example 19 with Fluency

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

the class FluencyBuilderForTreasureDataTest method buildWithCustomHttpsEndpointWithoutScheme.

@Test
void buildWithCustomHttpsEndpointWithoutScheme() throws IOException, NoSuchFieldException, IllegalAccessException {
    try (Fluency fluency = new FluencyBuilderForTreasureData().build(APIKEY, "custom.endpoint.org")) {
        assertBuffer(fluency.getBuffer());
        assertFlusher(fluency.getFlusher());
        assertDefaultFluentdSender((TreasureDataSender) fluency.getFlusher().getIngester().getSender(), "custom.endpoint.org", true);
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) Test(org.junit.jupiter.api.Test)

Example 20 with Fluency

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

the class Main method main.

public static void main(String[] args) throws IOException {
    String host = args[0];
    int port = Integer.parseInt(args[1]);
    String tag = args[2];
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(true);
    builder.setWaitUntilBufferFlushed(5000);
    builder.setWaitUntilFlusherTerminated(5000);
    builder.setSenderMaxRetryCount(4);
    Fluency fluency = builder.build(host, port);
    Map<String, Object> event = new HashMap<>();
    event.put("name", "komamitsu");
    event.put("comment", "zzz");
    fluency.emit(tag, event);
    fluency.close();
}
Also used : Fluency(org.komamitsu.fluency.Fluency) HashMap(java.util.HashMap) FluencyBuilderForFluentd(org.komamitsu.fluency.fluentd.FluencyBuilderForFluentd)

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