This is an automated email from the ASF dual-hosted git repository. wangxin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push: new 6b5b430 [Dubbo-1695] Enhance the test coverage part-16 : dubbo-rpc/dubbo-rpc-api module (#2004) 6b5b430 is described below commit 6b5b4308c84acb979ff1cd0e46c327a84db1339c Author: tooyoung <co...@whanice.com> AuthorDate: Mon Jul 2 10:03:17 2018 +0800 [Dubbo-1695] Enhance the test coverage part-16 : dubbo-rpc/dubbo-rpc-api module (#2004) * add unit test for rpc filter * rebase master * MICS: add test * add test for context * remove unused file * reformat test code --- .../java/org/apache/dubbo/rpc/RpcContextTest.java | 148 +++++++++++++++++++++ .../Person.java => ServiceHolderTest.java} | 79 +++++------ .../org/apache/dubbo/rpc/StaticContextTest.java | 64 +++++++++ .../dubbo/rpc/filter/ClassLoaderFilterTest.java | 53 ++++++++ .../dubbo/rpc/filter/ExceptionFilterTest.java | 71 ++++++++++ .../dubbo/rpc/filter/ExecuteLimitFilterTest.java | 131 ++++++++++++++++++ .../apache/dubbo/rpc/filter/GenericFilterTest.java | 88 ++++++++++++ .../dubbo/rpc/filter/GenericImplFilterTest.java | 113 ++++++++++++++++ .../apache/dubbo/rpc/filter/TimeoutFilterTest.java | 66 +++++++++ .../apache/dubbo/rpc/filter/TokenFilterTest.java | 90 +++++++++++++ .../apache/dubbo/rpc/proxy/AbstractProxyTest.java | 56 ++++++++ .../rpc/proxy/InvokerInvocationHandlerTest.java | 54 ++++++++ .../javassist/JavassistProxyFactoryTest.java} | 72 ++++------ .../dubbo/rpc/proxy/jdk/JdkProxyFactoryTest.java | 11 ++ .../org/apache/dubbo/rpc/support/DemoService.java | 2 + .../apache/dubbo/rpc/support/DemoServiceImpl.java | 2 +- .../apache/dubbo/rpc/support/LocalException.java | 9 ++ .../org/apache/dubbo/rpc/support/MyInvoker.java | 5 + .../java/org/apache/dubbo/rpc/support/Person.java | 7 + 19 files changed, 1030 insertions(+), 91 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java new file mode 100644 index 0000000..d298824 --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/RpcContextTest.java @@ -0,0 +1,148 @@ +package org.apache.dubbo.rpc; + +import org.apache.dubbo.common.URL; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +public class RpcContextTest { + + @Test + public void testGetContext() { + + RpcContext rpcContext = RpcContext.getContext(); + Assert.assertNotNull(rpcContext); + + RpcContext.removeContext(); + // if null, will return the initialize value. + //Assert.assertNull(RpcContext.getContext()); + Assert.assertNotNull(RpcContext.getContext()); + Assert.assertNotEquals(rpcContext, RpcContext.getContext()); + + RpcContext serverRpcContext = RpcContext.getServerContext(); + Assert.assertNotNull(serverRpcContext); + + RpcContext.removeServerContext(); + Assert.assertNotEquals(serverRpcContext, RpcContext.getServerContext()); + + } + + @Test + public void testAddress() { + RpcContext context = RpcContext.getContext(); + context.setLocalAddress("127.0.0.1", 20880); + Assert.assertTrue(context.getLocalAddress().getPort() == 20880); + Assert.assertEquals("127.0.0.1:20880", context.getLocalAddressString()); + + context.setRemoteAddress("127.0.0.1", 20880); + Assert.assertTrue(context.getRemoteAddress().getPort() == 20880); + Assert.assertEquals("127.0.0.1:20880", context.getRemoteAddressString()); + + context.setRemoteAddress("127.0.0.1", -1); + context.setLocalAddress("127.0.0.1", -1); + Assert.assertTrue(context.getRemoteAddress().getPort() == 0); + Assert.assertTrue(context.getLocalAddress().getPort() == 0); + Assert.assertEquals("127.0.0.1", context.getRemoteHostName()); + Assert.assertEquals("127.0.0.1", context.getLocalHostName()); + } + + @Test + public void testCheckSide() { + + RpcContext context = RpcContext.getContext(); + + //TODO fix npe + //context.isProviderSide(); + + context.setUrl(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1")); + Assert.assertFalse(context.isConsumerSide()); + Assert.assertTrue(context.isProviderSide()); + + context.setUrl(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&side=consumer")); + Assert.assertTrue(context.isConsumerSide()); + Assert.assertFalse(context.isProviderSide()); + } + + @Test + public void testAttachments() { + + RpcContext context = RpcContext.getContext(); + Map<String, String> map = new HashMap<String, String>(); + map.put("_11", "1111"); + map.put("_22", "2222"); + map.put(".33", "3333"); + + context.setAttachments(map); + Assert.assertEquals(map, context.getAttachments()); + + Assert.assertEquals("1111", context.getAttachment("_11")); + context.setAttachment("_11", "11.11"); + Assert.assertEquals("11.11", context.getAttachment("_11")); + + context.setAttachment(null, "22222"); + context.setAttachment("_22", null); + Assert.assertEquals("22222", context.getAttachment(null)); + Assert.assertNull(context.getAttachment("_22")); + + Assert.assertNull(context.getAttachment("_33")); + Assert.assertEquals("3333", context.getAttachment(".33")); + + context.clearAttachments(); + Assert.assertNull(context.getAttachment("_11")); + } + + @Test + public void testObject() { + + RpcContext context = RpcContext.getContext(); + Map<String, Object> map = new HashMap<String, Object>(); + map.put("_11", "1111"); + map.put("_22", "2222"); + map.put(".33", "3333"); + + map.forEach(context::set); + + Assert.assertEquals(map, context.get()); + + Assert.assertEquals("1111", context.get("_11")); + context.set("_11", "11.11"); + Assert.assertEquals("11.11", context.get("_11")); + + context.set(null, "22222"); + context.set("_22", null); + Assert.assertEquals("22222", context.get(null)); + Assert.assertNull(context.get("_22")); + + Assert.assertNull(context.get("_33")); + Assert.assertEquals("3333", context.get(".33")); + + map.keySet().forEach(context::remove); + Assert.assertNull(context.get("_11")); + } + + @Test + public void testAsync() { + + CompletableFuture<Object> future = new CompletableFuture<>(); + AsyncContext asyncContext = new AsyncContextImpl(future); + + RpcContext rpcContext = RpcContext.getContext(); + Assert.assertFalse(rpcContext.isAsyncStarted()); + + rpcContext.setAsyncContext(asyncContext); + Assert.assertFalse(rpcContext.isAsyncStarted()); + + RpcContext.startAsync(); + Assert.assertTrue(rpcContext.isAsyncStarted()); + + asyncContext.write(new Object()); + Assert.assertTrue(future.isDone()); + + rpcContext.stopAsync(); + Assert.assertFalse(rpcContext.isAsyncStarted()); + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/ServiceHolderTest.java similarity index 61% copy from dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java copy to dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/ServiceHolderTest.java index b043606..9a9a42f 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/ServiceHolderTest.java @@ -1,45 +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.dubbo.rpc.support; - -import java.io.Serializable; - -/** - * Person.java - */ -public class Person implements Serializable { - - private static final long serialVersionUID = 1L; - private String name; - private int age; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } -} \ No newline at end of file +/* + * 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.dubbo.rpc; + +import org.junit.Assert; +import org.junit.Test; + +public class ServiceHolderTest { + + @Test + public void testHolderClass() { + + ServiceClassHolder holder = ServiceClassHolder.getInstance(); + + holder.pushServiceClass(ServiceHolderTest.class); + + Assert.assertEquals(ServiceHolderTest.class, holder.popServiceClass()); + + } +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/StaticContextTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/StaticContextTest.java new file mode 100644 index 0000000..723b1be --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/StaticContextTest.java @@ -0,0 +1,64 @@ +/* + * 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.dubbo.rpc; + +import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.URL; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class StaticContextTest { + + @Test + public void testGetContext() { + String name = "custom"; + + StaticContext context = StaticContext.getContext(name); + Assert.assertTrue(context != null); + Assert.assertEquals(name, context.getName()); + + StaticContext.remove(name); + + StaticContext sysContext = StaticContext.getSystemContext(); + Assert.assertTrue(sysContext != null); + + } + + @Test + public void testGetKey() { + String interfaceName = "interface"; + String method = "method"; + String group = "group"; + String version = "1.0"; + + String suffix = "suffix"; + + Map<String, String> para = new HashMap<>(); + para.put(Constants.INTERFACE_KEY, interfaceName); + para.put(Constants.GROUP_KEY, group); + para.put(Constants.VERSION_KEY, version); + + URL url = new URL("dubbo", "localhost", 20880, interfaceName, para); + + Assert.assertEquals(StaticContext.getKey(url, method, suffix), + StaticContext.getKey(para, method, suffix)); + + } +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ClassLoaderFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ClassLoaderFilterTest.java new file mode 100644 index 0000000..0cdcb4f --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ClassLoaderFilterTest.java @@ -0,0 +1,53 @@ +package org.apache.dubbo.rpc.filter; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.support.DemoService; +import org.apache.dubbo.rpc.support.MyInvoker; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.net.URLClassLoader; + +public class ClassLoaderFilterTest { + + private ClassLoaderFilter classLoaderFilter = new ClassLoaderFilter(); + + @Test + public void testInvoke() throws Exception { + URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1"); + + String path = DemoService.class.getResource("/").getPath(); + final URLClassLoader cl = new URLClassLoader(new java.net.URL[]{new java.net.URL("file:" + path)}) { + @Override + public Class<?> loadClass(String name) throws ClassNotFoundException { + try { + return findClass(name); + } catch (ClassNotFoundException e) { + return super.loadClass(name); + } + } + }; + final Class<?> clazz = cl.loadClass(DemoService.class.getCanonicalName()); + Invoker invoker = new MyInvoker(url) { + @Override + public Class getInterface() { + return clazz; + } + + @Override + public Result invoke(Invocation invocation) throws RpcException { + Assert.assertEquals(cl, Thread.currentThread().getContextClassLoader()); + return null; + } + }; + Invocation invocation = Mockito.mock(Invocation.class); + + classLoaderFilter.invoke(invoker, invocation); + } +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java index e08adf8..803ae05 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExceptionFilterTest.java @@ -17,11 +17,18 @@ package org.apache.dubbo.rpc.filter; import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.RpcResult; import org.apache.dubbo.rpc.support.DemoService; +import org.apache.dubbo.rpc.support.LocalException; + +import com.alibaba.com.caucho.hessian.HessianException; +import org.junit.Assert; import org.junit.Test; import org.mockito.Mockito; @@ -29,6 +36,7 @@ import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * ExceptionFilterTest @@ -60,4 +68,67 @@ public class ExceptionFilterTest { RpcContext.removeContext(); } + @SuppressWarnings("unchecked") + @Test + public void testJavaException() { + + ExceptionFilter exceptionFilter = new ExceptionFilter(); + RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"}); + + RpcResult rpcResult = new RpcResult(); + rpcResult.setException(new IllegalArgumentException("java")); + + Invoker<DemoService> invoker = mock(Invoker.class); + when(invoker.invoke(invocation)).thenReturn(rpcResult); + when(invoker.getInterface()).thenReturn(DemoService.class); + + Result newResult = exceptionFilter.invoke(invoker, invocation); + + Assert.assertEquals(rpcResult.getException(), newResult.getException()); + + } + + @SuppressWarnings("unchecked") + @Test + public void testRuntimeException() { + + ExceptionFilter exceptionFilter = new ExceptionFilter(); + RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"}); + + RpcResult rpcResult = new RpcResult(); + rpcResult.setException(new LocalException("localException")); + + Invoker<DemoService> invoker = mock(Invoker.class); + when(invoker.invoke(invocation)).thenReturn(rpcResult); + when(invoker.getInterface()).thenReturn(DemoService.class); + + Result newResult = exceptionFilter.invoke(invoker, invocation); + + Assert.assertEquals(rpcResult.getException(), newResult.getException()); + + } + + @SuppressWarnings("unchecked") + @Test + public void testConvertToRunTimeException() { + + ExceptionFilter exceptionFilter = new ExceptionFilter(); + RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"}); + + RpcResult rpcResult = new RpcResult(); + rpcResult.setException(new HessianException("hessian")); + + Invoker<DemoService> invoker = mock(Invoker.class); + when(invoker.invoke(invocation)).thenReturn(rpcResult); + when(invoker.getInterface()).thenReturn(DemoService.class); + + Result newResult = exceptionFilter.invoke(invoker, invocation); + + Assert.assertFalse(newResult.getException() instanceof HessianException); + + Assert.assertEquals(newResult.getException().getClass(), RuntimeException.class); + Assert.assertEquals(newResult.getException().getMessage(), StringUtils.toString(rpcResult.getException())); + + } + } \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilterTest.java new file mode 100644 index 0000000..f0a3b5c --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/ExecuteLimitFilterTest.java @@ -0,0 +1,131 @@ +/* + * 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.dubbo.rpc.filter; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcResult; +import org.apache.dubbo.rpc.RpcStatus; +import org.apache.dubbo.rpc.support.BlockMyInvoker; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; + +public class ExecuteLimitFilterTest { + + private ExecuteLimitFilter executeLimitFilter = new ExecuteLimitFilter(); + + @Test + public void testNoExecuteLimitInvoke() throws Exception { + Invoker invoker = Mockito.mock(Invoker.class); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult("result")); + when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1")); + + Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getMethodName()).thenReturn("testNoExecuteLimitInvoke"); + + Result result = executeLimitFilter.invoke(invoker, invocation); + Assert.assertEquals("result", result.getValue()); + } + + @Test + public void testExecuteLimitInvoke() throws Exception { + Invoker invoker = Mockito.mock(Invoker.class); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult("result")); + when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=10")); + + Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getMethodName()).thenReturn("testExecuteLimitInvoke"); + + Result result = executeLimitFilter.invoke(invoker, invocation); + Assert.assertEquals("result", result.getValue()); + } + + @Test + public void testExecuteLimitInvokeWitException() throws Exception { + Invoker invoker = Mockito.mock(Invoker.class); + doThrow(new RpcException()) + .when(invoker).invoke(any(Invocation.class)); + + URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=10"); + when(invoker.getUrl()).thenReturn(url); + + Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getMethodName()).thenReturn("testExecuteLimitInvokeWitException"); + + try { + executeLimitFilter.invoke(invoker, invocation); + } catch (Exception e) { + Assert.assertTrue(e instanceof RpcException); + } + Assert.assertEquals(1, RpcStatus.getStatus(url, invocation.getMethodName()).getFailed()); + } + + @Test + public void testMoreThanExecuteLimitInvoke() throws Exception { + int maxExecute = 10; + int totalExecute = 20; + final AtomicInteger failed = new AtomicInteger(0); + + final Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getMethodName()).thenReturn("testMoreThanExecuteLimitInvoke"); + + URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&executes=" + maxExecute); + final Invoker<ExecuteLimitFilter> invoker = new BlockMyInvoker<ExecuteLimitFilter>(url, 1000); + + final CountDownLatch latch = new CountDownLatch(1); + for (int i = 0; i < totalExecute; i++) { + Thread thread = new Thread(new Runnable() { + + public void run() { + try { + latch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + try { + executeLimitFilter.invoke(invoker, invocation); + } catch (RpcException expected) { + failed.incrementAndGet(); + } + + } + }); + thread.start(); + } + latch.countDown(); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + Assert.assertEquals(totalExecute - maxExecute, failed.get()); + } +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java new file mode 100644 index 0000000..eea14ce --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericFilterTest.java @@ -0,0 +1,88 @@ +/* + * 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.dubbo.rpc.filter; + +import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.*; +import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.rpc.support.DemoService; +import org.apache.dubbo.rpc.support.Person; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +public class GenericFilterTest { + GenericFilter genericFilter = new GenericFilter(); + + @Test + public void testInvokeWithDefault() throws Exception { + + Method genericInvoke = GenericService.class.getMethods()[0]; + + Map<String, Object> person = new HashMap<String, Object>(); + person.put("name", "dubbo"); + person.put("age", 10); + + RpcInvocation invocation = new RpcInvocation(Constants.$INVOKE, genericInvoke.getParameterTypes(), + new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}, new Object[]{person}}); + + URL url = URL.valueOf("test://test:11/com.alibaba.dubbo.rpc.support.DemoService?" + + "accesslog=true&group=dubbo&version=1.1"); + Invoker invoker = Mockito.mock(Invoker.class); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult(new Person("person", 10))); + when(invoker.getUrl()).thenReturn(url); + when(invoker.getInterface()).thenReturn(DemoService.class); + + Result result = genericFilter.invoke(invoker, invocation); + + Assert.assertEquals(HashMap.class, result.getValue().getClass()); + Assert.assertEquals(10, ((HashMap) result.getValue()).get("age")); + + } + + @Test(expected = RpcException.class) + public void testInvokeWithJavaException() throws Exception { + + Method genericInvoke = GenericService.class.getMethods()[0]; + + Map<String, Object> person = new HashMap<String, Object>(); + person.put("name", "dubbo"); + person.put("age", 10); + + RpcInvocation invocation = new RpcInvocation(Constants.$INVOKE, genericInvoke.getParameterTypes(), + new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}, new Object[]{person}}); + invocation.setAttachment(Constants.GENERIC_KEY, Constants.GENERIC_SERIALIZATION_NATIVE_JAVA); + + URL url = URL.valueOf("test://test:11/com.alibaba.dubbo.rpc.support.DemoService?" + + "accesslog=true&group=dubbo&version=1.1"); + Invoker invoker = Mockito.mock(Invoker.class); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult(new Person("person", 10))); + when(invoker.getUrl()).thenReturn(url); + when(invoker.getInterface()).thenReturn(DemoService.class); + + genericFilter.invoke(invoker, invocation); + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java new file mode 100644 index 0000000..02ea4ed --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/GenericImplFilterTest.java @@ -0,0 +1,113 @@ +/* + * 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.dubbo.rpc.filter; + +import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.RpcResult; +import org.apache.dubbo.rpc.service.GenericException; +import org.apache.dubbo.rpc.service.GenericService; +import org.apache.dubbo.rpc.support.DemoService; +import org.apache.dubbo.rpc.support.Person; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.when; + +public class GenericImplFilterTest { + + private GenericImplFilter genericImplFilter = new GenericImplFilter(); + + @Test + public void testInvoke() throws Exception { + + RpcInvocation invocation = new RpcInvocation("getPerson", + new Class[]{Person.class}, new Object[]{new Person("dubbo", 10)}); + + + URL url = URL.valueOf("test://test:11/com.alibaba.dubbo.rpc.support.DemoService?" + + "accesslog=true&group=dubbo&version=1.1&generic=true"); + Invoker invoker = Mockito.mock(Invoker.class); + + Map<String, Object> person = new HashMap<String, Object>(); + person.put("name", "dubbo"); + person.put("age", 10); + + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult(person)); + when(invoker.getUrl()).thenReturn(url); + when(invoker.getInterface()).thenReturn(DemoService.class); + + Result result = genericImplFilter.invoke(invoker, invocation); + + Assert.assertEquals(Person.class, result.getValue().getClass()); + Assert.assertEquals(10, ((Person) result.getValue()).getAge()); + } + + @Test + public void testInvokeWithException() throws Exception { + + RpcInvocation invocation = new RpcInvocation("getPerson", + new Class[]{Person.class}, new Object[]{new Person("dubbo", 10)}); + + URL url = URL.valueOf("test://test:11/com.alibaba.dubbo.rpc.support.DemoService?" + + "accesslog=true&group=dubbo&version=1.1&generic=true"); + Invoker invoker = Mockito.mock(Invoker.class); + + when(invoker.invoke(any(Invocation.class))).thenReturn( + new RpcResult(new GenericException(new RuntimeException("failed")))); + when(invoker.getUrl()).thenReturn(url); + when(invoker.getInterface()).thenReturn(DemoService.class); + + Result result = genericImplFilter.invoke(invoker, invocation); + Assert.assertEquals(RuntimeException.class, result.getException().getClass()); + + } + + @Test + public void testInvokeWith$Invoke() throws Exception { + + Method genericInvoke = GenericService.class.getMethods()[0]; + + Map<String, Object> person = new HashMap<String, Object>(); + person.put("name", "dubbo"); + person.put("age", 10); + + RpcInvocation invocation = new RpcInvocation(Constants.$INVOKE, genericInvoke.getParameterTypes(), + new Object[]{"getPerson", new String[]{Person.class.getCanonicalName()}, new Object[]{person}}); + + URL url = URL.valueOf("test://test:11/com.alibaba.dubbo.rpc.support.DemoService?" + + "accesslog=true&group=dubbo&version=1.1&generic=true"); + Invoker invoker = Mockito.mock(Invoker.class); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult(new Person("person", 10))); + when(invoker.getUrl()).thenReturn(url); + + genericImplFilter.invoke(invoker, invocation); + Assert.assertEquals("true", invocation.getAttachment(Constants.GENERIC_KEY)); + + } +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/TimeoutFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/TimeoutFilterTest.java new file mode 100644 index 0000000..4ee8e55 --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/TimeoutFilterTest.java @@ -0,0 +1,66 @@ +/* + * 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.dubbo.rpc.filter; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcResult; +import org.apache.dubbo.rpc.support.BlockMyInvoker; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.when; + +public class TimeoutFilterTest { + + private TimeoutFilter timeoutFilter = new TimeoutFilter(); + + @Test + public void testInvokeWithoutTimeout() throws Exception { + int timeout = 3000; + + Invoker invoker = Mockito.mock(Invoker.class); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult("result")); + when(invoker.getUrl()).thenReturn(URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&timeout=" + timeout)); + + Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getMethodName()).thenReturn("testInvokeWithoutTimeout"); + + Result result = timeoutFilter.invoke(invoker, invocation); + Assert.assertEquals("result", result.getValue()); + } + + @Test + public void testInvokeWithTimeout() throws Exception { + int timeout = 100; + + URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&timeout=" + timeout); + Invoker invoker = new BlockMyInvoker(url, (timeout + 100)); + + Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getMethodName()).thenReturn("testInvokeWithTimeout"); + + Result result = timeoutFilter.invoke(invoker, invocation); + Assert.assertEquals("alibaba", result.getValue()); + + } +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/TokenFilterTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/TokenFilterTest.java new file mode 100644 index 0000000..6d8b0f3 --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/filter/TokenFilterTest.java @@ -0,0 +1,90 @@ +/* + * 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.dubbo.rpc.filter; + +import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.Result; +import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.rpc.RpcResult; + +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +public class TokenFilterTest { + + private TokenFilter tokenFilter = new TokenFilter(); + + @Test + public void testInvokeWithToken() throws Exception { + String token = "token"; + + Invoker invoker = Mockito.mock(Invoker.class); + URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token); + when(invoker.getUrl()).thenReturn(url); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult("result")); + + Map<String, String> attachments = new HashMap<String, String>(); + attachments.put(Constants.TOKEN_KEY, token); + Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getAttachments()).thenReturn(attachments); + + Result result = tokenFilter.invoke(invoker, invocation); + Assert.assertEquals("result", result.getValue()); + } + + @Test(expected = RpcException.class) + public void testInvokeWithWrongToken() throws Exception { + String token = "token"; + + Invoker invoker = Mockito.mock(Invoker.class); + URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token); + when(invoker.getUrl()).thenReturn(url); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult("result")); + + Map<String, String> attachments = new HashMap<String, String>(); + attachments.put(Constants.TOKEN_KEY, "wrongToken"); + Invocation invocation = Mockito.mock(Invocation.class); + when(invocation.getAttachments()).thenReturn(attachments); + + tokenFilter.invoke(invoker, invocation); + } + + @Test(expected = RpcException.class) + public void testInvokeWithoutToken() throws Exception { + String token = "token"; + + Invoker invoker = Mockito.mock(Invoker.class); + URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&token=" + token); + when(invoker.getUrl()).thenReturn(url); + when(invoker.invoke(any(Invocation.class))).thenReturn(new RpcResult("result")); + + Invocation invocation = Mockito.mock(Invocation.class); + + tokenFilter.invoke(invoker, invocation); + } +} + diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/AbstractProxyTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/AbstractProxyTest.java new file mode 100644 index 0000000..78d48fd --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/AbstractProxyTest.java @@ -0,0 +1,56 @@ +package org.apache.dubbo.rpc.proxy; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.ProxyFactory; +import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.support.DemoService; +import org.apache.dubbo.rpc.support.DemoServiceImpl; +import org.apache.dubbo.rpc.support.MyInvoker; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; + + +public abstract class AbstractProxyTest { + + public static ProxyFactory factory; + + @Test + public void testGetProxy() throws Exception { + URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); + + Invoker<DemoService> invoker = new MyInvoker<>(url); + + DemoService proxy = factory.getProxy(invoker); + + Assert.assertNotNull(proxy); + + Assert.assertTrue(Arrays.asList(proxy.getClass().getInterfaces()).contains(DemoService.class)); + + // Not equal + //Assert.assertEquals(proxy.toString(), invoker.toString()); + //Assert.assertEquals(proxy.hashCode(), invoker.hashCode()); + + Assert.assertEquals(invoker.invoke(new RpcInvocation("echo", new Class[]{String.class}, new Object[]{"aa"})).getValue() + , proxy.echo("aa")); + } + + @Test + public void testGetInvoker() throws Exception { + URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1"); + + DemoService origin = new org.apache.dubbo.rpc.support.DemoServiceImpl(); + + Invoker<DemoService> invoker = factory.getInvoker(new DemoServiceImpl(), DemoService.class, url); + + Assert.assertEquals(invoker.getInterface(), DemoService.class); + + Assert.assertEquals(invoker.invoke(new RpcInvocation("echo", new Class[]{String.class}, new Object[]{"aa"})).getValue(), + origin.echo("aa")); + + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandlerTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandlerTest.java new file mode 100644 index 0000000..f06df9a --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandlerTest.java @@ -0,0 +1,54 @@ +/* + * 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.dubbo.rpc.proxy; + +import org.apache.dubbo.rpc.Invoker; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import java.lang.reflect.Method; + +import static org.mockito.Mockito.*; + +public class InvokerInvocationHandlerTest { + + @Mock + private Invoker<?> invoker; + @InjectMocks + private InvokerInvocationHandler invokerInvocationHandler; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testInvokeToString() throws Throwable { + String methodName = "toString"; + + when(invoker.toString()).thenReturn(methodName); + Method method = invoker.getClass().getMethod(methodName); + + Object result = invokerInvocationHandler.invoke(null, method, new Object[]{}); + Assert.assertEquals(methodName, result); + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/javassist/JavassistProxyFactoryTest.java similarity index 60% copy from dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java copy to dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/javassist/JavassistProxyFactoryTest.java index b043606..9bb521d 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/javassist/JavassistProxyFactoryTest.java @@ -1,45 +1,27 @@ -/* - * 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.dubbo.rpc.support; - -import java.io.Serializable; - -/** - * Person.java - */ -public class Person implements Serializable { - - private static final long serialVersionUID = 1L; - private String name; - private int age; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } -} \ No newline at end of file +/* + * 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.dubbo.rpc.proxy.javassist; + +import org.apache.dubbo.rpc.proxy.AbstractProxyTest; + +public class JavassistProxyFactoryTest extends AbstractProxyTest { + + static { + factory = new JavassistProxyFactory(); + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/jdk/JdkProxyFactoryTest.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/jdk/JdkProxyFactoryTest.java new file mode 100644 index 0000000..cd3926e --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/proxy/jdk/JdkProxyFactoryTest.java @@ -0,0 +1,11 @@ +package org.apache.dubbo.rpc.proxy.jdk; + +import org.apache.dubbo.rpc.proxy.AbstractProxyTest; + +public class JdkProxyFactoryTest extends AbstractProxyTest { + + static { + factory = new JdkProxyFactory(); + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoService.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoService.java index b84f379..4830b9c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoService.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoService.java @@ -43,4 +43,6 @@ public interface DemoService { byte getbyte(byte arg); + Person getPerson(Person person); + } \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoServiceImpl.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoServiceImpl.java index b2355ac..3770e6c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoServiceImpl.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/DemoServiceImpl.java @@ -83,7 +83,7 @@ public class DemoServiceImpl implements DemoService { return arg; } - public Person gerPerson(Person person) { + public Person getPerson(Person person) { return person; } } \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/LocalException.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/LocalException.java new file mode 100644 index 0000000..c28bc22 --- /dev/null +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/LocalException.java @@ -0,0 +1,9 @@ +package org.apache.dubbo.rpc.support; + +public class LocalException extends RuntimeException { + + public LocalException(String message) { + super(message); + } + +} diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java index 23d9c4e..eb944c9 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MyInvoker.java @@ -73,4 +73,9 @@ public class MyInvoker<T> implements Invoker<T> { public void destroy() { } + @Override + public String toString() { + return "MyInvoker.toString()"; + } + } diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java index b043606..7512d05 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/Person.java @@ -27,6 +27,13 @@ public class Person implements Serializable { private String name; private int age; + public Person() {} + + public Person(String name, int age) { + this.name = name; + this.age = age; + } + public String getName() { return name; }