Search in sources :

Example 21 with Properties

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

the class TestDateParser method test1.

@Test
public void test1() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("ISO_DATE_TIME");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", DateTimeFormatter.ISO_DATE_TIME.format(ZonedDateTime.now()));
    parse.process(event);
    assertTrue("date not parsed", event.get("field") instanceof Date);
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Date(java.util.Date) Test(org.junit.Test)

Example 22 with Properties

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

the class TestDateParser method testIncomplete.

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

Example 23 with Properties

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

the class TestDateParser method testAgain.

@Test
public void testAgain() throws ProcessorException {
    DateParser parse = new DateParser();
    parse.setPattern("yyyy-MM-dd'T'HH:m:ss.SSSxx");
    parse.setTimezone("CET");
    parse.setField("field");
    Assert.assertTrue(parse.configure(new Properties(Collections.emptyMap())));
    Event event = Tools.getEvent();
    event.put("field", "2016-08-04T18:57:37.238+0000");
    parse.process(event);
    Date date = (Date) event.get("field");
    OffsetDateTime t = OffsetDateTime.ofInstant(date.toInstant(), ZoneId.of("GMT"));
    Assert.assertEquals("date not parsed", 18, 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)

Example 24 with Properties

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

the class TestEtl method test2.

@Test
public void test2() throws ProcessorException {
    Etl etl = new Etl.Remove();
    etl.setLvalue(new String[] { "a" });
    boolean done = etl.configure(new Properties(Collections.emptyMap()));
    Assert.assertTrue("configuration failed", done);
    Event event = Tools.getEvent();
    event.put("a", 0);
    etl.process(event);
    Assert.assertEquals("evaluation failed", null, event.applyAtPath((i, j, k) -> i.get(j), new String[] { "a" }, 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 25 with Properties

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

the class TestEtl method test3.

@Test
public void test3() throws ProcessorException {
    Etl.Rename etl = new Etl.Rename();
    etl.setLvalue(new String[] { "b" });
    etl.setSource(new String[] { "a" });
    boolean done = etl.configure(new Properties(Collections.emptyMap()));
    Assert.assertTrue("configuration failed", done);
    Event event = Tools.getEvent();
    event.put("a", 0);
    etl.process(event);
    Assert.assertEquals("evaluation failed", 0, event.applyAtPath((i, j, k) -> i.get(j), new String[] { "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)

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