Search in sources :

Example 16 with Properties

use of loghub.configuration.Properties 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 17 with Properties

use of loghub.configuration.Properties 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 18 with Properties

use of loghub.configuration.Properties 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 19 with Properties

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

Example 20 with Properties

use of loghub.configuration.Properties in project LogHub by fbacchella.

the class TestDateParser method testAgain2.

@Test
public void testAgain2() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("MMM dd HH:mm:ss.SSS");
    parse.setTimezone("CET");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "Jul 26 16:40:22.238");
    parse.process(event);
    Date date = (Date) event.get("field");
    OffsetDateTime t = OffsetDateTime.ofInstant(date.toInstant(), ZoneId.of("GMT"));
    Assert.assertEquals("date not parsed", 14, t.getLong(ChronoField.HOUR_OF_DAY));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Properties (loghub.configuration.Properties)74 Test (org.junit.Test)65 Event (loghub.Event)64 Pipeline (loghub.Pipeline)23 Date (java.util.Date)17 Map (java.util.Map)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)10 Collections (java.util.Collections)7 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)7 Level (org.apache.logging.log4j.Level)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 LogUtils (loghub.LogUtils)6 ProcessorException (loghub.ProcessorException)6 Tools (loghub.Tools)6 Assert (org.junit.Assert)6 BeforeClass (org.junit.BeforeClass)6 ConfigException (loghub.configuration.ConfigException)5 StringReader (java.io.StringReader)4