use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class AbstractDatabaseManagerTest method testBuffering04.
@Test
public void testBuffering04() throws Exception {
setUp("name", 10);
final LogEvent event1 = mock(LogEvent.class);
final LogEvent event2 = mock(LogEvent.class);
final LogEvent event3 = mock(LogEvent.class);
manager.startup();
then(manager).should().startupInternal();
manager.write(event1);
manager.write(event2);
manager.write(event3);
manager.shutdown();
then(manager).should().connectAndStart();
then(manager).should().writeInternal(same(event1));
then(manager).should().writeInternal(same(event2));
then(manager).should().writeInternal(same(event3));
then(manager).should().commitAndClose();
then(manager).should().shutdownInternal();
then(manager).shouldHaveNoMoreInteractions();
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class JmsAppenderTest method testAppendToQueue.
@Test
public void testAppendToQueue() throws Exception {
final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsAppender");
final LogEvent event = createLogEvent();
appender.append(event);
then(session).should().createTextMessage(eq(LOG_MESSAGE));
then(textMessage).should().setJMSTimestamp(anyLong());
then(messageProducer).should().send(textMessage);
appender.stop();
then(session).should().close();
then(connection).should().close();
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class JmsAppenderTest method testJmsTopicAppenderCompatibility.
@Test
public void testJmsTopicAppenderCompatibility() throws Exception {
final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsTopicAppender");
final LogEvent expected = createLogEvent();
appender.append(expected);
then(session).should().createObjectMessage(eq(expected));
then(objectMessage).should().setJMSTimestamp(anyLong());
then(messageProducer).should().send(objectMessage);
appender.stop();
then(session).should().close();
then(connection).should().close();
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class SocketAppenderTest method testTcpAppenderDeadlock.
@Test
public void testTcpAppenderDeadlock() throws Exception {
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder().withHost("localhost").withPort(DYN_PORT).withReconnectDelayMillis(100).withName("test").withImmediateFail(false).build();
// @formatter:on
appender.start();
// set appender on root and set level to debug
logger.addAppender(appender);
logger.setAdditive(false);
logger.setLevel(Level.DEBUG);
final TcpSocketTestServer tcpSocketServer = new TcpSocketTestServer(DYN_PORT);
try {
tcpSocketServer.start();
logger.debug("This message is written because a deadlock never.");
final LogEvent event = tcpSocketServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull("No event retrieved", event);
} finally {
tcpSocketServer.shutdown();
}
}
use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class SocketAppenderTest method testTcpAppender.
static void testTcpAppender(final TcpSocketTestServer tcpTestServer, final Logger logger, final int bufferSize) throws Exception {
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder().withHost("localhost").withPort(tcpTestServer.getLocalPort()).withReconnectDelayMillis(-1).withName("test").withImmediateFail(false).withBufferSize(bufferSize).build();
// @formatter:on
appender.start();
Assert.assertEquals(bufferSize, appender.getManager().getByteBuffer().capacity());
// set appender on root and set level to debug
logger.addAppender(appender);
logger.setAdditive(false);
logger.setLevel(Level.DEBUG);
final String tcKey = "UUID";
final String expectedUuidStr = UUID.randomUUID().toString();
ThreadContext.put(tcKey, expectedUuidStr);
ThreadContext.push(expectedUuidStr);
final String expectedExMsg = "This is a test";
try {
logger.debug("This is a test message");
final Throwable child = new LoggingException(expectedExMsg);
logger.error("Throwing an exception", child);
logger.debug("This is another test message");
} finally {
ThreadContext.remove(tcKey);
ThreadContext.pop();
}
Thread.sleep(250);
LogEvent event = tcpTestServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull("No event retrieved", event);
assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("This is a test message"));
assertTrue("Message not delivered via TCP", tcpTestServer.getCount() > 0);
assertEquals(expectedUuidStr, event.getContextData().getValue(tcKey));
event = tcpTestServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull("No event retrieved", event);
assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("Throwing an exception"));
assertTrue("Message not delivered via TCP", tcpTestServer.getCount() > 1);
assertEquals(expectedUuidStr, event.getContextStack().pop());
assertNotNull(event.getThrownProxy());
assertEquals(expectedExMsg, event.getThrownProxy().getMessage());
}
Aggregations