use of com.github.valfirst.slf4jtest.LoggingEvent in project vividus by vividus-framework.
the class SpelExpressionResolverTests method shouldProcessParsingExpressionAndReturnOriginalValue.
@Test
void shouldProcessParsingExpressionAndReturnOriginalValue() {
var expressionString = "#{generate(regexify '[a-zA-Z0-9]{1}[a-zA-Z0-9\\ ]{1,12}[a-zA-Z0-9]{1}')}";
assertEquals(expressionString, PARSER.resolve(expressionString));
var loggingEvents = LOGGER.getLoggingEvents();
assertThat(loggingEvents, Matchers.hasSize(1));
LoggingEvent event = loggingEvents.get(0);
assertEquals("Unable to evaluate the string '#{generate(regexify '[a-zA-Z0-9]{1}[a-zA-Z0-9\\ ]{1," + "12}[a-zA-Z0-9]{1}')}' as SpEL expression, it'll be used as is", event.getFormattedMessage());
assertInstanceOf(SpelParseException.class, event.getThrowable().get());
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project opentracing-toolbox by zalando.
the class DefaultActivationTest method shouldActivateSpan.
@Test
void shouldActivateSpan() throws SQLException {
final DataSource dataSource = unit.trace(original);
try (final Connection connection = dataSource.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute("SELECT 1");
}
final List<LoggingEvent> events = logger.getLoggingEvents();
assertThat(events, hasSize(1));
final LoggingEvent event = events.get(0);
assertThat(event.getMdc(), hasKey("trace_id"));
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project opentracing-toolbox by zalando.
the class CustomConfigurationTest method correlatesWithTraceSpanAndRequestId.
@Test
void correlatesWithTraceSpanAndRequestId() {
final Span span = tracer.buildSpan("test").start();
final String requestId = UUID.randomUUID().toString();
span.setBaggageItem("request_id", requestId);
try (final Scope ignored = tracer.activateSpan(span)) {
log.info("Correlating...");
} finally {
span.finish();
}
final LoggingEvent event = getOnlyElement(log.getLoggingEvents());
final ImmutableMap<String, String> mdc = event.getMdc();
assertThat(mdc, aMapWithSize(3));
assertThat(mdc, hasEntry("trace", span.context().toTraceId()));
assertThat(mdc, hasEntry("span", span.context().toSpanId()));
assertThat(mdc, hasEntry("request_id", requestId));
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project opentracing-toolbox by zalando.
the class DefaultConfigurationTest method correlatesWithTraceSpanAndFlowId.
@Test
void correlatesWithTraceSpanAndFlowId() {
final Span span = tracer.buildSpan("test").start();
final String flowId = UUID.randomUUID().toString();
span.setBaggageItem("flow_id", flowId);
try (final Scope ignored = tracer.activateSpan(span)) {
log.info("Correlating...");
} finally {
span.finish();
}
final LoggingEvent event = getOnlyElement(log.getLoggingEvents());
final ImmutableMap<String, String> mdc = event.getMdc();
assertThat(mdc, aMapWithSize(3));
assertThat(mdc, hasEntry("trace_id", span.context().toTraceId()));
assertThat(mdc, hasEntry("span_id", span.context().toSpanId()));
assertThat(mdc, hasEntry("flow_id", flowId));
}
use of com.github.valfirst.slf4jtest.LoggingEvent in project adventure by KyoriPowered.
the class ComponentLoggerTest method testUnwrapThrowable.
@Test
void testUnwrapThrowable() {
final Component message = Component.text("Hello world");
final Exception error = new RichTestException(Component.translatable("test.failed", NamedTextColor.DARK_PURPLE));
this.makeLogger().warn(message, error);
final List<LoggingEvent> events = LOGGER.getLoggingEvents();
assertEquals(1, events.size());
final Throwable thrownException = events.get(0).getThrowable().orElse(null);
assertNotNull(thrownException);
assertEquals("test.failed", thrownException.getMessage());
assertArrayEquals(error.getStackTrace(), thrownException.getStackTrace());
assertTrue(thrownException.toString().startsWith("net.kyori.adventure.text.logger.slf4j.ComponentLoggerTest$RichTestException"));
}
Aggregations