Search in sources :

Example 6 with Fluency

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

the class FluencyBuilderForFluentdTest method buildWithCustomHostAndPort.

@Test
void buildWithCustomHostAndPort() throws IOException {
    try (Fluency fluency = new FluencyBuilderForFluentd().build("192.168.0.99", 54321)) {
        assertBuffer(fluency.getBuffer());
        assertFlusher(fluency.getFlusher());
        assertDefaultFluentdSender((FluentdSender) fluency.getFlusher().getIngester().getSender(), "192.168.0.99", 54321, TCPSender.class);
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) Test(org.junit.jupiter.api.Test)

Example 7 with Fluency

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

the class FluencyTest method testWithAckResponseButWrongReceiveToken.

@ParameterizedTest
@MethodSource("sslFlagsProvider")
void testWithAckResponseButWrongReceiveToken(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());
        MessagePacker packer = MessagePack.newDefaultPacker(clientSocket.getOutputStream());
        packer.packMapHeader(1).packString("ack").packString(UUID.randomUUID().toString()).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);
    assertEquals(exception.getClass(), TimeoutException.class);
}
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 8 with Fluency

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

the class FluencyTest method testWithoutAckResponse.

@ParameterizedTest
@MethodSource("sslFlagsProvider")
void testWithoutAckResponse(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(1, map.size());
        assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
        unpacker.close();
    }, serverPort -> {
        FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
        builder.setSslEnabled(sslEnabled);
        try (Fluency fluency = builder.build(serverPort)) {
            fluency.emit("foo.bar", new HashMap<>());
        }
    }, 5000);
    assertNull(exception);
}
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 9 with Fluency

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

the class FluencyTest method testBufferWithJacksonModule.

@ParameterizedTest
@MethodSource("sslFlagsProvider")
void testBufferWithJacksonModule() throws IOException {
    AtomicBoolean serialized = new AtomicBoolean();
    SimpleModule simpleModule = new SimpleModule();
    simpleModule.addSerializer(Foo.class, new FooSerializer(serialized));
    FluentdRecordFormatter.Config recordFormatterConfig = new FluentdRecordFormatter.Config();
    recordFormatterConfig.setJacksonModules(Collections.singletonList(simpleModule));
    Fluency fluency = new FluencyBuilder().buildFromIngester(new FluentdRecordFormatter(recordFormatterConfig), ingester);
    Map<String, Object> event = new HashMap<>();
    Foo foo = new Foo();
    foo.s = "Hello";
    event.put("foo", foo);
    fluency.emit("tag", event);
    assertThat(serialized.get(), is(true));
}
Also used : HashMap(java.util.HashMap) FluentdRecordFormatter(org.komamitsu.fluency.fluentd.recordformat.FluentdRecordFormatter) FluencyBuilder(org.komamitsu.fluency.FluencyBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Fluency(org.komamitsu.fluency.Fluency) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with Fluency

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

the class FluencyTest method testSenderErrorHandler.

@Test
void testSenderErrorHandler() throws IOException, InterruptedException {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    final AtomicReference<Throwable> errorContainer = new AtomicReference<>();
    FluencyBuilderForFluentd builder = new FluencyBuilderForFluentd();
    builder.setSenderMaxRetryCount(1);
    builder.setErrorHandler(e -> {
        errorContainer.set(e);
        countDownLatch.countDown();
    });
    try (Fluency fluency = builder.build(Integer.MAX_VALUE)) {
        HashMap<String, Object> event = new HashMap<>();
        event.put("name", "foo");
        fluency.emit("tag", event);
        if (!countDownLatch.await(10, TimeUnit.SECONDS)) {
            throw new AssertionError("Timeout");
        }
        assertThat(errorContainer.get(), is(instanceOf(RetryableSender.RetryOverException.class)));
    }
}
Also used : Fluency(org.komamitsu.fluency.Fluency) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) RetryableSender(org.komamitsu.fluency.fluentd.ingester.sender.RetryableSender) Test(org.junit.jupiter.api.Test) 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