Search in sources :

Example 1 with GlobalConfig

use of com.tencent.polaris.api.config.global.GlobalConfig in project spring-cloud-tencent by Tencent.

the class PolarisRegistrationTest method setUp.

@Before
public void setUp() {
    // mock DiscoveryPropertiesAutoConfiguration
    DiscoveryPropertiesAutoConfiguration discoveryPropertiesAutoConfiguration = mock(DiscoveryPropertiesAutoConfiguration.class);
    doReturn(true).when(discoveryPropertiesAutoConfiguration).isRegisterEnabled();
    // mock PolarisDiscoveryProperties
    PolarisDiscoveryProperties polarisDiscoveryProperties = mock(PolarisDiscoveryProperties.class);
    doReturn(SERVICE_PROVIDER).when(polarisDiscoveryProperties).getService();
    doReturn(PORT).when(polarisDiscoveryProperties).getPort();
    doReturn("http").when(polarisDiscoveryProperties).getProtocol();
    // mock SDKContext
    APIConfig apiConfig = mock(APIConfig.class);
    doReturn(HOST).when(apiConfig).getBindIP();
    GlobalConfig globalConfig = mock(GlobalConfig.class);
    doReturn(apiConfig).when(globalConfig).getAPI();
    Configuration configuration = mock(Configuration.class);
    doReturn(globalConfig).when(configuration).getGlobal();
    SDKContext polarisContext = mock(SDKContext.class);
    doReturn(configuration).when(polarisContext).getConfig();
    // mock StaticMetadataManager
    StaticMetadataManager staticMetadataManager = mock(StaticMetadataManager.class);
    doReturn(Collections.singletonMap("key1", "value1")).when(staticMetadataManager).getMergedStaticMetadata();
    doReturn(Collections.singletonMap("key2", "value2")).when(staticMetadataManager).getLocationMetadata();
    polarisRegistration = new PolarisRegistration(discoveryPropertiesAutoConfiguration, polarisDiscoveryProperties, polarisContext, staticMetadataManager);
}
Also used : SDKContext(com.tencent.polaris.client.api.SDKContext) DiscoveryPropertiesAutoConfiguration(com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration) Configuration(com.tencent.polaris.api.config.Configuration) PolarisDiscoveryProperties(com.tencent.cloud.polaris.PolarisDiscoveryProperties) APIConfig(com.tencent.polaris.api.config.global.APIConfig) GlobalConfig(com.tencent.polaris.api.config.global.GlobalConfig) StaticMetadataManager(com.tencent.cloud.common.metadata.StaticMetadataManager) DiscoveryPropertiesAutoConfiguration(com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration) Before(org.junit.Before)

Example 2 with GlobalConfig

use of com.tencent.polaris.api.config.global.GlobalConfig in project polaris-java by polarismesh.

the class GlobalConfigImpl method setDefault.

@Override
public void setDefault(Object defaultObject) {
    if (null == system) {
        system = new SystemConfigImpl();
    }
    if (null == api) {
        api = new APIConfigImpl();
    }
    if (CollectionUtils.isEmpty(serverConnectors) && null == serverConnector) {
        serverConnector = new ServerConnectorConfigImpl();
    }
    if (null == statReporter) {
        statReporter = new StatReporterConfigImpl();
    }
    if (null != defaultObject) {
        GlobalConfig globalConfig = (GlobalConfig) defaultObject;
        system.setDefault(globalConfig.getSystem());
        api.setDefault(globalConfig.getAPI());
        // Only grpc server connector should be set default.
        if (CollectionUtils.isNotEmpty(serverConnectors)) {
            for (ServerConnectorConfigImpl serverConnectorConfig : serverConnectors) {
                if (DefaultPlugins.SERVER_CONNECTOR_GRPC.equals(serverConnectorConfig.getProtocol())) {
                    serverConnectorConfig.setDefault(globalConfig.getServerConnector());
                    serverConnector = serverConnectorConfig;
                }
            }
        } else {
            serverConnector.setDefault(globalConfig.getServerConnector());
        }
        statReporter.setDefault(globalConfig.getStatReporter());
    }
}
Also used : GlobalConfig(com.tencent.polaris.api.config.global.GlobalConfig)

Aggregations

GlobalConfig (com.tencent.polaris.api.config.global.GlobalConfig)2 StaticMetadataManager (com.tencent.cloud.common.metadata.StaticMetadataManager)1 DiscoveryPropertiesAutoConfiguration (com.tencent.cloud.polaris.DiscoveryPropertiesAutoConfiguration)1 PolarisDiscoveryProperties (com.tencent.cloud.polaris.PolarisDiscoveryProperties)1 Configuration (com.tencent.polaris.api.config.Configuration)1 APIConfig (com.tencent.polaris.api.config.global.APIConfig)1 SDKContext (com.tencent.polaris.client.api.SDKContext)1 Before (org.junit.Before)1