Search in sources :

Example 1 with Ingester

use of org.komamitsu.fluency.ingester.Ingester in project fluency by komamitsu.

the class FluentdIngesterTest method close.

@Test
void close() throws IOException {
    Ingester ingester = new FluentdIngester(new FluentdIngester.Config(), fluentdSender);
    ingester.close();
    verify(fluentdSender, times(1)).close();
}
Also used : Ingester(org.komamitsu.fluency.ingester.Ingester) Test(org.junit.jupiter.api.Test)

Example 2 with Ingester

use of org.komamitsu.fluency.ingester.Ingester in project fluency by komamitsu.

the class FluentdIngesterTest method ingestWithAck.

@Test
void ingestWithAck() throws IOException {
    FluentdIngester.Config config = new FluentdIngester.Config();
    config.setAckResponseMode(true);
    Ingester ingester = new FluentdIngester(config, fluentdSender);
    ingester.ingest(TAG, ByteBuffer.wrap(DATA));
    ArgumentCaptor<String> ackTokenArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(fluentdSender, times(1)).sendWithAck(byteBuffersArgumentCaptor.capture(), ackTokenArgumentCaptor.capture());
    List<ByteBuffer> byteBuffers = byteBuffersArgumentCaptor.getAllValues().get(0);
    byte[] ingested = getIngestedData(byteBuffers);
    MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(ingested);
    ImmutableArrayValue arrayValue = unpacker.unpackValue().asArrayValue();
    assertEquals(3, arrayValue.size());
    assertEquals(TAG, arrayValue.get(0).asStringValue().asString());
    assertArrayEquals(DATA, arrayValue.get(1).asRawValue().asByteArray());
    Map<Value, Value> options = arrayValue.get(2).asMapValue().map();
    assertEquals(2, options.size());
    assertEquals(DATA.length, options.get(ValueFactory.newString("size")).asIntegerValue().asInt());
    String ackToken = options.get(ValueFactory.newString("chunk")).asRawValue().asString();
    List<String> ackTokenArgumentCaptorAllValues = ackTokenArgumentCaptor.getAllValues();
    assertEquals(1, ackTokenArgumentCaptorAllValues.size());
    assertEquals(ackToken, ackTokenArgumentCaptorAllValues.get(0));
}
Also used : ByteBuffer(java.nio.ByteBuffer) MessageUnpacker(org.msgpack.core.MessageUnpacker) ImmutableArrayValue(org.msgpack.value.ImmutableArrayValue) Value(org.msgpack.value.Value) Ingester(org.komamitsu.fluency.ingester.Ingester) ImmutableArrayValue(org.msgpack.value.ImmutableArrayValue) Test(org.junit.jupiter.api.Test)

Example 3 with Ingester

use of org.komamitsu.fluency.ingester.Ingester in project fluency by komamitsu.

the class BufferTest method setUp.

@BeforeEach
void setUp() {
    recordFormatter = new JsonRecordFormatter();
    ingester = mock(Ingester.class);
    bufferConfig = new Buffer.Config();
}
Also used : ByteBuffer(java.nio.ByteBuffer) Ingester(org.komamitsu.fluency.ingester.Ingester) JsonRecordFormatter(org.komamitsu.fluency.JsonRecordFormatter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Ingester

use of org.komamitsu.fluency.ingester.Ingester in project fluency by komamitsu.

the class BufferTest method flush.

@Test
void flush() throws IOException {
    Buffer buffer = new Buffer(bufferConfig, recordFormatter);
    Ingester ingester = mock(Ingester.class);
    buffer.flush(ingester, false);
    verify(ingester, times(0)).ingest(anyString(), any(ByteBuffer.class));
    Map<String, Object> data = new HashMap<>();
    data.put("name", "komamitsu");
    buffer.append("foodb.bartbl", 1420070400, data);
    buffer.flush(ingester, false);
    verify(ingester, times(0)).ingest(anyString(), any(ByteBuffer.class));
    buffer.flush(ingester, true);
    verify(ingester, times(1)).ingest(eq("foodb.bartbl"), any(ByteBuffer.class));
}
Also used : ByteBuffer(java.nio.ByteBuffer) HashMap(java.util.HashMap) Ingester(org.komamitsu.fluency.ingester.Ingester) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 5 with Ingester

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

Aggregations

Ingester (org.komamitsu.fluency.ingester.Ingester)9 Test (org.junit.jupiter.api.Test)7 ByteBuffer (java.nio.ByteBuffer)6 HashMap (java.util.HashMap)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Buffer (org.komamitsu.fluency.buffer.Buffer)3 Flusher (org.komamitsu.fluency.flusher.Flusher)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Fluency (org.komamitsu.fluency.Fluency)2 AwsS3Ingester (org.komamitsu.fluency.aws.s3.ingester.AwsS3Ingester)2 DefaultS3DestinationDecider (org.komamitsu.fluency.aws.s3.ingester.DefaultS3DestinationDecider)2 AwsS3Sender (org.komamitsu.fluency.aws.s3.ingester.sender.AwsS3Sender)2 AwsS3RecordFormatter (org.komamitsu.fluency.aws.s3.recordformat.AwsS3RecordFormatter)2 CsvRecordFormatter (org.komamitsu.fluency.aws.s3.recordformat.CsvRecordFormatter)2 JsonlRecordFormatter (org.komamitsu.fluency.aws.s3.recordformat.JsonlRecordFormatter)2 MessagePackRecordFormatter (org.komamitsu.fluency.aws.s3.recordformat.MessagePackRecordFormatter)2 RecordFormatter (org.komamitsu.fluency.recordformat.RecordFormatter)2 MessageUnpacker (org.msgpack.core.MessageUnpacker)2