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);
}
}
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);
}
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);
}
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));
}
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)));
}
}
Aggregations