Search in sources :

Example 1 with ProcessorException

use of loghub.ProcessorException 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 2 with ProcessorException

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

Example 3 with ProcessorException

use of loghub.ProcessorException 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 4 with ProcessorException

use of loghub.ProcessorException in project LogHub by fbacchella.

the class Groovy method process.

@Override
public boolean process(Event event) throws ProcessorException {
    Binding groovyBinding = new Binding();
    groovyBinding.setVariable("event", event);
    groovyScript.setBinding(groovyBinding);
    try {
        return Boolean.TRUE.equals(groovyScript.run());
    } catch (Exception e) {
        throw event.buildException("groovy script failed", e);
    }
}
Also used : Binding(groovy.lang.Binding) ProcessorException(loghub.ProcessorException)

Aggregations

ProcessorException (loghub.ProcessorException)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Event (loghub.Event)3 LogUtils (loghub.LogUtils)3 Pipeline (loghub.Pipeline)3 Tools (loghub.Tools)3 ConfigException (loghub.configuration.ConfigException)3 Properties (loghub.configuration.Properties)3 Level (org.apache.logging.log4j.Level)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 Assert (org.junit.Assert)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)3 Binding (groovy.lang.Binding)1