Search in sources :

Example 11 with LoggingEvent

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());
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) Test(org.junit.jupiter.api.Test)

Example 12 with LoggingEvent

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"));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Example 13 with LoggingEvent

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));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) Scope(io.opentracing.Scope) MockSpan(io.opentracing.mock.MockSpan) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with LoggingEvent

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));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) Scope(io.opentracing.Scope) MockSpan(io.opentracing.mock.MockSpan) Span(io.opentracing.Span) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with LoggingEvent

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"));
}
Also used : LoggingEvent(com.github.valfirst.slf4jtest.LoggingEvent) ComponentMessageThrowable(net.kyori.adventure.util.ComponentMessageThrowable) Component(net.kyori.adventure.text.Component) Test(org.junit.jupiter.api.Test)

Aggregations

LoggingEvent (com.github.valfirst.slf4jtest.LoggingEvent)18 Test (org.junit.jupiter.api.Test)17 Scope (io.opentracing.Scope)2 Span (io.opentracing.Span)2 MockSpan (io.opentracing.mock.MockSpan)2 BufferedImage (java.awt.image.BufferedImage)2 Path (java.nio.file.Path)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TestCase (org.vividus.zephyr.model.TestCase)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1 Component (net.kyori.adventure.text.Component)1