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));
}
}
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]);
}
}
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"));
}
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));
}
}
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"));
}
Aggregations