mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-22 23:11:52 +08:00
test: add dubbo integration-test
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Testcontainers
|
||||
@Tag("dubbo-container")
|
||||
class AlibabaDubbo2612ContainerTest {
|
||||
|
||||
private static final DubboProviderScenario SCENARIO = new DubboProviderScenario(
|
||||
"alibaba-dubbo-2.6.12",
|
||||
"alibaba",
|
||||
"dubbo.alibaba.provider.jar",
|
||||
"eclipse-temurin:8-jre",
|
||||
20880,
|
||||
Opcodes.V1_8,
|
||||
List.of(
|
||||
new DubboProtocolTarget("dubbo", 20880),
|
||||
new DubboProtocolTarget("hessian", 28080)
|
||||
)
|
||||
);
|
||||
|
||||
@Container
|
||||
static final GenericContainer<?> container = DubboContainerFactory.buildProvider(SCENARIO);
|
||||
|
||||
@Test
|
||||
void testDubboServiceRegistration() {
|
||||
DubboServiceAssertion.assertCommandService(container, SCENARIO);
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Testcontainers
|
||||
@Tag("dubbo-container")
|
||||
class ApacheDubbo27xContainerTest {
|
||||
|
||||
private static final String IMAGE = "eclipse-temurin:17-jdk";
|
||||
|
||||
private static final DubboProviderScenario APACHE_276 = apacheScenario(
|
||||
"apache-dubbo-2.7.6",
|
||||
"dubbo.apache276.provider.jar",
|
||||
20885,
|
||||
28086
|
||||
);
|
||||
private static final DubboProviderScenario APACHE_277 = apacheScenario(
|
||||
"apache-dubbo-2.7.7",
|
||||
"dubbo.apache277.provider.jar",
|
||||
20886,
|
||||
28088
|
||||
);
|
||||
private static final DubboProviderScenario APACHE_278 = apacheScenario(
|
||||
"apache-dubbo-2.7.8",
|
||||
"dubbo.apache278.provider.jar",
|
||||
20887,
|
||||
28090
|
||||
);
|
||||
private static final DubboProviderScenario APACHE_2723 = apacheScenario(
|
||||
"apache-dubbo-2.7.23",
|
||||
"dubbo.apache2723.provider.jar",
|
||||
20881,
|
||||
28082
|
||||
);
|
||||
|
||||
@Container
|
||||
static final GenericContainer<?> apache276 = DubboContainerFactory.buildProvider(APACHE_276);
|
||||
@Container
|
||||
static final GenericContainer<?> apache277 = DubboContainerFactory.buildProvider(APACHE_277);
|
||||
@Container
|
||||
static final GenericContainer<?> apache278 = DubboContainerFactory.buildProvider(APACHE_278);
|
||||
@Container
|
||||
static final GenericContainer<?> apache2723 = DubboContainerFactory.buildProvider(APACHE_2723);
|
||||
|
||||
static Stream<Arguments> scenarios() {
|
||||
return Stream.of(
|
||||
Arguments.of(apache276, APACHE_276),
|
||||
Arguments.of(apache277, APACHE_277),
|
||||
Arguments.of(apache278, APACHE_278),
|
||||
Arguments.of(apache2723, APACHE_2723)
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{1}")
|
||||
@MethodSource("scenarios")
|
||||
void testDubboServiceRegistration(GenericContainer<?> container, DubboProviderScenario scenario) {
|
||||
DubboServiceAssertion.assertCommandService(container, scenario);
|
||||
}
|
||||
|
||||
private static DubboProviderScenario apacheScenario(String name, String providerJarProperty, int dubboPort, int hessianPort) {
|
||||
return new DubboProviderScenario(
|
||||
name,
|
||||
"apache",
|
||||
providerJarProperty,
|
||||
IMAGE,
|
||||
dubboPort,
|
||||
Opcodes.V1_8,
|
||||
List.of(
|
||||
new DubboProtocolTarget("dubbo", dubboPort),
|
||||
new DubboProtocolTarget("hessian", hessianPort)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import net.bytebuddy.jar.asm.Opcodes;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Testcontainers
|
||||
@Tag("dubbo-container")
|
||||
class ApacheDubbo336ContainerTest {
|
||||
|
||||
private static final DubboProviderScenario SCENARIO = new DubboProviderScenario(
|
||||
"apache-dubbo-3.3.6",
|
||||
"apache",
|
||||
"dubbo.apache336.provider.jar",
|
||||
"eclipse-temurin:17-jdk",
|
||||
20882,
|
||||
Opcodes.V1_8,
|
||||
List.of(
|
||||
new DubboProtocolTarget("dubbo", 20882),
|
||||
new DubboProtocolTarget("hessian", 28084),
|
||||
new DubboProtocolTarget("tri", 50051)
|
||||
)
|
||||
);
|
||||
|
||||
@Container
|
||||
static final GenericContainer<?> container = DubboContainerFactory.buildProvider(SCENARIO);
|
||||
|
||||
@Test
|
||||
void testDubboServiceRegistration() {
|
||||
DubboServiceAssertion.assertCommandService(container, SCENARIO);
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
final class DubboClientRunner {
|
||||
|
||||
private DubboClientRunner() {
|
||||
}
|
||||
|
||||
static String loadBytes(String clientKind, String url, String base64) {
|
||||
return run(clientKind, "load-bytes", url, base64);
|
||||
}
|
||||
|
||||
static String runCommand(String clientKind, String url, String interfaceName, String command) {
|
||||
return run(clientKind, "run-command", url, interfaceName, command);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static String run(String clientKind, String... args) {
|
||||
List<String> command = new ArrayList<String>();
|
||||
String javaExecutable = javaExecutable(clientKind);
|
||||
command.add(javaExecutable);
|
||||
if (supportsAddOpens(javaExecutable)) {
|
||||
command.add("--add-opens=java.base/java.lang=ALL-UNNAMED");
|
||||
command.add("--add-opens=java.base/java.math=ALL-UNNAMED");
|
||||
}
|
||||
command.add("-cp");
|
||||
command.add(clientClasspath(clientKind));
|
||||
command.add(mainClass(clientKind));
|
||||
for (String arg : args) {
|
||||
command.add(arg);
|
||||
}
|
||||
|
||||
Process process = new ProcessBuilder(command)
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
copy(process.getInputStream(), output);
|
||||
int exitCode = process.waitFor();
|
||||
String rendered = output.toString(StandardCharsets.UTF_8).trim();
|
||||
if (exitCode != 0) {
|
||||
throw new IllegalStateException("Dubbo client failed with exit code " + exitCode + "\n" + rendered);
|
||||
}
|
||||
return rendered;
|
||||
}
|
||||
|
||||
private static String clientClasspath(String clientKind) {
|
||||
String property = System.getProperty("dubbo." + clientKind + ".client.classpath");
|
||||
if (isBlank(property)) {
|
||||
throw new IllegalStateException("missing dubbo." + clientKind + ".client.classpath system property");
|
||||
}
|
||||
return property;
|
||||
}
|
||||
|
||||
private static String mainClass(String clientKind) {
|
||||
if ("alibaba".equals(clientKind)) {
|
||||
return "io.github.reajason.dubbo.fixture.client.alibaba.AlibabaDubboClient";
|
||||
}
|
||||
if ("apache".equals(clientKind)) {
|
||||
return "io.github.reajason.dubbo.fixture.client.apache.ApacheDubboClient";
|
||||
}
|
||||
throw new IllegalArgumentException("unsupported client kind: " + clientKind);
|
||||
}
|
||||
|
||||
private static String javaExecutable(String clientKind) {
|
||||
if (!"alibaba".equals(clientKind)) {
|
||||
return "java";
|
||||
}
|
||||
String java8Home = System.getenv("JAVA8_HOME");
|
||||
if (isBlank(java8Home)) {
|
||||
java8Home = System.getProperty("java8.home");
|
||||
}
|
||||
if (isBlank(java8Home)) {
|
||||
return "java";
|
||||
}
|
||||
return java8Home + "/bin/java";
|
||||
}
|
||||
|
||||
private static boolean supportsAddOpens(String javaExecutable) throws java.io.IOException, InterruptedException {
|
||||
Process process = new ProcessBuilder(javaExecutable, "-version")
|
||||
.redirectErrorStream(true)
|
||||
.start();
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
copy(process.getInputStream(), output);
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode != 0) {
|
||||
return true;
|
||||
}
|
||||
return majorVersion(output.toString(StandardCharsets.UTF_8)) >= 9;
|
||||
}
|
||||
|
||||
private static int majorVersion(String versionOutput) {
|
||||
Matcher matcher = Pattern.compile("version \"([^\"]+)\"").matcher(versionOutput);
|
||||
if (!matcher.find()) {
|
||||
return 9;
|
||||
}
|
||||
String version = matcher.group(1);
|
||||
if (version.startsWith("1.")) {
|
||||
int dot = version.indexOf('.', 2);
|
||||
return leadingInteger(dot < 0 ? version.substring(2) : version.substring(2, dot));
|
||||
}
|
||||
int dot = version.indexOf('.');
|
||||
return leadingInteger(dot < 0 ? version : version.substring(0, dot));
|
||||
}
|
||||
|
||||
private static int leadingInteger(String value) {
|
||||
Matcher matcher = Pattern.compile("^(\\d+)").matcher(value);
|
||||
return matcher.find() ? Integer.parseInt(matcher.group(1)) : 9;
|
||||
}
|
||||
|
||||
private static boolean isBlank(String value) {
|
||||
return value == null || value.trim().isEmpty();
|
||||
}
|
||||
|
||||
private static void copy(InputStream inputStream, ByteArrayOutputStream outputStream) throws java.io.IOException {
|
||||
byte[] buffer = new byte[4096];
|
||||
int read;
|
||||
while ((read = inputStream.read(buffer)) >= 0) {
|
||||
outputStream.write(buffer, 0, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
import org.testcontainers.containers.wait.strategy.Wait;
|
||||
import org.testcontainers.utility.MountableFile;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
|
||||
final class DubboContainerFactory {
|
||||
|
||||
private DubboContainerFactory() {
|
||||
}
|
||||
|
||||
static GenericContainer<?> buildProvider(DubboProviderScenario scenario) {
|
||||
String jarPath = providerJarPath(scenario.providerJarProperty());
|
||||
GenericContainer<?> container = new GenericContainer<>(scenario.imageName())
|
||||
.withCopyFileToContainer(MountableFile.forHostPath(jarPath), "/app/app.jar")
|
||||
.withWorkingDirectory("/app")
|
||||
.withExposedPorts(exposedPorts(scenario))
|
||||
.waitingFor(Wait.forLogMessage(".*Provider started.*", 1)
|
||||
.withStartupTimeout(Duration.ofMinutes(3)));
|
||||
|
||||
if ("alibaba".equals(scenario.clientKind())) {
|
||||
container.withCommand("java", "-jar", "/app/app.jar");
|
||||
} else {
|
||||
container.withCommand(
|
||||
"java",
|
||||
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
|
||||
"--add-opens", "java.base/java.math=ALL-UNNAMED",
|
||||
"-jar", "/app/app.jar"
|
||||
);
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
private static Integer[] exposedPorts(DubboProviderScenario scenario) {
|
||||
return scenario.commandTargets().stream()
|
||||
.map(DubboProtocolTarget::port)
|
||||
.distinct()
|
||||
.toArray(Integer[]::new);
|
||||
}
|
||||
|
||||
private static String providerJarPath(String propertyName) {
|
||||
String value = System.getProperty(propertyName);
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
throw new IllegalStateException("missing " + propertyName + " system property");
|
||||
}
|
||||
Path path = Path.of(value);
|
||||
if (!Files.isRegularFile(path)) {
|
||||
throw new IllegalStateException("provider jar does not exist: " + path);
|
||||
}
|
||||
return path.toAbsolutePath().toString();
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
final class DubboProtocolTarget {
|
||||
private final String protocol;
|
||||
private final int port;
|
||||
|
||||
DubboProtocolTarget(String protocol, int port) {
|
||||
this.protocol = protocol;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
String protocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
int port() {
|
||||
return port;
|
||||
}
|
||||
|
||||
String url(String host, String interfaceName) {
|
||||
return protocol + "://" + host + ":" + port + "/" + interfaceName;
|
||||
}
|
||||
|
||||
String url(String host, int mappedPort, String interfaceName) {
|
||||
return protocol + "://" + host + ":" + mappedPort + "/" + interfaceName;
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import com.reajason.javaweb.memshell.ShellType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
final class DubboProviderScenario {
|
||||
private final String name;
|
||||
private final String clientKind;
|
||||
private final String providerJarProperty;
|
||||
private final String imageName;
|
||||
private final int loaderPort;
|
||||
private final int targetJdkVersion;
|
||||
private final List<DubboProtocolTarget> commandTargets;
|
||||
|
||||
DubboProviderScenario(String name, String clientKind, String providerJarProperty, String imageName,
|
||||
int loaderPort, int targetJdkVersion, List<DubboProtocolTarget> commandTargets) {
|
||||
this.name = name;
|
||||
this.clientKind = clientKind;
|
||||
this.providerJarProperty = providerJarProperty;
|
||||
this.imageName = imageName;
|
||||
this.loaderPort = loaderPort;
|
||||
this.targetJdkVersion = targetJdkVersion;
|
||||
this.commandTargets = commandTargets;
|
||||
}
|
||||
|
||||
String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
String clientKind() {
|
||||
return clientKind;
|
||||
}
|
||||
|
||||
String providerJarProperty() {
|
||||
return providerJarProperty;
|
||||
}
|
||||
|
||||
String imageName() {
|
||||
return imageName;
|
||||
}
|
||||
|
||||
int loaderPort() {
|
||||
return loaderPort;
|
||||
}
|
||||
|
||||
int targetJdkVersion() {
|
||||
return targetJdkVersion;
|
||||
}
|
||||
|
||||
List<DubboProtocolTarget> commandTargets() {
|
||||
return commandTargets;
|
||||
}
|
||||
|
||||
String shellType() {
|
||||
if ("alibaba".equals(clientKind)) {
|
||||
return ShellType.ALIBABA_DUBBO_SERVICE;
|
||||
}
|
||||
return ShellType.APACHE_DUBBO_SERVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import com.reajason.javaweb.Server;
|
||||
import com.reajason.javaweb.integration.ShellAssertion;
|
||||
import com.reajason.javaweb.memshell.MemShellResult;
|
||||
import com.reajason.javaweb.memshell.ShellTool;
|
||||
import com.reajason.javaweb.memshell.config.CommandConfig;
|
||||
import com.reajason.javaweb.memshell.config.ShellToolConfig;
|
||||
import com.reajason.javaweb.packer.Packers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.testcontainers.containers.GenericContainer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
@Slf4j
|
||||
final class DubboServiceAssertion {
|
||||
|
||||
private static final String LOADER_INTERFACE = "io.github.reajason.dubbo.fixture.api.BytecodeLoadingService";
|
||||
private static final String COMMAND = "id";
|
||||
|
||||
private DubboServiceAssertion() {
|
||||
}
|
||||
|
||||
static void assertCommandService(GenericContainer<?> container, DubboProviderScenario scenario) {
|
||||
ShellToolConfig shellToolConfig = ShellAssertion.getShellToolConfig(
|
||||
scenario.shellType(),
|
||||
ShellTool.Command,
|
||||
Packers.Base64
|
||||
);
|
||||
MemShellResult result = ShellAssertion.generate(
|
||||
null,
|
||||
Server.Dubbo,
|
||||
null,
|
||||
scenario.shellType(),
|
||||
ShellTool.Command,
|
||||
scenario.targetJdkVersion(),
|
||||
shellToolConfig,
|
||||
Packers.Base64
|
||||
);
|
||||
String interfaceName = result.getInjectorConfig().getUrlPattern();
|
||||
String host = container.getHost();
|
||||
String loaderUrl = "dubbo://" + host + ":" + container.getMappedPort(scenario.loaderPort()) + "/" + LOADER_INTERFACE;
|
||||
|
||||
log.info("loading {} into {} via {}", interfaceName, scenario.name(), loaderUrl);
|
||||
String loadOutput = DubboClientRunner.loadBytes(scenario.clientKind(), loaderUrl, result.getInjectorBytesBase64Str());
|
||||
log.info("{} load output: {}", scenario.name(), loadOutput);
|
||||
|
||||
List<String> fallbackUrls = scenario.commandTargets().stream()
|
||||
.map(target -> target.url(host, container.getMappedPort(target.port()), interfaceName))
|
||||
.collect(Collectors.toList());
|
||||
List<String> commandUrls = DubboUrlResolver.resolveCommandUrls(loadOutput, interfaceName, fallbackUrls);
|
||||
|
||||
for (String commandUrl : commandUrls) {
|
||||
String output = DubboClientRunner.runCommand(scenario.clientKind(), commandUrl, interfaceName, COMMAND);
|
||||
log.info("{} {} command output: {}", scenario.name(), DubboUrlResolver.protocolOf(commandUrl), output);
|
||||
assertThat(output, anyOf(containsString("uid="), containsString("injected-ok")));
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
final class DubboUrlResolver {
|
||||
|
||||
private DubboUrlResolver() {
|
||||
}
|
||||
|
||||
static List<String> resolveCommandUrls(String loadOutput, String interfaceName, List<String> fallbackUrls) {
|
||||
Map<String, String> discoveredByProtocol = new LinkedHashMap<String, String>();
|
||||
Pattern pattern = Pattern.compile("(dubbo|hessian|tri)://[^\\s,]*" + Pattern.quote(interfaceName) + "(?:\\?[^\\s,]*)?");
|
||||
Matcher matcher = pattern.matcher(loadOutput);
|
||||
while (matcher.find()) {
|
||||
String candidate = matcher.group();
|
||||
discoveredByProtocol.put(protocolOf(candidate), candidate);
|
||||
}
|
||||
return fallbackUrls.stream()
|
||||
.map(fallback -> {
|
||||
String discovered = discoveredByProtocol.get(protocolOf(fallback));
|
||||
return discovered == null ? fallback : rewriteEndpoint(discovered, fallback);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
static String protocolOf(String url) {
|
||||
int separator = url.indexOf("://");
|
||||
return separator < 0 ? url : url.substring(0, separator);
|
||||
}
|
||||
|
||||
static String rewriteHost(String url, String host) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
return new URI(
|
||||
uri.getScheme(),
|
||||
uri.getUserInfo(),
|
||||
host,
|
||||
uri.getPort(),
|
||||
uri.getPath(),
|
||||
uri.getQuery(),
|
||||
uri.getFragment()
|
||||
).toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("invalid direct url: " + url, e);
|
||||
}
|
||||
}
|
||||
|
||||
static String rewriteEndpoint(String url, String endpointUrl) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
URI endpoint = new URI(endpointUrl);
|
||||
return new URI(
|
||||
uri.getScheme(),
|
||||
uri.getUserInfo(),
|
||||
endpoint.getHost(),
|
||||
endpoint.getPort(),
|
||||
uri.getPath(),
|
||||
uri.getQuery(),
|
||||
uri.getFragment()
|
||||
).toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("invalid direct url: " + url + " or " + endpointUrl, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.reajason.javaweb.integration.memshell.dubbo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
|
||||
class DubboUrlResolverTest {
|
||||
|
||||
@Test
|
||||
void discoveredUrlsOverrideFallbackByProtocolAndRewriteHost() {
|
||||
String interfaceName = "org.example.ICommandService";
|
||||
String loadOutput = "ok dubbo://x.x.x.x:20880/" + interfaceName + "?side=provider, "
|
||||
+ "hessian://10.1.2.3:28080/" + interfaceName;
|
||||
|
||||
List<String> resolved = DubboUrlResolver.resolveCommandUrls(
|
||||
loadOutput,
|
||||
interfaceName,
|
||||
List.of(
|
||||
"dubbo://127.0.0.1:1111/" + interfaceName,
|
||||
"hessian://127.0.0.1:2222/" + interfaceName,
|
||||
"tri://127.0.0.1:3333/" + interfaceName
|
||||
)
|
||||
);
|
||||
|
||||
assertThat(resolved, contains(
|
||||
"dubbo://127.0.0.1:1111/" + interfaceName + "?side=provider",
|
||||
"hessian://127.0.0.1:2222/" + interfaceName,
|
||||
"tri://127.0.0.1:3333/" + interfaceName
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user