Search in sources :

Example 36 with Event

use of loghub.Event 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 37 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestElasticSearch method testSendInQueue.

@Test
public void testSendInQueue() throws InterruptedException {
    Stats.reset();
    int count = 20;
    ArrayBlockingQueue<Event> queue = new ArrayBlockingQueue<>(count - 1);
    ElasticSearch es = new ElasticSearch(queue);
    es.setDestinations(new String[] { "http://localhost:" + serverPort });
    es.setTimeout(1);
    es.setBuffersize(10);
    Assert.assertTrue("Elastic configuration failed", es.configure(new Properties(Collections.emptyMap())));
    es.start();
    for (int i = 0; i < count; i++) {
        Event ev = Tools.getEvent();
        ev.put("type", "junit");
        ev.put("value", "atest" + i);
        ev.setTimestamp(new Date(0));
        queue.add(ev);
        Thread.sleep(1);
    }
    es.close();
    Thread.sleep(1000);
    if (failure != null) {
        throw failure;
    }
    Assert.assertEquals(count, received.get());
    Assert.assertEquals(count, Stats.sent.intValue());
    Assert.assertEquals(0, Stats.failed.intValue());
    Assert.assertEquals(0, Properties.metrics.counter("Allevents.inflight").getCount());
    logger.debug("event received: {}", received);
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 38 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestElasticSearch method testSend.

@Test
public void testSend() throws InterruptedException {
    int count = 20;
    ElasticSearch es = new ElasticSearch(new ArrayBlockingQueue<>(count));
    es.setDestinations(new String[] { "http://localhost:" + serverPort });
    es.setTimeout(1);
    es.setBuffersize(10);
    Assert.assertTrue("Elastic configuration failed", es.configure(new Properties(Collections.emptyMap())));
    es.start();
    for (int i = 0; i < count; i++) {
        Event ev = Tools.getEvent();
        ev.put("type", "junit");
        ev.put("value", "atest" + i);
        ev.setTimestamp(new Date(0));
        Assert.assertTrue(es.send(ev));
        Thread.sleep(1);
    }
    es.close();
    Thread.sleep(1000);
    if (failure != null) {
        throw failure;
    }
    Assert.assertEquals(count, received.get());
    logger.debug("event received: {}", received);
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 39 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestTest method testSub.

@Test(timeout = 2000)
public void testSub() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("testclause.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("a", 2);
    conf.mainQueue.add(sent);
    EventsProcessor ep = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
    sent.inject(conf.namedPipeLine.get("subpipe"), conf.mainQueue);
    ep.start();
    Event received = conf.outputQueues.get("subpipe").take();
    Assert.assertEquals("conversion not expected", 2, received.get("d"));
    ep.interrupt();
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) EventsProcessor(loghub.EventsProcessor) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 40 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestTest method testOK.

@Test
public void testOK() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("testclause.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("a", 1);
    Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
    Assert.assertEquals("conversion not expected", 1, sent.get("b"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Aggregations

Event (loghub.Event)102 Test (org.junit.Test)90 Properties (loghub.configuration.Properties)63 Pipeline (loghub.Pipeline)23 Date (java.util.Date)19 Map (java.util.Map)18 HashMap (java.util.HashMap)14 IOException (java.io.IOException)13 Tools (loghub.Tools)13 URL (java.net.URL)8 Collections (java.util.Collections)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 Level (org.apache.logging.log4j.Level)7 List (java.util.List)6 EventsProcessor (loghub.EventsProcessor)6 LogManager (org.apache.logging.log4j.LogManager)6 Logger (org.apache.logging.log4j.Logger)6 LogUtils (loghub.LogUtils)5 ProcessorException (loghub.ProcessorException)5 Assert (org.junit.Assert)5