Topology build(List<Call.CallDetail> serviceRelationClientCalls, List<Call.CallDetail> serviceRelationServerCalls) {

        Map<String, Node> nodes = new HashMap<>();
        List<Call> calls = new LinkedList<>();
        HashMap<String, Call> callMap = new HashMap<>();

        for (Call.CallDetail clientCall : serviceRelationClientCalls) {
            final IDManager.ServiceID.ServiceIDDefinition sourceService = IDManager.ServiceID.analysisId(
                clientCall.getSource());
            String sourceServiceId = clientCall.getSource();
            IDManager.ServiceID.ServiceIDDefinition destService = IDManager.ServiceID.analysisId(
                clientCall.getTarget());
            String targetServiceId = clientCall.getTarget();

            /*
             * Use the alias name to make topology relationship accurate.
             */
            if (networkAddressAliasCache.get(destService.getName()) != null) {
                /*
                 * If alias exists, mean this network address is representing a real service.
                 */
                final NetworkAddressAlias networkAddressAlias = networkAddressAliasCache.get(destService.getName());
                destService = IDManager.ServiceID.analysisId(
                    networkAddressAlias.getRepresentServiceId());
                targetServiceId = IDManager.ServiceID.buildId(destService.getName(), true);
            }

            /*
             * Set the conjectural node type.
             */
            if (!nodes.containsKey(targetServiceId)) {
                final Node conjecturalNode = buildNode(targetServiceId, destService);
                nodes.put(targetServiceId, conjecturalNode);
                if (!conjecturalNode.isReal() && StringUtil.isEmpty(conjecturalNode.getType())) {
                    conjecturalNode.setType(
                        componentLibraryCatalogService.getServerNameBasedOnComponent(clientCall.getComponentId()));
                }
            }

            if (!nodes.containsKey(sourceServiceId)) {
                nodes.put(sourceServiceId, buildNode(sourceServiceId, sourceService));
            }

            final String relationId = IDManager.ServiceID.buildRelationId(
                new IDManager.ServiceID.ServiceRelationDefine(sourceServiceId, targetServiceId));

            if (!callMap.containsKey(relationId)) {
                Call call = new Call();

                callMap.put(relationId, call);
                call.setSource(sourceServiceId);
                call.setTarget(targetServiceId);
                call.setId(relationId);
                call.addDetectPoint(DetectPoint.CLIENT);
                call.addSourceComponent(componentLibraryCatalogService.getComponentName(clientCall.getComponentId()));
                calls.add(call);
            } else {
                Call call = callMap.get(relationId);
                call.addSourceComponent(componentLibraryCatalogService.getComponentName(clientCall.getComponentId()));
            }
        }

        for (Call.CallDetail serverCall : serviceRelationServerCalls) {
            final IDManager.ServiceID.ServiceIDDefinition sourceService = IDManager.ServiceID.analysisId(
                serverCall.getSource());
            IDManager.ServiceID.ServiceIDDefinition destService = IDManager.ServiceID.analysisId(
                serverCall.getTarget());

            /*
             * Create the client node if it hasn't been created in client side call.
             */
            Node clientSideNode = nodes.get(serverCall.getSource());
            if (clientSideNode == null) {
                clientSideNode = buildNode(serverCall.getSource(), sourceService);
                nodes.put(serverCall.getSource(), clientSideNode);
            }
            /*
             * conjectural node type.
             */
            if (!clientSideNode.isReal()) {
                clientSideNode.setType(
                    componentLibraryCatalogService.getServerNameBasedOnComponent(serverCall.getComponentId()));
            }
            /*
             * Format the User name type.
             */
            if (userID.equals(serverCall.getSource())) {
                nodes.get(userID).setType(Const.USER_SERVICE_NAME.toUpperCase());
            }
            /*
             * Create the server node if it hasn't been created.
             */
            if (!nodes.containsKey(serverCall.getTarget())) {
                final Node node = buildNode(serverCall.getTarget(), destService);
                nodes.put(serverCall.getTarget(), node);
            }
            /*
             * Set the node type due to service side component id has higher priority
             */
            final Node serverSideNode = nodes.get(serverCall.getTarget());
            final String nodeType = serverSideNode.getType();
            if (nodeType == null || !serverSideNode.hasSetOnceAtServerSide()) {
                serverSideNode.setTypeFromServerSide(
                    componentLibraryCatalogService.getComponentName(serverCall.getComponentId()));
            } else {
                final Integer componentId = componentLibraryCatalogService.getComponentId(nodeType);
                if (componentId != null) {
                    if (componentLibraryCatalogService.compare(componentId, serverCall.getComponentId())) {
                        serverSideNode.setTypeFromServerSide(
                            componentLibraryCatalogService.getComponentName(serverCall.getComponentId()));
                    } else {
                        //Do nothing, as the current value has higher priority
                    }
                } else {
                    serverSideNode.setTypeFromServerSide(
                        componentLibraryCatalogService.getComponentName(serverCall.getComponentId()));
                }
            }

            if (!callMap.containsKey(serverCall.getId())) {
                Call call = new Call();
                callMap.put(serverCall.getId(), call);
                call.setSource(serverCall.getSource());
                call.setTarget(serverCall.getTarget());
                call.setId(serverCall.getId());
                call.addDetectPoint(DetectPoint.SERVER);
                call.addTargetComponent(componentLibraryCatalogService.getComponentName(serverCall.getComponentId()));
                calls.add(call);
            } else {
                Call call = callMap.get(serverCall.getId());
                call.addDetectPoint(DetectPoint.SERVER);
                call.addTargetComponent(componentLibraryCatalogService.getComponentName(serverCall.getComponentId()));
            }
        }

        Topology topology = new Topology();
        topology.getCalls().addAll(calls);
        topology.getNodes().addAll(nodes.values());
        return topology;
    }
@SneakyThrows
    @Test
    public void testServiceTopologyBuild() {
        Service svrA = getSvrA();
        Service svrB = getSvrB();
        final ServiceTopologyBuilder serviceTopologyBuilder = new ServiceTopologyBuilder(moduleManager);
        Whitebox.setInternalState(serviceTopologyBuilder, "metadataQueryService", metadataQueryService);
        when(metadataQueryService.getService(svrA.getId())).thenReturn(svrA);
        when(metadataQueryService.getService(svrB.getId())).thenReturn(svrB);
        List<Call.CallDetail> serviceRelationClientCalls = new ArrayList<>();
        Call.CallDetail call1 = new Call.CallDetail();
        call1.buildFromServiceRelation(
            IDManager.ServiceID.buildRelationId(
                new IDManager.ServiceID.ServiceRelationDefine(
                    IDManager.ServiceID.buildId(svrA.getName(), true),
                    IDManager.ServiceID.buildId(svrB.getName(), true)
                )
            ),
            // mtls
            142,
            DetectPoint.CLIENT
        );
        serviceRelationClientCalls.add(call1);
        Call.CallDetail call2 = new Call.CallDetail();
        call2.buildFromServiceRelation(
            IDManager.ServiceID.buildRelationId(
                new IDManager.ServiceID.ServiceRelationDefine(
                    IDManager.ServiceID.buildId(svrA.getName(), true),
                    IDManager.ServiceID.buildId(svrB.getName(), true)
                )
            ),
            // http
            49,
            DetectPoint.CLIENT
        );
        serviceRelationClientCalls.add(call2);

        List<Call.CallDetail> serviceRelationServerCalls = new ArrayList<>();
        Call.CallDetail call3 = new Call.CallDetail();
        call3.buildFromServiceRelation(
            IDManager.ServiceID.buildRelationId(
                new IDManager.ServiceID.ServiceRelationDefine(
                    IDManager.ServiceID.buildId(svrA.getName(), true),
                    IDManager.ServiceID.buildId(svrB.getName(), true)
                )
            ),
            // mtls
            142,
            DetectPoint.SERVER
        );
        serviceRelationServerCalls.add(call3);
        Call.CallDetail call4 = new Call.CallDetail();
        call4.buildFromServiceRelation(
            IDManager.ServiceID.buildRelationId(
                new IDManager.ServiceID.ServiceRelationDefine(
                    IDManager.ServiceID.buildId(svrA.getName(), true),
                    IDManager.ServiceID.buildId(svrB.getName(), true)
                )
            ),
            // http
            49,
            DetectPoint.SERVER
        );
        serviceRelationServerCalls.add(call4);
        final Topology topology = serviceTopologyBuilder.build(serviceRelationClientCalls, serviceRelationServerCalls);
        Assertions.assertEquals(2, topology.getNodes().size());
        for (final Node node : topology.getNodes()) {
            if (node.getName().equals("SvrB")) {
                Assertions.assertEquals("http", node.getType());
                Assertions.assertEquals(Set.of(Layer.MESH.name(), Layer.MESH_DP.name()), node.getLayers());
            } else if (node.getName().equals("SvrA")) {
                Assertions.assertEquals(null, node.getType());
                Assertions.assertEquals(Set.of(Layer.GENERAL.name()), node.getLayers());
            }
        }
        for (final Call call : topology.getCalls()) {
            Assertions.assertEquals(2, call.getSourceComponents().size());
            Assertions.assertEquals(List.of("mtls", "http"), call.getTargetComponents());
        }
    }