From 19cb9820d9defa612bb0c84ae82a7cc5b34ea3e6 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 17:33:12 +0800 Subject: [PATCH 01/32] feat[Future]:compatible java1.8 CompletableFuture --- .../alipay/sofa/rpc/message/AbstractResponseFuture.java | 6 +++--- .../java/com/alipay/sofa/rpc/message/ResponseFuture.java | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index afa3bf51d..6ce912747 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -27,7 +27,7 @@ * @author GengZhang * @since 5.4.0 */ -public abstract class AbstractResponseFuture implements ResponseFuture { +public abstract class AbstractResponseFuture extends ResponseFuture { protected static final CancellationException CANCELLATION_CAUSE = new CancellationException(); @@ -97,7 +97,7 @@ protected TimeoutException clientTimeoutException() { /** * 解析结果,拿到返回值 - * + * * @return do return self * @throws ExecutionException 执行异常 */ @@ -111,7 +111,7 @@ protected TimeoutException clientTimeoutException() { protected abstract void releaseIfNeed(Object result); protected boolean await(long timeout, TimeUnit unit) - throws InterruptedException { + throws InterruptedException { return await0(unit.toNanos(timeout), true); } diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java index 54ed2953d..df93b4835 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java @@ -19,6 +19,7 @@ import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; /** @@ -26,7 +27,7 @@ * * @author GengZhang */ -public interface ResponseFuture extends Future { +public abstract class ResponseFuture extends CompletableFuture { /** * 增加多个响应监听器 @@ -34,7 +35,7 @@ public interface ResponseFuture extends Future { * @param sofaResponseCallbacks 多个响应监听器 * @return 对象本身 */ - ResponseFuture addListeners(List sofaResponseCallbacks); + public abstract ResponseFuture addListeners(List sofaResponseCallbacks); /** * 增加单个响应监听器 @@ -42,6 +43,6 @@ public interface ResponseFuture extends Future { * @param sofaResponseCallback 多个响应监听器 * @return 对象本身 */ - ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); + public abstract ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); } From f5eb764ae3a2588d9c311c0a3b604cbb01270d8e Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 17:45:57 +0800 Subject: [PATCH 02/32] feat[Future]:compatible java1.8 CompletableFuture --- .../sofa/rpc/message/AbstractResponseFuture.java | 14 +++++++------- .../alipay/sofa/rpc/message/ResponseFuture.java | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index 6ce912747..301402aef 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -34,29 +34,29 @@ public abstract class AbstractResponseFuture extends ResponseFuture { /** * 返回的结果 */ - protected volatile Object result; + protected volatile Object result; /** * 异常 */ - protected volatile Throwable cause; + protected volatile Throwable cause; /** * 用户设置的超时时间 */ - protected final int timeout; + protected final int timeout; /** * Future生成时间 */ - protected final long genTime = RpcRuntimeContext.now(); + protected final long genTime = RpcRuntimeContext.now(); /** * Future已发送时间 */ - protected volatile long sentTime; + protected volatile long sentTime; /** * Future完成的时间 */ - protected volatile long doneTime; + protected volatile long doneTime; /** * 构造函数 @@ -135,7 +135,7 @@ private boolean await0(long timeoutNanos, boolean interruptable) throws Interrup } incWaiters(); try { - for (;;) { + for (; ; ) { try { wait(waitTime / 1000000, (int) (waitTime % 1000000)); } catch (InterruptedException e) { diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java index df93b4835..640f61c6c 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; /** * 响应Future,可以调用get方法进行获取响应,也可以注入监听器,有结果或者都会通知 From 682ac4005431eadc4ad1fc8f435800b375b8d590 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 17:50:14 +0800 Subject: [PATCH 03/32] feat[Future]:compatible java1.8 CompletableFuture --- .../main/java/com/alipay/sofa/rpc/message/ResponseFuture.java | 4 ++-- .../com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java index 640f61c6c..fde5cfccd 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java @@ -34,7 +34,7 @@ public abstract class ResponseFuture extends CompletableFuture { * @param sofaResponseCallbacks 多个响应监听器 * @return 对象本身 */ - public abstract ResponseFuture addListeners(List sofaResponseCallbacks); + public abstract ResponseFuture addListeners(List sofaResponseCallbacks); /** * 增加单个响应监听器 @@ -42,6 +42,6 @@ public abstract class ResponseFuture extends CompletableFuture { * @param sofaResponseCallback 多个响应监听器 * @return 对象本身 */ - public abstract ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); + public abstract ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); } diff --git a/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java b/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java index ebac6d72a..335949c1b 100644 --- a/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java +++ b/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java @@ -31,7 +31,7 @@ * * @author ScienJus */ -public class HystrixResponseFuture implements ResponseFuture { +public class HystrixResponseFuture extends ResponseFuture { private Future delegate; From 6fe8c4a8429cf878b44c0343a4793da022d0c432 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 18:31:41 +0800 Subject: [PATCH 04/32] feat[Future]:compatible java1.8 CompletableFuture --- .../main/java/com/alipay/sofa/rpc/message/ResponseFuture.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java index fde5cfccd..640f61c6c 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java @@ -34,7 +34,7 @@ public abstract class ResponseFuture extends CompletableFuture { * @param sofaResponseCallbacks 多个响应监听器 * @return 对象本身 */ - public abstract ResponseFuture addListeners(List sofaResponseCallbacks); + public abstract ResponseFuture addListeners(List sofaResponseCallbacks); /** * 增加单个响应监听器 @@ -42,6 +42,6 @@ public abstract class ResponseFuture extends CompletableFuture { * @param sofaResponseCallback 多个响应监听器 * @return 对象本身 */ - public abstract ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); + public abstract ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); } From 964db3c2fcc11abacb8e40bc8adbebf4add19629 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 19:01:41 +0800 Subject: [PATCH 05/32] feat[Future]:compatible java1.8 CompletableFuture --- .../com/alipay/sofa/rpc/message/AbstractResponseFuture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index 301402aef..a3255484e 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -27,7 +27,7 @@ * @author GengZhang * @since 5.4.0 */ -public abstract class AbstractResponseFuture extends ResponseFuture { +public abstract class AbstractResponseFuture extends ResponseFuture { protected static final CancellationException CANCELLATION_CAUSE = new CancellationException(); From 7badd318d2edc53ded7ed851f6cb9f0e945a1f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=85=E5=B3=B0=E5=A4=A7=E9=B8=A1=E8=85=BF?= <839737769@qq.com> Date: Tue, 4 Apr 2023 19:29:24 +0800 Subject: [PATCH 06/32] Update maven.yml --- .github/workflows/maven.yml | 57 +++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 53b1d6e2f..1ede2b121 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,32 +1,45 @@ -# This workflow will build a Java project with Maven +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name: build +name:build + on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - # enable manually running the workflow workflow_dispatch: + jobs: build: - runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: ./mvnw clean install -Pci-install -B -U -e && bash ./tools/check_format.sh - - name: Test with Maven - run: ./mvnw package -Pci-test - - name: Codecov - uses: codecov/codecov-action@v1 - + - uses: actions/checkout@v3 + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn clean install -Pci-install -B -U -e && bash ./tools/check_format.sh + release: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: maven + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import + gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase + - name: Build with Maven + run: mvn --batch-mode deploy -DskipTests -Prelease + env: + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} From e1d0a9b1d4c58ffd3af39ca22f39b616e6bcf2db Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 22:13:37 +0800 Subject: [PATCH 07/32] =?UTF-8?q?feat[Future]:=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sofa/rpc/message/AbstractResponseFuture.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index a3255484e..81d480925 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -34,29 +34,29 @@ public abstract class AbstractResponseFuture extends ResponseFuture { /** * 返回的结果 */ - protected volatile Object result; + protected volatile Object result; /** * 异常 */ - protected volatile Throwable cause; + protected volatile Throwable cause; /** * 用户设置的超时时间 */ - protected final int timeout; + protected final int timeout; /** * Future生成时间 */ - protected final long genTime = RpcRuntimeContext.now(); + protected final long genTime = RpcRuntimeContext.now(); /** * Future已发送时间 */ - protected volatile long sentTime; + protected volatile long sentTime; /** * Future完成的时间 */ - protected volatile long doneTime; + protected volatile long doneTime; /** * 构造函数 @@ -111,7 +111,7 @@ protected TimeoutException clientTimeoutException() { protected abstract void releaseIfNeed(Object result); protected boolean await(long timeout, TimeUnit unit) - throws InterruptedException { + throws InterruptedException { return await0(unit.toNanos(timeout), true); } @@ -135,7 +135,7 @@ private boolean await0(long timeoutNanos, boolean interruptable) throws Interrup } incWaiters(); try { - for (; ; ) { + for (;;) { try { wait(waitTime / 1000000, (int) (waitTime % 1000000)); } catch (InterruptedException e) { From b7944a22fdfb498cda13a1f4631976292a46a774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=85=E5=B3=B0=E5=A4=A7=E9=B8=A1=E8=85=BF?= <839737769@qq.com> Date: Tue, 4 Apr 2023 22:19:39 +0800 Subject: [PATCH 08/32] Update maven.yml --- .github/workflows/maven.yml | 56 ++++++++++++++----------------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1ede2b121..2aa391963 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,45 +1,31 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# This workflow will build a Java project with Maven # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven -name:build - +name: build on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + # enable manually running the workflow workflow_dispatch: - jobs: build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn clean install -Pci-install -B -U -e && bash ./tools/check_format.sh - release: - needs: build runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v3 - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: '8' - distribution: 'temurin' - cache: maven - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import - gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase - - name: Build with Maven - run: mvn --batch-mode deploy -DskipTests -Prelease - env: - MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: ./mvnw clean install -Pci-install -B -U -e && bash ./tools/check_format.sh + - name: Test with Maven + run: ./mvnw package -Pci-test + - name: Codecov + uses: codecov/codecov-action@v1 From 87311b356e25cfa81f5f53f880908a9a110a689f Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 22:27:34 +0800 Subject: [PATCH 09/32] =?UTF-8?q?feat[Future]:=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/rpc/message/AbstractResponseFuture.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index 81d480925..3b26cea43 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -27,7 +27,7 @@ * @author GengZhang * @since 5.4.0 */ -public abstract class AbstractResponseFuture extends ResponseFuture { +public abstract class AbstractResponseFuture extends ResponseFuture { protected static final CancellationException CANCELLATION_CAUSE = new CancellationException(); @@ -111,7 +111,7 @@ protected TimeoutException clientTimeoutException() { protected abstract void releaseIfNeed(Object result); protected boolean await(long timeout, TimeUnit unit) - throws InterruptedException { + throws InterruptedException { return await0(unit.toNanos(timeout), true); } @@ -316,4 +316,4 @@ protected void setDoneTime() { public long getElapsedTime() { return doneTime - genTime; } -} +} \ No newline at end of file From 8c06b4e158b318f477d74a7a78eecbaf0e925574 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 22:43:21 +0800 Subject: [PATCH 10/32] =?UTF-8?q?feat[Future]:=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/rpc/message/AbstractResponseFuture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index 3b26cea43..aa751a08e 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -111,7 +111,7 @@ protected TimeoutException clientTimeoutException() { protected abstract void releaseIfNeed(Object result); protected boolean await(long timeout, TimeUnit unit) - throws InterruptedException { + throws InterruptedException { return await0(unit.toNanos(timeout), true); } From aa9a1be5ce4bb03172c61c5e416a3a1b368edf08 Mon Sep 17 00:00:00 2001 From: yangsen Date: Tue, 4 Apr 2023 23:39:41 +0800 Subject: [PATCH 11/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9E=E6=B5=8B?= =?UTF-8?q?=E8=AF=95demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java index 373103e43..000f6ec2d 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java @@ -91,6 +91,11 @@ public void testAll() { // 链路异步化调用--正常 RpcInvokeContext.getContext().setResponseCallback(buildCallback(ret, latch)); + + RpcInvokeContext.getContext().getFuture().thenAccept(req->{ + LOGGER.info("CompletableFuture result: {}", req); + }); + String ret0 = asyncHelloService.sayHello("xxx", 22); Assert.assertNull(ret0); // 第一次返回null try { From f8250df2d1088737b1e8975d539f858dec1ad931 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 5 Apr 2023 00:53:07 +0800 Subject: [PATCH 12/32] =?UTF-8?q?feat[Future]:=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2aa391963..fa4525e83 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -28,4 +28,4 @@ jobs: - name: Test with Maven run: ./mvnw package -Pci-test - name: Codecov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v1 \ No newline at end of file From 0a1b40755a05d02483ee6f9751038001c8498508 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 5 Apr 2023 21:44:46 +0800 Subject: [PATCH 13/32] =?UTF-8?q?feat[Future]:=E5=9B=9E=E6=BB=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java index 000f6ec2d..4797ae4dc 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java @@ -92,9 +92,9 @@ public void testAll() { // 链路异步化调用--正常 RpcInvokeContext.getContext().setResponseCallback(buildCallback(ret, latch)); - RpcInvokeContext.getContext().getFuture().thenAccept(req->{ + /*RpcInvokeContext.getContext().getFuture().thenAccept(req->{ LOGGER.info("CompletableFuture result: {}", req); - }); + });*/ String ret0 = asyncHelloService.sayHello("xxx", 22); Assert.assertNull(ret0); // 第一次返回null From 4d13a3e5da1fe2138689ac3ec279266954508b38 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 5 Apr 2023 22:18:46 +0800 Subject: [PATCH 14/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9E=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java index 4797ae4dc..000f6ec2d 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java @@ -92,9 +92,9 @@ public void testAll() { // 链路异步化调用--正常 RpcInvokeContext.getContext().setResponseCallback(buildCallback(ret, latch)); - /*RpcInvokeContext.getContext().getFuture().thenAccept(req->{ + RpcInvokeContext.getContext().getFuture().thenAccept(req->{ LOGGER.info("CompletableFuture result: {}", req); - });*/ + }); String ret0 = asyncHelloService.sayHello("xxx", 22); Assert.assertNull(ret0); // 第一次返回null From 34c4c092a5d1b606ba78f09b055d16a3c03255f6 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 5 Apr 2023 22:37:36 +0800 Subject: [PATCH 15/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9E=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/rpc/test/async/AsyncChainTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java index 000f6ec2d..d28a5eac0 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java @@ -92,9 +92,13 @@ public void testAll() { // 链路异步化调用--正常 RpcInvokeContext.getContext().setResponseCallback(buildCallback(ret, latch)); - RpcInvokeContext.getContext().getFuture().thenAccept(req->{ - LOGGER.info("CompletableFuture result: {}", req); - }); + try { + RpcInvokeContext.getContext().getFuture().thenAccept(req->{ + LOGGER.info("CompletableFuture result: {}", req); + }); + }catch (Exception e){ + LOGGER.error("CompletableFuture error: {}", e); + } String ret0 = asyncHelloService.sayHello("xxx", 22); Assert.assertNull(ret0); // 第一次返回null From adf85aab61526791ac878deb769fd60158fc2a7e Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 5 Apr 2023 22:57:58 +0800 Subject: [PATCH 16/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9E=E5=8D=95?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/rpc/test/async/AsyncChainTest.java | 8 -------- .../rpc/transport/http/Http2ClearTextHessianTest.java | 4 ++++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java index d28a5eac0..7da4126dc 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/async/AsyncChainTest.java @@ -92,14 +92,6 @@ public void testAll() { // 链路异步化调用--正常 RpcInvokeContext.getContext().setResponseCallback(buildCallback(ret, latch)); - try { - RpcInvokeContext.getContext().getFuture().thenAccept(req->{ - LOGGER.info("CompletableFuture result: {}", req); - }); - }catch (Exception e){ - LOGGER.error("CompletableFuture error: {}", e); - } - String ret0 = asyncHelloService.sayHello("xxx", 22); Assert.assertNull(ret0); // 第一次返回null try { diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java index 667646a9d..f7563e320 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java @@ -116,9 +116,13 @@ public void testHessian() { ResponseFuture future = RpcInvokeContext.getContext().getFuture(); try { response = future.get(); + RpcInvokeContext.getContext().getFuture().thenAccept(req->{ + LOGGER.info("CompletableFuture result: {}", req); + }); Assert.assertEquals(200, response.getId()); Assert.assertEquals("yyyxx", response.getName()); } catch (Exception e) { + LOGGER.error("CompletableFuture error: {}", e); e.printStackTrace(); Assert.fail(); } From f7cda08c6648bd25f502eed0e54786e3475b258e Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 6 Apr 2023 00:37:44 +0800 Subject: [PATCH 17/32] feat[Future]:files end with a newline --- .github/workflows/maven.yml | 2 +- .../com/alipay/sofa/rpc/message/AbstractResponseFuture.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fa4525e83..2aa391963 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -28,4 +28,4 @@ jobs: - name: Test with Maven run: ./mvnw package -Pci-test - name: Codecov - uses: codecov/codecov-action@v1 \ No newline at end of file + uses: codecov/codecov-action@v1 diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index aa751a08e..086ae2505 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -316,4 +316,4 @@ protected void setDoneTime() { public long getElapsedTime() { return doneTime - genTime; } -} \ No newline at end of file +} From 8efc6246942aa226d4629463f8bc3760f00cedb7 Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 6 Apr 2023 10:04:04 +0800 Subject: [PATCH 18/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9E=E5=8D=95?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java | 4 ++++ .../sofa/rpc/transport/http/Http2ClearTextHessianTest.java | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java index a3db3527d..1dab4233c 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java @@ -152,6 +152,10 @@ public void testAll() { String ret = helloService.sayHello("xxx", 22); Assert.assertNull(ret); // 第一次返回null + RpcInvokeContext.getContext().getFuture().thenAccept(req->{ + LOGGER.info("RpcInvokeContext CompletableFuture result: {}", req); + }); + Thread.sleep(1500); // 1s 过去,被rpc设置超时了 Future future = SofaResponseFuture.getFuture(); ret = (String) future.get(); diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java index f7563e320..41ff31f9b 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java @@ -116,9 +116,6 @@ public void testHessian() { ResponseFuture future = RpcInvokeContext.getContext().getFuture(); try { response = future.get(); - RpcInvokeContext.getContext().getFuture().thenAccept(req->{ - LOGGER.info("CompletableFuture result: {}", req); - }); Assert.assertEquals(200, response.getId()); Assert.assertEquals("yyyxx", response.getName()); } catch (Exception e) { From 34025eee11c262d09407977be569662acbf78ad0 Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 6 Apr 2023 10:10:29 +0800 Subject: [PATCH 19/32] =?UTF-8?q?feat[Future]:=E6=9C=80=E5=90=8E=E4=B8=80?= =?UTF-8?q?=E8=A1=8C=E6=96=B0=E5=A2=9E=E6=8D=A2=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/maven.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2aa391963..53b1d6e2f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,3 +29,4 @@ jobs: run: ./mvnw package -Pci-test - name: Codecov uses: codecov/codecov-action@v1 + From 255393c22c7bc5751a07668b3c60d290c1ff5550 Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 6 Apr 2023 10:11:16 +0800 Subject: [PATCH 20/32] =?UTF-8?q?feat[Future]:=E5=88=A0=E9=99=A4=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sofa/rpc/transport/http/Http2ClearTextHessianTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java index 41ff31f9b..667646a9d 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java @@ -119,7 +119,6 @@ public void testHessian() { Assert.assertEquals(200, response.getId()); Assert.assertEquals("yyyxx", response.getName()); } catch (Exception e) { - LOGGER.error("CompletableFuture error: {}", e); e.printStackTrace(); Assert.fail(); } From 4452ae12cb954be4cbe1b78d661d539abdefaef1 Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 6 Apr 2023 10:31:15 +0800 Subject: [PATCH 21/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9ELogger?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alipay/sofa/rpc/test/invoke/FutureTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java index 1dab4233c..84464a3e6 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java @@ -25,9 +25,12 @@ import com.alipay.sofa.rpc.context.RpcInvokeContext; import com.alipay.sofa.rpc.core.exception.SofaRpcException; import com.alipay.sofa.rpc.filter.Filter; +import com.alipay.sofa.rpc.log.Logger; +import com.alipay.sofa.rpc.log.LoggerFactory; import com.alipay.sofa.rpc.test.ActivelyDestroyTest; import com.alipay.sofa.rpc.test.HelloService; import com.alipay.sofa.rpc.test.HelloServiceImpl; +import com.alipay.sofa.rpc.triple.TripleHessianInvokeTest; import org.junit.Assert; import org.junit.Test; @@ -44,6 +47,8 @@ */ public class FutureTest extends ActivelyDestroyTest { + private static final Logger LOGGER = LoggerFactory.getLogger(ActivelyDestroyTest.class); + @Test public void testAll() { From 945693292b6aaf20d793f162cc96dd84da9a2cbe Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 6 Apr 2023 10:48:48 +0800 Subject: [PATCH 22/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9ELogger?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java index 84464a3e6..7d0abedb3 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java @@ -47,7 +47,7 @@ */ public class FutureTest extends ActivelyDestroyTest { - private static final Logger LOGGER = LoggerFactory.getLogger(ActivelyDestroyTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(FutureTest.class); @Test public void testAll() { From 63478bc5d617a3e4258d46f4c9b2e255e5f81521 Mon Sep 17 00:00:00 2001 From: yangsen Date: Thu, 6 Apr 2023 11:17:42 +0800 Subject: [PATCH 23/32] =?UTF-8?q?feat[Future]:=E6=96=B0=E5=A2=9EHttp2Clear?= =?UTF-8?q?TextHessianTest=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/alipay/sofa/rpc/test/invoke/FutureTest.java | 2 +- .../sofa/rpc/transport/http/Http2ClearTextHessianTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java index 7d0abedb3..09f9217ee 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/test/invoke/FutureTest.java @@ -158,7 +158,7 @@ public void testAll() { Assert.assertNull(ret); // 第一次返回null RpcInvokeContext.getContext().getFuture().thenAccept(req->{ - LOGGER.info("RpcInvokeContext CompletableFuture result: {}", req); + LOGGER.info("FutureTest RpcInvokeContext CompletableFuture result: {}", req); }); Thread.sleep(1500); // 1s 过去,被rpc设置超时了 diff --git a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java index 667646a9d..b1b68a2db 100644 --- a/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java +++ b/test/test-integration/src/test/java/com/alipay/sofa/rpc/transport/http/Http2ClearTextHessianTest.java @@ -25,6 +25,8 @@ import com.alipay.sofa.rpc.core.exception.SofaRpcException; import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback; import com.alipay.sofa.rpc.core.request.RequestBase; +import com.alipay.sofa.rpc.log.Logger; +import com.alipay.sofa.rpc.log.LoggerFactory; import com.alipay.sofa.rpc.message.ResponseFuture; import com.alipay.sofa.rpc.server.bolt.pb.EchoRequest; import com.alipay.sofa.rpc.server.bolt.pb.Group; @@ -43,6 +45,8 @@ */ public class Http2ClearTextHessianTest extends ActivelyDestroyTest { + private static final Logger LOGGER = LoggerFactory.getLogger(Http2ClearTextHessianTest.class); + @Test public void testHessian() { // 只有1个线程 执行 @@ -116,6 +120,9 @@ public void testHessian() { ResponseFuture future = RpcInvokeContext.getContext().getFuture(); try { response = future.get(); + RpcInvokeContext.getContext().getFuture().thenAccept(req->{ + LOGGER.info("Http2ClearTextHessianTest CompletableFuture result: {}", req); + }); Assert.assertEquals(200, response.getId()); Assert.assertEquals("yyyxx", response.getName()); } catch (Exception e) { From 57a1ecc17b3353979e96aa04779eb8079b5c79c5 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 12 Apr 2023 11:21:37 +0800 Subject: [PATCH 24/32] =?UTF-8?q?feat[Future]:=E5=9B=9E=E6=BB=9AResponseFu?= =?UTF-8?q?ture=E4=B8=BA=E7=BB=A7=E6=89=BF=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alipay/sofa/rpc/message/AbstractResponseFuture.java | 7 ++----- .../java/com/alipay/sofa/rpc/message/ResponseFuture.java | 9 +++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index 086ae2505..e654a5e86 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -18,16 +18,13 @@ import com.alipay.sofa.rpc.context.RpcRuntimeContext; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.*; /** * @author GengZhang * @since 5.4.0 */ -public abstract class AbstractResponseFuture extends ResponseFuture { +public abstract class AbstractResponseFuture extends CompletableFuture implements ResponseFuture { protected static final CancellationException CANCELLATION_CAUSE = new CancellationException(); diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java index 640f61c6c..c842e239d 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java @@ -19,14 +19,15 @@ import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback; import java.util.List; -import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Future; /** * 响应Future,可以调用get方法进行获取响应,也可以注入监听器,有结果或者都会通知 * * @author GengZhang */ -public abstract class ResponseFuture extends CompletableFuture { +public interface ResponseFuture extends Future, CompletionStage { /** * 增加多个响应监听器 @@ -34,7 +35,7 @@ public abstract class ResponseFuture extends CompletableFuture { * @param sofaResponseCallbacks 多个响应监听器 * @return 对象本身 */ - public abstract ResponseFuture addListeners(List sofaResponseCallbacks); + ResponseFuture addListeners(List sofaResponseCallbacks); /** * 增加单个响应监听器 @@ -42,6 +43,6 @@ public abstract class ResponseFuture extends CompletableFuture { * @param sofaResponseCallback 多个响应监听器 * @return 对象本身 */ - public abstract ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); + ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); } From db141302aa15aba55a310a93306705f4de5ee144 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 12 Apr 2023 11:57:20 +0800 Subject: [PATCH 25/32] =?UTF-8?q?fix[Future]:=E4=BF=AE=E5=A4=8D=E5=8D=95?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rpc/context/RpcInternalContextTest.java | 94 ++++++++++++------- .../aft/InvocationStatDimensionStatTest.java | 91 +++++++++++------- 2 files changed, 117 insertions(+), 68 deletions(-) diff --git a/core/api/src/test/java/com/alipay/sofa/rpc/context/RpcInternalContextTest.java b/core/api/src/test/java/com/alipay/sofa/rpc/context/RpcInternalContextTest.java index a3a77e496..ecf402e1a 100644 --- a/core/api/src/test/java/com/alipay/sofa/rpc/context/RpcInternalContextTest.java +++ b/core/api/src/test/java/com/alipay/sofa/rpc/context/RpcInternalContextTest.java @@ -18,6 +18,7 @@ import com.alipay.sofa.rpc.client.ProviderHelper; import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback; +import com.alipay.sofa.rpc.message.AbstractResponseFuture; import com.alipay.sofa.rpc.message.ResponseFuture; import org.junit.After; import org.junit.Assert; @@ -136,48 +137,69 @@ public void testAttachment() { Assert.assertNull(context.removeAttachment("11")); } - @Test - public void testClear() { - RpcInternalContext context = RpcInternalContext.getContext(); - context.setRemoteAddress("127.0.0.1", 1234); - context.setLocalAddress("127.0.0.1", 2345); - context.setFuture(new ResponseFuture() { - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return false; - } + private static class MyResponseFuture extends AbstractResponseFuture { - @Override - public boolean isCancelled() { - return false; - } + /** + * 构造函数 + * + * @param timeout + */ + public MyResponseFuture(int timeout) { + super(timeout); + } - @Override - public boolean isDone() { - return false; - } + @Override + public ResponseFuture addListeners(List sofaResponseCallbacks) { + return null; + } - @Override - public String get() throws InterruptedException, ExecutionException { - return null; - } + @Override + public ResponseFuture addListener(SofaResponseCallback sofaResponseCallback) { + return null; + } - @Override - public String get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, - TimeoutException { - return null; - } + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } - @Override - public ResponseFuture addListeners(List sofaResponseCallbacks) { - return null; - } + @Override + public boolean isCancelled() { + return false; + } - @Override - public ResponseFuture addListener(SofaResponseCallback sofaResponseCallback) { - return null; - } - }); + @Override + public boolean isDone() { + return false; + } + + @Override + public void notifyListeners() { + + } + + @Override + public String get() throws InterruptedException, ExecutionException { + return null; + } + + @Override + protected String getNow() throws ExecutionException { + return null; + } + + @Override + protected void releaseIfNeed(Object result) { + + } + } + + @Test + public void testClear() { + RpcInternalContext context = RpcInternalContext.getContext(); + context.setRemoteAddress("127.0.0.1", 1234); + context.setLocalAddress("127.0.0.1", 2345); + context.setFuture(new MyResponseFuture(1)); context.setProviderInfo(ProviderHelper.toProviderInfo("127.0.0.1:80")); context.setAttachment("_xxxx", "yyyy"); diff --git a/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java b/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java index 5418f3f87..a58f4580e 100644 --- a/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java +++ b/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java @@ -26,6 +26,7 @@ import com.alipay.sofa.rpc.core.exception.SofaTimeOutException; import com.alipay.sofa.rpc.core.invoke.SofaResponseCallback; import com.alipay.sofa.rpc.core.request.RequestBase; +import com.alipay.sofa.rpc.message.AbstractResponseFuture; import com.alipay.sofa.rpc.message.ResponseFuture; import org.junit.Assert; import org.junit.Before; @@ -231,6 +232,63 @@ public void testRegulationEffective() throws InterruptedException { } + private static class MyResponseFuture extends AbstractResponseFuture { + + /** + * 构造函数 + * + * @param timeout + */ + public MyResponseFuture(int timeout) { + super(timeout); + } + + @Override + public ResponseFuture addListeners(List sofaResponseCallbacks) { + return null; + } + + @Override + public ResponseFuture addListener(SofaResponseCallback sofaResponseCallback) { + return null; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return false; + } + + @Override + public void notifyListeners() { + + } + + @Override + public String get() throws InterruptedException, ExecutionException { + return null; + } + + @Override + protected String getNow() throws ExecutionException { + return null; + } + + @Override + protected void releaseIfNeed(Object result) { + + } + } + private void prepareInvokeContext() { final RpcInvokeContext context = new RpcInvokeContext(); context.setResponseCallback(new SofaResponseCallback() { @@ -238,42 +296,11 @@ private void prepareInvokeContext() { public void onAppResponse(final Object appResponse, String methodName, RequestBase request) { //放到 future 中方便测试. LOGGER.info("回调成功" + appResponse); - context.setFuture(new ResponseFuture() { - @Override - public ResponseFuture addListeners(List sofaResponseCallbacks) { - return null; - } - - @Override - public ResponseFuture addListener(SofaResponseCallback sofaResponseCallback) { - return null; - } - - @Override - public boolean cancel(boolean mayInterruptIfRunning) { - return false; - } - - @Override - public boolean isCancelled() { - return false; - } - - @Override - public boolean isDone() { - return false; - } - + context.setFuture(new MyResponseFuture(1){ @Override public String get() throws InterruptedException, ExecutionException { return (String) appResponse; } - - @Override - public String get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, - TimeoutException { - return null; - } }); } From b85bb7cc694bd68cf8b192707f778b071d0eb2bb Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 12 Apr 2023 12:14:03 +0800 Subject: [PATCH 26/32] =?UTF-8?q?fix[Future]:=E4=BF=AE=E5=A4=8DHystrixResp?= =?UTF-8?q?onseFuture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java b/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java index 335949c1b..7f0abb1ee 100644 --- a/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java +++ b/fault/fault-hystrix/src/main/java/com/alipay/sofa/rpc/hystrix/HystrixResponseFuture.java @@ -21,17 +21,14 @@ import com.netflix.hystrix.HystrixCommand; import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.*; /** * the {@link Future}(from {@link HystrixCommand#queue()}) wrapper that can be used as a {@link ResponseFuture} * * @author ScienJus */ -public class HystrixResponseFuture extends ResponseFuture { +public class HystrixResponseFuture extends CompletableFuture implements ResponseFuture { private Future delegate; From 9c793f55aa44e984624f16440e91973ab677ad6b Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 12 Apr 2023 12:41:03 +0800 Subject: [PATCH 27/32] =?UTF-8?q?fix[Future]:=E4=BF=AE=E5=A4=8DHystrixResp?= =?UTF-8?q?onseFuture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rpc/client/aft/InvocationStatDimensionStatTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java b/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java index a58f4580e..9b641b498 100644 --- a/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java +++ b/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java @@ -278,6 +278,12 @@ public String get() throws InterruptedException, ExecutionException { return null; } + @Override + public String get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, + TimeoutException { + return null; + } + @Override protected String getNow() throws ExecutionException { return null; From 6800b15dda1419b963a237a3775ab3acd6391d38 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 12 Apr 2023 12:43:42 +0800 Subject: [PATCH 28/32] =?UTF-8?q?fix[Future]:=E4=BF=AE=E5=A4=8DHystrixResp?= =?UTF-8?q?onseFuture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sofa/rpc/client/aft/InvocationStatDimensionStatTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java b/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java index 9b641b498..448b18765 100644 --- a/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java +++ b/fault/fault-tolerance/src/test/java/com/alipay/sofa/rpc/client/aft/InvocationStatDimensionStatTest.java @@ -280,7 +280,7 @@ public String get() throws InterruptedException, ExecutionException { @Override public String get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, - TimeoutException { + TimeoutException { return null; } @@ -302,7 +302,7 @@ private void prepareInvokeContext() { public void onAppResponse(final Object appResponse, String methodName, RequestBase request) { //放到 future 中方便测试. LOGGER.info("回调成功" + appResponse); - context.setFuture(new MyResponseFuture(1){ + context.setFuture(new MyResponseFuture(1) { @Override public String get() throws InterruptedException, ExecutionException { return (String) appResponse; From 88602afd65ea3a5e8a945fa7b6af73d4e2c47e68 Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 5 May 2023 10:31:40 +0800 Subject: [PATCH 29/32] =?UTF-8?q?fix[ResponseFuture]:=E5=9B=9E=E9=80=80?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E8=BF=94=E5=9B=9Etype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/alipay/sofa/rpc/message/ResponseFuture.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java index c842e239d..b0fa02d0c 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java @@ -35,7 +35,7 @@ public interface ResponseFuture extends Future, CompletionStage { * @param sofaResponseCallbacks 多个响应监听器 * @return 对象本身 */ - ResponseFuture addListeners(List sofaResponseCallbacks); + ResponseFuture addListeners(List sofaResponseCallbacks); /** * 增加单个响应监听器 @@ -43,6 +43,6 @@ public interface ResponseFuture extends Future, CompletionStage { * @param sofaResponseCallback 多个响应监听器 * @return 对象本身 */ - ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); + ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); } From 593578eb9fdbb99ed3242e1eb377c544edc549b8 Mon Sep 17 00:00:00 2001 From: yangsen Date: Sat, 6 May 2023 14:27:33 +0800 Subject: [PATCH 30/32] =?UTF-8?q?fix[ResponseFuture]:=E5=9B=9E=E6=BB=9A?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/alipay/sofa/rpc/message/ResponseFuture.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java index b0fa02d0c..c842e239d 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/ResponseFuture.java @@ -35,7 +35,7 @@ public interface ResponseFuture extends Future, CompletionStage { * @param sofaResponseCallbacks 多个响应监听器 * @return 对象本身 */ - ResponseFuture addListeners(List sofaResponseCallbacks); + ResponseFuture addListeners(List sofaResponseCallbacks); /** * 增加单个响应监听器 @@ -43,6 +43,6 @@ public interface ResponseFuture extends Future, CompletionStage { * @param sofaResponseCallback 多个响应监听器 * @return 对象本身 */ - ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); + ResponseFuture addListener(SofaResponseCallback sofaResponseCallback); } From cd7d4165cf113e9c80df926eb529a31fbb02366d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E9=B8=A1=E8=85=BF?= <839737769@qq.com> Date: Sat, 6 May 2023 17:56:42 +0800 Subject: [PATCH 31/32] Update AbstractResponseFuture.java --- .../com/alipay/sofa/rpc/message/AbstractResponseFuture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index e654a5e86..e663ac9cb 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -94,7 +94,7 @@ protected TimeoutException clientTimeoutException() { /** * 解析结果,拿到返回值 - * + * * @return do return self * @throws ExecutionException 执行异常 */ From 3ca6ee859c3c9d3e732c1eb7cc5857508b4334f9 Mon Sep 17 00:00:00 2001 From: yangsen Date: Wed, 24 May 2023 16:27:07 +0800 Subject: [PATCH 32/32] =?UTF-8?q?feat[=E5=85=BC=E5=AE=B9completableFuture]?= =?UTF-8?q?:=E5=85=BC=E5=AE=B9completableFuture=20=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=AE=8C=E6=88=90=E3=80=81=E5=BC=82=E5=B8=B8=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alipay/sofa/rpc/message/AbstractResponseFuture.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java index e654a5e86..787c48273 100644 --- a/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java +++ b/core/api/src/main/java/com/alipay/sofa/rpc/message/AbstractResponseFuture.java @@ -214,6 +214,8 @@ public void setSuccess(V result) { this.releaseIfNeed(result); } if (setSuccess0(result)) { + //塞回future + complete(result); notifyListeners(); return; } @@ -251,6 +253,8 @@ public void setFailure(Throwable cause) { return; } if (setFailure0(cause)) { + //塞回exception + completeExceptionally(cause); notifyListeners(); return; }