|
36 | 36 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.HSQLDB; |
37 | 37 | import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.OTHER_SQL; |
38 | 38 | import static java.util.Arrays.asList; |
39 | | -import static java.util.stream.Collectors.toList; |
40 | 39 | import static org.assertj.core.api.Assertions.assertThat; |
41 | 40 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
42 | 41 | import static org.assertj.core.api.Assertions.catchThrowable; |
|
52 | 51 | import io.opentelemetry.instrumentation.jdbc.TestDriver; |
53 | 52 | import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; |
54 | 53 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
55 | | -import io.opentelemetry.sdk.logs.data.LogRecordData; |
56 | 54 | import io.opentelemetry.sdk.testing.assertj.AttributeAssertion; |
57 | 55 | import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; |
58 | 56 | import io.opentelemetry.sdk.testing.assertj.TraceAssert; |
|
78 | 76 | import org.apache.derby.jdbc.EmbeddedDataSource; |
79 | 77 | import org.apache.derby.jdbc.EmbeddedDriver; |
80 | 78 | import org.assertj.core.api.ThrowingConsumer; |
81 | | -import org.awaitility.Awaitility; |
82 | 79 | import org.h2.jdbcx.JdbcDataSource; |
83 | 80 | import org.hsqldb.jdbc.JDBCDriver; |
84 | 81 | import org.junit.jupiter.api.BeforeAll; |
@@ -459,30 +456,19 @@ void testFailedStatement() throws SQLException { |
459 | 456 | .hasException(emitExceptionAsSpanEvents() ? error : null))); |
460 | 457 |
|
461 | 458 | if (emitExceptionAsLogs()) { |
462 | | - assertExceptionLog(); |
| 459 | + testing() |
| 460 | + .waitAndAssertLogRecords( |
| 461 | + logRecord -> |
| 462 | + logRecord |
| 463 | + .hasSeverity(Severity.WARN) |
| 464 | + .hasEventName("db.client.operation.exception") |
| 465 | + .hasAttributesSatisfyingExactly( |
| 466 | + equalTo(EXCEPTION_TYPE, error.getClass().getName()), |
| 467 | + equalTo(EXCEPTION_MESSAGE, error.getMessage()), |
| 468 | + satisfies(EXCEPTION_STACKTRACE, val -> val.isNotNull()))); |
463 | 469 | } |
464 | 470 | } |
465 | 471 |
|
466 | | - private void assertExceptionLog() { |
467 | | - Awaitility.await() |
468 | | - .untilAsserted( |
469 | | - () -> { |
470 | | - List<LogRecordData> logs = |
471 | | - testing().logRecords().stream() |
472 | | - .filter(log -> "db.client.operation.exception".equals(log.getEventName())) |
473 | | - .collect(toList()); |
474 | | - |
475 | | - assertThat(logs).hasSize(1); |
476 | | - assertThat(logs.get(0)) |
477 | | - .hasSeverity(Severity.WARN) |
478 | | - .hasEventName("db.client.operation.exception") |
479 | | - .hasAttributesSatisfyingExactly( |
480 | | - satisfies(EXCEPTION_TYPE, val -> val.isNotNull()), |
481 | | - satisfies(EXCEPTION_MESSAGE, val -> val.isNotNull()), |
482 | | - satisfies(EXCEPTION_STACKTRACE, val -> val.isNotNull())); |
483 | | - }); |
484 | | - } |
485 | | - |
486 | 472 | static Stream<Arguments> preparedStatementStream() throws SQLException { |
487 | 473 | return Stream.of( |
488 | 474 | Arguments.of( |
|
0 commit comments