Search in sources :

Example 26 with Fluency

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

the class FluencyTest method testWithAckResponseButNotReceiveToken.

@ParameterizedTest
@MethodSource("sslFlagsProvider")
void testWithAckResponseButNotReceiveToken(final boolean sslEnabled) throws Throwable {
    Exception exception = new ConfigurableTestServer(sslEnabled).run(clientSocket -> {
        MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream());
        assertEquals(3, unpacker.unpackArrayHeader());
        assertEquals("foo.bar", unpacker.unpackString());
        ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue();
        Map<Value, Value> map = unpacker.unpackValue().asMapValue().map();
        assertEquals(2, map.size());
        assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
        assertNotNull(map.get(KEY_OPTION_CHUNK).asRawValue().asString());
        unpacker.close();
    }, serverPort -> {
        FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
        builder.setSslEnabled(sslEnabled);
        builder.setAckResponseMode(true);
        try (Fluency fluency = builder.build(serverPort)) {
            fluency.emit("foo.bar", new HashMap<>());
        }
    }, 5000);
    assertEquals(exception.getClass(), TimeoutException.class);
}
Also used : Fluency(org.komamitsu.fluency.Fluency) MessageUnpacker(org.msgpack.core.MessageUnpacker) ImmutableRawValue(org.msgpack.value.ImmutableRawValue) StringValue(org.msgpack.value.StringValue) Value(org.msgpack.value.Value) ImmutableRawValue(org.msgpack.value.ImmutableRawValue) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with Fluency

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

the class FluencyBuilderForAwsS3Test method buildWithDefaultConfig.

@ParameterizedTest
@EnumSource(FluencyBuilderForAwsS3.FormatType.class)
void buildWithDefaultConfig(FluencyBuilderForAwsS3.FormatType formatType) {
    FluencyBuilderForAwsS3 builder = builderWithDefaultConfig;
    AwsS3Sender sender = mock(AwsS3Sender.class);
    doReturn(sender).when(builder).createSender(any(AwsS3Sender.Config.class));
    builder.setFormatType(formatType);
    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();
    assertNull(senderConfig.getEndpoint());
    assertNull(senderConfig.getRegion());
    assertNull(senderConfig.getAwsAccessKeyId());
    assertNull(senderConfig.getAwsSecretAccessKey());
    assertEquals(10, senderConfig.getRetryMax());
    assertEquals(1000, senderConfig.getRetryIntervalMs());
    assertEquals(30000, senderConfig.getMaxRetryIntervalMs());
    assertEquals(2.0, senderConfig.getRetryFactor());
    assertEquals(8192, senderConfig.getWorkBufSize());
    assertTrue(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();
    Class<? extends AwsS3RecordFormatter> expectedAwsS3RecordFormatter = null;
    String expectedS3KeySuffix = null;
    switch(formatType) {
        case MESSAGE_PACK:
            expectedAwsS3RecordFormatter = MessagePackRecordFormatter.class;
            expectedS3KeySuffix = ".msgpack.gz";
            break;
        case JSONL:
            expectedAwsS3RecordFormatter = JsonlRecordFormatter.class;
            expectedS3KeySuffix = ".jsonl.gz";
            break;
        case CSV:
            expectedAwsS3RecordFormatter = CsvRecordFormatter.class;
            expectedS3KeySuffix = ".csv.gz";
            break;
    }
    assertEquals(expectedAwsS3RecordFormatter, recordFormatter.getClass());
    AwsS3Ingester ingester = (AwsS3Ingester) ingesterArgumentCaptor.getValue();
    assertEquals(sender, ingester.getSender());
    DefaultS3DestinationDecider destinationDecider = (DefaultS3DestinationDecider) ingester.getS3DestinationDecider();
    assertNull(destinationDecider.getKeyPrefix());
    assertEquals(expectedS3KeySuffix, destinationDecider.getKeySuffix());
    assertEquals(UTC, 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(512 * 1024 * 1024, bufferConfig.getMaxBufferSize());
    assertEquals(4 * 1024 * 1024, bufferConfig.getChunkInitialSize());
    assertEquals(64 * 1024 * 1024, bufferConfig.getChunkRetentionSize());
    assertEquals(30 * 1000, 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) AwsS3Ingester(org.komamitsu.fluency.aws.s3.ingester.AwsS3Ingester) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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