Search in sources :

Example 66 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class FailoverClusterInvokerTest method testInvokerDestoryAndReList.

/**
 * When invokers in directory changes after a failed request but just before a retry effort,
 * then we should reselect from the latest invokers before retry.
 */
@Test
public void testInvokerDestoryAndReList() {
    final URL url = URL.valueOf("test://localhost/" + Demo.class.getName() + "?loadbalance=roundrobin&retries=" + retries);
    RpcException exception = new RpcException(RpcException.TIMEOUT_EXCEPTION);
    MockInvoker<Demo> invoker1 = new MockInvoker<Demo>(Demo.class, url);
    invoker1.setException(exception);
    MockInvoker<Demo> invoker2 = new MockInvoker<Demo>(Demo.class, url);
    invoker2.setException(exception);
    final List<Invoker<Demo>> invokers = new ArrayList<Invoker<Demo>>();
    invokers.add(invoker1);
    invokers.add(invoker2);
    Callable<Object> callable = new Callable<Object>() {

        public Object call() throws Exception {
            // Simulation: all invokers are destroyed
            for (Invoker<Demo> invoker : invokers) {
                invoker.destroy();
            }
            invokers.clear();
            MockInvoker<Demo> invoker3 = new MockInvoker<Demo>(Demo.class, url);
            invokers.add(invoker3);
            return null;
        }
    };
    invoker1.setCallable(callable);
    invoker2.setCallable(callable);
    RpcInvocation inv = new RpcInvocation();
    inv.setMethodName("test");
    Directory<Demo> dic = new MockDirectory<Demo>(url, invokers);
    FailoverClusterInvoker<Demo> clusterinvoker = new FailoverClusterInvoker<Demo>(dic);
    clusterinvoker.invoke(inv);
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Callable(java.util.concurrent.Callable) Invoker(com.alibaba.dubbo.rpc.Invoker) AbstractInvoker(com.alibaba.dubbo.rpc.protocol.AbstractInvoker) RpcException(com.alibaba.dubbo.rpc.RpcException) Test(org.junit.Test)

Example 67 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_return.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_return() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getSomething.mock", "return x").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("x", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething3");
    try {
        ret = cluster.invoke(invocation);
        Assert.fail("fail invoke");
    } catch (RpcException e) {
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 68 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "fail").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("somethingmock", ret.getValue());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 69 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_Fock_Default.

/**
 * Test if mock policy works fine: fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_Fock_Default() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("mock", "fail:return x").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getSomething");
    Result ret = cluster.invoke(invocation);
    Assert.assertEquals("x", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("getSomething2");
    ret = cluster.invoke(invocation);
    Assert.assertEquals("x", ret.getValue());
    // If no mock was configured, return null directly
    invocation = new RpcInvocation();
    invocation.setMethodName("sayHello");
    ret = cluster.invoke(invocation);
    Assert.assertEquals("x", ret.getValue());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Example 70 with RpcInvocation

use of com.alibaba.dubbo.rpc.RpcInvocation in project dubbo by alibaba.

the class MockClusterInvokerTest method testMockInvokerFromOverride_Invoke_check_boolean.

@Test
public void testMockInvokerFromOverride_Invoke_check_boolean() {
    URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName()).addParameter("getBoolean1.mock", "force:return true").addParameter("invoke_return_error", "true");
    Invoker<IHelloService> cluster = getClusterInvoker(url);
    // Configured with mock
    RpcInvocation invocation = new RpcInvocation();
    invocation.setMethodName("getBoolean1");
    Result ret = cluster.invoke(invocation);
    Assert.assertTrue("result type must be Boolean but was : " + ret.getValue().getClass(), ret.getValue() instanceof Boolean);
    Assert.assertEquals(true, Boolean.parseBoolean(ret.getValue().toString()));
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) Test(org.junit.Test)

Aggregations

RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)104 Test (org.junit.Test)77 URL (com.alibaba.dubbo.common.URL)62 ArrayList (java.util.ArrayList)45 Invoker (com.alibaba.dubbo.rpc.Invoker)37 Result (com.alibaba.dubbo.rpc.Result)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)22 RpcException (com.alibaba.dubbo.rpc.RpcException)22 Router (com.alibaba.dubbo.rpc.cluster.Router)15 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)13 Invocation (com.alibaba.dubbo.rpc.Invocation)12 List (java.util.List)10 RpcResult (com.alibaba.dubbo.rpc.RpcResult)9 Method (java.lang.reflect.Method)6 Protocol (com.alibaba.dubbo.rpc.Protocol)4 MockProtocol (com.alibaba.dubbo.rpc.support.MockProtocol)4 RemotingException (com.alibaba.dubbo.remoting.RemotingException)3 TimeoutException (com.alibaba.dubbo.remoting.TimeoutException)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3