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