Skip to content

Commit 0ea7355

Browse files
committed
fix up test
1 parent 09c8939 commit 0ea7355

File tree

2 files changed

+28
-31
lines changed

2 files changed

+28
-31
lines changed

instrumentation/rabbitmq-2.7/javaagent/build.gradle.kts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ dependencies {
2424
testInstrumentation(project(":instrumentation:reactor:reactor-3.1:javaagent"))
2525

2626
testLibrary("io.projectreactor.rabbitmq:reactor-rabbitmq:1.0.0.RELEASE")
27-
28-
// reactor-rabbitmq 1.5.6 (and earlier) still calls useNio() which was removed in 5.27.0
29-
latestDepTestLibrary("com.rabbitmq:amqp-client:5.26.+")
3027
}
3128

3229
tasks.withType<Test>().configureEach {
3330
// TODO run tests both with and without experimental span attributes
3431
jvmArgs("-Dotel.instrumentation.rabbitmq.experimental-span-attributes=true")
3532
jvmArgs("-Dotel.instrumentation.messaging.experimental.receive-telemetry.enabled=true")
3633

34+
systemProperty("testLatestDeps", findProperty("testLatestDeps") ?: "false")
35+
3736
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service)
3837
}

instrumentation/rabbitmq-2.7/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/rabbitmq/ReactorRabbitMqTest.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,32 @@
55

66
package io.opentelemetry.javaagent.instrumentation.rabbitmq;
77

8-
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
8+
import static io.opentelemetry.api.common.AttributeKey.stringKey;
9+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
10+
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
911
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS;
1012
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT;
1113
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE;
1214
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MESSAGING_SYSTEM;
13-
import static org.junit.jupiter.api.Assertions.assertNotNull;
15+
import static io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingSystemIncubatingValues.RABBITMQ;
16+
import static org.assertj.core.api.Assertions.assertThat;
1417

15-
import io.opentelemetry.api.common.AttributeKey;
1618
import io.opentelemetry.api.trace.SpanKind;
1719
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
1820
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
19-
import org.junit.jupiter.api.Assertions;
2021
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
2123
import org.junit.jupiter.api.extension.RegisterExtension;
2224
import reactor.rabbitmq.ExchangeSpecification;
2325
import reactor.rabbitmq.RabbitFlux;
2426
import reactor.rabbitmq.Sender;
2527
import reactor.rabbitmq.SenderOptions;
2628

29+
@DisabledIfSystemProperty(
30+
named = "testLatestDeps",
31+
matches = "true",
32+
disabledReason =
33+
"reactor-rabbitmq 1.5.6 (and earlier) still calls `void useNio()` which was removed in 5.27.0")
2734
class ReactorRabbitMqTest extends AbstractRabbitMqTest {
2835
@RegisterExtension
2936
private static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
@@ -33,33 +40,24 @@ void testShouldNotFailDeclaringExchange() {
3340
Sender sender =
3441
RabbitFlux.createSender(new SenderOptions().connectionFactory(connectionFactory));
3542

36-
try {
37-
sender.declareExchange(ExchangeSpecification.exchange("testExchange")).block();
38-
} catch (RuntimeException e) {
39-
Assertions.fail("Should not fail declaring exchange", e);
40-
}
43+
sender.declareExchange(ExchangeSpecification.exchange("testExchange")).block();
4144

4245
testing.waitAndAssertTraces(
4346
trace ->
4447
trace.hasSpansSatisfyingExactly(
45-
span -> {
46-
span.hasName("exchange.declare")
47-
.hasKind(SpanKind.CLIENT)
48-
.hasAttribute(MESSAGING_SYSTEM, "rabbitmq")
49-
.hasAttribute(AttributeKey.stringKey("rabbitmq.command"), "exchange.declare")
50-
.hasAttributesSatisfying(
51-
attributes ->
52-
assertThat(attributes)
53-
.satisfies(
54-
attrs -> {
55-
String peerAddr = attrs.get(NETWORK_PEER_ADDRESS);
56-
assertThat(peerAddr).isIn(rabbitMqIp, null);
57-
58-
String networkType = attrs.get(NETWORK_TYPE);
59-
assertThat(networkType).isIn("ipv4", "ipv6", null);
60-
61-
assertNotNull(attrs.get(NETWORK_PEER_PORT));
62-
}));
63-
}));
48+
span ->
49+
span.hasName("exchange.declare")
50+
.hasKind(SpanKind.CLIENT)
51+
.hasAttributesSatisfyingExactly(
52+
equalTo(MESSAGING_SYSTEM, RABBITMQ),
53+
equalTo(stringKey("rabbitmq.command"), "exchange.declare"),
54+
satisfies(
55+
NETWORK_PEER_ADDRESS,
56+
addr -> addr.satisfies(a -> assertThat(a).isIn(rabbitMqIp, null))),
57+
satisfies(
58+
NETWORK_TYPE,
59+
type ->
60+
type.satisfies(t -> assertThat(t).isIn("ipv4", "ipv6", null))),
61+
satisfies(NETWORK_PEER_PORT, port -> assertThat(port).isNotNull()))));
6462
}
6563
}

0 commit comments

Comments
 (0)