Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public String execute(CommandContext commandContext, String[] args) {
if (service == null || service.length() == 0) {
service = args[0];
method = args.length > 1 ? args[1] : null;
times = args.length > 2 ? args[2] : "1";
} else {
method = args.length > 0 ? args[0] : null;
times = args.length > 1 ? args[1] : "1";
}
if (StringUtils.isNumber(method)) {
times = method;
method = null;
} else {
times = args.length > 2 ? args[2] : "1";
}
if (!StringUtils.isNumber(times)) {
return "Illegal times " + times + ", must be integer.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
Expand Down Expand Up @@ -118,6 +121,34 @@ void testCountByServiceKey() throws Exception {
assertThat(sb.toString(), containsString(buildTable(methodName, 10, 10, "1", "0", "0")));
}

@Test
void testCountTimesWithDefaultService() throws Exception {
String methodName = "sayHello";
RpcStatus.removeStatus(url, methodName);
// "count sayHello 2" after "cd org.apache.dubbo.qos.legacy.service.DemoService"
String[] args = new String[] {"sayHello", "2"};
// Two results followed by the prompt
latch = new CountDownLatch(3);
mockChannel = new MockNettyChannel(url, latch);
mockChannel.attr(ChangeTelnet.SERVICE_KEY).set(DemoService.class.getName());
given(mockCommandContext.getRemote()).willReturn(mockChannel);

ExtensionLoader.getExtensionLoader(Protocol.class)
.getExtension(DubboProtocol.NAME)
.export(mockInvoker);
RpcStatus.beginCount(url, methodName);
RpcStatus.endCount(url, methodName, 10L, true);
count.execute(mockCommandContext, args);

assertTrue(latch.await(5, TimeUnit.SECONDS));
String table = buildTable(methodName, 10, 10, "1", "0", "0");
assertEquals(
2,
mockChannel.getReceivedObjects().stream()
.filter(o -> o.toString().contains(table))
.count());
}

public static String buildTable(
String methodName, long averageElapsed, long maxElapsed, String total, String failed, String active) {
List<String> header = new LinkedList<>();
Expand Down
Loading