use of org.apache.logging.log4j.core.time.internal.DummyNanoClock in project logging-log4j2 by apache.
the class SmtpManagerTest method testAdd_WhereRingBufferLogEvent.
// LOG4J2-3172
@Test
void testAdd_WhereRingBufferLogEvent() {
RingBufferLogEvent event = new RingBufferLogEvent();
event.setValues(null, null, null, null, null, getReusableMessage("test message"), null, null, null, 0, null, 0, null, ClockFactory.getClock(), new DummyNanoClock());
testAdd(event);
}
use of org.apache.logging.log4j.core.time.internal.DummyNanoClock in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testGetMillisReturnsConstructorMillisForNormalMessage.
@Test
public void testGetMillisReturnsConstructorMillisForNormalMessage() {
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(123, 456), new DummyNanoClock(1));
assertEquals(123, evt.getTimeMillis());
assertEquals(456, evt.getInstant().getNanoOfMillisecond());
}
use of org.apache.logging.log4j.core.time.internal.DummyNanoClock in project logging-log4j2 by apache.
the class AsyncLoggerTestNanoTime method testAsyncLogUsesNanoTimeClock.
@Test
public void testAsyncLogUsesNanoTimeClock() throws Exception {
final File file = new File("target", "NanoTimeToFileTest.log");
// System.out.println(f.getAbsolutePath());
file.delete();
final AsyncLogger log = (AsyncLogger) LogManager.getLogger("com.foo.Bar");
final long before = System.nanoTime();
log.info("Use actual System.nanoTime()");
assertTrue("using SystemNanoClock", log.getNanoClock() instanceof SystemNanoClock);
final long DUMMYNANOTIME = -53;
log.getContext().getConfiguration().setNanoClock(new DummyNanoClock(DUMMYNANOTIME));
log.updateConfiguration(log.getContext().getConfiguration());
// trigger a new nano clock lookup
log.updateConfiguration(log.getContext().getConfiguration());
log.info("Use dummy nano clock");
assertTrue("using SystemNanoClock", log.getNanoClock() instanceof DummyNanoClock);
// stop async thread
CoreLoggerContexts.stopLoggerContext(file);
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String line1 = reader.readLine();
final String line2 = reader.readLine();
// System.out.println(line1);
// System.out.println(line2);
reader.close();
file.delete();
assertNotNull("line1", line1);
assertNotNull("line2", line2);
final String[] line1Parts = line1.split(" AND ");
assertEquals("Use actual System.nanoTime()", line1Parts[2]);
assertEquals(line1Parts[0], line1Parts[1]);
final long loggedNanoTime = Long.parseLong(line1Parts[0]);
assertTrue("used system nano time", loggedNanoTime - before < TimeUnit.SECONDS.toNanos(1));
final String[] line2Parts = line2.split(" AND ");
assertEquals("Use dummy nano clock", line2Parts[2]);
assertEquals(String.valueOf(DUMMYNANOTIME), line2Parts[0]);
assertEquals(String.valueOf(DUMMYNANOTIME), line2Parts[1]);
}
use of org.apache.logging.log4j.core.time.internal.DummyNanoClock in project logging-log4j2 by apache.
the class PatternParserTest method testNanoPatternLongChangesNanoClockFactoryMode.
@Test
public void testNanoPatternLongChangesNanoClockFactoryMode() {
final Configuration config = new NullConfiguration();
assertTrue(config.getNanoClock() instanceof DummyNanoClock);
final PatternParser pp = new PatternParser(config, KEY, null);
assertTrue(config.getNanoClock() instanceof DummyNanoClock);
pp.parse("%m");
assertTrue(config.getNanoClock() instanceof DummyNanoClock);
pp.parse("%N");
assertTrue(config.getNanoClock() instanceof SystemNanoClock);
}
use of org.apache.logging.log4j.core.time.internal.DummyNanoClock in project logging-log4j2 by apache.
the class PatternParserTest method testNanoPatternShortChangesConfigurationNanoClock.
@Test
public void testNanoPatternShortChangesConfigurationNanoClock() {
final Configuration config = new NullConfiguration();
assertTrue(config.getNanoClock() instanceof DummyNanoClock);
final PatternParser pp = new PatternParser(config, KEY, null);
assertTrue(config.getNanoClock() instanceof DummyNanoClock);
pp.parse("%m");
assertTrue(config.getNanoClock() instanceof DummyNanoClock);
// this changes the config clock
pp.parse("%nano");
assertTrue(config.getNanoClock() instanceof SystemNanoClock);
}
Aggregations