-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
522f0c8
commit b23f926
Showing
11 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
integration-tests/discovery-nacos-tests/cross-group-consumer/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. | ||
~ 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. | ||
--> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>com.huaweicloud</groupId> | ||
<artifactId>discovery-nacos-tests</artifactId> | ||
<version>1.12.0-2022.0.x-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<name>Integration Tests::Discovery Nacos Tests::Order Consumer Test</name> | ||
<artifactId>nacos-cross-group-consumer-test</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.huaweicloud</groupId> | ||
<artifactId>discovery-tests-common</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.huaweicloud</groupId> | ||
<artifactId>spring-cloud-starter-huawei-nacos</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-openfeign</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>docker</id> | ||
<properties> | ||
<server.port>9001</server.port> | ||
</properties> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.commonjava.maven.plugins</groupId> | ||
<artifactId>directory-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.odavid.maven.plugins</groupId> | ||
<artifactId>mixin-maven-plugin</artifactId> | ||
<configuration> | ||
<mixins> | ||
<mixin> | ||
<groupId>com.huaweicloud</groupId> | ||
<artifactId>docker-build-config</artifactId> | ||
<version>${project.version}</version> | ||
</mixin> | ||
</mixins> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
...ests/cross-group-consumer/src/main/java/com/huaweicloud/sample/CrossGroupApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. | ||
* 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.huaweicloud.sample; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.client.loadbalancer.LoadBalanced; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
@EnableFeignClients | ||
public class CrossGroupApplication { | ||
|
||
public static void main(String[] args) { | ||
try { | ||
SpringApplication.run(CrossGroupApplication.class, args); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@LoadBalanced | ||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...tests/cross-group-consumer/src/main/java/com/huaweicloud/sample/CrossGroupController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. | ||
* 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.huaweicloud.sample; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@RestController | ||
public class CrossGroupController { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Autowired | ||
public CrossGroupController(RestTemplate restTemplate) { | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
@RequestMapping("/cross-group") | ||
public String crossGroup(@RequestParam("id") String id) { | ||
String callServiceResult = restTemplate.getForObject("http://price/price?id=" + id, String.class); | ||
return callServiceResult; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ration-tests/discovery-nacos-tests/cross-group-consumer/src/main/resources/bootstrap.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# | ||
## --------------------------------------------------------------------------- | ||
## | ||
## Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. | ||
## | ||
## 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. | ||
## --------------------------------------------------------------------------- | ||
|
||
server: | ||
port: 9001 | ||
|
||
spring: | ||
application: | ||
name: cross-group-consumer | ||
cloud: | ||
servicecomb: | ||
cross-group: | ||
enabled: true | ||
service-group-mappings: | ||
price: DEFAULT_GROUP | ||
nacos: | ||
discovery: | ||
enabled: true | ||
server-addr: http://127.0.0.1:8848 | ||
service: ${spring.application.name} | ||
metadata: | ||
x-test: value | ||
x-test2: value2 | ||
group: CROSS_GROUP | ||
config: | ||
group: CROSS_GROUP | ||
enabled: true | ||
server-addr: http://127.0.0.1:8848 | ||
service: ${spring.application.name} | ||
|
||
test: | ||
value: | ||
bootstrapOverride: "orderBootstrapOverride" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ery-tests-client/src/test/java/com/huaweicloud/sample/CrossGroupProviderControllerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. | ||
* 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.huaweicloud.sample; | ||
|
||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
public class CrossGroupProviderControllerIT { | ||
final String url = "http://127.0.0.1:9001"; | ||
|
||
final RestTemplate template = new RestTemplate(); | ||
|
||
@Test | ||
public void testCrossGroup() { | ||
String result = template.getForObject(url + "/cross-group?id=hello", String.class); | ||
assertThat(result).isEqualTo("hello"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...nacos/src/main/java/com/huaweicloud/nacos/discovery/NacosCrossGroupAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2020-2022 Huawei Technologies Co., Ltd. All rights reserved. | ||
* 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.huaweicloud.nacos.discovery; | ||
|
||
import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; | ||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties; | ||
import com.alibaba.cloud.nacos.NacosServiceManager; | ||
import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration; | ||
|
||
@Configuration | ||
@ConditionalOnNacosDiscoveryEnabled | ||
@AutoConfigureBefore(NacosDiscoveryAutoConfiguration.class) | ||
@ConditionalOnProperty(value = "spring.cloud.servicecomb.cross-group.enabled", havingValue = "true") | ||
public class NacosCrossGroupAutoConfiguration { | ||
@Bean | ||
public NacosServiceCrossGroupDiscovery nacosServiceCrossGroupDiscovery(NacosDiscoveryProperties discoveryProperties, | ||
NacosServiceManager nacosServiceManager, NacosCrossGroupServiceConfig nacosCrossGroupServiceConfig) { | ||
return new NacosServiceCrossGroupDiscovery(discoveryProperties, nacosServiceManager, nacosCrossGroupServiceConfig); | ||
} | ||
|
||
@Bean | ||
public NacosCrossGroupServiceConfig nacosCrossGroupServiceConfig() { | ||
return new NacosCrossGroupServiceConfig(); | ||
} | ||
} |
Oops, something went wrong.