com.alibaba.dubbo.config.api.DemoService Java Examples
The following examples show how to use
com.alibaba.dubbo.config.api.DemoService.
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: ServiceConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void testExport() throws Exception { service.export(); assertThat(service.getExportedUrls(), hasSize(1)); URL url = service.toUrl(); assertThat(url.getProtocol(), equalTo("mockprotocol2")); assertThat(url.getPath(), equalTo(DemoService.class.getName())); assertThat(url.getParameters(), hasEntry(Constants.ANYHOST_KEY, "true")); assertThat(url.getParameters(), hasEntry(Constants.APPLICATION_KEY, "app")); assertThat(url.getParameters(), hasKey(Constants.BIND_IP_KEY)); assertThat(url.getParameters(), hasKey(Constants.BIND_PORT_KEY)); assertThat(url.getParameters(), hasEntry(Constants.DEFAULT_KEY + "." + Constants.EXPORT_KEY, "true")); assertThat(url.getParameters(), hasEntry(Constants.EXPORT_KEY, "true")); assertThat(url.getParameters(), hasEntry("echo.0.callback", "false")); assertThat(url.getParameters(), hasEntry(Constants.GENERIC_KEY, "false")); assertThat(url.getParameters(), hasEntry(Constants.INTERFACE_KEY, DemoService.class.getName())); assertThat(url.getParameters(), hasKey(Constants.METHODS_KEY)); assertThat(url.getParameters().get(Constants.METHODS_KEY), containsString("echo")); assertThat(url.getParameters(), hasEntry(Constants.SIDE_KEY, Constants.PROVIDER)); Mockito.verify(protocolDelegate).export(Mockito.any(Invoker.class)); }
Example #2
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testGenericReferenceException() { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); service.setRef(new DemoServiceImpl()); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote"); reference.setGeneric(true); GenericService genericService = reference.get(); try { List<Map<String, Object>> users = new ArrayList<Map<String, Object>>(); Map<String, Object> user = new HashMap<String, Object>(); user.put("class", "com.alibaba.dubbo.config.api.User"); user.put("name", "actual.provider"); users.add(user); users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{users}); Assert.assertEquals(1, users.size()); Assert.assertEquals("actual.provider", users.get(0).get("name")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #3
Source File: GenericServiceTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testGenericReferenceException() { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); service.setRef(new DemoServiceImpl()); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote"); reference.setGeneric(true); GenericService genericService = reference.get(); try { List<Map<String, Object>> users = new ArrayList<Map<String, Object>>(); Map<String, Object> user = new HashMap<String, Object>(); user.put("class", "com.alibaba.dubbo.config.api.User"); user.put("name", "actual.provider"); users.add(user); users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{users}); Assert.assertEquals(1, users.size()); Assert.assertEquals("actual.provider", users.get(0).get("name")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #4
Source File: UrlTestBase.java From dubbo3 with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example #5
Source File: InvokerSideConfigUrlTest.java From dubbo3 with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example #6
Source File: ReferenceConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testInjvm() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("test-protocol-random-port"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("multicast://224.5.6.7:1234"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); ServiceConfig<DemoService> demoService; demoService = new ServiceConfig<DemoService>(); demoService.setInterface(DemoService.class); demoService.setRef(new DemoServiceImpl()); demoService.setApplication(application); demoService.setRegistry(registry); demoService.setProtocol(protocol); ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>(); rc.setApplication(application); rc.setRegistry(registry); rc.setInterface(DemoService.class.getName()); rc.setInjvm(false); try { demoService.export(); rc.get(); Assert.assertTrue(!Constants.LOCAL_PROTOCOL.equalsIgnoreCase( rc.getInvoker().getUrl().getProtocol())); } finally { demoService.unexport(); } }
Example #7
Source File: ReferenceConfigTest.java From dubbo3 with Apache License 2.0 | 5 votes |
@Test public void testInjvm() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("test-protocol-random-port"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("multicast://224.5.6.7:1234"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); ServiceConfig<DemoService> demoService; demoService = new ServiceConfig<DemoService>(); demoService.setInterface(DemoService.class); demoService.setRef(new DemoServiceImpl()); demoService.setApplication(application); demoService.setRegistry(registry); demoService.setProtocol(protocol); ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>(); rc.setApplication(application); rc.setRegistry(registry); rc.setInterface(DemoService.class.getName()); rc.setInjvm(false); try { demoService.export(); rc.get(); Assert.assertTrue(!Constants.LOCAL_PROTOCOL.equalsIgnoreCase( rc.getInvoker().getUrl().getProtocol())); } finally { demoService.unexport(); } }
Example #8
Source File: ReferenceConfigTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void testInjvm() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("test-protocol-random-port"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("multicast://224.5.6.7:1234"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); ServiceConfig<DemoService> demoService; demoService = new ServiceConfig<DemoService>(); demoService.setInterface(DemoService.class); demoService.setRef(new DemoServiceImpl()); demoService.setApplication(application); demoService.setRegistry(registry); demoService.setProtocol(protocol); ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>(); rc.setApplication(application); rc.setRegistry(registry); rc.setInterface(DemoService.class.getName()); rc.setInjvm(false); try { demoService.export(); rc.get(); Assert.assertTrue(!Constants.LOCAL_PROTOCOL.equalsIgnoreCase( rc.getInvoker().getUrl().getProtocol())); } finally { demoService.unexport(); } }
Example #9
Source File: GenericServiceTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testGenericReferenceException() { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); service.setRef(new DemoServiceImpl()); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote"); reference.setGeneric(true); GenericService genericService = reference.get(); try { List<Map<String, Object>> users = new ArrayList<Map<String, Object>>(); Map<String, Object> user = new HashMap<String, Object>(); user.put("class", "com.alibaba.dubbo.config.api.User"); user.put("name", "actual.provider"); users.add(user); users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{users}); Assert.assertEquals(1, users.size()); Assert.assertEquals("actual.provider", users.get(0).get("name")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #10
Source File: UrlTestBase.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example #11
Source File: InvokerSideConfigUrlTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example #12
Source File: InvokerSideConfigUrlTest.java From dubbox with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example #13
Source File: UrlTestBase.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example #14
Source File: ReferenceConfigTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void testInjvm() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("test-protocol-random-port"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("multicast://224.5.6.7:1234"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); ServiceConfig<DemoService> demoService; demoService = new ServiceConfig<DemoService>(); demoService.setInterface(DemoService.class); demoService.setRef(new DemoServiceImpl()); demoService.setApplication(application); demoService.setRegistry(registry); demoService.setProtocol(protocol); ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>(); rc.setApplication(application); rc.setRegistry(registry); rc.setInterface(DemoService.class.getName()); rc.setInjvm(false); try { demoService.export(); rc.get(); Assert.assertTrue(!Constants.LOCAL_PROTOCOL.equalsIgnoreCase( rc.getInvoker().getUrl().getProtocol())); } finally { demoService.unexport(); } }
Example #15
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testGenericReferenceException() { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); service.setRef(new DemoServiceImpl()); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote"); reference.setGeneric(true); GenericService genericService = reference.get(); try { List<Map<String, Object>> users = new ArrayList<Map<String, Object>>(); Map<String, Object> user = new HashMap<String, Object>(); user.put("class", "com.alibaba.dubbo.config.api.User"); user.put("name", "actual.provider"); users.add(user); users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{users}); Assert.assertEquals(1, users.size()); Assert.assertEquals("actual.provider", users.get(0).get("name")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #16
Source File: UrlTestBase.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example #17
Source File: ReferenceConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testInjvm() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("test-protocol-random-port"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("multicast://224.5.6.7:1234"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); ServiceConfig<DemoService> demoService; demoService = new ServiceConfig<DemoService>(); demoService.setInterface(DemoService.class); demoService.setRef(new DemoServiceImpl()); demoService.setApplication(application); demoService.setRegistry(registry); demoService.setProtocol(protocol); ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>(); rc.setApplication(application); rc.setRegistry(registry); rc.setInterface(DemoService.class.getName()); rc.setInjvm(false); try { demoService.export(); rc.get(); Assert.assertTrue(!Constants.LOCAL_PROTOCOL.equalsIgnoreCase( rc.getInvoker().getUrl().getProtocol())); } finally { demoService.unexport(); } }
Example #18
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testGenericReferenceException() { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); service.setRef(new DemoServiceImpl()); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote"); reference.setGeneric(true); GenericService genericService = reference.get(); try { List<Map<String, Object>> users = new ArrayList<Map<String, Object>>(); Map<String, Object> user = new HashMap<String, Object>(); user.put("class", "com.alibaba.dubbo.config.api.User"); user.put("name", "actual.provider"); users.add(user); users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{users}); Assert.assertEquals(1, users.size()); Assert.assertEquals("actual.provider", users.get(0).get("name")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #19
Source File: InvokerSideConfigUrlTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
private void initRefConf() { appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example #20
Source File: ReferenceConfigTest.java From dubbox with Apache License 2.0 | 5 votes |
@Test public void testInjvm() throws Exception { ApplicationConfig application = new ApplicationConfig(); application.setName("test-protocol-random-port"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("multicast://224.5.6.7:1234"); ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("dubbo"); ServiceConfig<DemoService> demoService; demoService = new ServiceConfig<DemoService>(); demoService.setInterface(DemoService.class); demoService.setRef(new DemoServiceImpl()); demoService.setApplication(application); demoService.setRegistry(registry); demoService.setProtocol(protocol); ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>(); rc.setApplication(application); rc.setRegistry(registry); rc.setInterface(DemoService.class.getName()); rc.setInjvm(false); try { demoService.export(); rc.get(); Assert.assertTrue(!Constants.LOCAL_PROTOCOL.equalsIgnoreCase( rc.getInvoker().getUrl().getProtocol())); } finally { demoService.unexport(); } }
Example #21
Source File: GenericServiceTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testGenericReferenceException() { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); service.setRef(new DemoServiceImpl()); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote&timeout=3000"); reference.setGeneric(true); GenericService genericService = reference.get(); try { List<Map<String, Object>> users = new ArrayList<Map<String, Object>>(); Map<String, Object> user = new HashMap<String, Object>(); user.put("class", "com.alibaba.dubbo.config.api.User"); user.put("name", "actual.provider"); users.add(user); users = (List<Map<String, Object>>) genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{users}); Assert.assertEquals(1, users.size()); Assert.assertEquals("actual.provider", users.get(0).get("name")); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #22
Source File: InvokerSideConfigUrlTest.java From dubbox with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example #23
Source File: InvokerSideConfigUrlTest.java From dubbox with Apache License 2.0 | 5 votes |
private void initRefConf(){ appConfForConsumer = new ApplicationConfig(); appConfForReference = new ApplicationConfig(); regConfForConsumer = new RegistryConfig(); regConfForReference = new RegistryConfig(); methodConfForReference = new MethodConfig(); refConf = new ReferenceConfig<DemoService>(); consumerConf = new ConsumerConfig(); methodConfForReference.setName("sayName"); regConfForReference.setAddress("127.0.0.1:9090"); regConfForReference.setProtocol("mockregistry"); appConfForReference.setName("ConfigTests"); refConf.setInterface("com.alibaba.dubbo.config.api.DemoService"); refConf.setApplication(appConfForReference); consumerConf.setApplication(appConfForConsumer); refConf.setRegistry(regConfForReference); consumerConf.setRegistry(regConfForConsumer); refConf.setConsumer(consumerConf); refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference})); refConf.setScope(Constants.SCOPE_REMOTE); }
Example #24
Source File: UrlTestBase.java From dubbox with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example #25
Source File: UrlTestBase.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void initServConf() { appConfForProvider = new ApplicationConfig(); appConfForService = new ApplicationConfig(); regConfForProvider = new RegistryConfig(); regConfForService = new RegistryConfig(); provConf = new ProviderConfig(); protoConfForProvider = new ProtocolConfig(); protoConfForService = new ProtocolConfig(); methodConfForService = new MethodConfig(); servConf = new ServiceConfig<DemoService>(); provConf.setApplication(appConfForProvider); servConf.setApplication(appConfForService); provConf.setRegistry(regConfForProvider); servConf.setRegistry(regConfForService); provConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForProvider})); servConf.setProtocols(Arrays.asList(new ProtocolConfig[]{protoConfForService})); servConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForService})); servConf.setProvider(provConf); servConf.setRef(demoService); servConf.setInterfaceClass(DemoService.class); methodConfForService.setName("sayName"); regConfForService.setAddress("127.0.0.1:9090"); regConfForService.setProtocol("mockregistry"); appConfForService.setName("ConfigTests"); }
Example #26
Source File: DemoActionBySetter.java From dubbox with Apache License 2.0 | 4 votes |
public void setDemoService(DemoService demoService) { this.demoService = demoService; }
Example #27
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testGenericSerializationJava() throws Exception { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); DemoServiceImpl ref = new DemoServiceImpl(); service.setRef(ref); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote"); reference.setGeneric(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA); GenericService genericService = reference.get(); try { String name = "kimi"; ByteArrayOutputStream bos = new ByteArrayOutputStream(512); ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava").serialize(null, bos).writeObject(name); byte[] arg = bos.toByteArray(); Object obj = genericService.$invoke("sayName", new String[]{String.class.getName()}, new Object[]{arg}); Assert.assertTrue(obj instanceof byte[]); byte[] result = (byte[]) obj; Assert.assertEquals(ref.sayName(name), ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava").deserialize(null, new ByteArrayInputStream(result)).readObject().toString()); // getUsers List<User> users = new ArrayList<User>(); User user = new User(); user.setName(name); users.add(user); bos = new ByteArrayOutputStream(512); ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava").serialize(null, bos).writeObject(users); obj = genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{bos.toByteArray()}); Assert.assertTrue(obj instanceof byte[]); result = (byte[]) obj; Assert.assertEquals(users, ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava") .deserialize(null, new ByteArrayInputStream(result)) .readObject()); // echo(int) bos = new ByteArrayOutputStream(512); ExtensionLoader.getExtensionLoader(Serialization.class).getExtension("nativejava") .serialize(null, bos).writeObject(Integer.MAX_VALUE); obj = genericService.$invoke("echo", new String[]{int.class.getName()}, new Object[]{bos.toByteArray()}); Assert.assertTrue(obj instanceof byte[]); Assert.assertEquals(Integer.MAX_VALUE, ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava") .deserialize(null, new ByteArrayInputStream((byte[]) obj)) .readObject()); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #28
Source File: GenericServiceTest.java From dubbo3 with Apache License 2.0 | 4 votes |
@Test public void testGenericSerializationJava() throws Exception { ServiceConfig<DemoService> service = new ServiceConfig<DemoService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); DemoServiceImpl ref = new DemoServiceImpl(); service.setRef(ref); service.export(); try { ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?scope=remote"); reference.setGeneric(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA); GenericService genericService = reference.get(); try { String name = "kimi"; ByteArrayOutputStream bos = new ByteArrayOutputStream(512); ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava").serialize(null, bos).writeObject(name); byte[] arg = bos.toByteArray(); Object obj = genericService.$invoke("sayName", new String[]{String.class.getName()}, new Object[]{arg}); Assert.assertTrue(obj instanceof byte[]); byte[] result = (byte[]) obj; Assert.assertEquals(ref.sayName(name), ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava").deserialize(null, new ByteArrayInputStream(result)).readObject().toString()); // getUsers List<User> users = new ArrayList<User>(); User user = new User(); user.setName(name); users.add(user); bos = new ByteArrayOutputStream(512); ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava").serialize(null, bos).writeObject(users); obj = genericService.$invoke("getUsers", new String[]{List.class.getName()}, new Object[]{bos.toByteArray()}); Assert.assertTrue(obj instanceof byte[]); result = (byte[]) obj; Assert.assertEquals(users, ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava") .deserialize(null, new ByteArrayInputStream(result)) .readObject()); // echo(int) bos = new ByteArrayOutputStream(512); ExtensionLoader.getExtensionLoader(Serialization.class).getExtension("nativejava") .serialize(null, bos).writeObject(Integer.MAX_VALUE); obj = genericService.$invoke("echo", new String[]{int.class.getName()}, new Object[]{bos.toByteArray()}); Assert.assertTrue(obj instanceof byte[]); Assert.assertEquals(Integer.MAX_VALUE, ExtensionLoader.getExtensionLoader(Serialization.class) .getExtension("nativejava") .deserialize(null, new ByteArrayInputStream((byte[]) obj)) .readObject()); } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #29
Source File: GenericServiceTest.java From dubbox with Apache License 2.0 | 4 votes |
@Test public void testGenericServiceException() { ServiceConfig<GenericService> service = new ServiceConfig<GenericService>(); service.setApplication(new ApplicationConfig("generic-provider")); service.setRegistry(new RegistryConfig("N/A")); service.setProtocol(new ProtocolConfig("dubbo", 29581)); service.setInterface(DemoService.class.getName()); service.setRef(new GenericService() { public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException { if ("sayName".equals(method)) { return "Generic " + args[0]; } if ("throwDemoException".equals(method)) { throw new GenericException(DemoException.class.getName(), "Generic"); } if ("getUsers".equals(method)) { return args[0]; } return null; } }); service.export(); try { ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>(); reference.setApplication(new ApplicationConfig("generic-consumer")); reference.setInterface(DemoService.class); reference.setUrl("dubbo://127.0.0.1:29581?generic=true"); DemoService demoService = reference.get(); try { // say name Assert.assertEquals("Generic Haha", demoService.sayName("Haha")); // get users List<User> users = new ArrayList<User>(); users.add(new User("Aaa")); users = demoService.getUsers(users); Assert.assertEquals("Aaa", users.get(0).getName()); // throw demo exception try { demoService.throwDemoException(); Assert.fail(); } catch (DemoException e) { Assert.assertEquals("Generic", e.getMessage()); } } finally { reference.destroy(); } } finally { service.unexport(); } }
Example #30
Source File: DemoActionByAnnotation.java From dubbox with Apache License 2.0 | 4 votes |
public DemoService getDemoService() { return demoService; }