@Override
    public String execute(CommandContext commandContext, String[] args) {
        Channel channel = commandContext.getRemote();
        String service = channel.attr(ChangeTelnet.SERVICE_KEY).get();
        if ((service == null || service.length() == 0) && (args == null || args.length == 0)) {
            return "Please input service name, eg: \r\ncount XxxService\r\ncount XxxService xxxMethod\r\ncount XxxService xxxMethod 10\r\nor \"cd XxxService\" firstly.";
        }
        StringBuilder buf = new StringBuilder();
        if (service != null && service.length() > 0) {
            buf.append("Use default service ").append(service).append(".\r\n");
        }
        String method;
        String times;
        if (service == null || service.length() == 0) {
            service = args[0];
            method = args.length > 1 ? args[1] : null;
        } else {
            method = args.length > 0 ? args[0] : null;
        }
        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.";
        }
        final int t = Integer.parseInt(times);
        Invoker<?> invoker = null;
        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().getServiceKey())) {
                invoker = exporter.getInvoker();
                break;
            }
        }
        if (invoker != null) {
            if (t > 0) {
                final String mtd = method;
                final Invoker<?> inv = invoker;
                Thread thread = new Thread(
                        () -> {
                            for (int i = 0; i < t; i++) {
                                String result = count(inv, mtd);
                                try {
                                    send(channel, "\r\n" + result);
                                } catch (RemotingException e1) {
                                    return;
                                }
                                if (i < t - 1) {
                                    try {
                                        Thread.sleep(1000);
                                    } catch (InterruptedException ignored) {
                                    }
                                }
                            }
                            try {
                                send(channel, "\r\n" + PROMPT);
                            } catch (RemotingException ignored) {
                            }
                        },
                        "TelnetCount");
                thread.setDaemon(true);
                thread.start();
            }
        } else {
            buf.append("No such service ").append(service);
        }
        return buf.toString();
    }
@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")));
    }