protected CertPair refreshCert() throws IOException {
        KeyPair keyPair = signWithEcdsa();

        if (keyPair == null) {
            keyPair = signWithRsa();
        }

        if (keyPair == null) {
            logger.error(
                    CONFIG_SSL_CERT_GENERATE_FAILED,
                    "",
                    "",
                    "Generate Key failed. Please check if your system support.");
            return null;
        }

        String csr = generateCsr(keyPair);
        DubboCertificateServiceGrpc.DubboCertificateServiceBlockingStub stub =
                DubboCertificateServiceGrpc.newBlockingStub(channel);
        stub = setHeaderIfNeed(stub);

        String privateKeyPem = generatePrivatePemKey(keyPair);
        DubboCertificateResponse certificateResponse = stub.createCertificate(generateRequest(csr));

        if (certificateResponse == null || !certificateResponse.getSuccess()) {
            logger.error(
                    CONFIG_SSL_CERT_GENERATE_FAILED,
                    "",
                    "",
                    "Failed to generate cert from Dubbo Certificate Authority. " + "Message: "
                            + (certificateResponse == null ? "null" : certificateResponse.getMessage()));
            return null;
        }
        logger.info("Successfully generate cert from Dubbo Certificate Authority. Cert expire time: "
                + certificateResponse.getExpireTime());

        return new CertPair(
                privateKeyPem,
                certificateResponse.getCertPem(),
                String.join("\n", certificateResponse.getTrustCertsList()),
                certificateResponse.getExpireTime());
    }
@Test
    void testRefreshCert() throws IOException {
        try (MockedStatic<DubboCertManager> managerMock =
                Mockito.mockStatic(DubboCertManager.class, CALLS_REAL_METHODS)) {
            FrameworkModel frameworkModel = new FrameworkModel();
            DubboCertManager certManager = new DubboCertManager(frameworkModel);
            managerMock.when(DubboCertManager::signWithEcdsa).thenReturn(null);
            managerMock.when(DubboCertManager::signWithRsa).thenReturn(null);

            Assertions.assertNull(certManager.refreshCert());

            managerMock.when(DubboCertManager::signWithEcdsa).thenCallRealMethod();

            certManager.channel = Mockito.mock(Channel.class);
            try (MockedStatic<DubboCertificateServiceGrpc> mockGrpc =
                    Mockito.mockStatic(DubboCertificateServiceGrpc.class, CALLS_REAL_METHODS)) {
                DubboCertificateServiceGrpc.DubboCertificateServiceBlockingStub stub =
                        Mockito.mock(DubboCertificateServiceGrpc.DubboCertificateServiceBlockingStub.class);
                mockGrpc.when(() -> DubboCertificateServiceGrpc.newBlockingStub(Mockito.any(Channel.class)))
                        .thenReturn(stub);
                Mockito.when(stub.createCertificate(Mockito.any()))
                        .thenReturn(DubboCertificateResponse.newBuilder()
                                .setSuccess(false)
                                .build());

                certManager.certConfig = new CertConfig(null, null, null, null);
                Assertions.assertNull(certManager.refreshCert());

                String file = this.getClass()
                        .getClassLoader()
                        .getResource("certs/token")
                        .getFile();
                Mockito.when(stub.withInterceptors(Mockito.any())).thenReturn(stub);
                certManager.certConfig = new CertConfig(null, null, null, file);

                Assertions.assertNull(certManager.refreshCert());
                Mockito.verify(stub, Mockito.times(1)).withInterceptors(Mockito.any());

                Mockito.when(stub.createCertificate(Mockito.any()))
                        .thenReturn(DubboCertificateResponse.newBuilder()
                                .setSuccess(true)
                                .setCertPem("certPem")
                                .addTrustCerts("trustCerts")
                                .setExpireTime(123456)
                                .build());
                CertPair certPair = certManager.refreshCert();
                Assertions.assertNotNull(certPair);
                Assertions.assertEquals("certPem", certPair.getCertificate());
                Assertions.assertEquals("trustCerts", certPair.getTrustCerts());
                Assertions.assertEquals(123456, certPair.getExpireTime());

                Mockito.when(stub.createCertificate(Mockito.any())).thenReturn(null);
                Assertions.assertNull(certManager.refreshCert());
            }

            frameworkModel.destroy();
        }
    }