Java Code Examples for com.alibaba.dubbo.common.extension.ExtensionLoader

The following examples show how to use com.alibaba.dubbo.common.extension.ExtensionLoader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dubbo-2.6.5   Source File: ExtensionLoaderTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLoadDefaultActivateExtension() throws Exception {
    // test default
    URL url = URL.valueOf("test://localhost/test?ext=order1,default");
    List<ActivateExt1> list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, "ext", "default_group");
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class);
    Assert.assertTrue(list.get(1).getClass() == ActivateExt1Impl1.class);

    url = URL.valueOf("test://localhost/test?ext=default,order1");
    list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, "ext", "default_group");
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);
    Assert.assertTrue(list.get(1).getClass() == OrderActivateExtImpl1.class);
}
 
Example 2
Source Project: dubbo-2.6.5   Source File: AbstractClusterInvoker.java    License: Apache License 2.0 6 votes vote down vote up
@Override
    public Result invoke(final Invocation invocation) throws RpcException {
        checkWhetherDestroyed();
        LoadBalance loadbalance = null;

        // binding attachments into invocation.  从rpc上下文把参数绑定到执行者
        Map<String, String> contextAttachments = RpcContext.getContext().getAttachments();
        if (contextAttachments != null && contextAttachments.size() != 0) {
            ((RpcInvocation) invocation).addAttachments(contextAttachments);
        }

//        根据url找到可以路由的执行器集合=》
        List<Invoker<T>> invokers = list(invocation);
        if (invokers != null && !invokers.isEmpty()) {
//            获取loadbalance属性值,负载均衡策略配置,默认random,也可以在消费者端进行配置
            loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
                    .getMethodParameter(RpcUtils.getMethodName(invocation), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
        }
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
//        com.alibaba.dubbo.rpc.cluster.support.FailoverClusterInvoker.doInvoke()
        return doInvoke(invocation, invokers, loadbalance);
    }
 
Example 3
Source Project: brave   Source File: ITTracingFilter_Consumer.java    License: Apache License 2.0 6 votes vote down vote up
/** Shows if you aren't using RpcTracing, the old "dubbo.error_code" works */
@Test public void setsError_onUnimplemented_legacy() {
  ((TracingFilter) ExtensionLoader.getExtensionLoader(Filter.class)
      .getExtension("tracing")).isInit = false;

  ((TracingFilter) ExtensionLoader.getExtensionLoader(Filter.class)
      .getExtension("tracing"))
      .setTracing(tracing);

  assertThatThrownBy(() -> wrongClient.get().sayHello("jorge"))
      .isInstanceOf(RpcException.class);

  MutableSpan span =
      testSpanHandler.takeRemoteSpanWithErrorMessage(CLIENT, ".*Not found exported service.*");
  assertThat(span.tags())
      .containsEntry("dubbo.error_code", "1");
}
 
Example 4
Source Project: dubbox-hystrix   Source File: RegistryProtocolTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExport() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());

    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class,
            newRegistryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    Exporter<DemoService> exporter = registryProtocol.export(invoker);
    Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
    //同一个invoker,多次export的exporter不同
    Assert.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();
    
}
 
Example 5
Source Project: dubbox   Source File: ExtensionLoader_Adaptive_Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_getAdaptiveExtension_inject() throws Exception {
    LogUtil.start();
    Ext6 ext = ExtensionLoader.getExtensionLoader(Ext6.class).getAdaptiveExtension();

    URL url = new URL("p1", "1.2.3.4", 1010, "path1");
    url = url.addParameters("ext6", "impl1");
    
    assertEquals("Ext6Impl1-echo-Ext1Impl1-echo", ext.echo(url, "ha"));
    
    Assert.assertTrue("can not find error.", LogUtil.checkNoError());
    LogUtil.stop();
    
    url = url.addParameters("simple.ext", "impl2");
    assertEquals("Ext6Impl1-echo-Ext1Impl2-echo", ext.echo(url, "ha"));
    
}
 
Example 6
Source Project: dubbox-hystrix   Source File: HessianProtocolTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHessianProtocol() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
    HessianService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
 
Example 7
Source Project: dubbox-hystrix   Source File: AbstractConfig.java    License: Apache License 2.0 6 votes vote down vote up
protected static void checkMultiExtension(Class<?> type, String property, String value) {
    checkMultiName(property, value);
    if (value != null && value.length() > 0) {
        String[] values = value.split("\\s*[,]+\\s*");
        for (String v : values) {
            if (v.startsWith(Constants.REMOVE_VALUE_PREFIX)) {
                v = v.substring(1);
            }
            if (Constants.DEFAULT_KEY.equals(v)) {
            	continue;
            }
            if (! ExtensionLoader.getExtensionLoader(type).hasExtension(v)) {
                throw new IllegalStateException("No such extension " + v + " for " + property + "/" + type.getName());
            }
        }
    }
}
 
Example 8
Source Project: dubbo-2.6.5   Source File: ExtensionLoader_Adaptive_Test.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_urlHolder_getAdaptiveExtension_ExceptionWhenNotAdativeMethod() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();

    Map<String, String> map = new HashMap<String, String>();
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);

    try {
        ext.bang(url, 33);
        fail();
    } catch (UnsupportedOperationException expected) {
        assertThat(expected.getMessage(), containsString("method "));
        assertThat(
                expected.getMessage(),
                containsString("of interface com.alibaba.dubbo.common.extensionloader.ext2.Ext2 is not adaptive method!"));
    }
}
 
Example 9
Source Project: dubbo-2.6.5   Source File: HttpProtocolTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleClient() {
    HttpServiceImpl server = new HttpServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0&client=simple");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<HttpService> invoker = protocol.refer(HttpService.class, url);
    HttpService client = proxyFactory.getProxy(invoker);
    String result = client.sayHello("haha");
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
 
Example 10
Source Project: dubbo-2.6.5   Source File: ProtocolTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_destroyWontCloseAllProtocol() throws Exception {
    Protocol autowireProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();

    Protocol InjvmProtocol = ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("injvm");

    InjvmProtocol.export(invoker);

    Invoker<IEcho> refer = InjvmProtocol.refer(IEcho.class, url);
    IEcho echoProxy = proxyFactory.getProxy(refer);

    assertEquals("ok", echoProxy.echo("ok"));

    try {
        autowireProtocol.destroy();
    } catch (UnsupportedOperationException expected) {
        assertThat(expected.getMessage(), containsString("of interface com.alibaba.dubbo.rpc.Protocol is not adaptive method!"));
    }

    assertEquals("ok2", echoProxy.echo("ok2"));
}
 
Example 11
Source Project: dubbo3   Source File: PageServlet.java    License: Apache License 2.0 6 votes vote down vote up
protected final void writeMenu(HttpServletRequest request, PrintWriter writer, String nav) {
    writer.println("<table>");
    writer.println("<thead>");
    writer.println("    <tr>");
    for (PageHandler handler : menus) {
        String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler);
        Menu menu = handler.getClass().getAnnotation(Menu.class);
        writer.println("        <th><a href=\"" + uri + ".html\">" + menu.name() + "</a></th>");
    }
    writer.println("    </tr>");
    writer.println("</thead>");
    writer.println("<tbody>");
    writer.println("    <tr>");
    writer.println("        <td style=\"text-align: left\" colspan=\"" + menus.size() + "\">");
    writer.println(nav);
    writer.println("        </td>");
    writer.println("    </tr>");
    writer.println("</tbody>");
    writer.println("</table>");
    writer.println("<br/>");
}
 
Example 12
Source Project: dubbo3   Source File: DubboProtocol.java    License: Apache License 2.0 6 votes vote down vote up
private ExchangeServer createServer(URL url) {
    //默认开启server关闭时发送readonly事件
    url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString());
    //默认开启heartbeat
    url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT));
    String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER);

    if (str != null && str.length() > 0 && !ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str))
        throw new RpcException("Unsupported server type: " + str + ", url: " + url);

    url = url.addParameter(Constants.CODEC_KEY, DubboCodec.NAME);
    ExchangeServer server;
    try {
        server = Exchangers.bind(url, requestHandler);
    } catch (RemotingException e) {
        throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e);
    }
    str = url.getParameter(Constants.CLIENT_KEY);
    if (str != null && str.length() > 0) {
        Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions();
        if (!supportedTypes.contains(str)) {
            throw new RpcException("Unsupported client type: " + str);
        }
    }
    return server;
}
 
Example 13
Source Project: dubbox   Source File: RegistryProtocolTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testExport() {
    RegistryProtocol registryProtocol = new RegistryProtocol();
    registryProtocol.setCluster(new FailfastCluster());
    registryProtocol.setRegistryFactory(ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension());

    Protocol dubboProtocol = DubboProtocol.getDubboProtocol();
    registryProtocol.setProtocol(dubboProtocol);
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    DubboInvoker<DemoService> invoker = new DubboInvoker<DemoService>(DemoService.class,
            newRegistryUrl, new ExchangeClient[] { new MockedClient("10.20.20.20", 2222, true) });
    Exporter<DemoService> exporter = registryProtocol.export(invoker);
    Exporter<DemoService> exporter2 = registryProtocol.export(invoker);
    //同一个invoker,多次export的exporter不同
    Assert.assertNotSame(exporter, exporter2);
    exporter.unexport();
    exporter2.unexport();
    
}
 
Example 14
Source Project: dubbo-remoting-netty4   Source File: ClientsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportEmpty() {
    try {
        ExtensionLoader.getExtensionLoader(Transporter.class).getExtension("");
        fail();
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(), containsString("Extension name == null"));
    }
}
 
Example 15
Source Project: dubbo3   Source File: ExtensionLoaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_getExtensionLoader_Null() throws Exception {
    try {
        ExtensionLoader.getExtensionLoader(null);
        fail();
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(),
                containsString("Extension type == null"));
    }
}
 
Example 16
Source Project: dubbox   Source File: ExtensionLoader_Adaptive_Test.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_urlHolder_getAdaptiveExtension() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();
    
    Map<String, String> map = new HashMap<String, String>();
    map.put("ext2", "impl1");
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);
    
    UrlHolder holder = new UrlHolder();
    holder.setUrl(url);

    String echo = ext.echo(holder, "haha");
    assertEquals("Ext2Impl1-echo", echo);
}
 
Example 17
Source Project: dubbox   Source File: ExtensionLoaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_AddExtension_Adaptive() throws Exception {
    ExtensionLoader<AddExt2> loader = ExtensionLoader.getExtensionLoader(AddExt2.class);
    loader.addExtension(null, AddExt2_ManualAdaptive.class);

    AddExt2 adaptive = loader.getAdaptiveExtension();
    assertTrue(adaptive instanceof AddExt2_ManualAdaptive);
}
 
Example 18
Source Project: dubbox   Source File: ClientsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportEmpty() {
    try {
        ExtensionLoader.getExtensionLoader(Transporter.class).getExtension("");
        fail();
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(), containsString("Extension name == null"));
    }
}
 
Example 19
Source Project: dubbox   Source File: ExtensionLoaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_replaceExtension_Adaptive() throws Exception {
    ExtensionLoader<AddExt3> loader = ExtensionLoader.getExtensionLoader(AddExt3.class);

    AddExt3 adaptive = loader.getAdaptiveExtension();
    assertFalse(adaptive instanceof AddExt3_ManualAdaptive);

    loader.replaceExtension(null, AddExt3_ManualAdaptive.class);

    adaptive = loader.getAdaptiveExtension();
    assertTrue(adaptive instanceof AddExt3_ManualAdaptive);
}
 
Example 20
Source Project: dubbox   Source File: AbstractClusterInvokerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 测试均衡.
     */
    @Test
    public void testSelectBalance(){
        
        LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(RoundRobinLoadBalance.NAME);
        initlistsize5();
        
        Map<Invoker,AtomicLong> counter = new ConcurrentHashMap<Invoker,AtomicLong>();
        for(Invoker invoker :invokers){
            counter.put(invoker, new AtomicLong(0));
        }
        int runs = 1000;
        for(int i=0;i<runs;i++){
            selectedInvokers.clear();
            Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
            counter.get(sinvoker).incrementAndGet();
        }
        
        for (Invoker minvoker :counter.keySet() ){
            Long count = counter.get(minvoker).get();
//            System.out.println(count);
            if(minvoker.isAvailable())
                Assert.assertTrue("count should > avg", count>runs/invokers.size());
        }
        
        Assert.assertEquals(runs, counter.get(invoker2).get()+counter.get(invoker4).get());;
        
    }
 
Example 21
Source Project: dubbox   Source File: ThreadPoolStatusChecker.java    License: Apache License 2.0 5 votes vote down vote up
public Status check() {
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    Map<String, Object> executors = dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY);

    StringBuilder msg = new StringBuilder();
    Status.Level level = Status.Level.OK;
    for(Map.Entry<String, Object> entry : executors.entrySet()) {
        String port = entry.getKey();
        ExecutorService executor = (ExecutorService) entry.getValue();

        if (executor != null && executor instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
            boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
            Status.Level lvl = Status.Level.OK;
            if(!ok) {
                level = Status.Level.WARN;
                lvl = Status.Level.WARN;
            }

            if(msg.length() > 0) {
                msg.append(";");
            }
            msg.append("Pool status:" + lvl
                    + ", max:" + tp.getMaximumPoolSize()
                    + ", core:" + tp.getCorePoolSize()
                    + ", largest:" + tp.getLargestPoolSize()
                    + ", active:" + tp.getActiveCount()
                    + ", task:" + tp.getTaskCount()
                    + ", service port: " + port);
        }
    }
    return msg.length() == 0 ? new Status(Status.Level.UNKNOWN) : new Status(level, msg.toString());
}
 
Example 22
Source Project: dubbo-2.6.5   Source File: ExtensionLoaderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
    public void test_AddExtension_NoExtend() throws Exception {
//        ExtensionLoader.getExtensionLoader(Ext9Empty.class).getSupportedExtensions();
        ExtensionLoader.getExtensionLoader(Ext9Empty.class).addExtension("ext9", Ext9EmptyImpl.class);
        Ext9Empty ext = ExtensionLoader.getExtensionLoader(Ext9Empty.class).getExtension("ext9");

        assertThat(ext, instanceOf(Ext9Empty.class));
        assertEquals("ext9", ExtensionLoader.getExtensionLoader(Ext9Empty.class).getExtensionName(Ext9EmptyImpl.class));
    }
 
Example 23
Source Project: dubbox-hystrix   Source File: ProtocolConfig.java    License: Apache License 2.0 5 votes vote down vote up
public static void destroyAll() {
    AbstractRegistryFactory.destroyAll();
    ExtensionLoader<Protocol> loader = ExtensionLoader.getExtensionLoader(Protocol.class);
    for (String protocolName : loader.getLoadedExtensions()) {
        try {
            Protocol protocol = loader.getLoadedExtension(protocolName);
            if (protocol != null) {
                protocol.destroy();
            }
        } catch (Throwable t) {
            logger.warn(t.getMessage(), t);
        }
    }
}
 
Example 24
Source Project: dubbox-hystrix   Source File: AbstractClusterInvokerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 测试均衡.
     */
    @Test
    public void testSelectBalance(){
        
        LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(RoundRobinLoadBalance.NAME);
        initlistsize5();
        
        Map<Invoker,AtomicLong> counter = new ConcurrentHashMap<Invoker,AtomicLong>();
        for(Invoker invoker :invokers){
            counter.put(invoker, new AtomicLong(0));
        }
        int runs = 1000;
        for(int i=0;i<runs;i++){
            selectedInvokers.clear();
            Invoker sinvoker = cluster.select(lb, invocation, invokers, selectedInvokers);
            counter.get(sinvoker).incrementAndGet();
        }
        
        for (Invoker minvoker :counter.keySet() ){
            Long count = counter.get(minvoker).get();
//            System.out.println(count);
            if(minvoker.isAvailable())
                Assert.assertTrue("count should > avg", count>runs/invokers.size());
        }
        
        Assert.assertEquals(runs, counter.get(invoker2).get()+counter.get(invoker4).get());;
        
    }
 
Example 25
Source Project: dubbox   Source File: AbstractInterfaceConfig.java    License: Apache License 2.0 5 votes vote down vote up
protected URL loadMonitor(URL registryURL) {
    if (monitor == null) {
        String monitorAddress = ConfigUtils.getProperty("dubbo.monitor.address");
        String monitorProtocol = ConfigUtils.getProperty("dubbo.monitor.protocol");
        if (monitorAddress != null && monitorAddress.length() > 0
                || monitorProtocol != null && monitorProtocol.length() > 0) {
            monitor = new MonitorConfig();
        } else {
            return null;
        }
    }
    appendProperties(monitor);
    Map<String, String> map = new HashMap<String, String>();
    map.put(Constants.INTERFACE_KEY, MonitorService.class.getName());
    map.put("dubbo", Version.getVersion());
    map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
    if (ConfigUtils.getPid() > 0) {
        map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
    }
    appendParameters(map, monitor);
    String address = monitor.getAddress();
    String sysaddress = System.getProperty("dubbo.monitor.address");
    if (sysaddress != null && sysaddress.length() > 0) {
        address = sysaddress;
    }
    if (ConfigUtils.isNotEmpty(address)) {
        if (! map.containsKey(Constants.PROTOCOL_KEY)) {
            if (ExtensionLoader.getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) {
                map.put(Constants.PROTOCOL_KEY, "logstat");
            } else {
                map.put(Constants.PROTOCOL_KEY, "dubbo");
            }
        }
        return UrlUtils.parseURL(address, map);
    } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
        return registryURL.setProtocol("dubbo").addParameter(Constants.PROTOCOL_KEY, "registry").addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map));
    }
    return null;
}
 
Example 26
Source Project: dubbox   Source File: AbstractTest.java    License: Apache License 2.0 5 votes vote down vote up
protected void init() throws Exception {
    TServerTransport serverTransport = new TServerSocket( PORT );

    TBinaryProtocol.Factory bFactory = new TBinaryProtocol.Factory();

    server = new TThreadPoolServer(
            new TThreadPoolServer.Args( serverTransport )
                    .inputProtocolFactory( bFactory )
                    .outputProtocolFactory( bFactory )
                    .inputTransportFactory( getTransportFactory() )
                    .outputTransportFactory( getTransportFactory() )
                    .processor( getProcessor() ) );

    Thread startTread = new Thread() {

        @Override
        public void run() {
            server.serve();
        }

    };

    startTread.setName( "thrift-server" );

    startTread.start();

    while( !server.isServing() ) {
        Thread.sleep( 100 );
    }

    protocol = ExtensionLoader.getExtensionLoader(Protocol.class)
            .getExtension( ThriftProtocol.NAME );

    invoker = protocol.refer( getInterface(), getUrl() );

}
 
Example 27
Source Project: dubbox   Source File: ExtensionLoader_Adaptive_Test.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_getAdaptiveExtension_customizeAdaptiveKey() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();

    Map<String, String> map = new HashMap<String, String>();
    map.put("key2", "impl2");
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);

    String echo = ext.yell(url, "haha");
    assertEquals("Ext1Impl2-yell", echo);

    url = url.addParameter("key1", "impl3"); // 注意: URL是值类型
    echo = ext.yell(url, "haha");
    assertEquals("Ext1Impl3-yell", echo);
}
 
Example 28
Source Project: dubbo-2.6.5   Source File: ClientsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportEmpty() {
    try {
        ExtensionLoader.getExtensionLoader(Transporter.class).getExtension("");
        fail();
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(), containsString("Extension name == null"));
    }
}
 
Example 29
Source Project: dubbox   Source File: ClientsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportEmpty() {
    try {
        ExtensionLoader.getExtensionLoader(Transporter.class).getExtension("");
        fail();
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(), containsString("Extension name == null"));
    }
}
 
Example 30
Source Project: dubbo-2.6.5   Source File: CacheTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCacheProvider() throws Exception {
    CacheFactory cacheFactory = ExtensionLoader.getExtensionLoader(CacheFactory.class).getAdaptiveExtension();

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("findCache.cache", "threadlocal");
    URL url = new URL("dubbo", "127.0.0.1", 29582, "com.alibaba.dubbo.config.cache.CacheService", parameters);

    Invocation invocation = new RpcInvocation("findCache", new Class[]{String.class}, new String[]{"0"}, null, null);

    Cache cache = cacheFactory.getCache(url, invocation);
    assertTrue(cache instanceof ThreadLocalCache);
}