You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by jo...@apache.org on 2023/02/17 05:44:24 UTC
[shenyu] branch master updated: [ISSUE #3450] add brpc integrated test (#4319)
This is an automated email from the ASF dual-hosted git repository.
jooks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 175459c56 [ISSUE #3450] add brpc integrated test (#4319)
175459c56 is described below
commit 175459c56e9777783c7e2d3ea8fca6c25a741801
Author: dragon-zhang <zh...@apache.org>
AuthorDate: Fri Feb 17 13:44:16 2023 +0800
[ISSUE #3450] add brpc integrated test (#4319)
* [ISSUE #3450] add attributes and exclude log dep
* [ISSUE #3450] add brpc integrated test
* fix style
* simplify code
* update workflow
* fix CI
* fix profile
* fix build
* fix sql
* enable brpc plugin
* fix style
* try pass CI
* fix brpc config cache bug
* add cache
* fix bug
* fix version
* fix docker circular dependency
* fix port
* use registered host and port
* fix style
* fix compile
* try pass CI
---------
Co-authored-by: hailang <a1...@hotmail.com>
Co-authored-by: xiaoyu <xi...@apache.org>
---
.github/workflows/integrated-test.yml | 1 +
shenyu-bootstrap/pom.xml | 6 +
.../brpc/BrpcContextRefreshedEventListener.java | 6 +-
.../brpc/common/annotation/ShenyuBrpcService.java | 40 ++++++
.../shenyu/client/brpc/common/dto/BrpcRpcExt.java | 49 +++++++-
.../dto/convert/plugin/BrpcRegisterConfig.java | 51 +-------
.../{ => shenyu-examples-brpc-service}/Dockerfile | 3 +-
.../shenyu-examples-brpc-service/pom.xml | 54 ++++++++
.../src/main/resources/application.yml | 1 -
shenyu-integrated-test/pom.xml | 1 +
.../shenyu-integrated-test-brpc}/Dockerfile | 4 +-
.../shenyu-integrated-test-brpc/docker-compose.yml | 84 +++++++++++++
.../shenyu-integrated-test-brpc/pom.xml | 111 +++++++++++++++++
.../script/healthcheck.sh | 36 ++++++
.../script/services.list | 16 +--
.../test/brpc/BrpcIntegratedBootstrap.java | 34 +++++
.../src/main/resources/application-local.yml | 59 +++++++++
.../src/main/resources/application.yml | 18 +++
.../integrated/test/brpc/BrpcPluginTest.java | 50 ++++++++
.../shenyu/integratedtest/common/dto/BrpcTest.java | 107 ++++++++++++++++
.../plugin/brpc/cache/ApplicationConfigCache.java | 137 +++++++++++++++------
.../plugin/brpc/handler/BrpcMetaDataHandler.java | 2 +-
.../shenyu/plugin/brpc/proxy/BrpcProxyService.java | 16 +--
.../brpc/cache/ApplicationConfigCacheTest.java | 19 ---
24 files changed, 772 insertions(+), 133 deletions(-)
diff --git a/.github/workflows/integrated-test.yml b/.github/workflows/integrated-test.yml
index 0d5b05c58..9553782dd 100644
--- a/.github/workflows/integrated-test.yml
+++ b/.github/workflows/integrated-test.yml
@@ -34,6 +34,7 @@ jobs:
- shenyu-integrated-test-motan
- shenyu-integrated-test-spring-cloud
- shenyu-integrated-test-sofa
+ - shenyu-integrated-test-brpc
- shenyu-integrated-test-websocket
- shenyu-integrated-test-combination
- shenyu-integrated-test-sdk-apache-dubbo
diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml
index 731efbcb0..fdd05d434 100644
--- a/shenyu-bootstrap/pom.xml
+++ b/shenyu-bootstrap/pom.xml
@@ -545,6 +545,12 @@
<groupId>org.apache.shenyu</groupId>
<artifactId>shenyu-spring-boot-starter-plugin-brpc</artifactId>
<version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<!-- shenyu brpc plugin end -->
diff --git a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java
index 6ab8eaf45..bf53fe594 100644
--- a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java
+++ b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/BrpcContextRefreshedEventListener.java
@@ -153,15 +153,15 @@ public class BrpcContextRefreshedEventListener extends AbstractContextRefreshedE
.ruleName(ruleName)
.parameterTypes(parameterTypes)
.rpcType(RpcTypeEnum.BRPC.getName())
- .rpcExt(buildRpcExt(method))
+ .rpcExt(buildRpcExt(method, host, port))
.enabled(shenyuBrpcClient.enabled())
.build();
}
- private String buildRpcExt(final Method method) {
+ private String buildRpcExt(final Method method, final String host, final int port) {
List<BrpcRpcExt.RpcExt> list = new ArrayList<>();
list.add(build(method));
- BrpcRpcExt buildList = new BrpcRpcExt(list);
+ BrpcRpcExt buildList = new BrpcRpcExt(list, host, port);
return GsonUtils.getInstance().toJson(buildList);
}
diff --git a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/annotation/ShenyuBrpcService.java b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/annotation/ShenyuBrpcService.java
index b3bafd479..b3f217f7b 100644
--- a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/annotation/ShenyuBrpcService.java
+++ b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/annotation/ShenyuBrpcService.java
@@ -36,6 +36,46 @@ import java.lang.annotation.Target;
@ShenyuBrpcClient
public @interface ShenyuBrpcService {
+ /**
+ * Value string.
+ *
+ * @return the string
+ */
+ @AliasFor(annotation = ShenyuBrpcClient.class)
+ String value() default "";
+
+ /**
+ * Path string.
+ *
+ * @return the string
+ */
+ @AliasFor(annotation = ShenyuBrpcClient.class)
+ String path() default "";
+
+ /**
+ * Rule name string.
+ *
+ * @return the string
+ */
+ @AliasFor(annotation = ShenyuBrpcClient.class)
+ String ruleName() default "";
+
+ /**
+ * Desc string.
+ *
+ * @return String string
+ */
+ @AliasFor(annotation = ShenyuBrpcClient.class)
+ String desc() default "";
+
+ /**
+ * Enabled boolean.
+ *
+ * @return the boolean
+ */
+ @AliasFor(annotation = ShenyuBrpcClient.class)
+ boolean enabled() default true;
+
/**
* service id.
*
diff --git a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/dto/BrpcRpcExt.java b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/dto/BrpcRpcExt.java
index 07b82bb72..58f910d1f 100644
--- a/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/dto/BrpcRpcExt.java
+++ b/shenyu-client/shenyu-client-brpc/src/main/java/org/apache/shenyu/client/brpc/common/dto/BrpcRpcExt.java
@@ -31,6 +31,10 @@ public class BrpcRpcExt {
* we can't change the type of this field.
*/
private List<RpcExt> methodInfo;
+
+ private String host;
+
+ private Integer port;
/**
* constructor without params.
@@ -42,11 +46,51 @@ public class BrpcRpcExt {
* constructor with all params.
*
* @param methodInfo methodInfo
+ * @param host host
+ * @param port port
*/
- public BrpcRpcExt(final List<RpcExt> methodInfo) {
+ public BrpcRpcExt(final List<RpcExt> methodInfo, final String host, final Integer port) {
this.methodInfo = methodInfo;
+ this.host = host;
+ this.port = port;
}
-
+
+ /**
+ * get port.
+ *
+ * @return port
+ */
+ public Integer getPort() {
+ return port;
+ }
+
+ /**
+ * set port.
+ *
+ * @param port port
+ */
+ public void setPort(final Integer port) {
+ this.port = port;
+ }
+
+ /**
+ * get host.
+ *
+ * @return host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * set host.
+ *
+ * @param host host
+ */
+ public void setHost(final String host) {
+ this.host = host;
+ }
+
/**
* get methodInfo.
*
@@ -89,7 +133,6 @@ public class BrpcRpcExt {
/**
* constructor with params.
- *
* @param methodName methodName
* @param paramTypes params
*/
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/BrpcRegisterConfig.java b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/BrpcRegisterConfig.java
index a97c56107..d34e6d7f7 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/BrpcRegisterConfig.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/plugin/BrpcRegisterConfig.java
@@ -27,10 +27,6 @@ public class BrpcRegisterConfig implements Serializable {
private static final long serialVersionUID = -1124348422759120146L;
- private String address;
-
- private Integer port;
-
private String threadpool;
private Integer corethreads;
@@ -39,43 +35,6 @@ public class BrpcRegisterConfig implements Serializable {
private Integer queues;
-
- /**
- * get address.
- *
- * @return address
- */
- public String getAddress() {
- return address;
- }
-
- /**
- * set address.
- *
- * @param address address
- */
- public void setAddress(final String address) {
- this.address = address;
- }
-
- /**
- * get port.
- *
- * @return port
- */
- public Integer getPort() {
- return port;
- }
-
- /**
- * set port.
- *
- * @param port port
- */
- public void setPort(final Integer port) {
- this.port = port;
- }
-
/**
* get threadpool.
*
@@ -157,23 +116,19 @@ public class BrpcRegisterConfig implements Serializable {
return false;
}
BrpcRegisterConfig that = (BrpcRegisterConfig) o;
- return Objects.equals(address, that.address) && Objects.equals(port, that.port)
- && Objects.equals(threadpool, that.threadpool) && Objects.equals(corethreads, that.corethreads)
+ return Objects.equals(threadpool, that.threadpool) && Objects.equals(corethreads, that.corethreads)
&& Objects.equals(threads, that.threads) && Objects.equals(queues, that.queues);
}
@Override
public int hashCode() {
- return Objects.hash(address, port, threadpool, corethreads, threads, queues);
+ return Objects.hash(threadpool, corethreads, threads, queues);
}
@Override
public String toString() {
return "BrpcRegisterConfig{"
- + "address='" + address
- + '\''
- + ", port=" + port
- + ", threadpool='" + threadpool
+ + "threadpool='" + threadpool
+ '\''
+ ", corethreads=" + corethreads
+ ", threads=" + threads
diff --git a/shenyu-examples/shenyu-examples-brpc/Dockerfile b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/Dockerfile
similarity index 94%
copy from shenyu-examples/shenyu-examples-brpc/Dockerfile
copy to shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/Dockerfile
index ac04a788b..5817e18c5 100644
--- a/shenyu-examples/shenyu-examples-brpc/Dockerfile
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/Dockerfile
@@ -16,7 +16,7 @@
FROM openjdk:8-jre-alpine
-ENV APP_NAME shenyu-examples-brpc
+ENV APP_NAME shenyu-examples-brpc-service
ENV LOCAL_PATH /opt/${APP_NAME}
RUN mkdir -p ${LOCAL_PATH}
@@ -24,6 +24,7 @@ RUN mkdir -p ${LOCAL_PATH}
ADD target/${APP_NAME}.jar ${LOCAL_PATH}
WORKDIR ${LOCAL_PATH}
+EXPOSE 8011
EXPOSE 8005
CMD java -jar ${APP_NAME}.jar
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/pom.xml b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/pom.xml
index bd85841ad..901af0b40 100644
--- a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/pom.xml
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/pom.xml
@@ -38,15 +38,69 @@
<artifactId>shenyu-examples-brpc-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
</dependencies>
<build>
+ <finalName>shenyu-examples-brpc-service</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
+ <configuration>
+ <mainClass>org.apache.shenyu.examples.brpc.service.TestBrpcApplication</mainClass>
+ <executable>true</executable>
+ </configuration>
</plugin>
</plugins>
</build>
+ <profiles>
+ <profile>
+ <id>example</id>
+ <properties>
+ <docker.buildArg.APP_NAME>shenyu-examples-brpc-service</docker.buildArg.APP_NAME>
+ <docker.image.tag.repo>shenyu-examples-brpc-service</docker.image.tag.repo>
+ <docker.image.tag.tagName>latest</docker.image.tag.tagName>
+ </properties>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>${docker-maven-plugin.version}</version>
+ <configuration>
+ <images>
+ <image>
+ <name>shenyu-examples-brpc-service</name>
+ <build>
+ <contextDir>${project.basedir}</contextDir>
+ </build>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start</id>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
</project>
diff --git a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/resources/application.yml
index f3a2dfa39..051426ea7 100644
--- a/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/resources/application.yml
+++ b/shenyu-examples/shenyu-examples-brpc/shenyu-examples-brpc-service/src/main/resources/application.yml
@@ -38,7 +38,6 @@ shenyu:
ipAndPort: brpc
appName: brpc
port: 8005
- host: 127.0.0.1
# starlight
starlight:
diff --git a/shenyu-integrated-test/pom.xml b/shenyu-integrated-test/pom.xml
index 9cdc7a13e..8ec9e038f 100644
--- a/shenyu-integrated-test/pom.xml
+++ b/shenyu-integrated-test/pom.xml
@@ -38,6 +38,7 @@
<module>shenyu-integrated-test-grpc</module>
<module>shenyu-integrated-test-motan</module>
<module>shenyu-integrated-test-sofa</module>
+ <module>shenyu-integrated-test-brpc</module>
<module>shenyu-integrated-test-websocket</module>
<module>shenyu-integrated-test-combination</module>
<module>shenyu-integrated-test-sdk-apache-dubbo</module>
diff --git a/shenyu-examples/shenyu-examples-brpc/Dockerfile b/shenyu-integrated-test/shenyu-integrated-test-brpc/Dockerfile
similarity index 94%
copy from shenyu-examples/shenyu-examples-brpc/Dockerfile
copy to shenyu-integrated-test/shenyu-integrated-test-brpc/Dockerfile
index ac04a788b..5ecad2f32 100644
--- a/shenyu-examples/shenyu-examples-brpc/Dockerfile
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/Dockerfile
@@ -16,7 +16,7 @@
FROM openjdk:8-jre-alpine
-ENV APP_NAME shenyu-examples-brpc
+ENV APP_NAME shenyu-integrated-test-brpc
ENV LOCAL_PATH /opt/${APP_NAME}
RUN mkdir -p ${LOCAL_PATH}
@@ -24,6 +24,6 @@ RUN mkdir -p ${LOCAL_PATH}
ADD target/${APP_NAME}.jar ${LOCAL_PATH}
WORKDIR ${LOCAL_PATH}
-EXPOSE 8005
+EXPOSE 9195
CMD java -jar ${APP_NAME}.jar
diff --git a/shenyu-integrated-test/shenyu-integrated-test-brpc/docker-compose.yml b/shenyu-integrated-test/shenyu-integrated-test-brpc/docker-compose.yml
new file mode 100644
index 000000000..e0d8cdead
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/docker-compose.yml
@@ -0,0 +1,84 @@
+# Licensed to the 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. The 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. 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.
+version: "3.9"
+services:
+ shenyu-admin:
+ image: apache/shenyu-admin:latest
+ container_name: shenyu-admin
+ restart: always
+ networks:
+ - shenyu
+ ports:
+ - "9095:9095"
+ environment:
+ - SPRING_PROFILES_ACTIVE=h2
+ - shenyu.database.init_script=sql-script/h2/schema.sql
+ healthcheck:
+ test: ["CMD-SHELL", "wget -q -O - http://shenyu-admin:9095/actuator/health | grep UP || exit 1"]
+ timeout: 2s
+ retries: 30
+ start_period: 5s
+
+ shenyu-examples-brpc-service:
+ deploy:
+ resources:
+ limits:
+ memory: 2048M
+ container_name: shenyu-examples-brpc-service
+ image: shenyu-examples-brpc-service:latest
+ restart: always
+ environment:
+ - shenyu.register.serverLists=http://shenyu-admin:9095
+ healthcheck:
+ test: [ "CMD-SHELL", "wget -q -O - http://localhost:8011/actuator/health | grep UP || exit 1" ]
+ timeout: 2s
+ retries: 3
+ start_period: 5s
+ ports:
+ - "8011:8011"
+ - "8005:8005"
+ networks:
+ - shenyu
+ depends_on:
+ shenyu-integrated-test-brpc:
+ condition: service_healthy
+
+ shenyu-integrated-test-brpc:
+ container_name: shenyu-integrated-test-brpc
+ image: apache/shenyu-integrated-test-brpc:latest
+ restart: always
+ deploy:
+ resources:
+ limits:
+ memory: 2048M
+ environment:
+ - shenyu.sync.websocket.urls=ws://shenyu-admin:9095/websocket
+ depends_on:
+ shenyu-admin:
+ condition: service_healthy
+ ports:
+ - "9195:9195"
+ healthcheck:
+ test: [ "CMD", "wget", "-q", "-O", "-", "http://shenyu-integrated-test-brpc:9195/actuator/health" ]
+ timeout: 2s
+ retries: 3
+ start_period: 5s
+ networks:
+ - shenyu
+
+networks:
+ shenyu:
+ name: shenyu
diff --git a/shenyu-integrated-test/shenyu-integrated-test-brpc/pom.xml b/shenyu-integrated-test/shenyu-integrated-test-brpc/pom.xml
new file mode 100644
index 000000000..9f18b6cfc
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/pom.xml
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the 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.
+ ~ The 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. 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="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>shenyu-integrated-test</artifactId>
+ <groupId>org.apache.shenyu</groupId>
+ <version>${shenyu.version}</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>shenyu-integrated-test-brpc</artifactId>
+
+ <properties>
+ <maven.compiler.source>8</maven.compiler.source>
+ <maven.compiler.target>8</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-brpc</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-integrated-test-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>it</id>
+ <properties>
+ <docker.buildArg.APP_NAME>shenyu-integrated-test-brpc</docker.buildArg.APP_NAME>
+ <docker.image.tag.repo>apache/shenyu-integrated-test-brpc</docker.image.tag.repo>
+ <docker.image.tag.tagName>latest</docker.image.tag.tagName>
+ </properties>
+ <build>
+ <finalName>shenyu-integrated-test-brpc</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot.version}</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.apache.shenyu.integrated.test.brpc.BrpcIntegratedBootstrap</mainClass>
+ <executable>true</executable>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>${docker-maven-plugin.version}</version>
+ <configuration>
+ <images>
+ <image>
+ <name>apache/shenyu-integrated-test-brpc</name>
+ <build>
+ <contextDir>${project.basedir}</contextDir>
+ </build>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start</id>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skipTests>false</skipTests>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
\ No newline at end of file
diff --git a/shenyu-integrated-test/shenyu-integrated-test-brpc/script/healthcheck.sh b/shenyu-integrated-test/shenyu-integrated-test-brpc/script/healthcheck.sh
new file mode 100644
index 000000000..22a76034a
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/script/healthcheck.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Licensed to the 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.
+# The 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. 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.
+#
+
+PRGDIR=`dirname "$0"`
+for service in `grep -v -E "^$|^#" ${PRGDIR}/services.list`
+do
+ for loop in `seq 1 30`
+ do
+ status=`curl -o /dev/null -s -w %{http_code} $service`
+ echo -e "curl $service response $status"
+
+ if [ $status -eq 200 ]; then
+ break
+ fi
+
+ sleep 2
+ done
+done
+
+sleep 3
+echo -e "\n-------------------"
diff --git a/shenyu-examples/shenyu-examples-brpc/Dockerfile b/shenyu-integrated-test/shenyu-integrated-test-brpc/script/services.list
similarity index 77%
rename from shenyu-examples/shenyu-examples-brpc/Dockerfile
rename to shenyu-integrated-test/shenyu-integrated-test-brpc/script/services.list
index ac04a788b..c65735d7c 100644
--- a/shenyu-examples/shenyu-examples-brpc/Dockerfile
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/script/services.list
@@ -14,16 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-FROM openjdk:8-jre-alpine
-
-ENV APP_NAME shenyu-examples-brpc
-ENV LOCAL_PATH /opt/${APP_NAME}
-
-RUN mkdir -p ${LOCAL_PATH}
-
-ADD target/${APP_NAME}.jar ${LOCAL_PATH}
-
-WORKDIR ${LOCAL_PATH}
-EXPOSE 8005
-
-CMD java -jar ${APP_NAME}.jar
+http://localhost:9095/actuator/health
+http://localhost:9195/actuator/health
+http://localhost:8011/actuator/health
diff --git a/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/java/org/apache/shenyu/integrated/test/brpc/BrpcIntegratedBootstrap.java b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/java/org/apache/shenyu/integrated/test/brpc/BrpcIntegratedBootstrap.java
new file mode 100644
index 000000000..d10b48a60
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/java/org/apache/shenyu/integrated/test/brpc/BrpcIntegratedBootstrap.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the 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.
+ * The 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. 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.apache.shenyu.integrated.test.brpc;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class BrpcIntegratedBootstrap {
+
+ /**
+ * main mathod of app.
+ *
+ * @param args args
+ */
+ public static void main(final String[] args) {
+ SpringApplication.run(BrpcIntegratedBootstrap.class);
+ }
+}
diff --git a/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/resources/application-local.yml b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/resources/application-local.yml
new file mode 100644
index 000000000..8c4167785
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/resources/application-local.yml
@@ -0,0 +1,59 @@
+# Licensed to the 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.
+# The 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. 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: 9195
+ address: 0.0.0.0
+
+spring:
+ main:
+ allow-bean-definition-overriding: true
+ application:
+ name: shenyu-bootstrap
+
+management:
+ health:
+ defaults:
+ enabled: false
+
+shenyu:
+ switchConfig:
+ local: true
+ cross:
+ enabled: true
+ sync:
+ websocket:
+ urls: ws://localhost:9095/websocket
+ allowOrigin: ws://localhost:9195
+ exclude:
+ enabled: true
+ paths:
+ - /favicon.ico
+ - /actuator/health
+ local:
+ enabled: true
+ sha512Key: "BA3253876AED6BC22D4A6FF53D8406C6AD864195ED144AB5C87621B6C233B548BAEAE6956DF346EC8C17F5EA10F35EE3CBC514797ED7DDD3145464E2A0BAB413"
+ sharedPool:
+ enable: true
+
+logging:
+ level:
+ root: info
+ org.springframework.boot: info
+ org.apache.ibatis: info
+ org.apache.shenyu.bonuspoint: info
+ org.apache.shenyu.lottery: info
+ org.apache.shenyu: info
+
diff --git a/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/resources/application.yml b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/resources/application.yml
new file mode 100644
index 000000000..393ad24df
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/main/resources/application.yml
@@ -0,0 +1,18 @@
+# Licensed to the 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.
+# The 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. 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.
+
+spring:
+ profiles:
+ active: local
diff --git a/shenyu-integrated-test/shenyu-integrated-test-brpc/src/test/java/org/apache/shenyu/integrated/test/brpc/BrpcPluginTest.java b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/test/java/org/apache/shenyu/integrated/test/brpc/BrpcPluginTest.java
new file mode 100644
index 000000000..1e05e662b
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-brpc/src/test/java/org/apache/shenyu/integrated/test/brpc/BrpcPluginTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the 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.
+ * The 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. 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.apache.shenyu.integrated.test.brpc;
+
+import com.google.gson.reflect.TypeToken;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
+import org.apache.shenyu.integratedtest.common.dto.BrpcTest;
+import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
+import org.hamcrest.Matchers;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class BrpcPluginTest extends AbstractPluginDataInit {
+
+ @BeforeAll
+ public static void setup() throws IOException {
+ String pluginResult = initPlugin(PluginEnum.BRPC.getName(),
+ "{\"corethreads\":0, \"threads\":2147483647, \"queues\":0, \"threadpool\":\"shared\"}");
+ assertThat(pluginResult, Matchers.is("success"));
+ }
+
+ @Test
+ public void testHelloWorld() throws IOException {
+ BrpcTest response = HttpHelper.INSTANCE.getFromGateway("/brpc/getUser?userId=1001", new TypeToken<BrpcTest>() {
+ }.getType());
+ assertThat(response.getUserName(), is("User1"));
+ assertThat(response.getUserId(), is(1001L));
+ }
+}
diff --git a/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/dto/BrpcTest.java b/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/dto/BrpcTest.java
new file mode 100644
index 000000000..cf5b9af15
--- /dev/null
+++ b/shenyu-integrated-test/shenyu-integrated-test-common/src/main/java/org/apache/shenyu/integratedtest/common/dto/BrpcTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the 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.
+ * The 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. 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.apache.shenyu.integratedtest.common.dto;
+
+import java.util.List;
+
+public class BrpcTest {
+
+ private long userId;
+
+ private String userName;
+
+ private double balance;
+
+ private List<String> tags;
+
+ public BrpcTest() {
+
+ }
+
+ /**
+ * get user id.
+ *
+ * @return user id
+ */
+ public long getUserId() {
+ return userId;
+ }
+
+ /**
+ * set user id.
+ *
+ * @param userId user id
+ */
+ public void setUserId(final long userId) {
+ this.userId = userId;
+ }
+
+ /**
+ * get user name.
+ *
+ * @return user name
+ */
+ public String getUserName() {
+ return userName;
+ }
+
+ /**
+ * set user name.
+ *
+ * @param userName user name
+ */
+ public void setUserName(final String userName) {
+ this.userName = userName;
+ }
+
+ /**
+ * get balance.
+ *
+ * @return balance.
+ */
+ public double getBalance() {
+ return balance;
+ }
+
+ /**
+ * set balance.
+ *
+ * @param balance balance
+ */
+ public void setBalance(final double balance) {
+ this.balance = balance;
+ }
+
+ /**
+ * get tag list.
+ *
+ * @return list of tag
+ */
+ public List<String> getTags() {
+ return tags;
+ }
+
+ /**
+ * set tag list.
+ *
+ * @param tags tags
+ */
+ public void setTags(final List<String> tags) {
+ this.tags = tags;
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCache.java b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCache.java
index e130fff42..242b9e1a3 100644
--- a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCache.java
+++ b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCache.java
@@ -26,7 +26,9 @@ import com.baidu.cloud.starlight.core.rpc.proxy.JDKProxyFactory;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
+import com.google.common.cache.RemovalListener;
import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.MetaData;
@@ -40,6 +42,7 @@ import org.springframework.lang.NonNull;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
@@ -58,16 +61,29 @@ public final class ApplicationConfigCache {
private static final Logger LOG = LoggerFactory.getLogger(ApplicationConfigCache.class);
- private StarlightClient clientConfig;
+ private static final ConcurrentMap<ServiceConfig, AsyncGenericService> PROXY_CACHE = new ConcurrentHashMap<>();
+
+ private static final ConcurrentMap<ServiceConfig, StarlightClient> CLIENT_CACHE = new ConcurrentHashMap<>();
private JDKProxyFactory proxyFactory;
- private final LoadingCache<String, AsyncGenericService> cache = CacheBuilder.newBuilder()
+ private final LoadingCache<String, ServiceConfig> cache = CacheBuilder.newBuilder()
.maximumSize(Constants.CACHE_MAX_COUNT)
- .build(new CacheLoader<String, AsyncGenericService>() {
+ .removalListener((RemovalListener<Object, ServiceConfig>) notification -> {
+ ServiceConfig config = notification.getValue();
+ if (Objects.nonNull(config)) {
+ // After the configuration change, destroys the instance, but does not empty it.
+ // If it is not handled, it will get NULL when reinitializing and cause a NULL pointer problem.
+ PROXY_CACHE.remove(config);
+ Optional.ofNullable(CLIENT_CACHE.get(config))
+ .ifPresent(StarlightClient::destroy);
+ CLIENT_CACHE.remove(config);
+ }
+ })
+ .build(new CacheLoader<String, ServiceConfig>() {
@Override
- public AsyncGenericService load(@NonNull final String key) {
- return null;
+ public ServiceConfig load(@NonNull final String key) {
+ return new ServiceConfig();
}
});
@@ -75,16 +91,44 @@ public final class ApplicationConfigCache {
}
/**
- * init service.
+ * build service.
*
+ * @param serviceConfig the service config
* @param metaData the meta data
* @return service
*/
- public AsyncGenericService initService(final MetaData metaData) {
+ public AsyncGenericService buildService(final ServiceConfig serviceConfig,
+ final MetaData metaData) {
+ AsyncGenericService service = PROXY_CACHE.get(serviceConfig);
+ if (Objects.nonNull(service)) {
+ return service;
+ }
+ if (Objects.isNull(proxyFactory)) {
+ proxyFactory = new JDKProxyFactory();
+ }
+ StarlightClient client = CLIENT_CACHE.get(serviceConfig);
+ if (Objects.isNull(client)) {
+ BrpcParamExtInfo brpcParamExtInfo = GsonUtils.getInstance().fromJson(metaData.getRpcExt(), BrpcParamExtInfo.class);
+ client = new SingleStarlightClient(brpcParamExtInfo.getHost(), brpcParamExtInfo.getPort(), new TransportConfig());
+ client.init();
+ CLIENT_CACHE.put(serviceConfig, client);
+ }
+ service = proxyFactory.getProxy(AsyncGenericService.class, serviceConfig, client);
+ PROXY_CACHE.put(serviceConfig, service);
+ return service;
+ }
+
+ /**
+ * init service.
+ *
+ * @param metaData the meta data
+ * @return service config
+ */
+ public ServiceConfig initRef(final MetaData metaData) {
try {
- AsyncGenericService service = cache.get(metaData.getPath());
- if (Objects.nonNull(service)) {
- return service;
+ ServiceConfig serviceConfig = cache.get(metaData.getPath());
+ if (StringUtils.isNotBlank(serviceConfig.getServiceId())) {
+ return serviceConfig;
}
} catch (Exception e) {
LOG.warn("init brpc ref ex:{}", e.getMessage());
@@ -98,24 +142,18 @@ public final class ApplicationConfigCache {
* @param brpcRegisterConfig the config of brpc
*/
public void init(final BrpcRegisterConfig brpcRegisterConfig) {
- if (Objects.isNull(clientConfig)) {
- TransportConfig config = new TransportConfig();
- clientConfig = new SingleStarlightClient(brpcRegisterConfig.getAddress(), brpcRegisterConfig.getPort(), config);
- clientConfig.init();
+ if (Objects.isNull(proxyFactory)) {
proxyFactory = new JDKProxyFactory();
}
}
/**
- * Build service.
+ * Build service config.
*
* @param metaData the meta data
- * @return service
+ * @return service config
*/
- public AsyncGenericService build(final MetaData metaData) {
- if (Objects.isNull(clientConfig)) {
- throw new UnsupportedOperationException("unsupport!!");
- }
+ public ServiceConfig build(final MetaData metaData) {
ServiceConfig serviceConfig = new ServiceConfig();
serviceConfig.setProtocol(BRPC_PROTOCOL);
serviceConfig.setServiceId(metaData.getServiceName());
@@ -139,18 +177,16 @@ public final class ApplicationConfigCache {
}
}
});
- AsyncGenericService service = proxyFactory.getProxy(AsyncGenericService.class, serviceConfig, clientConfig);
- cache.put(metaData.getPath(), service);
- return service;
+ return serviceConfig;
}
/**
- * Get service.
+ * Get service config.
*
* @param path path
- * @return the service
+ * @return the service config
*/
- public AsyncGenericService get(final String path) {
+ public ServiceConfig get(final String path) {
try {
return cache.get(path);
} catch (ExecutionException e) {
@@ -185,15 +221,6 @@ public final class ApplicationConfigCache {
return String.join("_", className, methodName);
}
- /**
- * Gets the client config.
- *
- * @return the client config
- */
- public StarlightClient getClientConfig() {
- return clientConfig;
- }
-
/**
* Gets the proxy factory.
*
@@ -280,6 +307,10 @@ public final class ApplicationConfigCache {
public static class BrpcParamExtInfo {
private List<MethodInfo> methodInfo;
+
+ private String host;
+
+ private Integer port;
/**
* Gets method info.
@@ -298,6 +329,42 @@ public final class ApplicationConfigCache {
public void setMethodInfo(final List<MethodInfo> methodInfo) {
this.methodInfo = methodInfo;
}
+
+ /**
+ * get port.
+ *
+ * @return port
+ */
+ public Integer getPort() {
+ return port;
+ }
+
+ /**
+ * set port.
+ *
+ * @param port port
+ */
+ public void setPort(final Integer port) {
+ this.port = port;
+ }
+
+ /**
+ * get host.
+ *
+ * @return host
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * set host.
+ *
+ * @param host host
+ */
+ public void setHost(final String host) {
+ this.host = host;
+ }
}
/**
diff --git a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/handler/BrpcMetaDataHandler.java b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/handler/BrpcMetaDataHandler.java
index 233097eda..0eafc93b6 100644
--- a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/handler/BrpcMetaDataHandler.java
+++ b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/handler/BrpcMetaDataHandler.java
@@ -43,7 +43,7 @@ public class BrpcMetaDataHandler implements MetaDataHandler {
MetaData exist = META_DATA.get(metaData.getPath());
if (Objects.isNull(exist) || Objects.isNull(ApplicationConfigCache.getInstance().get(exist.getPath()))) {
// The first initialization
- ApplicationConfigCache.getInstance().initService(metaData);
+ ApplicationConfigCache.getInstance().initRef(metaData);
} else {
if (!exist.getServiceName().equals(metaData.getServiceName()) || !exist.getRpcExt().equals(metaData.getRpcExt())) {
// update
diff --git a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java
index e05ddaf0e..7a8b779c7 100644
--- a/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java
+++ b/shenyu-plugin/shenyu-plugin-brpc/src/main/java/org/apache/shenyu/plugin/brpc/proxy/BrpcProxyService.java
@@ -17,7 +17,9 @@
package org.apache.shenyu.plugin.brpc.proxy;
+import com.baidu.cloud.starlight.api.rpc.config.ServiceConfig;
import com.baidu.cloud.starlight.core.rpc.generic.AsyncGenericService;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.common.concurrent.ShenyuThreadFactory;
import org.apache.shenyu.common.concurrent.ShenyuThreadPoolExecutor;
import org.apache.shenyu.common.constant.Constants;
@@ -81,8 +83,8 @@ public class BrpcProxyService {
}
}
initThreadPool();
- CompletableFuture<Object> future = null;
- future = new CompletableFuture<>().supplyAsync(() -> getValue(metaData, params), threadPool);
+ //todo use com.baidu.cloud.starlight.api.rpc.threadpool.ThreadPoolFactory impl it
+ CompletableFuture<Object> future = CompletableFuture.supplyAsync(() -> getValue(metaData, params), threadPool);
return Mono.fromFuture(future.thenApply(ret -> {
if (Objects.isNull(ret)) {
ret = Constants.BRPC_RPC_RESULT_EMPTY;
@@ -95,13 +97,13 @@ public class BrpcProxyService {
private Object getValue(final MetaData metaData, final Object[] params) {
try {
- AsyncGenericService service = ApplicationConfigCache.getInstance().get(metaData.getPath());
- if (Objects.isNull(service)) {
+ ServiceConfig serviceConfig = ApplicationConfigCache.getInstance().get(metaData.getPath());
+ if (StringUtils.isBlank(serviceConfig.getServiceId())) {
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
- service = ApplicationConfigCache.getInstance().initService(metaData);
+ serviceConfig = ApplicationConfigCache.getInstance().initRef(metaData);
}
- Object result = service.$invokeFuture(metaData.getMethodName(), params).get();
- return result;
+ AsyncGenericService service = ApplicationConfigCache.getInstance().buildService(serviceConfig, metaData);
+ return service.$invokeFuture(metaData.getMethodName(), params).get();
} catch (Exception e) {
LOG.error("Exception caught in BrpcProxyService#genericInvoker.", e);
return null;
diff --git a/shenyu-plugin/shenyu-plugin-brpc/src/test/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCacheTest.java b/shenyu-plugin/shenyu-plugin-brpc/src/test/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCacheTest.java
index 894272dfa..5cde44667 100644
--- a/shenyu-plugin/shenyu-plugin-brpc/src/test/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCacheTest.java
+++ b/shenyu-plugin/shenyu-plugin-brpc/src/test/java/org/apache/shenyu/plugin/brpc/cache/ApplicationConfigCacheTest.java
@@ -18,9 +18,6 @@
package org.apache.shenyu.plugin.brpc.cache;
import org.apache.commons.lang3.tuple.Pair;
-import org.apache.shenyu.common.dto.PluginData;
-import org.apache.shenyu.common.dto.convert.plugin.BrpcRegisterConfig;
-import org.apache.shenyu.common.utils.GsonUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -82,20 +79,4 @@ public final class ApplicationConfigCacheTest {
paramExtInfo.setMethodInfo(list);
Assertions.assertEquals(paramExtInfo.getMethodInfo().get(0).getMethodName(), "methodName");
}
-
- @Test
- public void testApplicationConfigCache() {
- ApplicationConfigCache applicationConfigCache = ApplicationConfigCache.getInstance();
- Assertions.assertEquals(applicationConfigCache.getInstance().getClass(), ApplicationConfigCache.class);
- PluginData pluginData = new PluginData();
- pluginData.setEnabled(true);
- pluginData.setConfig("{\"address\" : \"127.0.0.1\", \"port\" : \"8005\"}");
- BrpcRegisterConfig registerConfig = GsonUtils.getInstance().fromJson(pluginData.getConfig(), BrpcRegisterConfig.class);
- applicationConfigCache.init(registerConfig);
- Assertions.assertNotNull(applicationConfigCache.getClientConfig());
- Assertions.assertNotNull(applicationConfigCache.getProxyFactory());
- Assertions.assertTrue(applicationConfigCache.getClientConfig().isActive());
- applicationConfigCache.getClientConfig().destroy();
- Assertions.assertFalse(applicationConfigCache.getClientConfig().isActive());
- }
}