@Override
    public CompletableFuture<RemotingCommand> electMaster(final ElectMasterRequestHeader request) {
        return this.scheduler.appendEvent("electMaster",
            () -> {
                ControllerResult<ElectMasterResponseHeader> electResult = this.replicasInfoManager.electMaster(request, this.electPolicy);
                AttributesBuilder attributesBuilder = ControllerMetricsManager.newAttributesBuilder()
                    .put(LABEL_CLUSTER_NAME, request.getClusterName())
                    .put(LABEL_BROKER_SET, request.getBrokerName());
                switch (electResult.getResponseCode()) {
                    case ResponseCode.SUCCESS:
                        ControllerMetricsManager.electionTotal.add(1,
                            attributesBuilder.put(LABEL_ELECTION_RESULT, ControllerMetricsConstant.ElectionResult.NEW_MASTER_ELECTED.getLowerCaseName()).build());
                        break;
                    case ResponseCode.CONTROLLER_MASTER_STILL_EXIST:
                        ControllerMetricsManager.electionTotal.add(1,
                            attributesBuilder.put(LABEL_ELECTION_RESULT, ControllerMetricsConstant.ElectionResult.KEEP_CURRENT_MASTER.getLowerCaseName()).build());
                        break;
                    case ResponseCode.CONTROLLER_MASTER_NOT_AVAILABLE:
                    case ResponseCode.CONTROLLER_ELECT_MASTER_FAILED:
                        ControllerMetricsManager.electionTotal.add(1,
                            attributesBuilder.put(LABEL_ELECTION_RESULT, ControllerMetricsConstant.ElectionResult.NO_MASTER_ELECTED.getLowerCaseName()).build());
                        break;
                    default:
                        break;
                }
                return electResult;
            }, true);
    }
@Test
    public void testElectMaster() throws Exception {
        final DLedgerController leader = mockMetaData(false);
        final ElectMasterRequestHeader request = ElectMasterRequestHeader.ofControllerTrigger(DEFAULT_BROKER_NAME);
        setBrokerElectPolicy(leader, 1L);
        final RemotingCommand resp = leader.electMaster(request).get(10, TimeUnit.SECONDS);
        final ElectMasterResponseHeader response = (ElectMasterResponseHeader) resp.readCustomHeader();
        assertEquals(2, response.getMasterEpoch().intValue());
        assertNotEquals(1L, response.getMasterBrokerId().longValue());
        assertNotEquals(DEFAULT_IP[0], response.getMasterAddress());
    }