Add statistics for nacos discovery and test case

pull/372/head
xiaolongzuo 6 years ago
parent 2cfabd353a
commit 03bd2c3c1d

@ -15,14 +15,15 @@
*/
package org.springframework.cloud.alicloud.context.nacos;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicationListener;
import java.util.Properties;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
/**
* @author pbting
@ -53,7 +54,7 @@ public class NacosDiscoveryParameterInitListener
}
// initialize nacos configuration
Properties properties = System.getProperties();
properties.setProperty("spring.cloud.nacos.discovery.server-mode", "EDAS");
// step 1: set some properties for spring cloud alibaba nacos discovery
properties.setProperty("spring.cloud.nacos.discovery.server-addr", "");
properties.setProperty("spring.cloud.nacos.discovery.endpoint",

@ -48,7 +48,9 @@ public class StatisticsTaskStarter implements InitializingBean {
private static final String NACOS_CONFIG_SERVER_MODE_KEY = "spring.cloud.nacos.config.server-mode";
private static final String NACOS_CONFIG_SERVER_MODE_VALUE = "EDAS";
private static final String NACOS_DISCOVERY_SERVER_MODE_KEY = "spring.cloud.nacos.discovery.server-mode";
private static final String NACOS_SERVER_MODE_VALUE = "EDAS";
@Autowired(required = false)
private AliCloudEdasSdk aliCloudEdasSdk;
@ -106,10 +108,14 @@ public class StatisticsTaskStarter implements InitializingBean {
if (acmContextBootstrapConfiguration != null && acmEnableEdas) {
components.add("SC-ACM");
}
if (NACOS_CONFIG_SERVER_MODE_VALUE
if (NACOS_SERVER_MODE_VALUE
.equals(System.getProperty(NACOS_CONFIG_SERVER_MODE_KEY))) {
components.add("SC-NACOS-CONFIG");
}
if (NACOS_SERVER_MODE_VALUE
.equals(System.getProperty(NACOS_DISCOVERY_SERVER_MODE_KEY))) {
components.add("SC-NACOS-DISCOVERY");
}
return components;
}

@ -0,0 +1,23 @@
/*
* Copyright (C) 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.alibaba.nacos;
/**
* @author xiaolongzuo
*/
public class NacosDiscoveryAutoConfiguration {
}

@ -16,43 +16,46 @@
package org.springframework.cloud.alicloud.context.nacos;
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import org.junit.BeforeClass;
import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication;
import org.springframework.cloud.alicloud.utils.ChangeOrderUtils;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
/**
* @author xiaolongzuo
*/
@PrepareForTest({EdasChangeOrderConfigurationFactory.class,
NacosConfigParameterInitListener.class, AliCloudAnsInitializer.class})
public class NacosDiscoveryParameterInitListenerTests extends BaseAliCloudSpringApplication {
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
NacosDiscoveryParameterInitListener.class, AliCloudAnsInitializer.class })
public class NacosDiscoveryParameterInitListenerTests
extends BaseAliCloudSpringApplication {
@BeforeClass
public static void setUp() {
ChangeOrderUtils.mockChangeOrder();
System.getProperties().setProperty("webContext", "/vipserver");
System.getProperties().setProperty("serverPort", "80");
}
@Test
public void testNacosParameterInitListener() {
assertThat(System.getProperty("spring.cloud.nacos.config.server-addr"))
assertThat(System.getProperty("spring.cloud.nacos.discovery.server-mode"))
.isEqualTo("EDAS");
assertThat(System.getProperty("spring.cloud.nacos.discovery.server-addr"))
.isEqualTo("");
assertThat(System.getProperty("spring.cloud.nacos.config.endpoint"))
assertThat(System.getProperty("spring.cloud.nacos.discovery.endpoint"))
.isEqualTo("testDomain");
assertThat(System.getProperty("spring.cloud.nacos.config.namespace"))
assertThat(System.getProperty("spring.cloud.nacos.discovery.namespace"))
.isEqualTo("testTenantId");
assertThat(System.getProperty("spring.cloud.nacos.config.access-key"))
assertThat(System.getProperty("spring.cloud.nacos.discovery.access-key"))
.isEqualTo("testAK");
assertThat(System.getProperty("spring.cloud.nacos.config.secret-key"))
assertThat(System.getProperty("spring.cloud.nacos.discovery.secret-key"))
.isEqualTo("testSK");
assertThat(System.getProperties().getProperty("webContext")).isEqualTo("/vipserver");
assertThat(System.getProperties().getProperty("webContext"))
.isEqualTo("/vipserver");
assertThat(System.getProperties().getProperty("serverPort")).isEqualTo("80");
}
}

Loading…
Cancel
Save