Search in sources :

Example 66 with Properties

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

the class TestScanBinary method testConfigFile.

@Test
public void testConfigFile() throws ProcessorException, InterruptedException, ConfigException, IOException {
    Properties conf = Tools.loadConf("scanbinary.conf");
    for (Pipeline pipe : conf.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(conf));
    }
    Event sent = Tools.getEvent();
    sent.put("binary", 0b110101);
    Tools.runProcessing(sent, conf.namedPipeLine.get("main"), conf);
    @SuppressWarnings("unchecked") Map<String, Number> value = (Map<String, Number>) sent.get("binary");
    Assert.assertEquals(0b101, value.get("a").intValue());
    Assert.assertEquals(0b10, value.get("b").intValue());
    Assert.assertEquals(0b1, value.get("c").intValue());
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) Map(java.util.Map) Pipeline(loghub.Pipeline) Test(org.junit.Test)

Example 67 with Properties

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

the class TestScript method testJs.

@Test
public void testJs() throws IOException, ProcessorException {
    Script s = new loghub.processors.Script();
    URL scripturl = getClass().getClassLoader().getResource("script.js");
    s.setScript(scripturl.getFile());
    Assert.assertTrue("Script engine for Javascript not found", s.configure(new Properties(Collections.emptyMap())));
    Event e = Tools.getEvent();
    s.process(e);
    Assert.assertTrue("event not transformed", (Boolean) e.get("done"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) URL(java.net.URL) Test(org.junit.Test)

Example 68 with Properties

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

the class TestScript method testPython.

@Test
public void testPython() throws IOException, ProcessorException {
    Script s = new loghub.processors.Script();
    URL scripturl = getClass().getClassLoader().getResource("script.py");
    s.setScript(scripturl.getFile());
    Assert.assertTrue("Script engine for Python not found", s.configure(new Properties(Collections.emptyMap())));
    Event e = Tools.getEvent();
    s.process(e);
    Assert.assertTrue("event not transformed", (Boolean) e.get("done"));
}
Also used : Event(loghub.Event) Properties(loghub.configuration.Properties) URL(java.net.URL) Test(org.junit.Test)

Example 69 with Properties

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

the class TestScript method enumerateScript.

@Test
public void enumerateScript() {
    Properties props = new Properties(Collections.emptyMap());
    ScriptEngineManager factory = new ScriptEngineManager(props.classloader);
    factory.getEngineFactories().stream().forEach(i -> {
        Assert.assertNotNull(i.getScriptEngine());
        logger.debug("{}/{}: {}/{}", () -> i.getEngineName(), () -> i.getEngineVersion(), () -> i.getLanguageName(), () -> i.getLanguageVersion());
    });
}
Also used : ScriptEngineManager(javax.script.ScriptEngineManager) Properties(loghub.configuration.Properties) Test(org.junit.Test)

Example 70 with Properties

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

the class Tools method loadConf.

public static Properties loadConf(String configname, boolean dostart) throws ConfigException, IOException {
    String conffile = Configuration.class.getClassLoader().getResource(configname).getFile();
    Properties props = Configuration.parse(conffile);
    for (Pipeline pipe : props.pipelines) {
        Assert.assertTrue("configuration failed", pipe.configure(props));
    }
    return props;
}
Also used : Properties(loghub.configuration.Properties)

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