mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
test: add dubbo integration-test
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("idea")
|
||||
}
|
||||
|
||||
group = "io.github.reajason"
|
||||
version = rootProject.version
|
||||
|
||||
val dubboClientCommon: SourceSet by sourceSets.creating
|
||||
val dubboClientAlibaba: SourceSet by sourceSets.creating
|
||||
val dubboClientApache: SourceSet by sourceSets.creating
|
||||
|
||||
val dubboClientCommonImplementation: Configuration by configurations.getting
|
||||
val dubboClientAlibabaImplementation: Configuration by configurations.getting
|
||||
val dubboClientApacheImplementation: Configuration by configurations.getting
|
||||
|
||||
val dubboClientCommonOutput = dubboClientCommon.output
|
||||
|
||||
dubboClientAlibaba.compileClasspath += dubboClientCommonOutput
|
||||
dubboClientAlibaba.runtimeClasspath += dubboClientCommonOutput
|
||||
dubboClientApache.compileClasspath += dubboClientCommonOutput
|
||||
dubboClientApache.runtimeClasspath += dubboClientCommonOutput
|
||||
|
||||
listOf(
|
||||
"dubboClientApacheCompileClasspath",
|
||||
"dubboClientApacheRuntimeClasspath"
|
||||
).forEach { configurationName ->
|
||||
configurations.named(configurationName) {
|
||||
exclude(group = "io.netty", module = "netty-transport-native-kqueue")
|
||||
exclude(group = "io.netty", module = "netty-resolver-dns-native-macos")
|
||||
}
|
||||
}
|
||||
|
||||
idea {
|
||||
module {
|
||||
excludeDirs.add(file("src/main"))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
dubboClientCommonImplementation("org.slf4j:slf4j-api:1.7.36")
|
||||
|
||||
dubboClientAlibabaImplementation(dubboClientCommonOutput)
|
||||
dubboClientAlibabaImplementation("com.alibaba:dubbo:2.6.12")
|
||||
dubboClientAlibabaImplementation("com.alibaba:hessian-lite:3.2.4")
|
||||
dubboClientAlibabaImplementation("com.caucho:hessian:4.0.51")
|
||||
dubboClientAlibabaImplementation("org.apache.httpcomponents:httpclient:4.5.3")
|
||||
dubboClientAlibabaImplementation("org.springframework:spring-web:5.3.39")
|
||||
dubboClientAlibabaImplementation("io.netty:netty-all:4.1.25.Final")
|
||||
dubboClientAlibabaImplementation("org.mortbay.jetty:jetty:6.1.26")
|
||||
dubboClientAlibabaImplementation("org.mortbay.jetty:jetty-util:6.1.26")
|
||||
dubboClientAlibabaImplementation("org.slf4j:slf4j-api:1.7.36")
|
||||
dubboClientAlibabaImplementation("ch.qos.logback:logback-classic:1.2.13")
|
||||
|
||||
dubboClientApacheImplementation(dubboClientCommonOutput)
|
||||
dubboClientApacheImplementation("org.apache.dubbo:dubbo:3.3.6") {
|
||||
exclude(group = "log4j", module = "log4j")
|
||||
}
|
||||
dubboClientApacheImplementation("org.apache.dubbo:dubbo-rpc-triple:3.3.6")
|
||||
dubboClientApacheImplementation("org.apache.dubbo.extensions:dubbo-rpc-http:3.3.1")
|
||||
dubboClientApacheImplementation("org.apache.dubbo.extensions:dubbo-rpc-hessian:3.3.0")
|
||||
dubboClientApacheImplementation("org.apache.dubbo:dubbo-remoting-http:3.3.0-beta.2")
|
||||
dubboClientApacheImplementation("com.caucho:hessian:4.0.51")
|
||||
dubboClientApacheImplementation("io.netty:netty-all:4.1.119.Final")
|
||||
dubboClientApacheImplementation("org.slf4j:slf4j-api:2.0.17")
|
||||
dubboClientApacheImplementation("ch.qos.logback:logback-classic:1.5.18")
|
||||
}
|
||||
|
||||
tasks.named<JavaCompile>(dubboClientCommon.compileJavaTaskName) {
|
||||
options.release.set(8)
|
||||
}
|
||||
|
||||
listOf(dubboClientAlibaba, dubboClientApache).forEach { sourceSet ->
|
||||
tasks.named<JavaCompile>(sourceSet.compileJavaTaskName) {
|
||||
options.release.set(8)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("dubboClientClasspath") {
|
||||
group = "verification"
|
||||
dependsOn(dubboClientAlibaba.classesTaskName, dubboClientApache.classesTaskName)
|
||||
doLast {
|
||||
layout.buildDirectory.file("dubbo-client-classpaths/alibaba.txt").get().asFile.apply {
|
||||
parentFile.mkdirs()
|
||||
writeText(dubboClientAlibaba.runtimeClasspath.asPath)
|
||||
}
|
||||
layout.buildDirectory.file("dubbo-client-classpaths/apache.txt").get().asFile.apply {
|
||||
parentFile.mkdirs()
|
||||
writeText(dubboClientApache.runtimeClasspath.asPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("classes") {
|
||||
dependsOn(dubboClientCommon.classesTaskName, dubboClientAlibaba.classesTaskName, dubboClientApache.classesTaskName)
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package io.github.reajason.dubbo.fixture.client.alibaba;
|
||||
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
import com.alibaba.dubbo.config.ApplicationConfig;
|
||||
import com.alibaba.dubbo.config.ReferenceConfig;
|
||||
import com.alibaba.dubbo.config.RegistryConfig;
|
||||
import com.alibaba.dubbo.rpc.service.GenericService;
|
||||
import io.github.reajason.dubbo.fixture.api.BytecodeLoadingService;
|
||||
import io.github.reajason.dubbo.fixture.client.ClientRuntimeSupport;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class AlibabaDubboClient {
|
||||
|
||||
private static final String LOOPBACK_HOST = "127.0.0.1";
|
||||
|
||||
public static void main(String[] args) {
|
||||
ClientRuntimeSupport.prepareClientJvm();
|
||||
forceLoopbackLocalAddress();
|
||||
if (args.length < 1) {
|
||||
throw new IllegalArgumentException("usage: load-bytes <url> <base64> | run-command <url> <interfaceName> <command>");
|
||||
}
|
||||
if ("load-bytes".equals(args[0])) {
|
||||
if (args.length < 3) {
|
||||
throw new IllegalArgumentException("usage: load-bytes <url> <base64>");
|
||||
}
|
||||
System.out.println(loadBytes(args[1], args[2]));
|
||||
return;
|
||||
}
|
||||
if ("run-command".equals(args[0])) {
|
||||
if (args.length < 4) {
|
||||
throw new IllegalArgumentException("usage: run-command <url> <interfaceName> <command>");
|
||||
}
|
||||
Object result = runCommand(args[1], args[2], args[3]);
|
||||
if (result instanceof byte[]) {
|
||||
System.out.println(new String((byte[]) result, StandardCharsets.UTF_8));
|
||||
} else {
|
||||
System.out.println(String.valueOf(result));
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("unsupported action: " + args[0]);
|
||||
}
|
||||
|
||||
public static String loadBytes(String url, String base64) {
|
||||
ClientRuntimeSupport.prepareClientJvm();
|
||||
forceLoopbackLocalAddress();
|
||||
ReferenceConfig<BytecodeLoadingService> reference = new ReferenceConfig<BytecodeLoadingService>();
|
||||
reference.setApplication(new ApplicationConfig("alibaba-dubbo-load-bytes-client"));
|
||||
reference.setRegistry(new RegistryConfig("N/A"));
|
||||
reference.setInterface(BytecodeLoadingService.class);
|
||||
reference.setCheck(false);
|
||||
reference.setTimeout(30000);
|
||||
reference.setRetries(0);
|
||||
reference.setUrl(url);
|
||||
|
||||
BytecodeLoadingService loadingService = reference.get();
|
||||
try {
|
||||
return loadingService.loadBytes(base64);
|
||||
} finally {
|
||||
reference.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public static Object runCommand(String url, String interfaceName, String command) {
|
||||
ClientRuntimeSupport.prepareClientJvm();
|
||||
forceLoopbackLocalAddress();
|
||||
ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
|
||||
reference.setApplication(new ApplicationConfig("alibaba-dubbo-command-client"));
|
||||
reference.setRegistry(new RegistryConfig("N/A"));
|
||||
reference.setInterface(interfaceName);
|
||||
reference.setGeneric(true);
|
||||
reference.setCheck(false);
|
||||
reference.setTimeout(30000);
|
||||
reference.setRetries(0);
|
||||
reference.setUrl(url);
|
||||
|
||||
GenericService genericService = reference.get();
|
||||
try {
|
||||
return genericService.$invoke(
|
||||
"handle",
|
||||
new String[]{byte[].class.getName()},
|
||||
new Object[]{command.getBytes(StandardCharsets.UTF_8)}
|
||||
);
|
||||
} finally {
|
||||
reference.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private static void forceLoopbackLocalAddress() {
|
||||
try {
|
||||
Field localAddressField = NetUtils.class.getDeclaredField("LOCAL_ADDRESS");
|
||||
localAddressField.setAccessible(true);
|
||||
localAddressField.set(null, InetAddress.getByName(LOOPBACK_HOST));
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort workaround for Dubbo 2.6.x local address selection on macOS.
|
||||
}
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package io.github.reajason.dubbo.fixture.client.apache;
|
||||
|
||||
import io.github.reajason.dubbo.fixture.api.BytecodeLoadingService;
|
||||
import io.github.reajason.dubbo.fixture.client.ClientRuntimeSupport;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.config.ReferenceConfig;
|
||||
import org.apache.dubbo.config.RegistryConfig;
|
||||
import org.apache.dubbo.rpc.service.GenericService;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ApacheDubboClient {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ClientRuntimeSupport.prepareClientJvm();
|
||||
if (args.length < 1) {
|
||||
throw new IllegalArgumentException("usage: load-bytes <url> <base64> | run-command <url> <interfaceName> <command>");
|
||||
}
|
||||
if ("load-bytes".equals(args[0])) {
|
||||
if (args.length < 3) {
|
||||
throw new IllegalArgumentException("usage: load-bytes <url> <base64>");
|
||||
}
|
||||
System.out.println(loadBytes(args[1], args[2]));
|
||||
return;
|
||||
}
|
||||
if ("run-command".equals(args[0])) {
|
||||
if (args.length < 4) {
|
||||
throw new IllegalArgumentException("usage: run-command <url> <interfaceName> <command>");
|
||||
}
|
||||
Object result = runCommand(args[1], args[2], args[3]);
|
||||
if (result instanceof byte[]) {
|
||||
System.out.println(new String((byte[]) result, StandardCharsets.UTF_8));
|
||||
} else {
|
||||
System.out.println(String.valueOf(result));
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("unsupported action: " + args[0]);
|
||||
}
|
||||
|
||||
public static String loadBytes(String url, String base64) {
|
||||
ClientRuntimeSupport.prepareClientJvm();
|
||||
ReferenceConfig<BytecodeLoadingService> reference = new ReferenceConfig<BytecodeLoadingService>();
|
||||
reference.setApplication(new ApplicationConfig("apache-dubbo-load-bytes-client"));
|
||||
reference.setRegistry(new RegistryConfig("N/A"));
|
||||
reference.setInterface(BytecodeLoadingService.class);
|
||||
reference.setCheck(false);
|
||||
reference.setTimeout(30000);
|
||||
reference.setRetries(0);
|
||||
reference.setUrl(url);
|
||||
|
||||
BytecodeLoadingService loadingService = reference.get();
|
||||
try {
|
||||
return loadingService.loadBytes(base64);
|
||||
} finally {
|
||||
reference.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
public static Object runCommand(String url, String interfaceName, String command) {
|
||||
ClientRuntimeSupport.prepareClientJvm();
|
||||
ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
|
||||
reference.setApplication(new ApplicationConfig("apache-dubbo-command-client"));
|
||||
reference.setRegistry(new RegistryConfig("N/A"));
|
||||
reference.setInterface(interfaceName);
|
||||
reference.setGeneric(true);
|
||||
reference.setCheck(false);
|
||||
reference.setTimeout(30000);
|
||||
reference.setRetries(0);
|
||||
reference.setUrl(url);
|
||||
|
||||
GenericService genericService = reference.get();
|
||||
try {
|
||||
return genericService.$invoke(
|
||||
"handle",
|
||||
new String[]{byte[].class.getName()},
|
||||
new Object[]{command.getBytes(StandardCharsets.UTF_8)}
|
||||
);
|
||||
} finally {
|
||||
reference.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package io.github.reajason.dubbo.fixture.api;
|
||||
|
||||
public interface BytecodeLoadingService {
|
||||
String loadBytes(String base64);
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package io.github.reajason.dubbo.fixture.client;
|
||||
|
||||
public final class ClientRuntimeSupport {
|
||||
|
||||
private static final String[] PROXY_PROPERTIES = new String[]{
|
||||
"proxyHost",
|
||||
"proxyPort",
|
||||
"http.proxyHost",
|
||||
"http.proxyPort",
|
||||
"https.proxyHost",
|
||||
"https.proxyPort",
|
||||
"socksProxyHost",
|
||||
"socksProxyPort",
|
||||
"ftp.proxyHost",
|
||||
"ftp.proxyPort"
|
||||
};
|
||||
|
||||
private ClientRuntimeSupport() {
|
||||
}
|
||||
|
||||
public static void prepareClientJvm() {
|
||||
System.setProperty("dubbo.compiler", "jdk");
|
||||
System.setProperty("java.net.preferIPv4Stack", "true");
|
||||
System.setProperty("java.net.useSystemProxies", "false");
|
||||
for (String property : PROXY_PROPERTIES) {
|
||||
System.clearProperty(property);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user