Search in sources :

Example 41 with Properties

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

the class TestDateParser method test3.

@Test
public void test3() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("yyyy-MM-dd'T'HH:m:ss");
    parse.setTimezone("Z");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "1970-01-01T00:00:00");
    parse.process(event);
    Date date = (Date) event.get("field");
    Assert.assertEquals("date not parsed", 0L, date.getTime());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 42 with Properties

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

the class TestDateParser method test4.

@Test
public void test4() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "Tue, 3 Jun 2008 11:05:30 +0110");
    parse.process(event);
    Assert.assertTrue("date not parsed", event.get("field") instanceof Date);
    Date date = (Date) event.get("field");
    Assert.assertEquals("date not parsed", 1212486930000L, date.getTime());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 43 with Properties

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

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

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

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