use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testToString.
@Test
public void testToString() {
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setApplication(new ApplicationConfig("consumer"));
reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
reference.setInterface(DemoService.class);
reference.setUrl("dubbo://127.0.0.1:20881");
String str = reference.toString();
assertTrue(str.startsWith("<dubbo:reference "));
assertTrue(str.contains(" url=\"dubbo://127.0.0.1:20881\" "));
assertTrue(str.contains(" interface=\"com.alibaba.dubbo.config.spring.api.DemoService\" "));
assertTrue(str.endsWith(" />"));
}
use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testCustomizeParameter.
@Test
@SuppressWarnings("unchecked")
public void testCustomizeParameter() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/customize-parameter.xml");
context.start();
ServiceBean<DemoService> serviceBean = (ServiceBean<DemoService>) context.getBean("demoServiceExport");
URL url = (URL) serviceBean.toUrls().get(0);
assertEquals("protocol-paramA", url.getParameter("protocol.paramA"));
assertEquals("service-paramA", url.getParameter("service.paramA"));
}
use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method test_retrySettingFail.
// BUG: DUBBO-846 2.0.9中,服务方法上的retry="false"设置失效
@Test
public void test_retrySettingFail() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-long-waiting.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference-retry-false.xml");
ctx.start();
try {
DemoService demoService = (DemoService) ctx.getBean("demoService");
try {
demoService.sayName("Haha");
fail();
} catch (RpcException expected) {
assertThat(expected.getMessage(), containsString("Tried 1 times"));
}
assertEquals(1, RpcContext.getContext().getUrls().size());
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testSystemPropertyOverrideApiDefault.
@Test
public void testSystemPropertyOverrideApiDefault() throws Exception {
System.setProperty("dubbo.application.name", "sysover");
System.setProperty("dubbo.application.owner", "sysowner");
System.setProperty("dubbo.registry.address", "N/A");
System.setProperty("dubbo.protocol.name", "dubbo");
System.setProperty("dubbo.protocol.port", "20834");
try {
ServiceConfig<DemoService> serviceConfig = new ServiceConfig<DemoService>();
serviceConfig.setInterface(DemoService.class);
serviceConfig.setRef(new DemoServiceImpl());
serviceConfig.export();
try {
assertEquals("sysover", serviceConfig.getApplication().getName());
assertEquals("sysowner", serviceConfig.getApplication().getOwner());
assertEquals("N/A", serviceConfig.getRegistry().getAddress());
assertEquals("dubbo", serviceConfig.getProtocol().getName());
assertEquals(20834, serviceConfig.getProtocol().getPort().intValue());
} finally {
serviceConfig.unexport();
}
} finally {
System.setProperty("dubbo.application.name", "");
System.setProperty("dubbo.application.owner", "");
System.setProperty("dubbo.registry.address", "");
System.setProperty("dubbo.protocol.name", "");
System.setProperty("dubbo.protocol.port", "");
}
}
use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testInitReference.
@Test
public void testInitReference() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml");
ctx.start();
try {
DemoService demoService = (DemoService) ctx.getBean("demoService");
assertEquals("say:world", demoService.sayName("world"));
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
Aggregations