@Test public void testLogCaptureOccursAtLowestLogLevel() throws Throwable { String expected = generateRandomString(); LOG.trace(expected); expectedLogs.verifyTrace(expected); }
@Test public void testThreadSafetyOfLogSaver() throws Throwable { CompletionService<Void> completionService = new ExecutorCompletionService<>(Executors.newCachedThreadPool()); final long scheduledLogTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS) + 500L; List<String> expectedStrings = new ArrayList<>(); for (int i = 0; i < 100; i++) { final String expected = generateRandomString(); expectedStrings.add(expected); completionService.submit( () -> { // Have all threads started and waiting to log at about the same moment. sleepMillis( Math.max( 1, scheduledLogTime - TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS))); LOG.trace(expected); return null; }); } // Wait for all the threads to complete. for (int i = 0; i < 100; i++) { completionService.take().get(); } for (String expected : expectedStrings) { expectedLogs.verifyTrace(expected); } }
expectedLogs.verifyDebug("DEBUGDEBUG"); expectedLogs.verifyDebug(debugTime.toString()); expectedLogs.verifyTrace("UNKNOWN TIMESTAMP"); expectedLogs.verifyTrace("UNKNOWNUNKNOWN"); expectedLogs.verifyNotLogged(unknownTime.toString());