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