com.alibaba.dubbo.rpc.service.EchoService Java Examples

The following examples show how to use com.alibaba.dubbo.rpc.service.EchoService. 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: AbstractProxyFactory.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example #2
Source File: RmiProtocolTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testRmiProtocol_echoService() throws Exception
   {
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       
    // cast to EchoService
       EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
       
       RemoteService remoteService = new RemoteServiceImpl();
       rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       
       // cast to EchoService
       echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
   }
 
Example #3
Source File: AbstractProxyFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example #4
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testDubboProtocolMultiService() throws Exception
{
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    
    RemoteService remote = new RemoteServiceImpl();
    protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    
    service.sayHello("world");
    
    // test netty client
    assertEquals("world", service.echo("world"));
    assertEquals("hello world@" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
    
    EchoService serviceEcho = (EchoService)service;
    assertEquals(serviceEcho.$echo("test"), "test");
    
    EchoService remoteEecho = (EchoService)remote;
    assertEquals(remoteEecho.$echo("ok"), "ok");
}
 
Example #5
Source File: RmiProtocolTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testRmiProtocol_echoService() throws Exception
   {
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       
    // cast to EchoService
       EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
       
       RemoteService remoteService = new RemoteServiceImpl();
       rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       
       // cast to EchoService
       echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
   }
 
Example #6
Source File: AbstractProxyFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example #7
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testDubboProtocolMultiService() throws Exception
{
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    
    RemoteService remote = new RemoteServiceImpl();
    protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    
    service.sayHello("world");
    
    // test netty client
    assertEquals("world", service.echo("world"));
    assertEquals("hello world@" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
    
    EchoService serviceEcho = (EchoService)service;
    assertEquals(serviceEcho.$echo("test"), "test");
    
    EchoService remoteEecho = (EchoService)remote;
    assertEquals(remoteEecho.$echo("ok"), "ok");
}
 
Example #8
Source File: AbstractProxyFactory.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example #9
Source File: DubboProtocolTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDubboProtocolMultiService() throws Exception
{
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    
    RemoteService remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));

    service.sayHello("world");

    // test netty client
    assertEquals("world", service.echo("world"));
    assertEquals("hello world@" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
    
    EchoService serviceEcho = (EchoService)service;
    assertEquals(serviceEcho.$echo("test"), "test");
    
    EchoService remoteEecho = (EchoService)remote;
    assertEquals(remoteEecho.$echo("ok"), "ok");
}
 
Example #10
Source File: DubboHealthIndicator.java    From dubbo-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
@Override
public void doHealthCheck(Health.Builder builder) throws Exception {
  boolean up = true;
  for (ClassIdBean classIdBean : ConsumerSubscribeListener.SUBSCRIBEDINTERFACES_SET) {
    Object service = DubboConsumerAutoConfiguration.getDubboReference(classIdBean);
    EchoService echoService = (EchoService) service;
    if (echoService != null) {
      try {
        echoService.$echo("Hello");
        builder.withDetail(classIdBean.toString(), Status.UP.getCode());
      } catch (Throwable t) {
        up = false;
        builder.withDetail(classIdBean.toString(),
            Status.DOWN.getCode() + ", message: " + t.getMessage());
      }
    }
  }
  if (up) {
    builder.up();
  } else {
    builder.down();
  }
}
 
Example #11
Source File: RmiProtocolTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testRmiProtocol_echoService() throws Exception
   {
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       
    // cast to EchoService
       EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
       
       RemoteService remoteService = new RemoteServiceImpl();
       rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       
       // cast to EchoService
       echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
   }
 
Example #12
Source File: DubboProtocolTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void testDubboProtocolMultiService() throws Exception
{
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    
    RemoteService remote = new RemoteServiceImpl();
    protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    
    service.sayHello("world");
    
    // test netty client
    assertEquals("world", service.echo("world"));
    assertEquals("hello world@" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
    
    EchoService serviceEcho = (EchoService)service;
    assertEquals(serviceEcho.$echo("test"), "test");
    
    EchoService remoteEecho = (EchoService)remote;
    assertEquals(remoteEecho.$echo("ok"), "ok");
}
 
Example #13
Source File: RmiProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testRmiProtocol_echoService() throws Exception {
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));

    // cast to EchoService
    EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
    assertEquals(echo.$echo("test"), "test");
    assertEquals(echo.$echo("abcdefg"), "abcdefg");
    assertEquals(echo.$echo(1234), 1234);

    rpcExporter.unexport();

    RemoteService remoteService = new RemoteServiceImpl();
    rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));

    // cast to EchoService
    echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
    assertEquals(echo.$echo("test"), "test");
    assertEquals(echo.$echo("abcdefg"), "abcdefg");
    assertEquals(echo.$echo(1234), 1234);

    rpcExporter.unexport();
}
 
Example #14
Source File: AbstractProxyFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example #15
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testDubboProtocolMultiService() throws Exception
{
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    
    RemoteService remote = new RemoteServiceImpl();
    protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    
    service.sayHello("world");
    
    // test netty client
    assertEquals("world", service.echo("world"));
    assertEquals("hello world@" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));
    
    EchoService serviceEcho = (EchoService)service;
    assertEquals(serviceEcho.$echo("test"), "test");
    
    EchoService remoteEecho = (EchoService)remote;
    assertEquals(remoteEecho.$echo("ok"), "ok");
}
 
Example #16
Source File: DubboProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Test
public void testDubboProtocolMultiService() throws Exception {
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));

    RemoteService remote = new RemoteServiceImpl();
    protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));
    remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + RemoteService.class.getName())));

    service.sayHello("world");

    // test netty client
    assertEquals("world", service.echo("world"));
    assertEquals("hello world@" + RemoteServiceImpl.class.getName(), remote.sayHello("world"));

    EchoService serviceEcho = (EchoService) service;
    assertEquals(serviceEcho.$echo("test"), "test");

    EchoService remoteEecho = (EchoService) remote;
    assertEquals(remoteEecho.$echo("ok"), "ok");
}
 
Example #17
Source File: RmiProtocolTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testRmiProtocol_echoService() throws Exception
   {
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       
    // cast to EchoService
       EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/TestService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
       
       RemoteService remoteService = new RemoteServiceImpl();
       rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       
       // cast to EchoService
       echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("rmi://127.0.0.1:9002/remoteService")));
       assertEquals(echo.$echo("test"), "test");
       assertEquals(echo.$echo("abcdefg"), "abcdefg");
       assertEquals(echo.$echo(1234), 1234);
       
       rpcExporter.unexport();
   }
 
Example #18
Source File: Consumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
private void testGetUser2() throws Exception {
    try {
        EchoService echoService = (EchoService)userProvider2;
        Object status = echoService.$echo("OK");
        System.out.println("echo: "+status);
        User user1 = userProvider2.GetUser("A003");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString()
                + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString());
        User user2 = userProvider2.GetUser0("A003","Moorse");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString()
                + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString());
        User user3 = userProvider2.getUser(1);
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString()
                + ", age:" + user3.getAge() + ", time:" + user3.getTime());
        User user4 = userProvider2.getUser(1, "name");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString()
                + ", age:" + user4.getAge() + ", time:" + user4.getTime());
        userProvider2.GetUser3();
        System.out.println("GetUser3 succ");

        User user9 = userProvider2.GetUser1("A003");
    } catch (Throwable e) {
        System.out.println("*************exception***********");
        e.printStackTrace();
    }
    try {
        userProvider2.GetErr("A003");
    } catch (Throwable t) {
        System.out.println("*************exception***********");
        t.printStackTrace();
    }
}
 
Example #19
Source File: DubboProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocol() throws Exception {
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
    assertEquals(service.enumlength(new Type[]{}), Type.Lower);
    assertEquals(service.getSize(null), -1);
    assertEquals(service.getSize(new String[]{"", "", ""}), 3);
    Map<String, String> map = new HashMap<String, String>();
    map.put("aa", "bb");
    Set<String> set = service.keys(map);
    assertEquals(set.size(), 1);
    assertEquals(set.iterator().next(), "aa");
    service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");

    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
    // test netty client
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < 1024 * 32 + 32; i++)
        buf.append('A');
    System.out.println(service.stringLength(buf.toString()));

    // cast to EchoService
    EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
    assertEquals(echo.$echo(buf.toString()), buf.toString());
    assertEquals(echo.$echo("test"), "test");
    assertEquals(echo.$echo("abcdefg"), "abcdefg");
    assertEquals(echo.$echo(1234), 1234);
}
 
Example #20
Source File: DubboProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocolWithMina() throws Exception {
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.SERVER_KEY, "mina")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.CLIENT_KEY, "mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(service.enumlength(new Type[]{}), Type.Lower);
        assertEquals(service.getSize(null), -1);
        assertEquals(service.getSize(new String[]{"", "", ""}), 3);
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("aa", "bb");
    for (int i = 0; i < 10; i++) {
        Set<String> set = service.keys(map);
        assertEquals(set.size(), 1);
        assertEquals(set.iterator().next(), "aa");
        service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");
    }

    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    // test netty client
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < 1024 * 32 + 32; i++)
        buf.append('A');
    System.out.println(service.stringLength(buf.toString()));

    // cast to EchoService
    EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(echo.$echo(buf.toString()), buf.toString());
        assertEquals(echo.$echo("test"), "test");
        assertEquals(echo.$echo("abcdefg"), "abcdefg");
        assertEquals(echo.$echo(1234), 1234);
    }
}
 
Example #21
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocolWithMina() throws Exception {
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.SERVER_KEY, "mina")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.CLIENT_KEY, "mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(service.enumlength(new Type[]{}), Type.Lower);
        assertEquals(service.getSize(null), -1);
        assertEquals(service.getSize(new String[]{"", "", ""}), 3);
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("aa", "bb");
    for(int i = 0; i < 10; i++) {
        Set<String> set = service.keys(map);
        assertEquals(set.size(), 1);
        assertEquals(set.iterator().next(), "aa");
        service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");
    }

    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    // test netty client
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < 1024 * 32 + 32; i++)
        buf.append('A');
    System.out.println(service.stringLength(buf.toString()));

    // cast to EchoService
    EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(echo.$echo(buf.toString()), buf.toString());
        assertEquals(echo.$echo("test"), "test");
        assertEquals(echo.$echo("abcdefg"), "abcdefg");
        assertEquals(echo.$echo(1234), 1234);
    }
}
 
Example #22
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocol() throws Exception
{
	DemoService service = new DemoServiceImpl();
	protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	assertEquals(service.enumlength(new Type[]{}), Type.Lower);
	assertEquals(service.getSize(null), -1);
	assertEquals(service.getSize(new String[]{"", "", ""}), 3);
	Map<String, String> map = new HashMap<String, String>();
	map.put("aa", "bb");
	Set<String> set = service.keys(map);
	assertEquals(set.size(), 1);
	assertEquals(set.iterator().next(), "aa");
	service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");

	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	// test netty client
	StringBuffer buf = new StringBuffer();
	for(int i=0;i<1024*32+32;i++)
		buf.append('A');
	System.out.println(service.stringLength(buf.toString()));

	// cast to EchoService
	EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	assertEquals(echo.$echo(buf.toString()), buf.toString());
	assertEquals(echo.$echo("test"), "test");
	assertEquals(echo.$echo("abcdefg"), "abcdefg");
	assertEquals(echo.$echo(1234), 1234);
}
 
Example #23
Source File: Consumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
private void testGetUser() throws Exception {
    try {
        EchoService echoService = (EchoService)userProvider;
        Object status = echoService.$echo("OK");
        System.out.println("echo: "+status);
        User user1 = userProvider.GetUser("A003");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString()
                + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString());
        User user2 = userProvider.GetUser0("A003","Moorse");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString()
                + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString());
        User user3 = userProvider.getUser(1);
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString()
                + ", age:" + user3.getAge() + ", time:" + user3.getTime());
        User user4 = userProvider.getUser(1, "name");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString()
                + ", age:" + user4.getAge() + ", time:" + user4.getTime());
        userProvider.GetUser3();
        System.out.println("GetUser3 succ");

        User user9 = userProvider.GetUser1("A003");
    } catch (Throwable e) {
        System.out.println("*************exception***********");
        e.printStackTrace();
    }
    try {
        userProvider.GetErr("A003");
    } catch (Throwable t) {
        System.out.println("*************exception***********");
        t.printStackTrace();
    }
}
 
Example #24
Source File: Consumer.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
private void testGetUser1() throws Exception {
    try {
        EchoService echoService = (EchoService)userProvider1;
        Object status = echoService.$echo("OK");
        System.out.println("echo: "+status);
        User user1 = userProvider1.GetUser("A003");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user1.getId() + ", name:" + user1.getName() + ", sex:" + user1.getSex().toString()
                + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString());
        User user2 = userProvider1.GetUser0("A003","Moorse");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user2.getId() + ", name:" + user2.getName() + ", sex:" + user2.getSex().toString()
                + ", age:" + user2.getAge() + ", time:" + user2.getTime().toString());
        User user3 = userProvider1.getUser(1);
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user3.getId() + ", name:" + user3.getName() + ", sex:" + user3.getSex().toString()
                + ", age:" + user3.getAge() + ", time:" + user3.getTime());
        User user4 = userProvider1.getUser(1, "name");
        System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
                " UserInfo, Id:" + user4.getId() + ", name:" + user4.getName() + ", sex:" + user4.getSex().toString()
                + ", age:" + user4.getAge() + ", time:" + user4.getTime());
        userProvider1.GetUser3();
        System.out.println("GetUser3 succ");

        User user9 = userProvider1.GetUser1("A003");
    } catch (Throwable e) {
        System.out.println("*************exception***********");
        e.printStackTrace();
    }
    try {
        userProvider1.GetErr("A003");
    } catch (Throwable t) {
        System.out.println("*************exception***********");
        t.printStackTrace();
    }
}
 
Example #25
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocolWithMina() throws Exception {
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.SERVER_KEY, "mina")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.CLIENT_KEY, "mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(service.enumlength(new Type[]{}), Type.Lower);
        assertEquals(service.getSize(null), -1);
        assertEquals(service.getSize(new String[]{"", "", ""}), 3);
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("aa", "bb");
    for(int i = 0; i < 10; i++) {
        Set<String> set = service.keys(map);
        assertEquals(set.size(), 1);
        assertEquals(set.iterator().next(), "aa");
        service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");
    }

    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    // test netty client
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < 1024 * 32 + 32; i++)
        buf.append('A');
    System.out.println(service.stringLength(buf.toString()));

    // cast to EchoService
    EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(echo.$echo(buf.toString()), buf.toString());
        assertEquals(echo.$echo("test"), "test");
        assertEquals(echo.$echo("abcdefg"), "abcdefg");
        assertEquals(echo.$echo(1234), 1234);
    }
}
 
Example #26
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocol() throws Exception
{
	DemoService service = new DemoServiceImpl();
	protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	assertEquals(service.enumlength(new Type[]{}), Type.Lower);
	assertEquals(service.getSize(null), -1);
	assertEquals(service.getSize(new String[]{"", "", ""}), 3);
	Map<String, String> map = new HashMap<String, String>();
	map.put("aa", "bb");
	Set<String> set = service.keys(map);
	assertEquals(set.size(), 1);
	assertEquals(set.iterator().next(), "aa");
	service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");

	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	// test netty client
	StringBuffer buf = new StringBuffer();
	for(int i=0;i<1024*32+32;i++)
		buf.append('A');
	System.out.println(service.stringLength(buf.toString()));

	// cast to EchoService
	EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	assertEquals(echo.$echo(buf.toString()), buf.toString());
	assertEquals(echo.$echo("test"), "test");
	assertEquals(echo.$echo("abcdefg"), "abcdefg");
	assertEquals(echo.$echo(1234), 1234);
}
 
Example #27
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocol() throws Exception
{
	DemoService service = new DemoServiceImpl();
	protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	assertEquals(service.enumlength(new Type[]{}), Type.Lower);
	assertEquals(service.getSize(null), -1);
	assertEquals(service.getSize(new String[]{"", "", ""}), 3);
	Map<String, String> map = new HashMap<String, String>();
	map.put("aa", "bb");
	Set<String> set = service.keys(map);
	assertEquals(set.size(), 1);
	assertEquals(set.iterator().next(), "aa");
	service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");

	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	// test netty client
	StringBuffer buf = new StringBuffer();
	for(int i=0;i<1024*32+32;i++)
		buf.append('A');
	System.out.println(service.stringLength(buf.toString()));

	// cast to EchoService
	EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	assertEquals(echo.$echo(buf.toString()), buf.toString());
	assertEquals(echo.$echo("test"), "test");
	assertEquals(echo.$echo("abcdefg"), "abcdefg");
	assertEquals(echo.$echo(1234), 1234);
}
 
Example #28
Source File: DubboProtocolTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocolWithMina() throws Exception {
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.SERVER_KEY, "mina")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.CLIENT_KEY, "mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(service.enumlength(new Type[]{}), Type.Lower);
        assertEquals(service.getSize(null), -1);
        assertEquals(service.getSize(new String[]{"", "", ""}), 3);
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("aa", "bb");
    for(int i = 0; i < 10; i++) {
        Set<String> set = service.keys(map);
        assertEquals(set.size(), 1);
        assertEquals(set.iterator().next(), "aa");
        service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");
    }

    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    // test netty client
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < 1024 * 32 + 32; i++)
        buf.append('A');
    System.out.println(service.stringLength(buf.toString()));

    // cast to EchoService
    EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(echo.$echo(buf.toString()), buf.toString());
        assertEquals(echo.$echo("test"), "test");
        assertEquals(echo.$echo("abcdefg"), "abcdefg");
        assertEquals(echo.$echo(1234), 1234);
    }
}
 
Example #29
Source File: DubboProtocolTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocol() throws Exception
{
	DemoService service = new DemoServiceImpl();
	protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName())));
	assertEquals(service.enumlength(new Type[]{}), Type.Lower);
	assertEquals(service.getSize(null), -1);
	assertEquals(service.getSize(new String[]{"", "", ""}), 3);
	Map<String, String> map = new HashMap<String, String>();
	map.put("aa", "bb");
	Set<String> set = service.keys(map);
	assertEquals(set.size(), 1);
	assertEquals(set.iterator().next(), "aa");
	service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");

	service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	// test netty client
	StringBuffer buf = new StringBuffer();
	for(int i=0;i<1024*32+32;i++)
		buf.append('A');
	System.out.println(service.stringLength(buf.toString()));

	// cast to EchoService
	EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=netty")));
	assertEquals(echo.$echo(buf.toString()), buf.toString());
	assertEquals(echo.$echo("test"), "test");
	assertEquals(echo.$echo("abcdefg"), "abcdefg");
	assertEquals(echo.$echo(1234), 1234);
}
 
Example #30
Source File: DubboProtocolTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testDubboProtocolWithMina() throws Exception {
    DemoService service = new DemoServiceImpl();
    protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.SERVER_KEY, "mina")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName()).addParameter(Constants.CLIENT_KEY, "mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(service.enumlength(new Type[]{}), Type.Lower);
        assertEquals(service.getSize(null), -1);
        assertEquals(service.getSize(new String[]{"", "", ""}), 3);
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("aa", "bb");
    for(int i = 0; i < 10; i++) {
        Set<String> set = service.keys(map);
        assertEquals(set.size(), 1);
        assertEquals(set.iterator().next(), "aa");
        service.invoke("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "", "invoke");
    }

    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    // test netty client
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < 1024 * 32 + 32; i++)
        buf.append('A');
    System.out.println(service.stringLength(buf.toString()));

    // cast to EchoService
    EchoService echo = proxy.getProxy(protocol.refer(EchoService.class, URL.valueOf("dubbo://127.0.0.1:9010/" + DemoService.class.getName() + "?client=mina")));
    for (int i = 0; i < 10; i++) {
        assertEquals(echo.$echo(buf.toString()), buf.toString());
        assertEquals(echo.$echo("test"), "test");
        assertEquals(echo.$echo("abcdefg"), "abcdefg");
        assertEquals(echo.$echo(1234), 1234);
    }
}