Search in sources :

Example 26 with AppResponse

use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.

the class MergeableClusterInvokerTest method testAddMenu.

@Test
public void testAddMenu() throws Exception {
    String menu = "first";
    List<String> menuItems = new ArrayList<String>() {

        {
            add("1");
            add("2");
        }
    };
    given(invocation.getMethodName()).willReturn("addMenu");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class, List.class });
    given(invocation.getArguments()).willReturn(new Object[] { menu, menuItems });
    given(invocation.getObjectAttachments()).willReturn(new HashMap<>());
    given(invocation.getInvoker()).willReturn(firstInvoker);
    given(firstInvoker.getUrl()).willReturn(url.addParameter(GROUP_KEY, "first"));
    given(firstInvoker.getInterface()).willReturn(MenuService.class);
    given(firstInvoker.invoke(invocation)).willReturn(new AppResponse());
    given(firstInvoker.isAvailable()).willReturn(true);
    given(secondInvoker.getUrl()).willReturn(url.addParameter(GROUP_KEY, "second"));
    given(secondInvoker.getInterface()).willReturn(MenuService.class);
    given(secondInvoker.invoke(invocation)).willReturn(new AppResponse());
    given(secondInvoker.isAvailable()).willReturn(true);
    given(directory.list(invocation)).willReturn(new ArrayList() {

        {
            add(firstInvoker);
            add(secondInvoker);
        }
    });
    given(directory.getUrl()).willReturn(url);
    given(directory.getConsumerUrl()).willReturn(url);
    given(directory.getConsumerUrl()).willReturn(url);
    given(directory.getInterface()).willReturn(MenuService.class);
    mergeableClusterInvoker = new MergeableClusterInvoker<MenuService>(directory);
    Result result = mergeableClusterInvoker.invoke(invocation);
    Assertions.assertNull(result.getValue());
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) ArrayList(java.util.ArrayList) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 27 with AppResponse

use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.

the class ValidationFilterTest method testItWithNotExistClass.

@Test
public void testItWithNotExistClass() throws Exception {
    URL url = URL.valueOf("test://test:11/test?validation=true");
    given(validation.getValidator(url)).willThrow(new IllegalStateException("Not found class test, cause: test"));
    given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
    given(invoker.getUrl()).willReturn(url);
    given(invocation.getMethodName()).willReturn("echo1");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
    given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
    validationFilter.setValidation(validation);
    Result result = validationFilter.invoke(invoker, invocation);
    assertThat(result.getException().getMessage(), is("Not found class test, cause: test"));
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 28 with AppResponse

use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.

the class ValidationFilterTest method testItWithoutUrlParameters.

@Test
public void testItWithoutUrlParameters() throws Exception {
    URL url = URL.valueOf("test://test:11/test");
    given(validation.getValidator(url)).willReturn(validator);
    given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
    given(invoker.getUrl()).willReturn(url);
    given(invocation.getMethodName()).willReturn("echo1");
    given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
    given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
    validationFilter.setValidation(validation);
    Result result = validationFilter.invoke(invoker, invocation);
    assertThat(String.valueOf(result.getValue()), is("success"));
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 29 with AppResponse

use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.

the class ValidationFilterTest method testItWhileThrowoutRpcException.

@Test
public void testItWhileThrowoutRpcException() throws Exception {
    Assertions.assertThrows(RpcException.class, () -> {
        URL url = URL.valueOf("test://test:11/test?validation=true");
        given(validation.getValidator(url)).willThrow(new RpcException("rpc exception"));
        given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
        given(invoker.getUrl()).willReturn(url);
        given(invocation.getMethodName()).willReturn("echo1");
        given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
        given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
        validationFilter.setValidation(validation);
        validationFilter.invoke(invoker, invocation);
    });
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) RpcException(org.apache.dubbo.rpc.RpcException) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 30 with AppResponse

use of org.apache.dubbo.rpc.AppResponse in project dubbo by alibaba.

the class FutureFilterTest method testSyncCallback.

@Test
public void testSyncCallback() {
    @SuppressWarnings("unchecked") 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 = eventFilter.invoke(invoker, invocation);
    assertEquals("High", filterResult.getValue());
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.protocol.dubbo.support.DemoService) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Aggregations

AppResponse (org.apache.dubbo.rpc.AppResponse)54 Test (org.junit.jupiter.api.Test)37 URL (org.apache.dubbo.common.URL)33 Invocation (org.apache.dubbo.rpc.Invocation)27 Result (org.apache.dubbo.rpc.Result)27 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)20 Invoker (org.apache.dubbo.rpc.Invoker)20 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)20 HashMap (java.util.HashMap)13 RpcException (org.apache.dubbo.rpc.RpcException)12 Method (java.lang.reflect.Method)8 Person (org.apache.dubbo.rpc.support.Person)7 TMessage (org.apache.thrift.protocol.TMessage)6 IMetricManager (com.alibaba.metrics.IMetricManager)5 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)5 Request (org.apache.dubbo.remoting.exchange.Request)5 Response (org.apache.dubbo.remoting.exchange.Response)5 DemoService (org.apache.dubbo.rpc.support.DemoService)5 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)5 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)5