remove comment

fix checkstyle

add license

fix checkstyle

fix checkstyle

remove comment

fix file consistency

remove imports

fix checkstyles

fix checkstyles

add dockerhub manage image

update image file
pull/2694/head
windwheel 3 years ago
parent 066587d3b5
commit 36d5f7ef6f

@ -7,6 +7,19 @@ on:
branches:
- 2021.x
jobs:
deploy-docker-iamge:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
integration-testing:
name: Integration Testing
runs-on: ubuntu-latest

@ -40,8 +40,8 @@ public class UserProperties {
public static class User {
private String name;
private Integer age;
public User(String name, Integer age){
public User(String name, Integer age) {
this.name = name;
this.age = age;
}

@ -16,7 +16,11 @@
package com.alibaba.cloud.tests.nacos.config;
import com.alibaba.cloud.testsupport.*;
import java.util.Properties;
import com.alibaba.cloud.testsupport.SpringCloudAlibaba;
import com.alibaba.cloud.testsupport.TestExtend;
import com.alibaba.cloud.testsupport.Tester;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigFactory;
import com.alibaba.nacos.api.config.ConfigService;
@ -24,21 +28,10 @@ import com.alibaba.nacos.api.exception.NacosException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.junit4.SpringRunner;
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;
import java.io.*;
import java.util.*;
import static com.alibaba.cloud.testsupport.Constant.REFRESH_CONFIG;
import static com.alibaba.cloud.testsupport.Constant.TIME_OUT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
/**
*
@ -46,30 +39,39 @@ import static org.mockito.Mockito.when;
*
* @author freeman
*/
//@HasDockerAndItEnabled
// @HasDockerAndItEnabled
@SpringCloudAlibaba(composeFiles = "docker/nacos-compose-test.yml", serviceName = "nacos-standalone")
@TestExtend(time = 3* TIME_OUT)
@TestExtend(time = 3 * TIME_OUT)
public class NacosConfigRefreshTest {
/**
* nacos upload conf file.
*/
public static final String YAML_CONTENT = "configdata:\n" + " user:\n"
+ " age: 22\n" + " name: freeman1123\n" + " map:\n"
+ " hobbies:\n" + " - art\n" + " - programming\n"
+ " - movie\n" + " intro: Hello, I'm freeman\n"
+ " extra: yo~\n" + " users:\n" + " - name: dad\n"
+ " age: 20\n" + " - name: mom\n" + " age: 18";
@Mock
protected ConfigService service1;
@BeforeAll
public static void setUp(){
public static void setUp() {
}
@BeforeEach
public void prepare() throws NacosException {
public void prepare() throws NacosException {
Properties nacosSettings = new Properties();
String serverIp8 = "127.0.0.1:8848";
nacosSettings.put(PropertyKeyConst.SERVER_ADDR, serverIp8);
nacosSettings.put(PropertyKeyConst.USERNAME, "nacos");
nacosSettings.put(PropertyKeyConst.PASSWORD, "nacos");
service1 = ConfigFactory.createConfigService(nacosSettings);
}
@Test
@ -80,43 +82,18 @@ public class NacosConfigRefreshTest {
Tester.testFunction("Dynamic refresh config", () -> {
// update config
updateConfig();
// wait config refresh
Thread.sleep(2000L);
String content = service1.getConfig("nacos-config-refresh.yml", "DEFAULT_GROUP", TIME_OUT);
ClassPathResource classPathResource = new ClassPathResource(REFRESH_CONFIG);
File file = classPathResource.getFile();
final BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String line = null;
StringBuilder sb = new StringBuilder();
while ((line = bufferedReader.readLine()) != null) {
sb.append(line).append("\n");
}
sb.deleteCharAt(sb.length()-1);
assertThat(content).isEqualTo(sb.toString());
String content = service1.getConfig("nacos-config-refresh.yml",
"DEFAULT_GROUP", TIME_OUT);
assertThat(content).isEqualTo(YAML_CONTENT);
});
}
private void updateConfig() throws NacosException {
service1.publishConfig("nacos-config-refresh.yml", "DEFAULT_GROUP",
"configdata:\n" +
" user:\n" +
" age: 22\n" +
" name: freeman1123\n" +
" map:\n" +
" hobbies:\n" +
" - art\n" +
" - programming\n" +
" - movie\n" +
" intro: Hello, I'm freeman\n" +
" extra: yo~\n" +
" users:\n" +
" - name: dad\n" +
" age: 20\n" +
" - name: mom\n" +
" age: 18",
service1.publishConfig("nacos-config-refresh.yml", "DEFAULT_GROUP", YAML_CONTENT,
"yaml");
}
}

@ -1,12 +1,6 @@
services:
# zookeeper:
# image: zookeeper
# ports:
# - "2181:2181"
# restart: on-failure
nacos:
image: zhusaidong/nacos-server-m1:2.0.3
image: nacos/nacos-server:2.0.1
container_name: nacos-standalone
environment:
- PREFER_HOST_MODE=hostname
@ -15,23 +9,4 @@ services:
- "8848:8848"
healthcheck:
test: "curl --fail http://127.0.0.1:8848/nacos/v1/console/health/liveness || exit 1"
interval: 5s
# etcd:
# image: "quay.io/coreos/etcd:latest"
# container_name: etcd
# environment:
# - ETCDCTL_API=3
# command: [
# "etcd",
# "--name=etcd0",
# "--advertise-client-urls=http://127.0.0.1:2379",
# "--listen-client-urls=http://0.0.0.0:2379",
# "--initial-advertise-peer-urls=http://127.0.0.1:2380",
# "--listen-peer-urls=http://0.0.0.0:2380",
# "--initial-cluster=etcd0=http://127.0.0.1:2380",
# ]
# ports:
# - "2379:2379"
# - "2380:2380"
# restart: always
interval: 5s

@ -1,16 +0,0 @@
configdata:
user:
age: 22
name: freeman1123
map:
hobbies:
- art
- programming
- movie
intro: Hello, I'm freeman
extra: yo~
users:
- name: dad
age: 20
- name: mom
age: 18

@ -52,6 +52,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
public class NacosDiscoveryTest {
static GenericContainer nacos;
static ConfigurableApplicationContext service1 = new SpringApplicationBuilder(
NacosDiscoveryTestApp.class).profiles("service-1").run();
static ConfigurableApplicationContext service2_0 = new SpringApplicationBuilder(
NacosDiscoveryTestApp.class).profiles("service-2").run();
static ConfigurableApplicationContext service2_1 = new SpringApplicationBuilder(
NacosDiscoveryTestApp.class).profiles("service-2").run();
static {
nacos = ContainerStarter.startNacos();
@ -65,15 +71,6 @@ public class NacosDiscoveryTest {
System.setProperty("spring.cloud.nacos.discovery.server-addr", serverAddr);
}
static ConfigurableApplicationContext service1 = new SpringApplicationBuilder(
NacosDiscoveryTestApp.class).profiles("service-1").run();
static ConfigurableApplicationContext service2_0 = new SpringApplicationBuilder(
NacosDiscoveryTestApp.class).profiles("service-2").run();
static ConfigurableApplicationContext service2_1 = new SpringApplicationBuilder(
NacosDiscoveryTestApp.class).profiles("service-2").run();
@BeforeAll
static void init() {
// give nacos a break

@ -1,10 +1,4 @@
services:
# zookeeper:
# image: zookeeper
# ports:
# - "2181:2181"
# restart: on-failure
nacos:
image: nacos/nacos-server:2.0.1
container_name: nacos-standalone
@ -15,23 +9,4 @@ services:
- "8848:8848"
healthcheck:
test: "curl --fail http://127.0.0.1:8848/nacos/v1/console/health/liveness || exit 1"
interval: 5s
# etcd:
# image: "quay.io/coreos/etcd:latest"
# container_name: etcd
# environment:
# - ETCDCTL_API=3
# command: [
# "etcd",
# "--name=etcd0",
# "--advertise-client-urls=http://127.0.0.1:2379",
# "--listen-client-urls=http://0.0.0.0:2379",
# "--initial-advertise-peer-urls=http://127.0.0.1:2380",
# "--listen-peer-urls=http://0.0.0.0:2380",
# "--initial-cluster=etcd0=http://127.0.0.1:2380",
# ]
# ports:
# - "2379:2379"
# - "2380:2380"
# restart: always
interval: 5s

@ -1,9 +1,30 @@
/*
* Copyright 2012-2020 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
*
* https://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.cloud.testsupport;
public class Constant {
//超时默认设置为5s
public static final long TIME_OUT = 5000;
public static final String REFRESH_CONFIG = "nacos-config-refresh.yml";
/**
* container timeout.
*/
public static final long TIME_OUT = 5000;
/**
* nacos refresh config.
*/
public static final String REFRESH_CONFIG = "nacos-config-refresh.yml";
}

@ -37,10 +37,10 @@ public class ContainerStarter {
private static final String ROCKETMQ_BROKER_CONFIG_PATH = "rocketmq/conf/broker.conf";
private static final String NACOS_VERSION = "1.4.2";
private static final String NACOS_VERSION = "1.4.2";
private static final String SENTINEL_VERSION = "1.8.3";
private static final String ROCKETMQ_VERSION = "4.9.2";
private static final String SEATA_VERSION = "1.4.2";
private static final String SEATA_VERSION = "1.4.2";
private static final Map<String, GenericContainer> nacosMap = new ConcurrentHashMap<>(
4);
@ -87,8 +87,7 @@ public class ContainerStarter {
// this image exposes 4 ports, include namesrv and broker
// we need use FixedHostPortGenericContainer !
GenericContainer rocketmq = new FixedHostPortGenericContainer(
"freemanlau/rocketmq:" + version)
.withFixedExposedPort(9876, 9876)
"freemanlau/rocketmq:" + version).withFixedExposedPort(9876, 9876)
.withFixedExposedPort(10909, 10909)
.withFixedExposedPort(10911, 10911)
.withFixedExposedPort(10912, 10912);

@ -27,7 +27,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
/**
* Disables test execution if Docker is unavailable.
* <p>
* We don't want to run integration tests on local machine, but still give a chance to run it.
* We don't want to run integration tests on local machine, but still give a chance to run
* it.
* <p>
* Typically, used for CI and local integration test.
* <p>

@ -1,25 +1,27 @@
/*
* Licensed to Apache Software Foundation (ASF) under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Apache Software Foundation (ASF) licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* Copyright 2012-2020 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
* https://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.
* 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.cloud.testsupport;
import java.lang.annotation.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.TestMethodOrder;
@ -33,7 +35,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@TestMethodOrder(OrderAnnotation.class)
@ExtendWith(SpringCloudAlibabaExtension.class)
public @interface SpringCloudAlibaba {
String[] composeFiles();
String serviceName();
String[] composeFiles();
String serviceName();
}

@ -1,20 +1,17 @@
/*
* Licensed to Apache Software Foundation (ASF) under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Apache Software Foundation (ASF) licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* Copyright 2012-2020 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
* https://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.
* 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.cloud.testsupport;
@ -39,68 +36,59 @@ import org.testcontainers.shaded.org.awaitility.Awaitility;
@Slf4j
final class SpringCloudAlibabaExtension
implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback {
private final boolean LOCAL_MODE = Objects.equals(System.getProperty("local"), "true");
implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback {
private final boolean LOCAL_MODE = Objects.equals(System.getProperty("local"),
"true");
private DockerComposeContainer<?> compose;
private DockerComposeContainer<?> compose;
@Override
@SuppressWarnings("UnstableApiUsage")
public void beforeAll(ExtensionContext context) throws IOException {
Awaitility.setDefaultTimeout(Duration.ofSeconds(60));
Awaitility.setDefaultPollInterval(Duration.ofSeconds(10));
@Override
@SuppressWarnings("UnstableApiUsage")
public void beforeAll(ExtensionContext context) throws IOException {
Awaitility.setDefaultTimeout(Duration.ofSeconds(60));
Awaitility.setDefaultPollInterval(Duration.ofSeconds(10));
if (LOCAL_MODE) {
runInLocal();
} else {
runInDockerContainer(context);
}
//
// final Class<?> clazz = context.getRequiredTestClass();
// Stream.of(clazz.getDeclaredFields())
// .filter(it -> Modifier.isStatic(it.getModifiers()));
}
if (LOCAL_MODE) {
runInLocal();
}
else {
runInDockerContainer(context);
}
}
private void runInLocal() {
Testcontainers.exposeHostPorts(3000);
}
private void runInLocal() {
Testcontainers.exposeHostPorts(3000);
}
private void runInDockerContainer(ExtensionContext context) {
compose = createDockerCompose(context);
compose.start();
}
private void runInDockerContainer(ExtensionContext context) {
compose = createDockerCompose(context);
compose.start();
}
@Override
public void afterAll(ExtensionContext context) {
if (compose != null) {
compose.stop();
}
}
@Override
public void afterAll(ExtensionContext context) {
if (compose != null) {
compose.stop();
}
}
@Override
public void beforeEach(ExtensionContext context) {
final Object instance = context.getRequiredTestInstance();
Stream.of(instance.getClass().getDeclaredFields());
}
@Override
public void beforeEach(ExtensionContext context) {
final Object instance = context.getRequiredTestInstance();
Stream.of(instance.getClass().getDeclaredFields());
}
private DockerComposeContainer<?> createDockerCompose(ExtensionContext context) {
final Class<?> clazz = context.getRequiredTestClass();
final SpringCloudAlibaba annotation = clazz.getAnnotation(
SpringCloudAlibaba.class);
final List<File> files = Stream.of(annotation.composeFiles())
.map(it -> SpringCloudAlibaba.class.getClassLoader().getResource(it))
.filter(Objects::nonNull)
.map(URL::getPath)
.map(File::new)
.collect(Collectors.toList());
compose = new DockerComposeContainer<>(files)
.withPull(true)
.withTailChildContainers(true);
private DockerComposeContainer<?> createDockerCompose(ExtensionContext context) {
final Class<?> clazz = context.getRequiredTestClass();
final SpringCloudAlibaba annotation = clazz
.getAnnotation(SpringCloudAlibaba.class);
final List<File> files = Stream.of(annotation.composeFiles())
.map(it -> SpringCloudAlibaba.class.getClassLoader().getResource(it))
.filter(Objects::nonNull).map(URL::getPath).map(File::new)
.collect(Collectors.toList());
compose = new DockerComposeContainer<>(files).withPull(true)
.withTailChildContainers(true);
return compose;
}
return compose;
}
}

@ -1,16 +1,34 @@
/*
* Copyright 2012-2020 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
*
* https://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.cloud.testsupport;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
import org.junit.jupiter.api.extension.ExtendWith;
@Target({ElementType.TYPE, ElementType.METHOD})
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ExtendWith(TestTimeoutExtension.class)
public @interface TestExtend {
//设置超时时间
long time();
long time();
}

@ -1,37 +1,52 @@
/*
* Copyright 2012-2020 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
*
* https://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.cloud.testsupport;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class TestTimeoutExtension
implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback {
@Override
public void afterAll(ExtensionContext context) throws Exception {
}
@Override
public void beforeAll(ExtensionContext context) throws Exception {
}
public class TestTimeoutExtension implements BeforeAllCallback, BeforeEachCallback, AfterAllCallback {
@Override
public void afterAll(ExtensionContext context) throws Exception {
}
@Override
public void beforeAll(ExtensionContext context) throws Exception {
}
@Override
public void beforeEach(ExtensionContext context) throws Exception {
final Class<?> clazz = context.getRequiredTestClass();
final TestExtend annotation = clazz.getAnnotation(
TestExtend.class);
ScheduledExecutorService singlonThread = Executors.newSingleThreadScheduledExecutor();
while (!singlonThread.awaitTermination( annotation.time(), TimeUnit.MILLISECONDS)){
singlonThread.shutdown();
}
}
@Override
public void beforeEach(ExtensionContext context) throws Exception {
final Class<?> clazz = context.getRequiredTestClass();
final TestExtend annotation = clazz.getAnnotation(TestExtend.class);
ScheduledExecutorService singlonThread = Executors
.newSingleThreadScheduledExecutor();
while (!singlonThread.awaitTermination(annotation.time(),
TimeUnit.MILLISECONDS)) {
singlonThread.shutdown();
}
}
}

@ -30,20 +30,26 @@ public class Tester {
*/
public static void testFunction(String function, Func func) {
try {
System.out.println("============================================================================");
System.out.println(
"============================================================================");
System.out.println("Testing '" + function + "' ......");
System.out.println("============================================================================");
System.out.println(
"============================================================================");
func.justDo();
System.out.println("============================================================================");
System.out.println(
"============================================================================");
System.out.println("Function '" + function + "' OK !");
System.out.println("============================================================================\n");
System.out.println(
"============================================================================\n");
}
catch (Throwable e) {
System.err.println("============================================================================");
System.err.println(
"============================================================================");
System.err.println("Function '" + function + "' err !");
System.err.println("============================================================================\n");
System.err.println(
"============================================================================\n");
throw new RuntimeException(e);
}
}

Loading…
Cancel
Save