Search in sources :

Example 1 with GenericService

use of org.apache.dubbo.rpc.service.GenericService in project dubbo by alibaba.

the class EnumBak method testGenericEnum.

@Test
public void testGenericEnum() throws InterruptedException {
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE);
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    URL consumerurl = serviceurl;
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Object obj = demoProxy.$invoke("enumlength", new String[] { Type[].class.getName() }, new Object[] { new Type[] { Type.High, Type.High } });
    System.out.println("obj---------->" + obj);
    invoker.destroy();
    reference.destroy();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 2 with GenericService

use of org.apache.dubbo.rpc.service.GenericService in project dubbo by alibaba.

the class EnumBak method testGenricEnumCompat.

// verify compatibility when 2.0.5 invokes 2.0.3
@Disabled
@Test
public void testGenricEnumCompat() {
    int port = NetUtils.getAvailablePort();
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE);
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Object obj = demoProxy.$invoke("enumlength", new String[] { Type[].class.getName() }, new Object[] { new Type[] { Type.High, Type.High } });
    System.out.println("obj---------->" + obj);
    reference.destroy();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with GenericService

use of org.apache.dubbo.rpc.service.GenericService in project dubbo by alibaba.

the class ConfigTest method testReferGenericExport.

@Test
public void testReferGenericExport() throws Exception {
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);
    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef((method, parameterTypes, args) -> null);
    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("test-refer-generic-export")).service(sc).reference(ref);
    try {
        bootstrap.start();
        Assertions.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) BeanCreationException(org.springframework.beans.factory.BeanCreationException) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 4 with GenericService

use of org.apache.dubbo.rpc.service.GenericService in project dubbo by alibaba.

the class HessianProtocolTest method testGenericInvoke.

@Test
public void testGenericInvoke() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assertions.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("hessian://127.0.0.1:" + port + "/" + HessianService.class.getName() + "?version=1.0.0");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    String result = (String) client.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "haha" });
    Assertions.assertTrue(server.isCalled());
    Assertions.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
Also used : GenericService(org.apache.dubbo.rpc.service.GenericService) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 5 with GenericService

use of org.apache.dubbo.rpc.service.GenericService in project dubbo by alibaba.

the class HessianProtocolTest method testGenericInvokeWithBean.

@Test
public void testGenericInvokeWithBean() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assertions.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    int port = NetUtils.getAvailablePort();
    URL url = URL.valueOf("hessian://127.0.0.1:" + port + "/" + HessianService.class.getName() + "?version=1.0.0&generic=bean");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);
    JavaBeanDescriptor javaBeanDescriptor = JavaBeanSerializeUtil.serialize("haha");
    Object result = client.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { javaBeanDescriptor });
    Assertions.assertTrue(server.isCalled());
    Assertions.assertEquals("Hello, haha", JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) result));
    invoker.destroy();
    exporter.unexport();
}
Also used : JavaBeanDescriptor(org.apache.dubbo.common.beanutil.JavaBeanDescriptor) GenericService(org.apache.dubbo.rpc.service.GenericService) ProxyFactory(org.apache.dubbo.rpc.ProxyFactory) Protocol(org.apache.dubbo.rpc.Protocol) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Aggregations

GenericService (org.apache.dubbo.rpc.service.GenericService)23 Test (org.junit.jupiter.api.Test)20 URL (org.apache.dubbo.common.URL)14 Protocol (org.apache.dubbo.rpc.Protocol)9 ProxyFactory (org.apache.dubbo.rpc.ProxyFactory)9 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)8 RegistryConfig (org.apache.dubbo.config.RegistryConfig)8 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)8 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)7 ServiceConfig (org.apache.dubbo.config.ServiceConfig)7 ArrayList (java.util.ArrayList)5 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)5 ComplexObject (org.apache.dubbo.service.ComplexObject)4 DemoService (org.apache.dubbo.service.DemoService)4 DemoServiceImpl (org.apache.dubbo.service.DemoServiceImpl)4 HashMap (java.util.HashMap)3 List (java.util.List)3 JavaBeanDescriptor (org.apache.dubbo.common.beanutil.JavaBeanDescriptor)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2