Skip to content

Commit

Permalink
Merge branch 'alibaba:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
huangkemingyyds committed Aug 31, 2024
2 parents 560632e + 209dfe8 commit a8580eb
Show file tree
Hide file tree
Showing 1,063 changed files with 34,880 additions and 26,832 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ name: "Continuous Integration"
on:
push:
branches: [ master, develop, v1.x-develop, v1.X ]
pull_request:
pull_request_target:
branches: [ develop, v1.x-develop ]

permissions:
contents: read # to fetch code (actions/checkout)
permissions: read-all

jobs:
ci:
Expand All @@ -21,16 +20,20 @@ jobs:
java: [8]
steps:
- name: "Cache Maven Repos"
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- if: github.event_name == 'pull_request_target'
run: echo "REF=refs/pull/${{ github.event.number }}/merge" >> "$GITHUB_ENV"
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: "Set up JDK ${{ matrix.java }}"
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
Expand All @@ -44,6 +47,11 @@ jobs:
- name: "Test With Maven"
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Codecov"
uses: codecov/[email protected]
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
verbose: true
fail_ci_if_error: true
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./config/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./logger-adapter-impl/log4j2-adapter/target/site/jacoco/jacoco.xml,./logger-adapter-impl/logback-adapter-12/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./persistence/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-auth-plugin/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-control-plugin/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/config/target/site/jacoco/jacoco.xml,./plugin/control/target/site/jacoco/jacoco.xml,./plugin/datasource/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./plugin/environment/target/site/jacoco/jacoco.xml,./plugin/trace/target/site/jacoco/jacoco.xml,./prometheus/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ test/logs
derby.log
yarn.lock
.flattened-pom.xml
lefthook.yml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ You can view the full documentation from the [Nacos website](https://nacos.io/en

You can also read this online eBook from the [NACOS ARCHITECTURE & PRINCIPLES](https://www.yuque.com/nacos/ebook/kbyo6n).

All the latest and long-term notice can also be found here from [Github notice issue](https://github.com/alibaba/nacos/labels/notice).
All the latest and long-term notice can also be found here from [GitHub notice issue](https://github.com/alibaba/nacos/labels/notice).

## Contributing

Expand Down Expand Up @@ -134,7 +134,7 @@ https://cn.aliyun.com/product/aliware/mse?spm=nacos-website.topbar.0.0.0
## Download

- [Nacos Official Website](https://nacos.io/download/nacos-server)
- [Github Release](https://github.com/alibaba/nacos/releases)
- [GitHub Release](https://github.com/alibaba/nacos/releases)

## Who is using

Expand Down
4 changes: 2 additions & 2 deletions address/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,59 @@

import com.alibaba.nacos.address.constant.AddressServerConstants;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class AddressServerGeneratorManagerTest {

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class AddressServerGeneratorManagerTest {

@Test
public void testGenerateProductName() {
void testGenerateProductName() {
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
final String blankName = manager.generateProductName("");
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, blankName);

final String defaultName = manager.generateProductName(AddressServerConstants.DEFAULT_PRODUCT);
Assert.assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);
assertEquals(AddressServerConstants.ALIWARE_NACOS_DEFAULT_PRODUCT_NAME, defaultName);

final String testName = manager.generateProductName("test");
Assert.assertEquals("nacos.as.test", testName);
assertEquals("nacos.as.test", testName);

}

@Test
public void testGenerateInstancesByIps() {
void testGenerateInstancesByIps() {
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();
final List<Instance> empty = manager.generateInstancesByIps(null, null, null, null);
Assert.assertNotNull(empty);
Assert.assertTrue(empty.isEmpty());
assertNotNull(empty);
assertTrue(empty.isEmpty());

String[] ipArray = new String[]{"192.168.3.1:8848", "192.168.3.2:8848", "192.168.3.3:8848"};
final List<Instance> instanceList = manager.generateInstancesByIps("DEFAULT_GROUP@@nacos.as.test", "test", "test",
ipArray);
Assert.assertNotNull(instanceList);
Assert.assertFalse(instanceList.isEmpty());
Assert.assertEquals(3, instanceList.size());
assertNotNull(instanceList);
assertFalse(instanceList.isEmpty());
assertEquals(3, instanceList.size());

final Instance instance1 = instanceList.get(0);
Assert.assertEquals("192.168.3.1", instance1.getIp());
assertEquals("192.168.3.1", instance1.getIp());

final Instance instance2 = instanceList.get(1);
Assert.assertEquals("192.168.3.2", instance2.getIp());
assertEquals("192.168.3.2", instance2.getIp());

final Instance instance3 = instanceList.get(2);
Assert.assertEquals("192.168.3.3", instance3.getIp());
assertEquals("192.168.3.3", instance3.getIp());

}

@Test
public void testGenerateResponseIps() {
void testGenerateResponseIps() {
final List<com.alibaba.nacos.api.naming.pojo.Instance> instanceList = new ArrayList<>();
Instance instance1 = new Instance();
instance1.setIp("192.168.3.1");
Expand All @@ -92,19 +96,19 @@ public void testGenerateResponseIps() {
.append("192.168.3.1:8848").append('\n')
.append("192.168.3.2:8848").append('\n')
.append("192.168.3.3:8848").append('\n');
Assert.assertEquals(ret.toString(), ipListStr);
assertEquals(ret.toString(), ipListStr);

}

@Test
public void testGenerateNacosServiceName() {
void testGenerateNacosServiceName() {
AddressServerGeneratorManager manager = new AddressServerGeneratorManager();

final String containDefault = manager.generateNacosServiceName("DEFAULT_GROUP@@test");
Assert.assertEquals("DEFAULT_GROUP@@test", containDefault);
assertEquals("DEFAULT_GROUP@@test", containDefault);

final String product = manager.generateNacosServiceName("product");
Assert.assertEquals("DEFAULT_GROUP@@product", product);
assertEquals("DEFAULT_GROUP@@product", product);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@
package com.alibaba.nacos.address.component;

import com.alibaba.nacos.address.constant.AddressServerConstants;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class AddressServerManagerTests {
class AddressServerManagerTests {

private static final AddressServerManager ADDRESS_SERVER_MANAGER = new AddressServerManager();

@Test
public void getRawProductName() {
void getRawProductName() {
assertEquals(AddressServerConstants.DEFAULT_PRODUCT, ADDRESS_SERVER_MANAGER.getRawProductName(""));
assertEquals(AddressServerConstants.DEFAULT_PRODUCT,
ADDRESS_SERVER_MANAGER.getRawProductName(AddressServerConstants.DEFAULT_PRODUCT));
assertEquals("otherProduct", ADDRESS_SERVER_MANAGER.getRawProductName("otherProduct"));
}

@Test
public void getDefaultClusterNameIfEmpty() {
void getDefaultClusterNameIfEmpty() {
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(""));
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER,
ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty(AddressServerConstants.DEFAULT_GET_CLUSTER));
assertEquals("otherServerList", ADDRESS_SERVER_MANAGER.getDefaultClusterNameIfEmpty("otherServerList"));
}

@Test
public void testGetRawClusterName() {
void testGetRawClusterName() {
assertEquals("serverList", ADDRESS_SERVER_MANAGER.getRawClusterName("serverList"));
assertEquals(AddressServerConstants.DEFAULT_GET_CLUSTER, ADDRESS_SERVER_MANAGER.getRawClusterName(""));
}

@Test
public void testSplitIps() {
void testSplitIps() {
final String[] emptyArr = ADDRESS_SERVER_MANAGER.splitIps("");
assertEquals(0, emptyArr.length);
final String[] one = ADDRESS_SERVER_MANAGER.splitIps("192.168.1.12:8848");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
import com.alibaba.nacos.naming.core.v2.ServiceManager;
import com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager;
import com.alibaba.nacos.naming.core.v2.pojo.Service;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(MockitoJUnitRunner.class)
public class AddressServerClusterControllerTest {
@ExtendWith(MockitoExtension.class)
class AddressServerClusterControllerTest {

@Mock
private InstanceOperator instanceOperator;
Expand All @@ -53,40 +53,40 @@ public class AddressServerClusterControllerTest {
private ClusterOperator clusterOperator;

private MockMvc mockMvc;
@Before
public void before() {

@BeforeEach
void before() {
mockMvc = MockMvcBuilders.standaloneSetup(
new AddressServerClusterController(instanceOperator, metadataManager, clusterOperator,
new AddressServerManager(), new AddressServerGeneratorManager())).build();
Service service = Service
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
ServiceManager.getInstance().getSingleton(service);
}
@After
public void tearDown() {

@AfterEach
void tearDown() {
Service service = Service
.newService(Constants.DEFAULT_NAMESPACE_ID, Constants.DEFAULT_GROUP, "nacos.as.default", false);
ServiceManager.getInstance().removeSingleton(service);
}

@Test
public void testPostCluster() throws Exception {
void testPostCluster() throws Exception {

mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());

}

@Test
public void testPostClusterWithErrorIps() throws Exception {
void testPostClusterWithErrorIps() throws Exception {
mockMvc.perform(post("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
}

@Test
public void testPostClusterThrowException() throws Exception {
void testPostClusterThrowException() throws Exception {

Mockito.doThrow(new NacosException(500, "create service error")).when(clusterOperator)
.updateClusterMetadata(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
Expand All @@ -97,34 +97,34 @@ public void testPostClusterThrowException() throws Exception {
.param("ips", "192.168.1")).andExpect(status().isInternalServerError());

}

@Test
public void testDeleteCluster() throws Exception {
void testDeleteCluster() throws Exception {
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isOk());
}

@Test
public void testDeleteClusterCannotFindService() throws Exception {
void testDeleteClusterCannotFindService() throws Exception {
tearDown();
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
.param("ips", "192.168.3.1,192.168.3.2")).andExpect(status().isNotFound());
}

@Test
public void testDeleteClusterEmptyIps() throws Exception {
void testDeleteClusterEmptyIps() throws Exception {
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
.param("ips", "")).andExpect(status().isBadRequest());
}

@Test
public void testDeleteClusterErrorIps() throws Exception {
void testDeleteClusterErrorIps() throws Exception {
mockMvc.perform(delete("/nacos/v1/as/nodes").param("product", "default").param("cluster", "serverList")
.param("ips", "192.168.1")).andExpect(status().isBadRequest());
}

@Test
public void testDeleteClusterThrowException() throws Exception {
void testDeleteClusterThrowException() throws Exception {
Mockito.doThrow(new NacosException(500, "remove service error")).when(instanceOperator)
.removeInstance(Mockito.eq(Constants.DEFAULT_NAMESPACE_ID), Mockito.eq(
Constants.DEFAULT_GROUP + AddressServerConstants.GROUP_SERVICE_NAME_SEP + "nacos.as.default"),
Expand Down
Loading

0 comments on commit a8580eb

Please sign in to comment.