use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestMerge method test.
@SuppressWarnings("rawtypes")
@Test
public void test() throws Throwable {
String conf = "pipeline[main] { merge {index: \"${e%s}\", seeds: {\"a\": 0, \"b\": \",\", \"d\": 0.0, \"e\": null, \"c\": [], \"count\": 'c', \"@timestamp\": '>', \"f\": {}}, doFire: [a] >= 2, inPipeline: \"main\", forward: false}}";
Properties p = Configuration.parse(new StringReader(conf));
Assert.assertTrue(p.pipelines.stream().allMatch(i -> i.configure(p)));
Merge m = (Merge) p.namedPipeLine.get("main").processors.stream().findFirst().get();
try {
m.process(Event.emptyEvent(ConnectionContext.EMPTY));
} catch (ProcessorException.DroppedEventException e1) {
}
Event e = Event.emptyEvent(ConnectionContext.EMPTY);
e.setTimestamp(new Date(0));
e.put("a", 1);
e.put("b", 2);
e.put("c", 3);
e.put("d", 4);
e.put("e", "5");
e.put("f", Collections.singletonMap(".f", 1));
boolean dropped = false;
try {
m.process(e);
} catch (ProcessorException.DroppedEventException e1) {
dropped = true;
}
long timestamp = 0;
try {
e.setTimestamp(new Date());
e.put("f", Collections.singletonMap(".f", "2"));
timestamp = e.getTimestamp().getTime();
Assert.assertTrue(m.process(e));
} catch (ProcessorException.DroppedEventException e1) {
dropped = true;
}
Thread.yield();
e = p.mainQueue.remove();
Assert.assertTrue(dropped);
Assert.assertTrue(p.mainQueue.isEmpty());
Assert.assertEquals("2,2", e.get("b"));
Assert.assertEquals(8.0, (double) e.get("d"), 1e-5);
Assert.assertEquals(null, e.get("e"));
Assert.assertTrue(e.get("f") instanceof Map);
Assert.assertTrue(((Map) e.get("f")).get(".f") instanceof List);
Assert.assertEquals(timestamp, e.getTimestamp().getTime());
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestMerge method testDefault.
@Test
public void testDefault() throws Throwable {
String conf = "pipeline[main] { merge {index: \"${e%s}\", doFire: true, default: null, onFire: $main, forward: true, inPipeline: \"main\"}}";
Properties p = Configuration.parse(new StringReader(conf));
Assert.assertTrue(p.pipelines.stream().allMatch(i -> i.configure(p)));
Merge m = (Merge) p.namedPipeLine.get("main").processors.stream().findFirst().get();
Event e = Event.emptyEvent(ConnectionContext.EMPTY);
e.setTimestamp(new Date(0));
e.put("a", 1);
e.put("b", 2);
e.put("c", 3);
e.put("d", '4');
e.put("e", "5");
boolean dropped = false;
try {
m.process(e);
} catch (ProcessorException.DroppedEventException e1) {
dropped = true;
}
try {
e.setTimestamp(new Date(1));
m.process(e);
} catch (ProcessorException.DroppedEventException e1) {
dropped = true;
}
e = p.mainQueue.remove();
Assert.assertFalse(dropped);
Assert.assertFalse(p.mainQueue.isEmpty());
Assert.assertEquals(0, e.keySet().size());
Assert.assertEquals(0L, e.getTimestamp().getTime());
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestMerge method testTimeout.
@Test(timeout = 5000)
public void testTimeout() throws Throwable {
String conf = "pipeline[main] { merge {index: \"${e%s}\", seeds: {\"a\": 0, \"b\": \",\", \"e\": 'c', \"c\": [], \"@timestamp\": null}, inPipeline: \"main\", timeout: 1 }}";
Properties p = Configuration.parse(new StringReader(conf));
Assert.assertTrue(p.pipelines.stream().allMatch(i -> i.configure(p)));
Merge m = (Merge) p.namedPipeLine.get("main").processors.stream().findFirst().get();
Event e = Event.emptyEvent(ConnectionContext.EMPTY);
e.setTimestamp(new Date(0));
e.put("a", 1);
e.put("b", 2);
e.put("c", 3);
e.put("d", 4);
e.put("e", "5");
try {
m.process(e);
} catch (ProcessorException.DroppedEventException e1) {
}
Assert.assertTrue(p.mainQueue.isEmpty());
Thread.sleep(2000);
e = p.mainQueue.element();
Assert.assertEquals(String.class, e.get("b").getClass());
Assert.assertEquals("2", e.get("b"));
Assert.assertEquals(1L, e.get("e"));
Assert.assertNotEquals(0L, e.getTimestamp().getTime());
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestNameResolver method test1.
@Test
public void test1() throws UnknownHostException, ProcessorException {
NameResolver nr = new NameResolver();
nr.setField("host");
nr.setDestination("fqdn");
nr.configure(new Properties(Collections.emptyMap()));
Event e = Tools.getEvent();
e.put("host", InetAddress.getByName("169.254.169.154"));
nr.process(e);
Assert.assertEquals("resolution failed", null, e.get("fqdn"));
}
use of loghub.configuration.Properties in project LogHub by fbacchella.
the class TestOnigurumaRegex method testNoNamedPattern.
@Test
public void testNoNamedPattern() throws ProcessorException {
OnigurumaRegex grok = new OnigurumaRegex();
grok.setField("message");
grok.setPattern(".*");
Properties props = new Properties(Collections.emptyMap());
Assert.assertTrue("Failed to configure grok", grok.configure(props));
Event e = Tools.getEvent();
e.put("message", "<15>a text");
Assert.assertTrue(e.process(grok));
}
Aggregations