Search in sources :

Example 26 with RpcInvocation

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

the class RegistryDirectoryTest method testforbid.

// forbid
private void testforbid(RegistryDirectory registryDirectory) {
    invocation = new RpcInvocation();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(new URL(Constants.EMPTY_PROTOCOL, Constants.ANYHOST_VALUE, 0, service, Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY));
    registryDirectory.notify(serviceUrls);
    Assert.assertEquals("invokers size=0 ,then the registry directory is not available", false, registryDirectory.isAvailable());
    try {
        registryDirectory.list(invocation);
        fail("forbid must throw RpcException");
    } catch (RpcException e) {
        Assert.assertEquals(RpcException.FORBIDDEN_EXCEPTION, e.getCode());
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL)

Example 27 with RpcInvocation

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

the class RegistryDirectoryTest method testParmeterRoute.

/**
 * When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
 */
@Test
public void testParmeterRoute() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
    serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
    serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));
    registryDirectory.notify(serviceUrls);
    invocation = new RpcInvocation(Constants.$INVOKE, new Class[] { String.class, String[].class, Object[].class }, new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });
    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 28 with RpcInvocation

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

the class RegistryDirectoryTest method test_Notified1invokers.

// notify one invoker
private void test_Notified1invokers(RegistryDirectory registryDirectory) {
    List<URL> serviceUrls = new ArrayList<URL>();
    // .addParameter("refer.autodestroy", "true")
    serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));
    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    invocation = new RpcInvocation();
    List invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    invocation.setMethodName("getXXX");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    invocation.setMethodName("getXXX1");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
    invocation.setMethodName("getXXX2");
    invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URL(com.alibaba.dubbo.common.URL)

Example 29 with RpcInvocation

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

the class RegistryDirectoryTest method testNofityOverrideUrls_Clean1.

/**
 * Test cleanup override rules, and sent remove rules and other override rules
 * Whether the test can be restored to the providerUrl when it is pushed
 */
@Test
public void testNofityOverrideUrls_Clean1() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
    registryDirectory.notify(durls);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1000"));
    registryDirectory.notify(durls);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://0.0.0.0"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    // Need to be restored to the original providerUrl
    Assert.assertEquals("1", aInvoker.getUrl().getParameter("timeout"));
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 30 with RpcInvocation

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

the class RegistryDirectoryTest method testNofityOverrideUrls_Provider.

/**
 * Test override rules for a certain provider
 */
@Test
public void testNofityOverrideUrls_Provider() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    List<URL> durls = new ArrayList<URL>();
    // One is the same, one is different
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE));
    durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2").addParameter(Constants.SIDE_KEY, Constants.CONSUMER_SIDE));
    registryDirectory.notify(durls);
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
    durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Invoker<?> bInvoker = invokers.get(1);
    Assert.assertEquals("3", aInvoker.getUrl().getParameter("timeout"));
    Assert.assertEquals("4", bInvoker.getUrl().getParameter("timeout"));
}
Also used : RegistryDirectory(com.alibaba.dubbo.registry.integration.RegistryDirectory) RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) Invoker(com.alibaba.dubbo.rpc.Invoker) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL) 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