Browse Source

Simplify exception asserts in hystrix tests (#9250)

Lauri Tulmin 1 year ago
parent
commit
d0a14cf7e9

+ 6 - 28
instrumentation/hystrix-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/hystrix/HystrixObservableTest.java

@@ -8,10 +8,6 @@ package io.opentelemetry.javaagent.instrumentation.hystrix;
 import static io.opentelemetry.api.common.AttributeKey.booleanKey;
 import static io.opentelemetry.api.common.AttributeKey.stringKey;
 import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
-import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
-import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_MESSAGE;
-import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_STACKTRACE;
-import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_TYPE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.catchException;
 import static org.junit.jupiter.api.Named.named;
@@ -237,7 +233,6 @@ class HystrixObservableTest {
                           String returnValue;
                           try {
                             returnValue = queue.take();
-
                           } catch (InterruptedException e) {
                             throw new RuntimeException(e);
                           }
@@ -292,16 +287,7 @@ class HystrixObservableTest {
                     span.hasName("ExampleGroup.TestCommand.execute")
                         .hasParent(trace.getSpan(0))
                         .hasStatus(StatusData.error())
-                        .hasEventsSatisfyingExactly(
-                            event ->
-                                event
-                                    .hasName("exception")
-                                    .hasAttributesSatisfyingExactly(
-                                        equalTo(
-                                            EXCEPTION_TYPE, "java.lang.IllegalArgumentException"),
-                                        satisfies(
-                                            EXCEPTION_STACKTRACE,
-                                            val -> val.isInstanceOf(String.class)))),
+                        .hasException(new IllegalArgumentException()),
                 span ->
                     span.hasName("ExampleGroup.TestCommand.fallback")
                         .hasParent(trace.getSpan(1))
@@ -378,7 +364,10 @@ class HystrixObservableTest {
                       return parameter.operation.apply(val);
                     }));
 
-    assertThat(exception).hasCauseInstanceOf(IllegalArgumentException.class);
+    assertThat(exception)
+        .isInstanceOf(HystrixRuntimeException.class)
+        .hasCauseInstanceOf(IllegalArgumentException.class);
+    HystrixRuntimeException hystrixRuntimeException = (HystrixRuntimeException) exception;
 
     testing.waitAndAssertTraces(
         trace ->
@@ -400,18 +389,7 @@ class HystrixObservableTest {
                 span ->
                     span.hasName("FailingGroup.TestCommand.fallback")
                         .hasParent(trace.getSpan(1))
-                        .hasEventsSatisfyingExactly(
-                            event ->
-                                event
-                                    .hasName("exception")
-                                    .hasAttributesSatisfyingExactly(
-                                        equalTo(
-                                            EXCEPTION_TYPE,
-                                            "java.lang.UnsupportedOperationException"),
-                                        satisfies(
-                                            EXCEPTION_STACKTRACE,
-                                            val -> val.isInstanceOf(String.class)),
-                                        equalTo(EXCEPTION_MESSAGE, "No fallback available.")))
+                        .hasException(hystrixRuntimeException.getFallbackException())
                         .hasAttributesSatisfyingExactly(
                             equalTo(stringKey("hystrix.command"), "TestCommand"),
                             equalTo(stringKey("hystrix.group"), "FailingGroup"),

+ 1 - 13
instrumentation/hystrix-1.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/hystrix/HystrixTest.java

@@ -8,9 +8,6 @@ package io.opentelemetry.javaagent.instrumentation.hystrix;
 import static io.opentelemetry.api.common.AttributeKey.booleanKey;
 import static io.opentelemetry.api.common.AttributeKey.stringKey;
 import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
-import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
-import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_STACKTRACE;
-import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.EXCEPTION_TYPE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Named.named;
 
@@ -109,16 +106,7 @@ class HystrixTest {
                     span.hasName("ExampleGroup.TestCommand.execute")
                         .hasParent(trace.getSpan(0))
                         .hasStatus(StatusData.error())
-                        .hasEventsSatisfyingExactly(
-                            event ->
-                                event
-                                    .hasName("exception")
-                                    .hasAttributesSatisfyingExactly(
-                                        equalTo(
-                                            EXCEPTION_TYPE, "java.lang.IllegalArgumentException"),
-                                        satisfies(
-                                            EXCEPTION_STACKTRACE,
-                                            val -> val.isInstanceOf(String.class))))
+                        .hasException(new IllegalArgumentException())
                         .hasAttributesSatisfyingExactly(
                             equalTo(stringKey("hystrix.command"), "TestCommand"),
                             equalTo(stringKey("hystrix.group"), "ExampleGroup"),