use of org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.TCPHeartbeater in project fluency by komamitsu.
the class MultiSenderTest method testConstructorForTCPSender.
@Test
void testConstructorForTCPSender() throws IOException {
MultiSender multiSender = null;
try {
TCPSender.Config senderConfig0 = new TCPSender.Config();
senderConfig0.setPort(24225);
TCPHeartbeater.Config hbConfig0 = new TCPHeartbeater.Config();
hbConfig0.setPort(24225);
TCPSender.Config senderConfig1 = new TCPSender.Config();
senderConfig1.setHost("0.0.0.0");
senderConfig1.setPort(24226);
TCPHeartbeater.Config hbConfig1 = new TCPHeartbeater.Config();
hbConfig1.setHost("0.0.0.0");
hbConfig1.setPort(24226);
multiSender = new MultiSender(new MultiSender.Config(), Arrays.asList(new TCPSender(senderConfig0, createFailureDetector(new TCPHeartbeater(hbConfig0))), new TCPSender(senderConfig1, createFailureDetector(new TCPHeartbeater(hbConfig1)))));
assertThat(multiSender.toString().length(), greaterThan(0));
assertEquals(2, multiSender.getSenders().size());
TCPSender tcpSender = (TCPSender) multiSender.getSenders().get(0);
assertEquals("127.0.0.1", tcpSender.getHost());
assertEquals(24225, tcpSender.getPort());
assertEquals("127.0.0.1", tcpSender.getFailureDetector().getHeartbeater().getHost());
assertEquals(24225, tcpSender.getFailureDetector().getHeartbeater().getPort());
tcpSender = (TCPSender) multiSender.getSenders().get(1);
assertEquals("0.0.0.0", tcpSender.getHost());
assertEquals(24226, tcpSender.getPort());
assertEquals("0.0.0.0", tcpSender.getFailureDetector().getHeartbeater().getHost());
assertEquals(24226, tcpSender.getFailureDetector().getHeartbeater().getPort());
} finally {
if (multiSender != null) {
multiSender.close();
}
}
}
use of org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.TCPHeartbeater in project fluency by komamitsu.
the class FailureDetectorTest method testIsAvailable.
@Test
void testIsAvailable() throws IOException, InterruptedException {
final ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().bind(null);
int localPort = serverSocketChannel.socket().getLocalPort();
final ExecutorService executorService = Executors.newSingleThreadExecutor();
Runnable serverTask = () -> {
while (!executorService.isShutdown()) {
try (SocketChannel accept = serverSocketChannel.accept()) {
LOG.debug("Accepted: {}", accept);
} catch (IOException e) {
LOG.warn("Stab TCP server got an error", e);
}
}
try {
serverSocketChannel.close();
} catch (IOException e) {
LOG.warn("Failed to close serverSocketChannel", e);
}
};
executorService.execute(serverTask);
TCPHeartbeater.Config heartbeaterConfig = new TCPHeartbeater.Config();
heartbeaterConfig.setPort(localPort);
PhiAccrualFailureDetectStrategy.Config failureDetectorConfig = new PhiAccrualFailureDetectStrategy.Config();
try (FailureDetector failureDetector = new FailureDetector(new PhiAccrualFailureDetectStrategy(failureDetectorConfig), new TCPHeartbeater(heartbeaterConfig))) {
assertTrue(failureDetector.isAvailable());
TimeUnit.SECONDS.sleep(4);
assertTrue(failureDetector.isAvailable());
executorService.shutdownNow();
for (int i = 0; i < 20; i++) {
if (!failureDetector.isAvailable()) {
break;
}
TimeUnit.MILLISECONDS.sleep(500);
}
assertFalse(failureDetector.isAvailable());
}
}
use of org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.TCPHeartbeater in project fluency by komamitsu.
the class TCPSenderTest method testSendWithHeartbeart.
@Test
void testSendWithHeartbeart() throws Exception {
testSendBase(port -> {
TCPHeartbeater.Config hbConfig = new TCPHeartbeater.Config();
hbConfig.setPort(port);
hbConfig.setIntervalMillis(400);
TCPSender.Config senderConfig = new TCPSender.Config();
senderConfig.setPort(port);
return new TCPSender(senderConfig, new FailureDetector(new PhiAccrualFailureDetectStrategy(), new TCPHeartbeater(hbConfig)));
}, greaterThan(1), greaterThan(1));
}
use of org.komamitsu.fluency.fluentd.ingester.sender.heartbeat.TCPHeartbeater in project fluency by komamitsu.
the class FluencyBuilderForFluentd method createBaseSender.
private FluentdSender createBaseSender(String host, Integer port, boolean withHeartBeater) {
if (withHeartBeater && port == null) {
throw new IllegalArgumentException("`port` should be specified when using heartbeat");
}
if (isSslEnabled()) {
SSLSender.Config senderConfig = new SSLSender.Config();
FailureDetector failureDetector = null;
if (host != null) {
senderConfig.setHost(host);
}
if (port != null) {
senderConfig.setPort(port);
}
if (withHeartBeater) {
SSLHeartbeater.Config hbConfig = new SSLHeartbeater.Config();
hbConfig.setHost(host);
hbConfig.setPort(port);
SSLHeartbeater heartbeater = new SSLHeartbeater(hbConfig);
failureDetector = new FailureDetector(new PhiAccrualFailureDetectStrategy(), heartbeater);
}
if (connectionTimeoutMilli != null) {
senderConfig.setConnectionTimeoutMilli(connectionTimeoutMilli);
}
if (readTimeoutMilli != null) {
senderConfig.setReadTimeoutMilli(readTimeoutMilli);
}
return new SSLSender(senderConfig, failureDetector);
} else {
TCPSender.Config senderConfig = new TCPSender.Config();
FailureDetector failureDetector = null;
if (host != null) {
senderConfig.setHost(host);
}
if (port != null) {
senderConfig.setPort(port);
}
if (withHeartBeater) {
TCPHeartbeater.Config hbConfig = new TCPHeartbeater.Config();
hbConfig.setHost(host);
hbConfig.setPort(port);
TCPHeartbeater heartbeater = new TCPHeartbeater(hbConfig);
failureDetector = new FailureDetector(new PhiAccrualFailureDetectStrategy(), heartbeater);
}
if (connectionTimeoutMilli != null) {
senderConfig.setConnectionTimeoutMilli(connectionTimeoutMilli);
}
if (readTimeoutMilli != null) {
senderConfig.setReadTimeoutMilli(readTimeoutMilli);
}
return new TCPSender(senderConfig, failureDetector);
}
}
Aggregations