Search in sources :

Example 21 with Invoker

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

the class RegistryDirectoryTest method testNofityOverrideUrls_CleanNOverride.

/**
     * 测试同时推送清除override和针对某个provider的override
     * 看override是否能够生效
     */
@Test
public void testNofityOverrideUrls_CleanNOverride() {
    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=3"));
    durls.add(URL.valueOf("override://0.0.0.0"));
    durls.add(URL.valueOf("override://10.20.30.140:9091?timeout=4"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Invoker<?> aInvoker = invokers.get(0);
    Assert.assertEquals("4", 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 22 with Invoker

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

the class RegistryDirectoryTest method testNofityOverrideUrls_Clean1.

/**
     * 测试清除override规则,同时下发清除规则和其他override规则
     * 测试是否能够恢复到推送时的providerUrl
     */
@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);
    //需要恢复到最初的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 23 with Invoker

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

the class RegistryDirectoryTest method testNotifyoverrideUrls_withInvoker.

/**
     * 测试override规则是否优先
     * 场景:与invoker 一起推override规则
     */
@Test
public void testNotifyoverrideUrls_withInvoker() {
    RegistryDirectory registryDirectory = getRegistryDirectory();
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.addParameter("timeout", "1000"));
    durls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
    durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(durls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    //开始验证参数值
    invocation = new RpcInvocation();
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    Assert.assertEquals("override rute must be first priority", "1", invokers.get(0).getUrl().getParameter("timeout"));
    Assert.assertEquals("override rute must be first priority", "5", invokers.get(0).getUrl().getParameter("connections"));
}
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 24 with Invoker

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

the class CallbackServiceCodec method referOrdestroyCallbackService.

/**
     * server端 应用一个callbackservice
     * @param url 
     */
@SuppressWarnings("unchecked")
private static Object referOrdestroyCallbackService(Channel channel, URL url, Class<?> clazz, Invocation inv, int instid, boolean isRefer) {
    Object proxy = null;
    String invokerCacheKey = getServerSideCallbackInvokerCacheKey(channel, clazz.getName(), instid);
    String proxyCacheKey = getServerSideCallbackServiceCacheKey(channel, clazz.getName(), instid);
    proxy = channel.getAttribute(proxyCacheKey);
    String countkey = getServerSideCountKey(channel, clazz.getName());
    if (isRefer) {
        if (proxy == null) {
            URL referurl = URL.valueOf("callback://" + url.getAddress() + "/" + clazz.getName() + "?" + Constants.INTERFACE_KEY + "=" + clazz.getName());
            referurl = referurl.addParametersIfAbsent(url.getParameters()).removeParameter(Constants.METHODS_KEY);
            if (!isInstancesOverLimit(channel, referurl, clazz.getName(), instid, true)) {
                @SuppressWarnings("rawtypes") Invoker<?> invoker = new ChannelWrappedInvoker(clazz, channel, referurl, String.valueOf(instid));
                proxy = proxyFactory.getProxy(invoker);
                channel.setAttribute(proxyCacheKey, proxy);
                channel.setAttribute(invokerCacheKey, invoker);
                increaseInstanceCount(channel, countkey);
                //convert error fail fast .
                //ignore concurrent problem. 
                Set<Invoker<?>> callbackInvokers = (Set<Invoker<?>>) channel.getAttribute(Constants.CHANNEL_CALLBACK_KEY);
                if (callbackInvokers == null) {
                    callbackInvokers = new ConcurrentHashSet<Invoker<?>>(1);
                    callbackInvokers.add(invoker);
                    channel.setAttribute(Constants.CHANNEL_CALLBACK_KEY, callbackInvokers);
                }
                logger.info("method " + inv.getMethodName() + " include a callback service :" + invoker.getUrl() + ", a proxy :" + invoker + " has been created.");
            }
        }
    } else {
        if (proxy != null) {
            Invoker<?> invoker = (Invoker<?>) channel.getAttribute(invokerCacheKey);
            try {
                Set<Invoker<?>> callbackInvokers = (Set<Invoker<?>>) channel.getAttribute(Constants.CHANNEL_CALLBACK_KEY);
                if (callbackInvokers != null) {
                    callbackInvokers.remove(invoker);
                }
                invoker.destroy();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
            //取消refer 直接在map中去除,
            channel.removeAttribute(proxyCacheKey);
            channel.removeAttribute(invokerCacheKey);
            decreaseInstanceCount(channel, countkey);
        }
    }
    return proxy;
}
Also used : Set(java.util.Set) ConcurrentHashSet(com.alibaba.dubbo.common.utils.ConcurrentHashSet) Invoker(com.alibaba.dubbo.rpc.Invoker) URL(com.alibaba.dubbo.common.URL) IOException(java.io.IOException) RemotingException(com.alibaba.dubbo.remoting.RemotingException)

Example 25 with Invoker

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

the class CompatibleFilterFilterTest method testResulthasException.

@Test
public void testResulthasException() {
    invocation = EasyMock.createMock(Invocation.class);
    EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
    EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
    EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
    EasyMock.replay(invocation);
    invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
    RpcResult result = new RpcResult();
    result.setException(new RuntimeException());
    result.setValue("High");
    EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
    URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
    EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
    EasyMock.replay(invoker);
    Result filterResult = compatibleFilter.invoke(invoker, invocation);
    assertEquals(filterResult, result);
}
Also used : Invocation(com.alibaba.dubbo.rpc.Invocation) Invoker(com.alibaba.dubbo.rpc.Invoker) RpcResult(com.alibaba.dubbo.rpc.RpcResult) DemoService(com.alibaba.dubbo.rpc.support.DemoService) URL(com.alibaba.dubbo.common.URL) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Aggregations

Invoker (com.alibaba.dubbo.rpc.Invoker)63 Test (org.junit.Test)48 ArrayList (java.util.ArrayList)37 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)36 URL (com.alibaba.dubbo.common.URL)32 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)19 Router (com.alibaba.dubbo.rpc.cluster.Router)12 Result (com.alibaba.dubbo.rpc.Result)11 MockInvoker (com.alibaba.dubbo.rpc.cluster.router.MockInvoker)11 Invocation (com.alibaba.dubbo.rpc.Invocation)9 RpcException (com.alibaba.dubbo.rpc.RpcException)9 RpcResult (com.alibaba.dubbo.rpc.RpcResult)9 LoadBalance (com.alibaba.dubbo.rpc.cluster.LoadBalance)8 DemoService (com.alibaba.dubbo.rpc.support.DemoService)7 LeastActiveLoadBalance (com.alibaba.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance)5 RandomLoadBalance (com.alibaba.dubbo.rpc.cluster.loadbalance.RandomLoadBalance)5 RoundRobinLoadBalance (com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 List (java.util.List)4 StaticDirectory (com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory)3