Java Code Examples for com.alibaba.dubbo.rpc.protocol.dubbo.support.ProtocolUtils#export()

The following examples show how to use com.alibaba.dubbo.rpc.protocol.dubbo.support.ProtocolUtils#export() . 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: DubboInvokerAvilableTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Test
public void test_Lazy_ChannelReadOnly() throws Exception{
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?lazy=true&connections=1");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    DubboInvoker<?> invoker = (DubboInvoker<?>)protocol.refer(IDemoService.class, url);
    Assert.assertEquals(true, invoker.isAvailable());
    
    try{
        getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
        fail();
    }catch (IllegalStateException e) {
        
    }
    //invoke method --> init client
    
    IDemoService service = (IDemoService)proxy.getProxy(invoker);
    Assert.assertEquals("ok", service.get());
    
    Assert.assertEquals(true, invoker.isAvailable());
    getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
    Assert.assertEquals(false, invoker.isAvailable());
}
 
Example 2
Source File: DubboInvokerAvilableTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void test_Lazy_ChannelReadOnly() throws Exception{
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?lazy=true&connections=1");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    DubboInvoker<?> invoker = (DubboInvoker<?>)protocol.refer(IDemoService.class, url);
    Assert.assertEquals(true, invoker.isAvailable());
    
    try{
        getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
        fail();
    }catch (IllegalStateException e) {
        
    }
    //invoke method --> init client
    
    IDemoService service = (IDemoService)proxy.getProxy(invoker);
    Assert.assertEquals("ok", service.get());
    
    Assert.assertEquals(true, invoker.isAvailable());
    getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
    Assert.assertEquals(false, invoker.isAvailable());
}
 
Example 3
Source File: DubboInvokerAvilableTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void test_Lazy_ChannelReadOnly() throws Exception{
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?lazy=true&connections=1");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    DubboInvoker<?> invoker = (DubboInvoker<?>)protocol.refer(IDemoService.class, url);
    Assert.assertEquals(true, invoker.isAvailable());
    
    try{
        getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
        fail();
    }catch (IllegalStateException e) {
        
    }
    //invoke method --> init client
    
    IDemoService service = (IDemoService)proxy.getProxy(invoker);
    Assert.assertEquals("ok", service.get());
    
    Assert.assertEquals(true, invoker.isAvailable());
    getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
    Assert.assertEquals(false, invoker.isAvailable());
}
 
Example 4
Source File: DubboInvokerAvilableTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void test_Lazy_ChannelReadOnly() throws Exception {
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?lazy=true&connections=1");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);

    DubboInvoker<?> invoker = (DubboInvoker<?>) protocol.refer(IDemoService.class, url);
    Assert.assertEquals(true, invoker.isAvailable());

    try {
        getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
        fail();
    } catch (IllegalStateException e) {

    }
    //invoke method --> init client

    IDemoService service = (IDemoService) proxy.getProxy(invoker);
    Assert.assertEquals("ok", service.get());

    Assert.assertEquals(true, invoker.isAvailable());
    getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
    Assert.assertEquals(false, invoker.isAvailable());
}
 
Example 5
Source File: ExplicitCallbackTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void exportService(){
  //先export一个service,测试共享连接的问题
    serviceURL=serviceURL.addParameter("connections", 1);
    URL hellourl = serviceURL.setPath(IHelloService.class.getName());
    hello_exporter = ProtocolUtils.export(new HelloServiceImpl(), IHelloService.class, hellourl);
    exporter = ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, serviceURL);
}
 
Example 6
Source File: ExplicitCallbackTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public void exportService(){
  //先export一个service,测试共享连接的问题
    serviceURL=serviceURL.addParameter("connections", 1);
    URL hellourl = serviceURL.setPath(IHelloService.class.getName());
    hello_exporter = ProtocolUtils.export(new HelloServiceImpl(), IHelloService.class, hellourl);
    exporter = ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, serviceURL);
}
 
Example 7
Source File: DubboLazyConnectTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testSticky4() {
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("dubbo://127.0.0.1:"+port+"/hi?"+Constants.LAZY_CONNECT_KEY+"=true");
    
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    IDemoService service = (IDemoService)ProtocolUtils.refer(IDemoService.class, url);
    Assert.assertEquals("ok", service.get());
}
 
Example 8
Source File: DubboInvokerAvilableTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_NoInvokers() throws Exception{
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?connections=1");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    DubboInvoker<?> invoker = (DubboInvoker<?>)protocol.refer(IDemoService.class, url);
    
    ExchangeClient[] clients = getClients(invoker);
    clients[0].close();
    Assert.assertEquals(false, invoker.isAvailable());
    
}
 
Example 9
Source File: ExplicitCallbackTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public void exportService(){
  //先export一个service,测试共享连接的问题
    serviceURL=serviceURL.addParameter("connections", 1);
    URL hellourl = serviceURL.setPath(IHelloService.class.getName());
    hello_exporter = ProtocolUtils.export(new HelloServiceImpl(), IHelloService.class, hellourl);
    exporter = ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, serviceURL);
}
 
Example 10
Source File: DubboInvokerAvilableTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_Normal_available(){
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    DubboInvoker<?> invoker = (DubboInvoker<?>)protocol.refer(IDemoService.class, url);
    Assert.assertEquals(true, invoker.isAvailable());
    invoker.destroy();
    Assert.assertEquals(false, invoker.isAvailable());
}
 
Example 11
Source File: DubboLazyConnectTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testSticky4() {
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("dubbo://127.0.0.1:" + port + "/hi?" + Constants.LAZY_CONNECT_KEY + "=true");

    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);

    IDemoService service = (IDemoService) ProtocolUtils.refer(IDemoService.class, url);
    Assert.assertEquals("ok", service.get());
}
 
Example 12
Source File: DubboLazyConnectTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testSticky4() {
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("dubbo://127.0.0.1:"+port+"/hi?"+Constants.LAZY_CONNECT_KEY+"=true");
    
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);
    
    IDemoService service = (IDemoService)ProtocolUtils.refer(IDemoService.class, url);
    Assert.assertEquals("ok", service.get());
}
 
Example 13
Source File: DubboInvokerAvilableTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_NoInvokers() throws Exception {
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi?connections=1");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);

    DubboInvoker<?> invoker = (DubboInvoker<?>) protocol.refer(IDemoService.class, url);

    ExchangeClient[] clients = getClients(invoker);
    clients[0].close();
    Assert.assertEquals(false, invoker.isAvailable());

}
 
Example 14
Source File: DubboInvokerAvilableTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_Normal_ChannelReadOnly() throws Exception {
    URL url = URL.valueOf("dubbo://127.0.0.1:20883/hi");
    ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, url);

    DubboInvoker<?> invoker = (DubboInvoker<?>) protocol.refer(IDemoService.class, url);
    Assert.assertEquals(true, invoker.isAvailable());

    getClients(invoker)[0].setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);

    Assert.assertEquals(false, invoker.isAvailable());

    // reset status since connection is shared among invokers
    getClients(invoker)[0].removeAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY);
}
 
Example 15
Source File: ExplicitCallbackTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public void exportService() {
    // export one service first, to test connection sharing
    serviceURL = serviceURL.addParameter("connections", 1);
    URL hellourl = serviceURL.setPath(IHelloService.class.getName());
    hello_exporter = ProtocolUtils.export(new HelloServiceImpl(), IHelloService.class, hellourl);
    exporter = ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, serviceURL);
}
 
Example 16
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void exportService(){
    exporter = ProtocolUtils.export(new NormalDemoService(), IDemoService.class, serviceURL);
}
 
Example 17
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public void exportService(){
    exporter = ProtocolUtils.export(new NormalDemoService(), IDemoService.class, serviceURL);
}
 
Example 18
Source File: ImplicitCallBackTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public void exportExService(){
    exporter = ProtocolUtils.export(new ExceptionDemoExService(), IDemoService.class, serviceURL);
}
 
Example 19
Source File: ImplicitCallBackTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public void exportExService(){
    exporter = ProtocolUtils.export(new ExceptionDemoExService(), IDemoService.class, serviceURL);
}
 
Example 20
Source File: ImplicitCallBackTest.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public void exportExService() {
    exporter = ProtocolUtils.export(new ExceptionDemoExService(), IDemoService.class, serviceURL);
}