Search in sources :

Example 91 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestScript method testPython.

@Test
public void testPython() throws IOException, ProcessorException {
    Script s = new loghub.processors.Script();
    URL scripturl = getClass().getClassLoader().getResource("script.py");
    s.setScript(scripturl.getFile());
    Assert.assertTrue("Script engine for Python not found", s.configure(new Properties(Collections.emptyMap())));
    Event e = Tools.getEvent();
    s.process(e);
    Assert.assertTrue("event not transformed", (Boolean) e.get("done"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) URL(java.net.URL) Test(org.junit.Test)

Example 92 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestConfigurations method testBuildPipeline.

@Test
public void testBuildPipeline() throws IOException, InterruptedException, ConfigException {
    Properties conf = Tools.loadConf("simple.conf");
    Event sent = Tools.getEvent();
    logger.debug("pipelines: " + conf.pipelines);
    logger.debug("namedPipeLine: " + conf.namedPipeLine);
    conf.mainQueue.add(sent);
    Event received = conf.mainQueue.poll(1, TimeUnit.SECONDS);
    Assert.assertEquals("not expected event received", sent, received);
}
Also used : Event(loghub.Event) Test(org.junit.Test)

Example 93 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestConfigurations method testSubPipeline.

@Test
public void testSubPipeline() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("subpipeline.conf");
    Event sent = Tools.getEvent();
    sent.put("a", "1");
    sent.put("b", "2");
    Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
    Event received = conf.mainQueue.remove();
    Assert.assertEquals("Subpipeline not processed", 1, received.get("a"));
    Assert.assertEquals("Subpipeline not processed", 2, received.get("b"));
}
Also used : Event(loghub.Event) Test(org.junit.Test)

Example 94 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestConfigurations method testTwoPipe.

@Test
public void testTwoPipe() throws InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("twopipe.conf");
    Thread t = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
    t.setDaemon(true);
    t.start();
    Event sent = Tools.getEvent();
    sent.put("message", "1");
    sent.inject(conf.namedPipeLine.get("pipeone"), conf.mainQueue);
    try {
        Event re = conf.outputQueues.get("main").poll(1, TimeUnit.SECONDS);
        Assert.assertEquals("wrong event received", "1", re.get("message"));
    } finally {
        logger.debug("{} is at main pipeline {}", sent, sent.getCurrentPipeline());
        t.interrupt();
    }
}
Also used : Event(loghub.Event) EventsProcessor(loghub.EventsProcessor) Test(org.junit.Test)

Example 95 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestWithZMQ method testSimpleInput.

@Test(timeout = 3000)
public void testSimpleInput() throws InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("simpleinput.conf");
    logger.debug("pipelines: {}", conf.pipelines);
    for (Receiver r : conf.receivers) {
        Assert.assertTrue("failed to configure " + r, r.configure(conf));
        r.start();
    }
    for (Sender s : conf.senders) {
        Assert.assertTrue("failed to configure " + s, s.configure(conf));
        s.start();
    }
    Socket out = tctxt.ctx.newSocket(Method.CONNECT, Type.SUB, "inproc://sender", 1, -1);
    out.subscribe(new byte[] {});
    Socket sender = tctxt.ctx.newSocket(Method.CONNECT, Type.PUB, "inproc://listener", 1, -1);
    // Wait for ZMQ to be started
    Thread.sleep(30);
    sender.send("something");
    Event received = conf.mainQueue.poll(1, TimeUnit.SECONDS);
    Assert.assertNotNull("nothing received", received);
    conf.outputQueues.get("main").add(received);
    byte[] buffer = out.recv();
    Assert.assertEquals("wrong send message", "something", new String(buffer));
    tctxt.ctx.close(sender);
    tctxt.ctx.close(out);
    for (Receiver r : conf.receivers) {
        r.interrupt();
    }
    for (Sender s : conf.senders) {
        s.interrupt();
    }
    SmartContext.getContext().terminate();
}
Also used : Sender(loghub.Sender) Receiver(loghub.Receiver) Event(loghub.Event) Socket(org.zeromq.ZMQ.Socket) 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