Search in sources :

Example 1 with StringCodec

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);
}
Also used : StringCodec(loghub.decoders.StringCodec)

Example 2 with StringCodec

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();
}
Also used : StringCodec(loghub.decoders.StringCodec) ServerSocket(java.net.ServerSocket) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline)

Example 3 with StringCodec

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);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) StringCodec(loghub.decoders.StringCodec) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) Event(loghub.Event) InetAddress(java.net.InetAddress)

Example 4 with StringCodec

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);
}
Also used : StringCodec(loghub.decoders.StringCodec) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline)

Aggregations

StringCodec (loghub.decoders.StringCodec)4 Pipeline (loghub.Pipeline)3 Properties (loghub.configuration.Properties)3 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 Event (loghub.Event)2 IOException (java.io.IOException)1 DatagramPacket (java.net.DatagramPacket)1 DatagramSocket (java.net.DatagramSocket)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1