Search in sources :

Example 46 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestVarExtractor method test2.

@Test
public void test2() throws ProcessorException {
    VarExtractor t = new VarExtractor();
    t.setField("message");
    t.setParser("(?<name>[a-z]+)[=:](?<value>[^;]+);?");
    Event e = Tools.getEvent();
    e.put("message", "a=1;b:2");
    e.process(t);
    System.out.println(e);
    Assert.assertEquals("key a not found", "1", e.get("a"));
    Assert.assertEquals("key b found", "2", e.get("b"));
    Assert.assertNull("key message found", e.get("message"));
}
Also used : Event(loghub.Event) Test(org.junit.Test)

Example 47 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestVarExtractor method test1.

@Test
public void test1() throws ProcessorException {
    VarExtractor t = new VarExtractor();
    t.setPath("sub");
    t.setField(".message");
    t.setParser("(?<name>[a-z]+)[=:](?<value>[^;]+);?");
    Event e = Tools.getEvent();
    e.put("message", "a=1;b:2;c");
    Assert.assertTrue(e.process(t));
    System.out.println(e);
    @SuppressWarnings("unchecked") Map<String, Object> sub = (Map<String, Object>) e.get("sub");
    Assert.assertEquals("key a not found", "1", sub.get("a"));
    Assert.assertEquals("key b not found", "2", sub.get("b"));
    Assert.assertEquals("key message not found", "c", e.get("message"));
}
Also used : Event(loghub.Event) Map(java.util.Map) Test(org.junit.Test)

Example 48 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestHttp method testHttpPostJson.

@Test
public void testHttpPostJson() throws IOException {
    makeReceiver(i -> {
    });
    doRequest(new URL("http", hostname, port, "/"), "{\"a\": 1}".getBytes("UTF-8"), i -> {
        try {
            i.setRequestMethod("PUT");
            i.setRequestProperty("Content-Type", "application/json");
        } catch (ProtocolException e1) {
            throw new UncheckedIOException(e1);
        }
    }, 200);
    Event e = queue.poll();
    logger.debug(e.getClass());
    Integer a = (Integer) e.get("a");
    Assert.assertEquals(1, a.intValue());
}
Also used : ProtocolException(java.net.ProtocolException) Event(loghub.Event) UncheckedIOException(java.io.UncheckedIOException) URL(java.net.URL) Test(org.junit.Test)

Example 49 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestHttp method testHttpGet.

@Test
public void testHttpGet() throws IOException {
    makeReceiver(i -> {
    });
    doRequest(new URL("http", hostname, port, "/?a=1"), new byte[] {}, i -> {
    }, 200);
    Event e = queue.poll();
    logger.debug(e.getClass());
    String a = (String) e.get("a");
    Assert.assertEquals("1", a);
}
Also used : Event(loghub.Event) URL(java.net.URL) Test(org.junit.Test)

Example 50 with Event

use of loghub.Event in project LogHub by fbacchella.

the class TestHttp method testGoodAuthentication.

@Test
public void testGoodAuthentication() throws IOException {
    makeReceiver(i -> {
        i.setUser("user");
        i.setPassword("password");
    });
    URL dest = new URL("http", hostname, port, "/?a=1");
    doRequest(dest, new byte[] {}, i -> {
        String authStr = Base64.getEncoder().encodeToString("user:password".getBytes());
        i.setRequestProperty("Authorization", "Basic " + authStr);
    }, 200);
    Event e = queue.poll();
    Assert.assertEquals("1", e.get("a"));
}
Also used : Event(loghub.Event) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Event (loghub.Event)102 Test (org.junit.Test)90 Properties (loghub.configuration.Properties)63 Pipeline (loghub.Pipeline)23 Date (java.util.Date)19 Map (java.util.Map)18 HashMap (java.util.HashMap)14 IOException (java.io.IOException)13 Tools (loghub.Tools)13 URL (java.net.URL)8 Collections (java.util.Collections)8 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)8 Level (org.apache.logging.log4j.Level)7 List (java.util.List)6 EventsProcessor (loghub.EventsProcessor)6 LogManager (org.apache.logging.log4j.LogManager)6 Logger (org.apache.logging.log4j.Logger)6 LogUtils (loghub.LogUtils)5 ProcessorException (loghub.ProcessorException)5 Assert (org.junit.Assert)5