Search in sources :

Example 1 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class FlumeEmbeddedAppenderTest method testFailover.

@Test
public void testFailover() throws InterruptedException, IOException {
    final Logger logger = LogManager.getLogger("testFailover");
    logger.debug("Starting testFailover");
    for (int i = 0; i < 10; ++i) {
        final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Primary " + i, "Test");
        EventLogger.logEvent(msg);
    }
    for (int i = 0; i < 10; ++i) {
        final Event event = primary.poll();
        Assert.assertNotNull("Event should not be null", event);
        final String body = getBody(event);
        final String expected = "Test Primary " + i;
        Assert.assertTrue("Channel contained event, but not expected message. Received: " + body, body.endsWith(expected));
    }
    // Give the AvroSink time to receive notification and notify the channel.
    Thread.sleep(500);
    primary.stop();
    for (int i = 0; i < 10; ++i) {
        final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Alternate " + i, "Test");
        EventLogger.logEvent(msg);
    }
    for (int i = 0; i < 10; ++i) {
        final Event event = alternate.poll();
        Assert.assertNotNull("Event should not be null", event);
        final String body = getBody(event);
        final String expected = "Test Alternate " + i;
        /* When running in Gump Flume consistently returns the last event from the primary channel after
               the failover, which fails this test */
        Assert.assertTrue("Channel contained event, but not expected message. Expected: " + expected + " Received: " + body, body.endsWith(expected));
    }
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent) EventLogger(org.apache.logging.log4j.EventLogger) Logger(org.apache.logging.log4j.Logger) StatusLogger(org.apache.logging.log4j.status.StatusLogger) Test(org.junit.Test)

Example 2 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class FlumePersistentAppenderTest method testMultiple.

@Test
public void testMultiple() {
    for (int i = 0; i < 10; ++i) {
        final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Multiple " + i, "Test");
        msg.put("counter", Integer.toString(i));
        EventLogger.logEvent(msg);
    }
    final boolean[] fields = new boolean[10];
    for (int i = 0; i < 10; ++i) {
        final Event event = primary.poll();
        Assert.assertNotNull("Received " + i + " events. Event " + (i + 1) + " is null", event);
        final String value = event.getHeaders().get("counter");
        Assert.assertNotNull("Missing counter", value);
        final int counter = Integer.parseInt(value);
        if (fields[counter]) {
            Assert.fail("Duplicate event");
        } else {
            fields[counter] = true;
        }
    }
    for (int i = 0; i < 10; ++i) {
        Assert.assertTrue("Channel contained event, but not expected message " + i, fields[i]);
    }
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent) Test(org.junit.Test)

Example 3 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class FlumeEmbeddedAgentTest method testLog4Event.

@Test
public void testLog4Event() throws IOException {
    final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Log4j", "Test");
    EventLogger.logEvent(msg);
    final Event event = primary.poll();
    Assert.assertNotNull(event);
    final String body = getBody(event);
    Assert.assertTrue("Channel contained event, but not expected message. Received: " + body, body.endsWith("Test Log4j"));
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent) Test(org.junit.Test)

Example 4 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class FlumeEmbeddedAppenderTest method testMultiple.

@Test
public void testMultiple() throws IOException {
    for (int i = 0; i < 10; ++i) {
        final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Multiple " + i, "Test");
        EventLogger.logEvent(msg);
    }
    for (int i = 0; i < 10; ++i) {
        final Event event = primary.poll();
        Assert.assertNotNull("Event should not be null", event);
        final String body = getBody(event);
        final String expected = "Test Multiple " + i;
        Assert.assertTrue("Channel contained event, but not expected message. Received: " + body, body.endsWith(expected));
    }
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent) Test(org.junit.Test)

Example 5 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class FlumeEmbeddedAppenderTest method testLog4Event.

@Test
public void testLog4Event() throws IOException {
    final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Log4j", "Test");
    EventLogger.logEvent(msg);
    final Event event = primary.poll();
    Assert.assertNotNull("Event should not be null", event);
    final String body = getBody(event);
    Assert.assertTrue("Channel contained event, but not expected message. Received: " + body, body.endsWith("Test Log4j"));
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent) Test(org.junit.Test)

Aggregations

StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)40 Test (org.junit.Test)32 Event (org.apache.flume.Event)12 AvroFlumeEvent (org.apache.flume.source.avro.AvroFlumeEvent)11 LogEvent (org.apache.logging.log4j.core.LogEvent)11 File (java.io.File)6 Message (org.apache.logging.log4j.message.Message)6 EventLogger (org.apache.logging.log4j.EventLogger)5 Logger (org.apache.logging.log4j.Logger)4 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)4 StatusLogger (org.apache.logging.log4j.status.StatusLogger)4 Appender (org.apache.logging.log4j.core.Appender)3 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)3 Map (java.util.Map)2 Marker (org.apache.logging.log4j.Marker)2 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)2 MapMessage (org.apache.logging.log4j.message.MapMessage)2 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1