Search in sources :

Example 1 with EventsProcessor

use of loghub.EventsProcessor in project LogHub by fbacchella.

the class Tools method runProcessing.

public static ProcessingStatus runProcessing(Event sent, String pipename, List<Processor> steps, BiConsumer<Properties, List<Processor>> prepare) throws ProcessorException {
    Properties props = new Properties(Collections.emptyMap());
    ProcessingStatus ps = new ProcessingStatus();
    ps.mainQueue = props.mainQueue;
    ps.status = new ArrayList<>();
    ps.repository = props.repository;
    Pipeline pipe = new Pipeline(steps, pipename, null);
    Map<String, Pipeline> namedPipeLine = Collections.singletonMap(pipename, pipe);
    EventsProcessor ep = new EventsProcessor(props.mainQueue, props.outputQueues, namedPipeLine, 100, props.repository);
    Processor processor;
    steps.forEach(i -> Assert.assertTrue(i.configure(props)));
    prepare.accept(props, steps);
    sent.inject(pipe, props.mainQueue);
    Event toprocess;
    // Process all the events, will hang forever is it don't finish
    try {
        while ((toprocess = props.mainQueue.poll(5, TimeUnit.SECONDS)) != null) {
            while ((processor = toprocess.next()) != null) {
                EventsProcessor.ProcessingStatus status = ep.process(toprocess, processor);
                ps.status.add(status.name());
                if (status != loghub.EventsProcessor.ProcessingStatus.SUCCESS) {
                    toprocess = null;
                    break;
                }
            }
            if (toprocess != null) {
                ps.mainQueue.put(toprocess);
                break;
            }
        }
    } catch (InterruptedException e) {
    }
    return ps;
}
Also used : EventsProcessor(loghub.EventsProcessor) Properties(loghub.configuration.Properties) EventsProcessor(loghub.EventsProcessor)

Example 2 with EventsProcessor

use of loghub.EventsProcessor in project LogHub by fbacchella.

the class TestConfigurations method testFork.

@Test
public void testFork() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("forkforward.conf");
    EventsProcessor ep = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
    ep.start();
    try {
        Event sent = Tools.getEvent();
        sent.inject(conf.namedPipeLine.get("mainfork"), conf.mainQueue);
        Event forked = conf.outputQueues.get("forked").poll(1, TimeUnit.SECONDS);
        Event initial = conf.outputQueues.get("mainfork").poll(1, TimeUnit.SECONDS);
        Assert.assertEquals(1, forked.size());
        Assert.assertEquals(1, initial.size());
        Assert.assertEquals(2, forked.get("b"));
        Assert.assertEquals(1, initial.get("a"));
    } finally {
        ep.interrupt();
    }
}
Also used : Event(loghub.Event) EventsProcessor(loghub.EventsProcessor) Test(org.junit.Test)

Example 3 with EventsProcessor

use of loghub.EventsProcessor in project LogHub by fbacchella.

the class TestConfigurations method testForward.

@Test
public void testForward() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("forkforward.conf");
    EventsProcessor ep = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
    ep.start();
    try {
        Event sent = Tools.getEvent();
        sent.inject(conf.namedPipeLine.get("mainforward"), conf.mainQueue);
        Event forwarded = conf.outputQueues.get("forked").poll(1, TimeUnit.SECONDS);
        Event initial = conf.outputQueues.get("mainforward").poll(1, TimeUnit.SECONDS);
        Assert.assertEquals(1, forwarded.size());
        Assert.assertNull(initial);
        Assert.assertEquals(2, forwarded.get("b"));
        Assert.assertNull(sent.get("a"));
    } finally {
        ep.interrupt();
    }
}
Also used : Event(loghub.Event) EventsProcessor(loghub.EventsProcessor) Test(org.junit.Test)

Example 4 with EventsProcessor

use of loghub.EventsProcessor in project LogHub by fbacchella.

the class TestWrapping method testSourceLoading.

@SuppressWarnings("unchecked")
@Test
public void testSourceLoading() throws ConfigException, IOException, ProcessorException, InterruptedException {
    Properties conf = Tools.loadConf("wrap.conf");
    Event ev = Event.emptyEvent(null);
    ev.put("a", new HashMap<Object, Object>());
    EventsProcessor ep = new EventsProcessor(conf.mainQueue, conf.outputQueues, conf.namedPipeLine, conf.maxSteps, conf.repository);
    ev.inject(conf.namedPipeLine.get("main"), conf.mainQueue);
    ep.start();
    Event processed = conf.outputQueues.get("main").poll(1, TimeUnit.SECONDS);
    Assert.assertEquals("b", ((Map<String, Object>) processed.get("a")).get("c"));
}
Also used : Event(loghub.Event) EventsProcessor(loghub.EventsProcessor) Test(org.junit.Test)

Example 5 with EventsProcessor

use of loghub.EventsProcessor 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)

Aggregations

EventsProcessor (loghub.EventsProcessor)8 Event (loghub.Event)6 Test (org.junit.Test)5 Properties (loghub.configuration.Properties)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneId (java.time.ZoneId)1 ZoneOffset (java.time.ZoneOffset)1 TemporalAccessor (java.time.temporal.TemporalAccessor)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Pipeline (loghub.Pipeline)1