Search in sources :

Example 6 with DemoService

use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.

the class AbstractProxyTest method testGetProxy.

@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);
    Assertions.assertNotNull(proxy);
    Assertions.assertTrue(Arrays.asList(proxy.getClass().getInterfaces()).contains(DemoService.class));
    // Not equal
    // Assertions.assertEquals(proxy.toString(), invoker.toString());
    // Assertions.assertEquals(proxy.hashCode(), invoker.hashCode());
    Assertions.assertEquals(invoker.invoke(new RpcInvocation("echo", DemoService.class.getName(), DemoService.class.getName() + ":dubbo", new Class[] { String.class }, new Object[] { "aa" })).getValue(), proxy.echo("aa"));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) DemoService(org.apache.dubbo.rpc.support.DemoService) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 7 with DemoService

use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.

the class ExceptionFilterTest method testRuntimeException.

@SuppressWarnings("unchecked")
@Test
public void testRuntimeException() {
    ExceptionFilter exceptionFilter = new ExceptionFilter();
    RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
    AppResponse appResponse = new AppResponse();
    appResponse.setException(new LocalException("localException"));
    Invoker<DemoService> invoker = mock(Invoker.class);
    when(invoker.invoke(invocation)).thenReturn(appResponse);
    when(invoker.getInterface()).thenReturn(DemoService.class);
    Result newResult = exceptionFilter.invoke(invoker, invocation);
    Assertions.assertEquals(appResponse.getException(), newResult.getException());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) LocalException(org.apache.dubbo.rpc.support.LocalException) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.support.DemoService) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 8 with DemoService

use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.

the class ExceptionFilterTest method testJavaException.

@SuppressWarnings("unchecked")
@Test
public void testJavaException() {
    ExceptionFilter exceptionFilter = new ExceptionFilter();
    RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
    AppResponse appResponse = new AppResponse();
    appResponse.setException(new IllegalArgumentException("java"));
    Invoker<DemoService> invoker = mock(Invoker.class);
    when(invoker.invoke(invocation)).thenReturn(appResponse);
    when(invoker.getInterface()).thenReturn(DemoService.class);
    Result newResult = exceptionFilter.invoke(invoker, invocation);
    Assertions.assertEquals(appResponse.getException(), newResult.getException());
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.support.DemoService) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 9 with DemoService

use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.

the class ContextFilterTest method testWithAttachments.

@Test
public void testWithAttachments() {
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    Invoker<DemoService> invoker = new MyInvoker<DemoService>(url);
    Invocation invocation = new MockInvocation();
    Result result = contextFilter.invoke(invoker, invocation);
    assertNull(RpcContext.getContext().getInvoker());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) DemoService(org.apache.dubbo.rpc.support.DemoService) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 10 with DemoService

use of org.apache.dubbo.rpc.support.DemoService in project dubbo by alibaba.

the class EchoFilterTest method testNonEcho.

@SuppressWarnings("unchecked")
@Test
public void testNonEcho() {
    Invocation invocation = mock(Invocation.class);
    given(invocation.getMethodName()).willReturn("echo");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Enum.class });
    given(invocation.getArguments()).willReturn(new Object[] { "hello" });
    given(invocation.getObjectAttachments()).willReturn(null);
    Invoker<DemoService> invoker = mock(Invoker.class);
    given(invoker.isAvailable()).willReturn(true);
    given(invoker.getInterface()).willReturn(DemoService.class);
    AppResponse result = new AppResponse();
    result.setValue("High");
    given(invoker.invoke(invocation)).willReturn(result);
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    given(invoker.getUrl()).willReturn(url);
    Result filterResult = echoFilter.invoke(invoker, invocation);
    assertEquals("High", filterResult.getValue());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.support.DemoService) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Aggregations

DemoService (org.apache.dubbo.rpc.support.DemoService)10 Test (org.junit.jupiter.api.Test)10 URL (org.apache.dubbo.common.URL)6 Result (org.apache.dubbo.rpc.Result)6 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)6 AppResponse (org.apache.dubbo.rpc.AppResponse)5 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)3 Invocation (org.apache.dubbo.rpc.Invocation)3 MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)2 MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)2 HessianException (com.alibaba.com.caucho.hessian.HessianException)1 Logger (org.apache.dubbo.common.logger.Logger)1 RpcException (org.apache.dubbo.rpc.RpcException)1 DemoServiceImpl (org.apache.dubbo.rpc.support.DemoServiceImpl)1 LocalException (org.apache.dubbo.rpc.support.LocalException)1