Add condition to match serviceKey. (#13869)
This commit is contained in:
parent
b2c66a6d99
commit
0553d70899
|
|
@ -58,7 +58,8 @@ public class ChangeTelnet implements BaseCommand {
|
|||
for (Exporter<?> exporter : dubboProtocol.getExporters()) {
|
||||
if (message.equals(exporter.getInvoker().getInterface().getSimpleName())
|
||||
|| message.equals(exporter.getInvoker().getInterface().getName())
|
||||
|| message.equals(exporter.getInvoker().getUrl().getPath())) {
|
||||
|| message.equals(exporter.getInvoker().getUrl().getPath())
|
||||
|| message.equals(exporter.getInvoker().getUrl().getServiceKey())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@ public class CountTelnet implements BaseCommand {
|
|||
for (Exporter<?> exporter : dubboProtocol.getExporters()) {
|
||||
if (service.equals(exporter.getInvoker().getInterface().getSimpleName())
|
||||
|| service.equals(exporter.getInvoker().getInterface().getName())
|
||||
|| service.equals(exporter.getInvoker().getUrl().getPath())) {
|
||||
|| service.equals(exporter.getInvoker().getUrl().getPath())
|
||||
|| service.equals(exporter.getInvoker().getUrl().getServiceKey())) {
|
||||
invoker = exporter.getInvoker();
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class ChangeTelnetTest {
|
|||
mockChannel.attr(ChangeTelnet.SERVICE_KEY).set("org.apache.dubbo.rpc.protocol.dubbo.support.DemoService");
|
||||
given(mockCommandContext.getRemote()).willReturn(mockChannel);
|
||||
given(mockInvoker.getInterface()).willReturn(DemoService.class);
|
||||
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:20884/demo"));
|
||||
given(mockInvoker.getUrl()).willReturn(URL.valueOf("dubbo://127.0.0.1:20884/demo?group=g&version=1.0.0"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
|
@ -110,6 +110,15 @@ class ChangeTelnetTest {
|
|||
assertEquals("Used the demo as default.\r\nYou can cancel default service by command: cd /", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangeServiceKey() {
|
||||
ExtensionLoader.getExtensionLoader(Protocol.class)
|
||||
.getExtension(DubboProtocol.NAME)
|
||||
.export(mockInvoker);
|
||||
String result = change.execute(mockCommandContext, new String[] {"g/demo:1.0.0"});
|
||||
assertEquals("Used the g/demo:1.0.0 as default.\r\nYou can cancel default service by command: cd /", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangeMessageNull() {
|
||||
String result = change.execute(mockCommandContext, null);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class CountTelnetTest {
|
|||
private CommandContext mockCommandContext;
|
||||
|
||||
private CountDownLatch latch;
|
||||
private final URL url = URL.valueOf("dubbo://127.0.0.1:20884/demo");
|
||||
private final URL url = URL.valueOf("dubbo://127.0.0.1:20884/demo?group=g&version=1.0.0");
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
|
@ -70,12 +70,14 @@ class CountTelnetTest {
|
|||
public void tearDown() {
|
||||
FrameworkModel.destroyAll();
|
||||
mockChannel.close();
|
||||
RpcStatus.removeStatus(url);
|
||||
reset(mockInvoker, mockCommandContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
void test() throws Exception {
|
||||
String methodName = "sayHello";
|
||||
RpcStatus.removeStatus(url, methodName);
|
||||
String[] args = new String[] {"org.apache.dubbo.qos.legacy.service.DemoService", "sayHello", "1"};
|
||||
|
||||
ExtensionLoader.getExtensionLoader(Protocol.class)
|
||||
|
|
@ -94,6 +96,28 @@ class CountTelnetTest {
|
|||
assertThat(sb.toString(), containsString(buildTable(methodName, 10, 10, "1", "0", "0")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCountByServiceKey() throws Exception {
|
||||
String methodName = "sayHello";
|
||||
RpcStatus.removeStatus(url, methodName);
|
||||
String[] args = new String[] {"g/demo:1.0.0", "sayHello", "1"};
|
||||
|
||||
ExtensionLoader.getExtensionLoader(Protocol.class)
|
||||
.getExtension(DubboProtocol.NAME)
|
||||
.export(mockInvoker);
|
||||
RpcStatus.beginCount(url, methodName);
|
||||
RpcStatus.endCount(url, methodName, 10L, true);
|
||||
count.execute(mockCommandContext, args);
|
||||
latch.await();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object o : mockChannel.getReceivedObjects()) {
|
||||
sb.append(o.toString());
|
||||
}
|
||||
|
||||
assertThat(sb.toString(), containsString(buildTable(methodName, 10, 10, "1", "0", "0")));
|
||||
}
|
||||
|
||||
public static String buildTable(
|
||||
String methodName, long averageElapsed, long maxElapsed, String total, String failed, String active) {
|
||||
List<String> header = new LinkedList<>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue