Search in sources :

Example 21 with Event

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

use of loghub.Event in project LogHub by fbacchella.

the class TestServer method testSimple.

@Test(timeout = 2000)
public void testSimple() throws InterruptedException {
    Properties empty = new Properties(Collections.emptyMap());
    BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(1);
    TesterReceiver r = new TesterReceiver(receiver, new Pipeline(Collections.emptyList(), "testone", null));
    r.configure(empty);
    final ChannelFuture[] sent = new ChannelFuture[1];
    EventLoopGroup workerGroup = new DefaultEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(workerGroup);
    b.channel(LocalChannel.class);
    b.handler(new SimpleChannelInboundHandler<ByteBuf>() {

        @Override
        public void channelActive(ChannelHandlerContext ctx) {
            sent[0] = ctx.writeAndFlush(Unpooled.copiedBuffer("Message\r\n", CharsetUtil.UTF_8));
        }

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
        }
    });
    // Start the client.
    ChannelFuture f = b.connect(new LocalAddress(TestServer.class.getCanonicalName())).sync();
    Thread.sleep(100);
    sent[0].sync();
    f.channel().close();
    // Wait until the connection is closed.
    f.channel().closeFuture().sync();
    Event e = receiver.poll();
    Assert.assertEquals("Message", e.get("message"));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LocalAddress(io.netty.channel.local.LocalAddress) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Properties(loghub.configuration.Properties) ByteBuf(io.netty.buffer.ByteBuf) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) IOException(java.io.IOException) Pipeline(loghub.Pipeline) ChannelPipeline(io.netty.channel.ChannelPipeline) EventLoopGroup(io.netty.channel.EventLoopGroup) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Event(loghub.Event) AbstractBootstrap(io.netty.bootstrap.AbstractBootstrap) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Test(org.junit.Test)

Example 23 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestConditions method testfailure.

@Test
public void testfailure() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("conditions.conf");
    Event sent = Tools.getEvent();
    sent.put("a", "a");
    Tools.runProcessing(sent, conf.namedPipeLine.get("failurepipe"), conf);
    Assert.assertEquals("conversion not expected", "a", sent.get("a"));
    Assert.assertEquals("conversion not expected", "failure", sent.get("test"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 24 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestConditions method testignored.

@Test
public void testignored() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("conditions.conf");
    Event sent = Tools.getEvent();
    sent.put("z", "1");
    Tools.runProcessing(sent, conf.namedPipeLine.get("ignore"), conf);
    Assert.assertEquals("success was called", null, sent.get("b"));
    Assert.assertEquals("failure was called", null, sent.get("c"));
    Assert.assertEquals("exception was called", null, sent.get("d"));
    Assert.assertEquals("Event was processed, when it should not have been", "1", sent.get("z"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 25 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestConditions method testsubpipe.

@Test
public void testsubpipe() throws InterruptedException, ProcessorException, ConfigException, IOException {
    Properties conf = Tools.loadConf("conditions.conf");
    Event sent = Tools.getEvent();
    sent.put("a", "1");
    Tools.runProcessing(sent, conf.namedPipeLine.get("subpipe"), conf);
    Assert.assertEquals("sup pipeline not processed", 1, sent.get("b"));
    Assert.assertEquals("sup pipeline not processed", 2, sent.get("c"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) 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