Search in sources :

Example 1 with DemoService

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

the class EchoFilterTest method testEcho.

@SuppressWarnings("unchecked")
@Test
public void testEcho() {
    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("hello", 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)

Example 2 with DemoService

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

the class DeprecatedFilterTest method testDeprecatedFilter.

@Test
public void testDeprecatedFilter() {
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&echo." + DEPRECATED_KEY + "=true");
    LogUtil.start();
    deprecatedFilter.invoke(new MyInvoker<DemoService>(url), new MockInvocation());
    assertEquals(1, LogUtil.findMessage("The service method org.apache.dubbo.rpc.support.DemoService.echo(String) is DEPRECATED"));
    LogUtil.stop();
}
Also used : DemoService(org.apache.dubbo.rpc.support.DemoService) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 3 with DemoService

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

the class ExceptionFilterTest method testConvertToRunTimeException.

@SuppressWarnings("unchecked")
@Test
public void testConvertToRunTimeException() throws Exception {
    ExceptionFilter exceptionFilter = new ExceptionFilter();
    RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
    AppResponse mockRpcResult = new AppResponse();
    mockRpcResult.setException(new HessianException("hessian"));
    Result mockAsyncResult = AsyncRpcResult.newDefaultAsyncResult(mockRpcResult, invocation);
    Invoker<DemoService> invoker = mock(Invoker.class);
    when(invoker.invoke(invocation)).thenReturn(mockAsyncResult);
    when(invoker.getInterface()).thenReturn(DemoService.class);
    Result asyncResult = exceptionFilter.invoke(invoker, invocation);
    AppResponse appResponse = (AppResponse) asyncResult.get();
    exceptionFilter.onResponse(appResponse, invoker, invocation);
    Assertions.assertFalse(appResponse.getException() instanceof HessianException);
    Assertions.assertEquals(appResponse.getException().getClass(), RuntimeException.class);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.support.DemoService) HessianException(com.alibaba.com.caucho.hessian.HessianException) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 4 with DemoService

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

the class ExceptionFilterTest method testRpcException.

@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = mock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    ExceptionFilter exceptionFilter = new ExceptionFilter();
    RpcInvocation invocation = new RpcInvocation("sayHello", DemoService.class.getName(), "", new Class<?>[] { String.class }, new Object[] { "world" });
    Invoker<DemoService> invoker = mock(Invoker.class);
    given(invoker.getInterface()).willReturn(DemoService.class);
    given(invoker.invoke(eq(invocation))).willThrow(exception);
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
        exceptionFilter.setLogger(logger);
        exceptionFilter.onError(e, invoker, invocation);
    }
    Mockito.verify(logger).error(eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), eq(exception));
    RpcContext.removeContext();
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) RpcException(org.apache.dubbo.rpc.RpcException) DemoService(org.apache.dubbo.rpc.support.DemoService) Logger(org.apache.dubbo.common.logger.Logger) Test(org.junit.jupiter.api.Test)

Example 5 with DemoService

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

the class AbstractProxyTest method testGetInvoker.

@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);
    Assertions.assertEquals(invoker.getInterface(), DemoService.class);
    Assertions.assertEquals(invoker.invoke(new RpcInvocation("echo", DemoService.class.getName(), DemoService.class.getName() + ":dubbo", new Class[] { String.class }, new Object[] { "aa" })).getValue(), origin.echo("aa"));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) DemoService(org.apache.dubbo.rpc.support.DemoService) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.rpc.support.DemoServiceImpl) 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