Search in sources :

Example 61 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestEtl method test1.

@Test
public void test1() throws ProcessorException {
    Etl.Assign etl = new Etl.Assign();
    etl.setLvalue(new String[] { "a", "b" });
    etl.setExpression("event.c + 1");
    boolean done = etl.configure(new Properties(Collections.emptyMap()));
    Assert.assertTrue("configuration failed", done);
    Event event = Tools.getEvent();
    event.put("c", 0);
    event.process(etl);
    Assert.assertEquals("evaluation failed", 1, event.applyAtPath((i, j, k) -> i.get(j), new String[] { "a", "b" }, null, false));
}
Also used : BeforeClass(org.junit.BeforeClass) Pipeline(loghub.Pipeline) Date(java.util.Date) Level(org.apache.logging.log4j.Level) IOException(java.io.IOException) HashMap(java.util.HashMap) Test(org.junit.Test) LogUtils(loghub.LogUtils) Tools(loghub.Tools) ConfigException(loghub.configuration.ConfigException) Logger(org.apache.logging.log4j.Logger) ProcessorException(loghub.ProcessorException) Map(java.util.Map) Assert(org.junit.Assert) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Event(loghub.Event) Properties(loghub.configuration.Properties) Event(loghub.Event) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 62 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestEtl method test5.

@Test
public void test5() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("etl.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("a", "a");
    Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
    Assert.assertEquals("conversion not expected", "a", sent.get("a"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 63 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestEtl method test7.

@Test
public void test7() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("etl.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    Map<String, Object> b = new HashMap<>(1);
    b.put("c", 1);
    sent.put("b", b);
    Tools.runProcessing(sent, conf.namedPipeLine.get("third"), conf);
    Assert.assertEquals("conversion not expected", 1, sent.get("a"));
}
Also used : HashMap(java.util.HashMap) Event(loghub.Event) Properties(loghub.configuration.Properties) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 64 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestEtl method test8.

@Test
public void test8() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("etl.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.setTimestamp(new Date(1));
    Tools.runProcessing(sent, conf.namedPipeLine.get("timestamp"), conf);
    Assert.assertEquals(new Date(0), sent.getTimestamp());
    Assert.assertEquals(new Date(1), sent.get("reception_time"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 65 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestEtl method test4.

@Test
public void test4() throws ProcessorException {
    Etl.Assign etl = new Etl.Assign();
    etl.setLvalue(new String[] { "a" });
    etl.setExpression("formatters.a.format(event)");
    Map<String, String> formats = Collections.singletonMap("a", "${@timestamp%t<GMT>H}");
    Map<String, Object> properties = new HashMap<>();
    properties.put("__FORMATTERS", formats);
    boolean done = etl.configure(new Properties(properties));
    Assert.assertTrue("configuration failed", done);
    Event event = Tools.getEvent();
    event.setTimestamp(new Date(3600 * 1000));
    event.process(etl);
    Assert.assertEquals("evaluation failed", "01", event.get("a"));
}
Also used : HashMap(java.util.HashMap) Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) 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