use of org.apache.logging.log4j.core.time.internal.FixedPreciseClock in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testCreateMementoRetainsParametersAndFormat.
@Test
public void testCreateMementoRetainsParametersAndFormat() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
// Initialize the event with parameters
evt.swapParameters(new Object[10]);
final String loggerName = "logger.name";
final Marker marker = MarkerManager.getMarker("marked man");
final String fqcn = "f.q.c.n";
final Level level = Level.TRACE;
final ReusableMessageFactory factory = new ReusableMessageFactory();
final Message message = factory.newMessage("Hello {}!", "World");
try {
final Throwable t = new InternalError("not a real error");
final ContextStack contextStack = new MutableThreadContextStack(Arrays.asList("a", "b"));
final String threadName = "main";
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, message, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
((StringMap) evt.getContextData()).putValue("key", "value");
final Message actual = evt.createMemento().getMessage();
assertEquals("Hello {}!", actual.getFormat());
assertArrayEquals(new String[] { "World" }, actual.getParameters());
assertEquals("Hello World!", actual.getFormattedMessage());
} finally {
ReusableMessageFactory.release(message);
}
}
use of org.apache.logging.log4j.core.time.internal.FixedPreciseClock in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testIsPopulated.
/**
* @see <a href="https://issues.apache.org/jira/browse/LOG4J2-2816">LOG4J2-2816</a>
*/
@Test
public void testIsPopulated() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
assertFalse(evt.isPopulated());
final String loggerName = null;
final Marker marker = null;
final String fqcn = null;
final Level level = null;
final Message data = null;
final Throwable t = null;
final ContextStack contextStack = null;
final String threadName = null;
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
assertTrue(evt.isPopulated());
evt.clear();
assertFalse(evt.isPopulated());
}
use of org.apache.logging.log4j.core.time.internal.FixedPreciseClock in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testGetLevelReturnsOffIfNullLevelSet.
@Test
public void testGetLevelReturnsOffIfNullLevelSet() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
final String loggerName = null;
final Marker marker = null;
final String fqcn = null;
final Level level = null;
final Message data = null;
final Throwable t = null;
final ContextStack contextStack = null;
final String threadName = null;
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
assertEquals(Level.OFF, evt.getLevel());
}
use of org.apache.logging.log4j.core.time.internal.FixedPreciseClock in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testMementoReuse.
@Test
public void testMementoReuse() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
// Initialize the event with parameters
evt.swapParameters(new Object[10]);
final String loggerName = "logger.name";
final Marker marker = MarkerManager.getMarker("marked man");
final String fqcn = "f.q.c.n";
final Level level = Level.TRACE;
final ReusableMessageFactory factory = new ReusableMessageFactory();
final Message message = factory.newMessage("Hello {}!", "World");
try {
final Throwable t = new InternalError("not a real error");
final ContextStack contextStack = new MutableThreadContextStack(Arrays.asList("a", "b"));
final String threadName = "main";
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, message, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
((StringMap) evt.getContextData()).putValue("key", "value");
final Message memento1 = evt.memento();
final Message memento2 = evt.memento();
assertThat(memento1, sameInstance(memento2));
} finally {
ReusableMessageFactory.release(message);
}
}
use of org.apache.logging.log4j.core.time.internal.FixedPreciseClock in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testSerializationDeserialization.
@SuppressWarnings("BanSerializableRead")
@Test
public void testSerializationDeserialization() throws IOException, ClassNotFoundException {
final RingBufferLogEvent evt = new RingBufferLogEvent();
final String loggerName = "logger.name";
final Marker marker = null;
final String fqcn = "f.q.c.n";
final Level level = Level.TRACE;
final Message data = new SimpleMessage("message");
final Throwable t = new InternalError("not a real error");
final ContextStack contextStack = null;
final String threadName = "main";
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
((StringMap) evt.getContextData()).putValue("key", "value");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(evt);
final ObjectInputStream in = new FilteredObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
final RingBufferLogEvent other = (RingBufferLogEvent) in.readObject();
assertEquals(loggerName, other.getLoggerName());
assertEquals(marker, other.getMarker());
assertEquals(fqcn, other.getLoggerFqcn());
assertEquals(level, other.getLevel());
assertEquals(data, other.getMessage());
assertNull("null after serialization", other.getThrown());
assertEquals(new ThrowableProxy(t), other.getThrownProxy());
assertEquals(evt.getContextData(), other.getContextData());
assertEquals(contextStack, other.getContextStack());
assertEquals(threadName, other.getThreadName());
assertEquals(location, other.getSource());
assertEquals(12345, other.getTimeMillis());
assertEquals(678, other.getInstant().getNanoOfMillisecond());
}
Aggregations