Skip to content

Commit ee07cb0

Browse files
authored
Test early and latest version in same test (#8)
1 parent 07a9b91 commit ee07cb0

File tree

3 files changed

+18
-65
lines changed

3 files changed

+18
-65
lines changed

instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,11 @@ dependencies {
1313
testLibrary("org.apache.dubbo:dubbo-config-api:2.7.0")
1414
}
1515

16-
testing {
17-
suites {
18-
val testLatestDepDubbo by registering(JvmTestSuite::class) {
19-
dependencies {
20-
implementation(project(":instrumentation:apache-dubbo-2.7:library-autoconfigure"))
21-
implementation("org.apache.dubbo:dubbo:+")
22-
}
23-
}
24-
}
25-
}
26-
2716
tasks.withType<Test>().configureEach {
17+
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
2818
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
2919
// to suppress non-fatal errors on jdk17
3020
jvmArgs("--add-opens=java.base/java.math=ALL-UNNAMED")
3121
// required on jdk17
3222
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
3323
}
34-
35-
if (findProperty("testLatestDeps") as Boolean) {
36-
tasks.check {
37-
dependsOn(testing.suites)
38-
}
39-
}

instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetterTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import static org.mockito.Mockito.when;
1010

1111
import java.net.InetSocketAddress;
12+
import java.util.Collections;
1213
import java.util.Iterator;
14+
import java.util.Map;
1315
import org.apache.dubbo.common.URL;
1416
import org.apache.dubbo.rpc.RpcContext;
1517
import org.apache.dubbo.rpc.RpcInvocation;
@@ -22,21 +24,32 @@
2224
class DubboHeadersGetterTest {
2325

2426
@Mock RpcContext context;
27+
@Mock RpcInvocation rpcInvocation;
2528

2629
@Test
2730
@SuppressWarnings("deprecation") // deprecation for RpcInvocation()
28-
void testKeys() {
31+
void testKeys() throws Exception {
2932
when(context.getUrl()).thenReturn(new URL("http", "localhost", 1));
3033
when(context.getRemoteAddress()).thenReturn(new InetSocketAddress(1));
3134
when(context.getLocalAddress()).thenReturn(new InetSocketAddress(1));
3235

33-
RpcInvocation invocation = new RpcInvocation();
34-
invocation.setAttachment("key", "value");
35-
DubboRequest request = DubboRequest.create(invocation, context);
36+
// for latest dep tests call getObjectAttachments, otherwise call getAttachments
37+
if (Boolean.getBoolean("testLatestDeps")) {
38+
when(getObjectAttachments()).thenReturn(Collections.singletonMap("key", "value"));
39+
} else {
40+
when(rpcInvocation.getAttachments()).thenReturn(Collections.singletonMap("key", "value"));
41+
}
42+
DubboRequest request = DubboRequest.create(rpcInvocation, context);
3643

3744
Iterator<String> iterator = DubboHeadersGetter.INSTANCE.keys(request).iterator();
3845
assertThat(iterator.hasNext()).isTrue();
3946
assertThat(iterator.next()).isEqualTo("key");
4047
assertThat(iterator.hasNext()).isFalse();
4148
}
49+
50+
@SuppressWarnings("unchecked")
51+
private Map<Object, Object> getObjectAttachments() throws Exception {
52+
return (Map<Object, Object>)
53+
RpcInvocation.class.getMethod("getObjectAttachments").invoke(rpcInvocation);
54+
}
4255
}

instrumentation/apache-dubbo-2.7/library-autoconfigure/src/testLatestDepDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetterTest.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)