use of org.slf4j.event.SubstituteLoggingEvent in project core-java by SpineEventEngine.
the class CommandHandlerShould method log_errors.
@Test
public void log_errors() {
final CommandEnvelope commandEnvelope = givenCommandEnvelope();
// Since we're in the tests mode `Environment` returns `SubstituteLogger` instance.
final SubstituteLogger log = (SubstituteLogger) handler.log();
// Restrict the queue size only to the number of calls we want to make.
final Queue<SubstituteLoggingEvent> queue = Queues.newArrayBlockingQueue(1);
log.setDelegate(new EventRecodingLogger(log, queue));
SubstituteLoggingEvent loggingEvent;
final RuntimeException exception = new RuntimeException("log_errors");
handler.onError(commandEnvelope, exception);
loggingEvent = queue.poll();
assertEquals(Level.ERROR, loggingEvent.getLevel());
assertEquals(commandEnvelope, handler.getLastErrorEnvelope());
assertEquals(exception, handler.getLastException());
}
use of org.slf4j.event.SubstituteLoggingEvent in project core-java by SpineEventEngine.
the class LoggingObserverShould method assertAtLevel.
private void assertAtLevel(Level level) {
final LoggingObserver<Object> observer = getObserver(level);
assertNotNull(observer);
// Since we're in the tests mode `Environment` returns `SubstituteLogger` instance.
final SubstituteLogger log = (SubstituteLogger) observer.log();
// Restrict the queue size only to the number of calls we want to make.
final Queue<SubstituteLoggingEvent> queue = Queues.newArrayBlockingQueue(3);
log.setDelegate(new EventRecodingLogger(log, queue));
SubstituteLoggingEvent loggingEvent;
final String value = newUuid();
observer.onNext(value);
loggingEvent = queue.poll();
assertNotNull(loggingEvent);
assertLogLevel(loggingEvent, level);
assertContains(loggingEvent, value);
assertContains(loggingEvent, "onNext");
final Timestamp currentTime = Time.getCurrentTime();
final String timeStr = Timestamps.toString(currentTime);
observer.onNext(currentTime);
loggingEvent = queue.poll();
assertNotNull(loggingEvent);
assertLogLevel(loggingEvent, level);
assertContains(loggingEvent, timeStr);
observer.onCompleted();
loggingEvent = queue.poll();
assertNotNull(loggingEvent);
assertLogLevel(loggingEvent, level);
assertContains(loggingEvent, "onCompleted");
}
Aggregations