Skip to content

Commit

Permalink
Test early and latest version in same test (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Jan 9, 2025
1 parent 07a9b91 commit ee07cb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,11 @@ dependencies {
testLibrary("org.apache.dubbo:dubbo-config-api:2.7.0")
}

testing {
suites {
val testLatestDepDubbo by registering(JvmTestSuite::class) {
dependencies {
implementation(project(":instrumentation:apache-dubbo-2.7:library-autoconfigure"))
implementation("org.apache.dubbo:dubbo:+")
}
}
}
}

tasks.withType<Test>().configureEach {
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean)
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
// to suppress non-fatal errors on jdk17
jvmArgs("--add-opens=java.base/java.math=ALL-UNNAMED")
// required on jdk17
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
}

if (findProperty("testLatestDeps") as Boolean) {
tasks.check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import static org.mockito.Mockito.when;

import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcInvocation;
Expand All @@ -22,21 +24,32 @@
class DubboHeadersGetterTest {

@Mock RpcContext context;
@Mock RpcInvocation rpcInvocation;

@Test
@SuppressWarnings("deprecation") // deprecation for RpcInvocation()
void testKeys() {
void testKeys() throws Exception {
when(context.getUrl()).thenReturn(new URL("http", "localhost", 1));
when(context.getRemoteAddress()).thenReturn(new InetSocketAddress(1));
when(context.getLocalAddress()).thenReturn(new InetSocketAddress(1));

RpcInvocation invocation = new RpcInvocation();
invocation.setAttachment("key", "value");
DubboRequest request = DubboRequest.create(invocation, context);
// for latest dep tests call getObjectAttachments, otherwise call getAttachments
if (Boolean.getBoolean("testLatestDeps")) {
when(getObjectAttachments()).thenReturn(Collections.singletonMap("key", "value"));
} else {
when(rpcInvocation.getAttachments()).thenReturn(Collections.singletonMap("key", "value"));
}
DubboRequest request = DubboRequest.create(rpcInvocation, context);

Iterator<String> iterator = DubboHeadersGetter.INSTANCE.keys(request).iterator();
assertThat(iterator.hasNext()).isTrue();
assertThat(iterator.next()).isEqualTo("key");
assertThat(iterator.hasNext()).isFalse();
}

@SuppressWarnings("unchecked")
private Map<Object, Object> getObjectAttachments() throws Exception {
return (Map<Object, Object>)
RpcInvocation.class.getMethod("getObjectAttachments").invoke(rpcInvocation);
}
}

This file was deleted.

0 comments on commit ee07cb0

Please sign in to comment.