This is an automated email from the ASF dual-hosted git repository.

earthchen pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.1 by this push:
     new 0489702e1c Fix tri future (#11455)
0489702e1c is described below

commit 0489702e1c1fdb62ad01bd30dc48a673656db500
Author: earthchen <[email protected]>
AuthorDate: Mon Feb 6 17:29:06 2023 +0800

    Fix tri future (#11455)
    
    * fix tri return future
    
    * fix ut
    
    * fix npe
    
    * fix sonar
---
 .../rpc/protocol/tri/ReflectionPackableMethod.java   | 20 ++++++++++----------
 .../rpc/protocol/tri/call/AbstractServerCall.java    |  4 ++++
 .../dubbo/rpc/protocol/tri/DescriptorService.java    |  5 +++++
 .../protocol/tri/ReflectionPackableMethodTest.java   | 11 +++++++++++
 .../protocol/tri/call/ReflectionServerCallTest.java  | 20 ++++++--------------
 5 files changed, 36 insertions(+), 24 deletions(-)

diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
index cab311698c..790d807605 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
@@ -17,14 +17,6 @@
 
 package org.apache.dubbo.rpc.protocol.tri;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.lang.reflect.ParameterizedType;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.constants.CommonConstants;
 import org.apache.dubbo.common.serialize.MultipleSerialization;
@@ -37,6 +29,14 @@ import org.apache.dubbo.rpc.model.PackableMethod;
 
 import com.google.protobuf.Message;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.ParameterizedType;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
 import static org.apache.dubbo.common.constants.CommonConstants.$ECHO;
 import static 
org.apache.dubbo.common.constants.CommonConstants.PROTOBUF_MESSAGE_CLASS_NAME;
 import static org.apache.dubbo.remoting.Constants.SERIALIZATION_KEY;
@@ -75,7 +75,7 @@ public class ReflectionPackableMethod implements 
PackableMethod {
                 break;
             case UNARY:
                 actualRequestTypes = method.getParameterClasses();
-                actualResponseType = method.getReturnClass();
+                actualResponseType = (Class<?>) method.getReturnTypes()[0];
                 break;
             default:
                 throw new IllegalStateException("Can not reach here");
@@ -478,7 +478,7 @@ public class ReflectionPackableMethod implements 
PackableMethod {
         if (clz == null) {
             try {
                 clz = ClassUtils.forName(className);
-            } catch (Throwable e) {
+            } catch (Exception e) {
                 // To catch IllegalStateException, LinkageError, 
ClassNotFoundException
                 clz = expectedClass;
             }
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java
index ca4d849ab4..cd538a7a58 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/call/AbstractServerCall.java
@@ -174,6 +174,10 @@ public abstract class AbstractServerCall implements 
ServerCall, ServerStream.Lis
 
     @Override
     public final void onComplete() {
+        if (listener == null) {
+            // It will enter here when there is an error in the header
+            return;
+        }
         listener.onComplete();
     }
 
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/DescriptorService.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/DescriptorService.java
index 666db4a4c4..51f4d1000e 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/DescriptorService.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/DescriptorService.java
@@ -18,8 +18,13 @@ package org.apache.dubbo.rpc.protocol.tri;
 
 import org.apache.dubbo.common.stream.StreamObserver;
 
+import java.util.concurrent.CompletableFuture;
+
 public interface DescriptorService {
 
+
+    CompletableFuture<String> unaryFuture();
+
     void noParameterMethod();
 
     /**
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethodTest.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethodTest.java
index c610e51b1f..1eadb5305e 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethodTest.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethodTest.java
@@ -27,6 +27,7 @@ import reactor.core.publisher.Mono;
 
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
+import java.util.concurrent.CompletableFuture;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -35,6 +36,16 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class ReflectionPackableMethodTest {
+
+
+    @Test
+    void testUnaryFuture() throws Exception {
+        Method method = DescriptorService.class.getMethod("unaryFuture");
+        MethodDescriptor descriptor = new ReflectionMethodDescriptor(method);
+        assertEquals(CompletableFuture.class, descriptor.getReturnClass());
+        assertEquals(String.class, descriptor.getReturnTypes()[0]);
+    }
+
     @Test
     void testMethodWithNoParameters() throws Exception {
         Method method = DescriptorService.class.getMethod("noParameterMethod");
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/call/ReflectionServerCallTest.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/call/ReflectionServerCallTest.java
index 0c3dc8fc97..7b85a34ee4 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/call/ReflectionServerCallTest.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/test/java/org/apache/dubbo/rpc/protocol/tri/call/ReflectionServerCallTest.java
@@ -20,7 +20,7 @@ package org.apache.dubbo.rpc.protocol.tri.call;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.rpc.Invoker;
 import org.apache.dubbo.rpc.model.FrameworkModel;
-import org.apache.dubbo.rpc.model.MethodDescriptor.RpcType;
+import org.apache.dubbo.rpc.model.MethodDescriptor;
 import org.apache.dubbo.rpc.model.ProviderModel;
 import org.apache.dubbo.rpc.model.ReflectionMethodDescriptor;
 import org.apache.dubbo.rpc.model.ServiceDescriptor;
@@ -46,8 +46,8 @@ class ReflectionServerCallTest {
         Invoker<?> invoker = Mockito.mock(Invoker.class);
         TripleServerStream serverStream = 
Mockito.mock(TripleServerStream.class);
         ProviderModel providerModel = Mockito.mock(ProviderModel.class);
-        ReflectionMethodDescriptor methodDescriptor = Mockito.mock(
-            ReflectionMethodDescriptor.class);
+        Method method = DescriptorService.class.getMethod("sayHello", 
HelloReply.class);
+        MethodDescriptor methodDescriptor = new 
ReflectionMethodDescriptor(method);
         URL url = Mockito.mock(URL.class);
         when(invoker.getUrl())
             .thenReturn(url);
@@ -68,19 +68,11 @@ class ReflectionServerCallTest {
         }
 
         ServiceDescriptor serviceDescriptor = 
Mockito.mock(ServiceDescriptor.class);
-        when(providerModel.getServiceModel())
-            .thenReturn(serviceDescriptor);
         when(serviceDescriptor.getMethods(anyString()))
             .thenReturn(Collections.singletonList(methodDescriptor));
-        when(methodDescriptor.getRpcType())
-            .thenReturn(RpcType.UNARY);
-        Method method = DescriptorService.class.getMethod("sayHello", 
HelloReply.class);
-        when(methodDescriptor.getMethod())
-            .thenReturn(method);
-        when(methodDescriptor.getParameterClasses())
-            .thenReturn(method.getParameterTypes());
-        when(methodDescriptor.getReturnClass())
-            .thenAnswer(invocation -> method.getReturnType());
+
+        when(providerModel.getServiceModel())
+            .thenReturn(serviceDescriptor);
 
         ReflectionAbstractServerCall call2 = new 
ReflectionAbstractServerCall(invoker, serverStream,
             new FrameworkModel(), "",

Reply via email to