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;
}
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();
}
}
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();
}
}
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"));
}
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();
}
Aggregations