Fix tri future (#11455)
* fix tri return future * fix ut * fix npe * fix sonar
This commit is contained in:
parent
c0b257adac
commit
0489702e1c
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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(), "",
|
||||
|
|
|
|||
Loading…
Reference in New Issue