|
5 | 5 |
|
6 | 6 | package io.opentelemetry.javaagent.instrumentation.jbosslogmanager.mdc.v1_1; |
7 | 7 |
|
8 | | -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
9 | 9 |
|
10 | 10 | import io.opentelemetry.api.trace.Span; |
11 | 11 | import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; |
@@ -58,11 +58,12 @@ void noIdsGeneratedWhenNoSpanProvided() { |
58 | 58 | try { |
59 | 59 | logger.info("log message 1"); |
60 | 60 |
|
61 | | - assertThat(logRecords).hasSize(1); |
62 | | - assertThat(logRecords.get(0).getMessage()).isEqualTo("log message 1"); |
63 | | - assertThat(logRecords.get(0).getMdc("trace_id")).isNull(); |
64 | | - assertThat(logRecords.get(0).getMdc("span_id")).isNull(); |
65 | | - assertThat(logRecords.get(0).getMdc("trace_flags")).isNull(); |
| 61 | + assertThat(logRecords).extracting(ExtLogRecord::getMessage).containsExactly("log message 1"); |
| 62 | + |
| 63 | + ExtLogRecord logRecord = logRecords.get(0); |
| 64 | + assertThat(logRecord.getMdc("trace_id")).isNull(); |
| 65 | + assertThat(logRecord.getMdc("span_id")).isNull(); |
| 66 | + assertThat(logRecord.getMdc("trace_flags")).isNull(); |
66 | 67 | } finally { |
67 | 68 | logger.removeHandler(handler); |
68 | 69 | } |
@@ -94,46 +95,47 @@ void idsGeneratedWhenSpanProvided() throws ReflectiveOperationException { |
94 | 95 | return Span.current(); |
95 | 96 | }); |
96 | 97 |
|
97 | | - assertThat(logRecords).hasSize(3); |
| 98 | + assertThat(logRecords) |
| 99 | + .extracting(ExtLogRecord::getMessage) |
| 100 | + .containsExactly("log message 1", "log message 2", "log message 3"); |
| 101 | + |
| 102 | + ExtLogRecord firstLogRecord = logRecords.get(0); |
| 103 | + ExtLogRecord secondLogRecord = logRecords.get(1); |
| 104 | + ExtLogRecord thirdLogRecord = logRecords.get(2); |
98 | 105 |
|
99 | 106 | Method getMdcCopy = null; |
100 | 107 | try { |
101 | | - getMdcCopy = logRecords.get(0).getClass().getMethod("getMdcCopy"); |
| 108 | + getMdcCopy = firstLogRecord.getClass().getMethod("getMdcCopy"); |
102 | 109 | } catch (NoSuchMethodException ignored) { |
103 | 110 | // ignored |
104 | 111 | } |
105 | 112 |
|
106 | | - assertThat(logRecords.get(0).getMessage()).isEqualTo("log message 1"); |
107 | | - assertThat(logRecords.get(0).getMdc("trace_id")) |
108 | | - .isEqualTo(span1.getSpanContext().getTraceId()); |
109 | | - assertThat(logRecords.get(0).getMdc("span_id")).isEqualTo(span1.getSpanContext().getSpanId()); |
110 | | - assertThat(logRecords.get(0).getMdc("trace_flags")) |
| 113 | + assertThat(firstLogRecord.getMdc("trace_id")).isEqualTo(span1.getSpanContext().getTraceId()); |
| 114 | + assertThat(firstLogRecord.getMdc("span_id")).isEqualTo(span1.getSpanContext().getSpanId()); |
| 115 | + assertThat(firstLogRecord.getMdc("trace_flags")) |
111 | 116 | .isEqualTo(span1.getSpanContext().getTraceFlags().asHex()); |
112 | 117 |
|
113 | 118 | if (getMdcCopy != null) { |
114 | 119 | @SuppressWarnings("unchecked") |
115 | | - Map<String, String> copiedMdc = (Map<String, String>) getMdcCopy.invoke(logRecords.get(0)); |
| 120 | + Map<String, String> copiedMdc = (Map<String, String>) getMdcCopy.invoke(firstLogRecord); |
116 | 121 | assertThat(copiedMdc.get("trace_id")).isEqualTo(span1.getSpanContext().getTraceId()); |
117 | 122 | assertThat(copiedMdc.get("span_id")).isEqualTo(span1.getSpanContext().getSpanId()); |
118 | 123 | assertThat(copiedMdc.get("trace_flags")) |
119 | 124 | .isEqualTo(span1.getSpanContext().getTraceFlags().asHex()); |
120 | 125 | } |
121 | 126 |
|
122 | | - assertThat(logRecords.get(1).getMessage()).isEqualTo("log message 2"); |
123 | | - assertThat(logRecords.get(1).getMdc("trace_id")).isNull(); |
124 | | - assertThat(logRecords.get(1).getMdc("span_id")).isNull(); |
125 | | - assertThat(logRecords.get(1).getMdc("trace_flags")).isNull(); |
| 127 | + assertThat(secondLogRecord.getMdc("trace_id")).isNull(); |
| 128 | + assertThat(secondLogRecord.getMdc("span_id")).isNull(); |
| 129 | + assertThat(secondLogRecord.getMdc("trace_flags")).isNull(); |
126 | 130 |
|
127 | | - assertThat(logRecords.get(2).getMessage()).isEqualTo("log message 3"); |
128 | | - assertThat(logRecords.get(2).getMdc("trace_id")) |
129 | | - .isEqualTo(span2.getSpanContext().getTraceId()); |
130 | | - assertThat(logRecords.get(2).getMdc("span_id")).isEqualTo(span2.getSpanContext().getSpanId()); |
131 | | - assertThat(logRecords.get(2).getMdc("trace_flags")) |
| 131 | + assertThat(thirdLogRecord.getMdc("trace_id")).isEqualTo(span2.getSpanContext().getTraceId()); |
| 132 | + assertThat(thirdLogRecord.getMdc("span_id")).isEqualTo(span2.getSpanContext().getSpanId()); |
| 133 | + assertThat(thirdLogRecord.getMdc("trace_flags")) |
132 | 134 | .isEqualTo(span2.getSpanContext().getTraceFlags().asHex()); |
133 | 135 |
|
134 | 136 | if (getMdcCopy != null) { |
135 | 137 | @SuppressWarnings("unchecked") |
136 | | - Map<String, String> copiedMdc = (Map<String, String>) getMdcCopy.invoke(logRecords.get(2)); |
| 138 | + Map<String, String> copiedMdc = (Map<String, String>) getMdcCopy.invoke(thirdLogRecord); |
137 | 139 | assertThat(copiedMdc.get("trace_id")).isEqualTo(span2.getSpanContext().getTraceId()); |
138 | 140 | assertThat(copiedMdc.get("span_id")).isEqualTo(span2.getSpanContext().getSpanId()); |
139 | 141 | assertThat(copiedMdc.get("trace_flags")) |
|
0 commit comments