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

The following examples show how to use com.alibaba.dubbo.common.extension.ExtensionLoader. 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 File: ProtocolTest.java    From dubbo-2.6.5 with 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 #2
Source File: AbstractClusterInvoker.java    From dubbo-2.6.5 with 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 File: DubboProtocol.java    From dubbo3 with 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 #4
Source File: PageServlet.java    From dubbo3 with 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 #5
Source File: HttpProtocolTest.java    From dubbo-2.6.5 with 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 #6
Source File: ExtensionLoader_Adaptive_Test.java    From dubbox with 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 #7
Source File: ExtensionLoader_Adaptive_Test.java    From dubbo-2.6.5 with 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 #8
Source File: ITTracingFilter_Consumer.java    From brave with 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 #9
Source File: RegistryProtocolTest.java    From dubbox with 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 #10
Source File: RegistryProtocolTest.java    From dubbox-hystrix with 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 #11
Source File: AbstractConfig.java    From dubbox-hystrix with 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 #12
Source File: HessianProtocolTest.java    From dubbox-hystrix with 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 #13
Source File: ExtensionLoaderTest.java    From dubbo-2.6.5 with 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 #14
Source File: ExtensionLoaderTest.java    From dubbox-hystrix with 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 #15
Source File: ClientsTest.java    From dubbox-hystrix with 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 #16
Source File: LoadBalanceTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public Map<Invoker,AtomicLong> getInvokeCounter(int runs,String loadbalanceName) {
    Map<Invoker,AtomicLong> counter = new ConcurrentHashMap<Invoker,AtomicLong>();
    LoadBalance lb = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(loadbalanceName);
    for(Invoker invoker :invokers){
        counter.put(invoker, new AtomicLong(0));
    }
    for(int i=0;i<runs;i++){
        Invoker sinvoker = lb.select(invokers, invokers.get(0).getUrl(), invocation);
        counter.get(sinvoker).incrementAndGet();
    }
    return counter;
}
 
Example #17
Source File: ThreadPoolStatusChecker.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
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 #18
Source File: ExtensionLoaderTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_getExtensionLoader_NotSpiAnnotation() throws Exception {
    try {
        ExtensionLoader.getExtensionLoader(NoSpiExt.class);
        fail();
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(),
                allOf(containsString("com.alibaba.dubbo.common.extensionloader.NoSpiExt"),
                        containsString("is not extension"),
                        containsString("WITHOUT @SPI Annotation")));
    }
}
 
Example #19
Source File: ThriftUtilsTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateMethodResultClassName() {

    Assert.assertEquals($__DemoStub.echoString_result.class.getName(),
            ThriftUtils.generateMethodResultClassName(
                    com.alibaba.dubbo.rpc.gen.dubbo.Demo.class.getName(),
                    "echoString"));

    Assert.assertEquals($__DemoStub.echoString_result.class.getName(),
            ExtensionLoader.getExtensionLoader(ClassNameGenerator.class)
                    .getExtension(DubboClassNameGenerator.NAME).generateResultClassName(
                    com.alibaba.dubbo.rpc.gen.dubbo.Demo.class.getName(), "echoString"));

}
 
Example #20
Source File: ExtensionLoaderTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_getDefaultExtension_NULL() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getDefaultExtension();
    assertNull(ext);
    
    String name = ExtensionLoader.getExtensionLoader(Ext2.class).getDefaultExtensionName();
    assertNull(name);
}
 
Example #21
Source File: ExtensionLoader_Adaptive_Test.java    From dubbox with 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 #22
Source File: Netty4Channel.java    From dubbo-plus with Apache License 2.0 5 votes vote down vote up
protected Codec2 getChannelCodec(URL url) {
    String codecName = url.getParameter(Constants.CODEC_KEY, "telnet");
    if (ExtensionLoader.getExtensionLoader(Codec2.class).hasExtension(codecName)) {
        return ExtensionLoader.getExtensionLoader(Codec2.class).getExtension(codecName);
    } else {
        return new CodecAdapter(ExtensionLoader.getExtensionLoader(Codec.class)
                .getExtension(codecName));
    }
}
 
Example #23
Source File: ExtensionLoaderTest.java    From dubbo-2.6.5 with 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 #24
Source File: ExtensionLoaderTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void test_hasExtension_wrapperIsNotExt() throws Exception {
    assertTrue(ExtensionLoader.getExtensionLoader(WrappedExt.class).hasExtension("impl1"));
    assertFalse(ExtensionLoader.getExtensionLoader(WrappedExt.class).hasExtension("impl1,impl2"));
    assertFalse(ExtensionLoader.getExtensionLoader(WrappedExt.class).hasExtension("xxx"));

    assertFalse(ExtensionLoader.getExtensionLoader(WrappedExt.class).hasExtension("wrapper1"));

    try {
        ExtensionLoader.getExtensionLoader(WrappedExt.class).hasExtension(null);
        fail();
    } catch (IllegalArgumentException expected) {
        assertThat(expected.getMessage(), containsString("Extension name == null"));
    }
}
 
Example #25
Source File: ExtensionLoaderTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadActivateExtension() throws Exception {
    // test default
    URL url = URL.valueOf("test://localhost/test");
    List<ActivateExt1> list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, new String[]{}, "default_group");
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.get(0).getClass() == ActivateExt1Impl1.class);

    // test group
    url = url.addParameter(Constants.GROUP_KEY, "group1");
    list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, new String[]{}, "group1");
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.get(0).getClass() == GroupActivateExtImpl.class);

    // test value
    url = url.removeParameter(Constants.GROUP_KEY);
    url = url.addParameter(Constants.GROUP_KEY, "value");
    url = url.addParameter("value", "value");
    list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, new String[]{}, "value");
    Assert.assertEquals(1, list.size());
    Assert.assertTrue(list.get(0).getClass() == ValueActivateExtImpl.class);

    // test order
    url = URL.valueOf("test://localhost/test");
    url = url.addParameter(Constants.GROUP_KEY, "order");
    list = ExtensionLoader.getExtensionLoader(ActivateExt1.class)
            .getActivateExtension(url, new String[]{}, "order");
    Assert.assertEquals(2, list.size());
    Assert.assertTrue(list.get(0).getClass() == OrderActivateExtImpl1.class);
    Assert.assertTrue(list.get(1).getClass() == OrderActivateExtImpl2.class);
}
 
Example #26
Source File: ExtensionLoader_Adaptive_Test.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_getAdaptiveExtension_UrlNpe() throws Exception {
    SimpleExt ext = ExtensionLoader.getExtensionLoader(SimpleExt.class).getAdaptiveExtension();

    try {
        ext.echo(null, "haha");
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("url == null", e.getMessage());
    }
}
 
Example #27
Source File: ExtensionLoader_Adaptive_Test.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_getAdaptiveExtension_ExceptionWhenNoUrlAttribute() throws Exception {
    try {
        ExtensionLoader.getExtensionLoader(NoUrlParamExt.class).getAdaptiveExtension();
        fail();
    } catch (Exception expected) {
        assertThat(expected.getMessage(), containsString("fail to create adative class for interface "));
        assertThat(expected.getMessage(), containsString(": not found url parameter or url attribute in parameters of method "));
    }
}
 
Example #28
Source File: RegistryStatusCheckerTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckOK() {
    ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension().getRegistry(registryUrl);
    ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension().getRegistry(registryUrl2);
    assertEquals(Status.Level.OK, new RegistryStatusChecker().check().getLevel());
    String message = new RegistryStatusChecker().check().getMessage();
    Assert.assertTrue(message.contains(registryUrl.getAddress() + "(connected)"));
    Assert.assertTrue(message.contains(registryUrl2.getAddress() + "(connected)"));
}
 
Example #29
Source File: AdaptiveCompiler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Class<?> compile(String code, ClassLoader classLoader) {
    Compiler compiler;
    ExtensionLoader<Compiler> loader = ExtensionLoader.getExtensionLoader(Compiler.class);
    String name = DEFAULT_COMPILER; // copy reference
    if (name != null && name.length() > 0) {
        compiler = loader.getExtension(name);
    } else {
        compiler = loader.getDefaultExtension();
    }
    return compiler.compile(code, classLoader);
}
 
Example #30
Source File: ExtensionLoaderTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_AddExtension() throws Exception {
    try {
        ExtensionLoader.getExtensionLoader(AddExt1.class).getExtension("Manual1");
        fail();
    } catch (IllegalStateException expected) {
        assertThat(expected.getMessage(), containsString("No such extension com.alibaba.dubbo.common.extensionloader.ext8_add.AddExt1 by name Manual"));
    }

    ExtensionLoader.getExtensionLoader(AddExt1.class).addExtension("Manual1", AddExt1_ManualAdd1.class);
    AddExt1 ext = ExtensionLoader.getExtensionLoader(AddExt1.class).getExtension("Manual1");

    assertThat(ext, instanceOf(AddExt1_ManualAdd1.class));
    assertEquals("Manual1", ExtensionLoader.getExtensionLoader(AddExt1.class).getExtensionName(AddExt1_ManualAdd1.class));
}