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);
}
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());
}
}
Aggregations