Search in sources :

Example 11 with Fluency

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

the class FluencyTest method testWithAckResponseWithProperToken.

@ParameterizedTest
@MethodSource("sslFlagsProvider")
public void testWithAckResponseWithProperToken(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());
        String ackResponseToken = map.get(KEY_OPTION_CHUNK).asRawValue().asString();
        assertNotNull(ackResponseToken);
        MessagePacker packer = MessagePack.newDefaultPacker(clientSocket.getOutputStream());
        packer.packMapHeader(1).packString("ack").packString(ackResponseToken).close();
        // Close the input stream after closing the output stream to avoid closing a socket too early
        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);
    assertNull(exception);
}
Also used : Fluency(org.komamitsu.fluency.Fluency) MessagePacker(org.msgpack.core.MessagePacker) 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 12 with Fluency

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

the class FluencyBuilderForTreasureDataTest method buildWithAllCustomConfig.

@Test
void buildWithAllCustomConfig() throws IOException {
    String tmpdir = System.getProperty("java.io.tmpdir");
    assertNotNull(tmpdir);
    FluencyBuilderForTreasureData builder = new FluencyBuilderForTreasureData();
    builder.setFlushAttemptIntervalMillis(200);
    builder.setMaxBufferSize(Long.MAX_VALUE);
    builder.setBufferChunkInitialSize(7 * 1024 * 1024);
    builder.setBufferChunkRetentionSize(13 * 1024 * 1024);
    builder.setBufferChunkRetentionTimeMillis(19 * 1000);
    builder.setJvmHeapBufferMode(true);
    builder.setWaitUntilBufferFlushed(42);
    builder.setWaitUntilFlusherTerminated(24);
    builder.setFileBackupDir(tmpdir);
    builder.setSenderRetryIntervalMillis(1234);
    builder.setSenderMaxRetryIntervalMillis(345678);
    builder.setSenderRetryFactor(3.14f);
    builder.setSenderRetryMax(17);
    builder.setSenderWorkBufSize(123456);
    ;
    try (Fluency fluency = builder.build(APIKEY)) {
        assertEquals(Buffer.class, fluency.getBuffer().getClass());
        Buffer buffer = fluency.getBuffer();
        assertEquals(Long.MAX_VALUE, buffer.getMaxBufferSize());
        assertEquals(tmpdir, buffer.getFileBackupDir());
        assertEquals("packed_forward", buffer.bufferFormatType());
        assertEquals(19 * 1000, buffer.getChunkRetentionTimeMillis());
        assertEquals(2f, buffer.getChunkExpandRatio());
        assertEquals(7 * 1024 * 1024, buffer.getChunkInitialSize());
        assertEquals(13 * 1024 * 1024, buffer.getChunkRetentionSize());
        assertTrue(buffer.getJvmHeapBufferMode());
        Flusher flusher = fluency.getFlusher();
        assertFalse(flusher.isTerminated());
        assertEquals(200, flusher.getFlushAttemptIntervalMillis());
        assertEquals(42, flusher.getWaitUntilBufferFlushed());
        assertEquals(24, flusher.getWaitUntilTerminated());
        assertEquals(TreasureDataSender.class, flusher.getIngester().getSender().getClass());
        TreasureDataSender sender = (TreasureDataSender) flusher.getIngester().getSender();
        assertEquals(1234, sender.getRetryInternalMs());
        assertEquals(345678, sender.getMaxRetryInternalMs());
        assertEquals(3.14f, sender.getRetryFactor());
        assertEquals(17, sender.getRetryMax());
        assertEquals(123456, sender.getWorkBufSize());
    }
}
Also used : Buffer(org.komamitsu.fluency.buffer.Buffer) Fluency(org.komamitsu.fluency.Fluency) Flusher(org.komamitsu.fluency.flusher.Flusher) TreasureDataSender(org.komamitsu.fluency.treasuredata.ingester.sender.TreasureDataSender) Test(org.junit.jupiter.api.Test)

Example 13 with Fluency

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

the class FluencyBuilderForTreasureDataTest method buildWithCustomHttpsEndpoint.

@Test
void buildWithCustomHttpsEndpoint() throws IOException, NoSuchFieldException, IllegalAccessException {
    try (Fluency fluency = new FluencyBuilderForTreasureData().build(APIKEY, "https://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 14 with Fluency

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

the class FluencyBuilderForTreasureDataTest method buildWithCustomHttpEndpoint.

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

Example 15 with Fluency

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

the class WithRealFluentd method testWithRealFluentd.

@Test
void testWithRealFluentd() throws Exception {
    WithRealFluentd.Config config = getConfig();
    assumeTrue(config != null);
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSslEnabled(config.sslEnabled);
    try (Fluency fluency = builder.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)

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