use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method test_returnSerializationFail.
// BUG: DUBBO-146 Dubbo序列化失败(如传输对象没有实现Serialiable接口),Provider端也没有异常输出,Consumer端超时出错
@Test
public void test_returnSerializationFail() throws Exception {
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-UnserializableBox.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");
try {
demoService.getBox();
fail();
} catch (RpcException expected) {
assertThat(expected.getMessage(), containsString("must implement java.io.Serializable"));
}
} 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 testSystemPropertyOverrideReferenceConfig.
@Test
public void testSystemPropertyOverrideReferenceConfig() throws Exception {
System.setProperty("dubbo.reference.retries", "5");
try {
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
service.setProtocol(protocolConfig);
service.export();
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setInterface(DemoService.class);
reference.setInjvm(true);
reference.setRetries(2);
reference.get();
assertEquals(Integer.valueOf(5), reference.getRetries());
} finally {
System.setProperty("dubbo.reference.retries", "");
}
}
use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testProtocolRandomPort.
@Test
public void testProtocolRandomPort() throws Exception {
ServiceConfig<DemoService> demoService = null;
ServiceConfig<HelloService> helloService = null;
ApplicationConfig application = new ApplicationConfig();
application.setName("test-protocol-random-port");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("N/A");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
protocol.setPort(-1);
demoService = new ServiceConfig<DemoService>();
demoService.setInterface(DemoService.class);
demoService.setRef(new DemoServiceImpl());
demoService.setApplication(application);
demoService.setRegistry(registry);
demoService.setProtocol(protocol);
helloService = new ServiceConfig<HelloService>();
helloService.setInterface(HelloService.class);
helloService.setRef(new HelloServiceImpl());
helloService.setApplication(application);
helloService.setRegistry(registry);
helloService.setProtocol(protocol);
try {
demoService.export();
helloService.export();
Assert.assertEquals(demoService.getExportedUrls().get(0).getPort(), helloService.getExportedUrls().get(0).getPort());
} finally {
unexportService(demoService);
unexportService(helloService);
}
}
use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testProviderNestedService.
@Test
@SuppressWarnings("unchecked")
public void testProviderNestedService() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/provider-nested-service.xml");
ctx.start();
try {
ServiceConfig<DemoService> serviceConfig = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig");
assertNotNull(serviceConfig.getProvider());
assertEquals(2000, serviceConfig.getProvider().getTimeout().intValue());
ServiceConfig<DemoService> serviceConfig2 = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig2");
assertNotNull(serviceConfig2.getProvider());
assertEquals(1000, serviceConfig2.getProvider().getTimeout().intValue());
} finally {
ctx.stop();
ctx.close();
}
}
use of com.alibaba.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testServiceClass.
@Test
public void testServiceClass() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-class.xml");
ctx.start();
try {
DemoService demoService = refer("dubbo://127.0.0.1:20887");
String hello = demoService.sayName("hello");
assertEquals("welcome:hello", hello);
} finally {
ctx.stop();
ctx.close();
}
}
Aggregations