use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testMultiProtocolDefault.
@Test
public void testMultiProtocolDefault() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-default.xml");
ctx.start();
try {
DemoService demoService = refer("rmi://127.0.0.1:10991");
String hello = demoService.sayName("hello");
assertEquals("say:hello", hello);
} finally {
ctx.stop();
ctx.close();
}
}
use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testSystemPropertyOverrideProperties.
@Test
public void testSystemPropertyOverrideProperties() throws Exception {
String portString = System.getProperty("dubbo.protocol.port");
System.clearProperty("dubbo.protocol.port");
try {
int port = 1234;
System.setProperty("dubbo.protocol.port", String.valueOf(port));
ApplicationConfig application = new ApplicationConfig();
application.setName("aaa");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("N/A");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("rmi");
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).start();
try {
URL url = service.getExportedUrls().get(0);
// from api
assertEquals("aaa", url.getParameter("application"));
// from dubbo-binder.properties
assertEquals("world", url.getParameter("owner"));
// from system property
assertEquals(1234, url.getPort());
} finally {
bootstrap.stop();
}
} finally {
if (portString != null) {
System.setProperty("dubbo.protocol.port", portString);
}
}
}
use of org.apache.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:30887");
String hello = demoService.sayName("hello");
assertEquals("welcome:hello", hello);
} finally {
ctx.stop();
ctx.close();
}
}
use of org.apache.dubbo.config.spring.api.DemoService 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();
}
}
use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method test_returnSerializationFail.
// BuG: DUBBO-146 Provider doesn't have exception output, and consumer has timeout error when serialization fails
// for example, object transported on the wire doesn't implement Serializable
@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();
}
}
Aggregations