@Override
    public String execute(CommandContext commandContext, String[] args) {
        logger.info("received publishMetadata command.");

        StringBuilder stringBuilder = new StringBuilder();
        List<ApplicationModel> applicationModels = frameworkModel.getApplicationModels();

        for (ApplicationModel applicationModel : applicationModels) {
            if (ArrayUtils.isEmpty(args)) {
                ServiceInstanceMetadataUtils.refreshMetadataAndInstance(applicationModel);
                stringBuilder
                        .append("publish metadata succeeded. App:")
                        .append(applicationModel.getApplicationName())
                        .append("\n");
            } else {
                try {
                    int delay = Integer.parseInt(args[0]);
                    FrameworkExecutorRepository frameworkExecutorRepository = applicationModel
                            .getFrameworkModel()
                            .getBeanFactory()
                            .getBean(FrameworkExecutorRepository.class);
                    frameworkExecutorRepository
                            .nextScheduledExecutor()
                            .schedule(
                                    () -> ServiceInstanceMetadataUtils.refreshMetadataAndInstance(applicationModel),
                                    delay,
                                    TimeUnit.SECONDS);
                } catch (NumberFormatException e) {
                    logger.error(CONFIG_PARAMETER_FORMAT_ERROR, "", "", "Wrong delay param", e);
                    return "publishMetadata failed! Wrong delay param!";
                }
                stringBuilder
                        .append("publish task submitted, will publish in ")
                        .append(args[0])
                        .append(" seconds. App:")
                        .append(applicationModel.getApplicationName())
                        .append("\n");
            }
        }
        return stringBuilder.toString();
    }
@Test
    void testExecute() {
        PublishMetadata publishMetadata = new PublishMetadata(frameworkModel);

        String result = publishMetadata.execute(Mockito.mock(CommandContext.class), new String[0]);
        String expectResult = "publish metadata succeeded. App:APP_0\n" + "publish metadata succeeded. App:APP_1\n"
                + "publish metadata succeeded. App:APP_2\n";
        Assertions.assertEquals(result, expectResult);

        // delay 5s
        result = publishMetadata.execute(Mockito.mock(CommandContext.class), new String[] {"5"});
        expectResult = "publish task submitted, will publish in 5 seconds. App:APP_0\n"
                + "publish task submitted, will publish in 5 seconds. App:APP_1\n"
                + "publish task submitted, will publish in 5 seconds. App:APP_2\n";
        Assertions.assertEquals(result, expectResult);

        // wrong delay param
        result = publishMetadata.execute(Mockito.mock(CommandContext.class), new String[] {"A"});
        expectResult = "publishMetadata failed! Wrong delay param!";
        Assertions.assertEquals(result, expectResult);
    }