Merge remote-tracking branch 'upstream/master'
commit
0b31eccbf0
@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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.discovery;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
|
import com.alibaba.nacos.api.naming.listener.EventListener;
|
||||||
|
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
|
||||||
|
import org.springframework.cloud.client.discovery.event.HeartbeatEvent;
|
||||||
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.context.ApplicationEventPublisherAware;
|
||||||
|
import org.springframework.context.SmartLifecycle;
|
||||||
|
import org.springframework.scheduling.TaskScheduler;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaojing
|
||||||
|
*/
|
||||||
|
public class NacosWatch implements ApplicationEventPublisherAware, SmartLifecycle {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(NacosWatch.class);
|
||||||
|
|
||||||
|
private final NacosDiscoveryProperties properties;
|
||||||
|
|
||||||
|
private final TaskScheduler taskScheduler;
|
||||||
|
|
||||||
|
private final AtomicLong nacosWatchIndex = new AtomicLong(0);
|
||||||
|
|
||||||
|
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
private ApplicationEventPublisher publisher;
|
||||||
|
|
||||||
|
private ScheduledFuture<?> watchFuture;
|
||||||
|
|
||||||
|
private Set<String> cacheServices = new HashSet<>();
|
||||||
|
|
||||||
|
private HashMap<String, EventListener> subscribeListeners = new HashMap<>();
|
||||||
|
|
||||||
|
public NacosWatch(NacosDiscoveryProperties properties) {
|
||||||
|
this(properties, getTaskScheduler());
|
||||||
|
}
|
||||||
|
|
||||||
|
public NacosWatch(NacosDiscoveryProperties properties, TaskScheduler taskScheduler) {
|
||||||
|
this.properties = properties;
|
||||||
|
this.taskScheduler = taskScheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ThreadPoolTaskScheduler getTaskScheduler() {
|
||||||
|
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||||
|
taskScheduler.initialize();
|
||||||
|
return taskScheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
|
||||||
|
this.publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAutoStartup() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop(Runnable callback) {
|
||||||
|
this.stop();
|
||||||
|
callback.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
if (this.running.compareAndSet(false, true)) {
|
||||||
|
this.watchFuture = this.taskScheduler.scheduleWithFixedDelay(
|
||||||
|
this::nacosServicesWatch, this.properties.getWatchDelay());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
if (this.running.compareAndSet(true, false) && this.watchFuture != null) {
|
||||||
|
this.watchFuture.cancel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRunning() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPhase() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nacosServicesWatch() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
boolean changed = false;
|
||||||
|
NamingService namingService = properties.namingServiceInstance();
|
||||||
|
|
||||||
|
ListView<String> listView = properties.namingServiceInstance()
|
||||||
|
.getServicesOfServer(1, Integer.MAX_VALUE);
|
||||||
|
|
||||||
|
List<String> serviceList = listView.getData();
|
||||||
|
|
||||||
|
// if there are new services found, publish event
|
||||||
|
Set<String> currentServices = new HashSet<>(serviceList);
|
||||||
|
currentServices.removeAll(cacheServices);
|
||||||
|
if (currentServices.size() > 0) {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if some services disappear, publish event
|
||||||
|
if (cacheServices.removeAll(new HashSet<>(serviceList))
|
||||||
|
&& cacheServices.size() > 0) {
|
||||||
|
changed = true;
|
||||||
|
|
||||||
|
for (String serviceName : cacheServices) {
|
||||||
|
namingService.unsubscribe(serviceName,
|
||||||
|
subscribeListeners.get(serviceName));
|
||||||
|
subscribeListeners.remove(serviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cacheServices = new HashSet<>(serviceList);
|
||||||
|
|
||||||
|
// subscribe services's node change, publish event if nodes changed
|
||||||
|
for (String serviceName : cacheServices) {
|
||||||
|
if (!subscribeListeners.containsKey(serviceName)) {
|
||||||
|
EventListener eventListener = event -> NacosWatch.this.publisher
|
||||||
|
.publishEvent(new HeartbeatEvent(NacosWatch.this,
|
||||||
|
nacosWatchIndex.getAndIncrement()));
|
||||||
|
subscribeListeners.put(serviceName, eventListener);
|
||||||
|
namingService.subscribe(serviceName, eventListener);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
this.publisher.publishEvent(
|
||||||
|
new HeartbeatEvent(this, nacosWatchIndex.getAndIncrement()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
log.error("Error watching Nacos Service change", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,107 +0,0 @@
|
|||||||
package org.springframework.cloud.alicloud.context.sms;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author pbting
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(prefix = "spring.cloud.alicloud.sms")
|
|
||||||
public class SmsConfigProperties implements Serializable {
|
|
||||||
|
|
||||||
// 产品名称:云通信短信API产品,开发者无需替换
|
|
||||||
public static final String smsProduct = "Dysmsapi";
|
|
||||||
// 产品域名,开发者无需替换
|
|
||||||
public static final String smsDomain = "dysmsapi.aliyuncs.com";
|
|
||||||
|
|
||||||
private AliCloudProperties aliCloudProperties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private String reportQueueName;
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private String upQueueName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected String connnectTimeout = "10000";
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
protected String readTimeout = "10000";
|
|
||||||
|
|
||||||
public SmsConfigProperties(AliCloudProperties aliCloudProperties) {
|
|
||||||
this.aliCloudProperties = aliCloudProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getConnnectTimeout() {
|
|
||||||
return connnectTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnnectTimeout(String connnectTimeout) {
|
|
||||||
this.connnectTimeout = connnectTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReadTimeout() {
|
|
||||||
return readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReadTimeout(String readTimeout) {
|
|
||||||
this.readTimeout = readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void overiideFromEnv(Environment environment) {
|
|
||||||
overiideCustomFromEnv(environment);
|
|
||||||
if (StringUtils.isEmpty(connnectTimeout)) {
|
|
||||||
String resolveResult = environment.resolveRequiredPlaceholders(
|
|
||||||
"${spring.cloud.alibaba.sms.connect-timeout:}");
|
|
||||||
this.setConnnectTimeout(
|
|
||||||
StringUtils.isEmpty(resolveResult) ? "10000" : resolveResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(readTimeout)) {
|
|
||||||
String resolveResult = environment.resolveRequiredPlaceholders(
|
|
||||||
"${spring.cloud.alibaba.sms.read-timeout:}");
|
|
||||||
this.setReadTimeout(
|
|
||||||
StringUtils.isEmpty(resolveResult) ? "10000" : resolveResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void overiideCustomFromEnv(Environment environment) {
|
|
||||||
// nothing to do
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReportQueueName() {
|
|
||||||
return reportQueueName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReportQueueName(String reportQueueName) {
|
|
||||||
this.reportQueueName = reportQueueName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUpQueueName() {
|
|
||||||
return upQueueName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccessKeyId() {
|
|
||||||
return aliCloudProperties.getAccessKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccessKeySecret() {
|
|
||||||
return aliCloudProperties.getSecretKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpQueueName(String upQueueName) {
|
|
||||||
this.upQueueName = upQueueName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
package org.springframework.cloud.alicloud.context.sms;
|
|
||||||
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author pbting
|
|
||||||
*/
|
|
||||||
public class SmsConfigRegistration {
|
|
||||||
|
|
||||||
private Environment environment;
|
|
||||||
|
|
||||||
private SmsConfigProperties smsConfigProperties;
|
|
||||||
|
|
||||||
public SmsConfigRegistration(Environment environment,
|
|
||||||
SmsConfigProperties smsConfigProperties) {
|
|
||||||
this.environment = environment;
|
|
||||||
this.smsConfigProperties = smsConfigProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void initSmsConfigRegistration() {
|
|
||||||
smsConfigProperties.overiideFromEnv(environment);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,74 @@
|
|||||||
|
package org.springframework.cloud.alicloud.context.sms;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author pbting
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
@ConfigurationProperties(prefix = "spring.cloud.alicloud.sms")
|
||||||
|
public class SmsProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product name.
|
||||||
|
*/
|
||||||
|
public static final String smsProduct = "Dysmsapi";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Product domain.
|
||||||
|
*/
|
||||||
|
public static final String smsDomain = "dysmsapi.aliyuncs.com";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report queue name.
|
||||||
|
*/
|
||||||
|
private String reportQueueName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Up queue name.
|
||||||
|
*/
|
||||||
|
private String upQueueName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect timeout.
|
||||||
|
*/
|
||||||
|
private String connectTimeout = "10000";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read timeout.
|
||||||
|
*/
|
||||||
|
private String readTimeout = "10000";
|
||||||
|
|
||||||
|
public String getConnectTimeout() {
|
||||||
|
return connectTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectTimeout(String connectTimeout) {
|
||||||
|
this.connectTimeout = connectTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReadTimeout() {
|
||||||
|
return readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadTimeout(String readTimeout) {
|
||||||
|
this.readTimeout = readTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReportQueueName() {
|
||||||
|
return reportQueueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReportQueueName(String reportQueueName) {
|
||||||
|
this.reportQueueName = reportQueueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUpQueueName() {
|
||||||
|
return upQueueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpQueueName(String upQueueName) {
|
||||||
|
this.upQueueName = upQueueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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 com.alibaba.csp.sentinel.datasource.nacos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
public class NacosDataSource {
|
||||||
|
}
|
@ -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 com.aliyuncs.dysmsapi.model.v20170525;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
public class SendSmsRequest {
|
||||||
|
}
|
@ -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 NacosConfigAutoConfiguration {
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.alicloud.context.ans;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
public class AnsContextApplicationListenerTests extends BaseAliCloudSpringApplication {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAnsContextApplicationListenerDefault() {
|
||||||
|
assertThat(System
|
||||||
|
.getProperty("com.alibaba.ans.shaded.com.taobao.vipserver.serverlist"))
|
||||||
|
.isEqualTo("192.168.1.100");
|
||||||
|
assertThat(System.getProperty("vipserver.server.port")).isEqualTo("8888");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* 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.alicloud.context.nacos;
|
||||||
|
|
||||||
|
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 com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
|
||||||
|
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
|
||||||
|
NacosParameterInitListener.class, AliCloudAnsInitializer.class })
|
||||||
|
public class NacosParameterInitListenerTests extends BaseAliCloudSpringApplication {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp() {
|
||||||
|
ChangeOrderUtils.mockChangeOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNacosParameterInitListener() {
|
||||||
|
assertThat(System.getProperty("spring.cloud.nacos.config.server-mode"))
|
||||||
|
.isEqualTo("EDAS");
|
||||||
|
assertThat(System.getProperty("spring.cloud.nacos.config.server-addr"))
|
||||||
|
.isEqualTo("");
|
||||||
|
assertThat(System.getProperty("spring.cloud.nacos.config.endpoint"))
|
||||||
|
.isEqualTo("testDomain");
|
||||||
|
assertThat(System.getProperty("spring.cloud.nacos.config.namespace"))
|
||||||
|
.isEqualTo("testTenantId");
|
||||||
|
assertThat(System.getProperty("spring.cloud.nacos.config.access-key"))
|
||||||
|
.isEqualTo("testAK");
|
||||||
|
assertThat(System.getProperty("spring.cloud.nacos.config.secret-key"))
|
||||||
|
.isEqualTo("testSK");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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.alicloud.context.sentinel;
|
||||||
|
|
||||||
|
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.context.Constants;
|
||||||
|
import org.springframework.cloud.alicloud.utils.ChangeOrderUtils;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
|
||||||
|
SentinelAliCloudListener.class })
|
||||||
|
public class SentinelAliCloudListenerTests extends BaseAliCloudSpringApplication {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUp() {
|
||||||
|
ChangeOrderUtils.mockChangeOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNacosParameterInitListener() {
|
||||||
|
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_ENDPOINT))
|
||||||
|
.isEqualTo("testDomain");
|
||||||
|
assertThat(System.getProperty(Constants.Sentinel.PROJECT_NAME))
|
||||||
|
.isEqualTo("testProjectName");
|
||||||
|
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_NAMESPACE))
|
||||||
|
.isEqualTo("testTenantId");
|
||||||
|
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_AK))
|
||||||
|
.isEqualTo("testAK");
|
||||||
|
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_SK))
|
||||||
|
.isEqualTo("testSK");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* 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.alicloud.context.sms;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||||
|
|
||||||
|
import org.assertj.core.api.AssertionsForClassTypes;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration;
|
||||||
|
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
public class SmsPropertiesTests {
|
||||||
|
|
||||||
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||||
|
.withConfiguration(AutoConfigurations.of(SmsContextAutoConfiguration.class,
|
||||||
|
EdasContextAutoConfiguration.class,
|
||||||
|
AliCloudContextAutoConfiguration.class));
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigurationValueDefaultsAreAsExpected() {
|
||||||
|
this.contextRunner.run(context -> {
|
||||||
|
SmsProperties config = context.getBean(SmsProperties.class);
|
||||||
|
assertThat(config.getReportQueueName()).isNull();
|
||||||
|
assertThat(config.getUpQueueName()).isNull();
|
||||||
|
assertThat(config.getConnectTimeout()).isEqualTo("10000");
|
||||||
|
assertThat(config.getReadTimeout()).isEqualTo("10000");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigurationValuesAreCorrectlyLoaded() {
|
||||||
|
this.contextRunner
|
||||||
|
.withPropertyValues("spring.cloud.alicloud.sms.reportQueueName=q1",
|
||||||
|
"spring.cloud.alicloud.sms.upQueueName=q2",
|
||||||
|
"spring.cloud.alicloud.sms.connect-timeout=20",
|
||||||
|
"spring.cloud.alicloud.sms.read-timeout=30")
|
||||||
|
.run(context -> {
|
||||||
|
SmsProperties config = context.getBean(SmsProperties.class);
|
||||||
|
AssertionsForClassTypes.assertThat(config.getReportQueueName())
|
||||||
|
.isEqualTo("q1");
|
||||||
|
AssertionsForClassTypes.assertThat(config.getUpQueueName())
|
||||||
|
.isEqualTo("q2");
|
||||||
|
AssertionsForClassTypes.assertThat(config.getConnectTimeout())
|
||||||
|
.isEqualTo("20");
|
||||||
|
AssertionsForClassTypes.assertThat(config.getReadTimeout())
|
||||||
|
.isEqualTo("30");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* 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.alicloud.utils;
|
||||||
|
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||||
|
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xiaolongzuo
|
||||||
|
*/
|
||||||
|
public class ChangeOrderUtils {
|
||||||
|
|
||||||
|
private ChangeOrderUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void mockChangeOrder() {
|
||||||
|
EdasChangeOrderConfiguration edasChangeOrderConfiguration = PowerMockito
|
||||||
|
.mock(EdasChangeOrderConfiguration.class);
|
||||||
|
PowerMockito.when(edasChangeOrderConfiguration.isEdasManaged()).thenReturn(true);
|
||||||
|
PowerMockito.when(edasChangeOrderConfiguration.getAddressServerDomain())
|
||||||
|
.thenReturn("testDomain");
|
||||||
|
PowerMockito.when(edasChangeOrderConfiguration.getTenantId())
|
||||||
|
.thenReturn("testTenantId");
|
||||||
|
PowerMockito.when(edasChangeOrderConfiguration.getDauthAccessKey())
|
||||||
|
.thenReturn("testAK");
|
||||||
|
PowerMockito.when(edasChangeOrderConfiguration.getDauthSecretKey())
|
||||||
|
.thenReturn("testSK");
|
||||||
|
PowerMockito.when(edasChangeOrderConfiguration.getProjectName())
|
||||||
|
.thenReturn("testProjectName");
|
||||||
|
PowerMockito.when(edasChangeOrderConfiguration.getAddressServerPort())
|
||||||
|
.thenReturn("8080");
|
||||||
|
PowerMockito.mockStatic(EdasChangeOrderConfigurationFactory.class);
|
||||||
|
PowerMockito
|
||||||
|
.when(EdasChangeOrderConfigurationFactory
|
||||||
|
.getEdasChangeOrderConfiguration())
|
||||||
|
.thenReturn(edasChangeOrderConfiguration);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue