use of loghub.decoders.StringCodec in project LogHub by fbacchella.
the class TcpLinesStream method configure.
@Override
public boolean configure(Properties properties) {
StringCodec stringcodec = new StringCodec();
stringcodec.setCharset(charset.toString());
stringcodec.setField(field);
decoder = stringcodec;
return super.configure(properties);
}
use of loghub.decoders.StringCodec in project LogHub by fbacchella.
the class TestHttp method makeReceiver.
public void makeReceiver(Consumer<Http> prepare) throws IOException {
// Generate a locally binded random socket
ServerSocket socket = new ServerSocket(0, 10, InetAddress.getLoopbackAddress());
hostname = socket.getInetAddress().getHostAddress();
port = socket.getLocalPort();
socket.close();
queue = new ArrayBlockingQueue<>(1);
receiver = new Http(queue, new Pipeline(Collections.emptyList(), "testhttp", null));
receiver.setHost(hostname);
receiver.setPort(port);
receiver.setDecoder(new StringCodec());
prepare.accept(receiver);
Assert.assertTrue(receiver.configure(new Properties(Collections.emptyMap())));
receiver.start();
}
use of loghub.decoders.StringCodec in project LogHub by fbacchella.
the class TestUdp method testsend.
private void testsend(int size) throws IOException, InterruptedException {
// Generate a locally binded random socket
DatagramSocket socket = new DatagramSocket(0, InetAddress.getLoopbackAddress());
String hostname = socket.getLocalAddress().getHostAddress();
int port = socket.getLocalPort();
socket.close();
InetSocketAddress destaddr = new InetSocketAddress(hostname, port);
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(10);
Udp r = new Udp(receiver, new Pipeline(Collections.emptyList(), "testone", null));
r.setBufferSize(size + 10);
r.setHost(hostname);
r.setPort(port);
r.setDecoder(new StringCodec());
Assert.assertTrue(r.configure(new Properties(Collections.emptyMap())));
r.start();
int originalMessageSize = 0;
try (DatagramSocket send = new DatagramSocket()) {
StringBuilder buffer = new StringBuilder();
while (buffer.length() <= size) {
buffer.append("message");
}
byte[] buf = buffer.toString().getBytes();
originalMessageSize = buffer.length();
DatagramPacket packet = new DatagramPacket(buf, buf.length, destaddr);
try {
logger.debug("Listening on {}", r.getListenAddress());
send.send(packet);
logger.debug("One message sent to {}", packet.getAddress());
} catch (IOException e1) {
logger.error("IO exception on port {}", r.getPort());
throw e1;
}
}
Event e = receiver.take();
r.interrupt();
Assert.assertTrue("Invalid message content", e.get("message").toString().startsWith("message"));
Assert.assertEquals("Invalid message size", originalMessageSize, e.get("message").toString().length());
Assert.assertTrue("didn't find valid hosts informations", e.get("host") instanceof InetAddress);
}
use of loghub.decoders.StringCodec in project LogHub by fbacchella.
the class TestZMQ method dotest.
private void dotest(Consumer<ZMQ> configure, Socket sender) throws InterruptedException {
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(1);
ZMQ r = new ZMQ(receiver, new Pipeline(Collections.emptyList(), "testone", null));
configure.accept(r);
r.setDecoder(new StringCodec());
Assert.assertTrue(r.configure(new Properties(Collections.emptyMap())));
r.start();
Thread.sleep(30);
Assert.assertTrue(sender.send("message 1"));
Event e = receiver.take();
Assert.assertEquals("Missing message", "message 1", e.get("message"));
tctxt.ctx.close(sender);
}
Aggregations