use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testDubboProtocolPortOverride.
@Test
public void testDubboProtocolPortOverride() throws Exception {
String dubboPort = System.getProperty("dubbo.protocol.dubbo.port");
int port = 55555;
System.setProperty("dubbo.protocol.dubbo.port", String.valueOf(port));
ServiceConfig<DemoService> service = null;
DubboBootstrap bootstrap = null;
try {
ApplicationConfig application = new ApplicationConfig();
application.setName("dubbo-protocol-port-override");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("N/A");
ProtocolConfig protocol = new ProtocolConfig();
service = new ServiceConfig<DemoService>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).start();
Assertions.assertEquals(port, service.getExportedUrls().get(0).getPort());
} finally {
if (StringUtils.isNotEmpty(dubboPort)) {
System.setProperty("dubbo.protocol.dubbo.port", dubboPort);
}
if (bootstrap != null) {
bootstrap.stop();
}
}
}
use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method test_RpcContext_getUrls.
// DUBBO-147 find all invoker instances which have been tried from RpcContext
@Test
public void test_RpcContext_getUrls() 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-getUrls.xml");
ctx.start();
try {
DemoService demoService = (DemoService) ctx.getBean("demoService");
try {
demoService.sayName("Haha");
fail();
} catch (RpcException expected) {
assertThat(expected.getMessage(), containsString("Tried 3 times"));
}
assertEquals(3, RpcContext.getContext().getUrls().size());
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testSystemPropertyOverrideXml.
@SuppressWarnings("unchecked")
@Test
public void testSystemPropertyOverrideXml() 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", "20819");
System.setProperty("dubbo.service.register", "false");
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override.xml");
providerContext.start();
try {
ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig");
URL url = service.getExportedUrls().get(0);
assertEquals("sysover", url.getParameter("application"));
assertEquals("sysowner", url.getParameter("owner"));
assertEquals("dubbo", url.getProtocol());
assertEquals(20819, url.getPort());
String register = url.getParameter("register");
assertTrue(register != null && !"".equals(register));
assertEquals(false, Boolean.valueOf(register));
} 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", "");
System.setProperty("dubbo.service.register", "");
providerContext.stop();
providerContext.close();
}
}
use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testForks.
@Test
public void testForks() {
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");
int forks = 10;
reference.setForks(forks);
String str = reference.toString();
assertTrue(str.contains("forks=\"" + forks + "\""));
}
use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.
the class ConfigTest method testInitReference.
@Test
public void testInitReference() throws Exception {
String configPath = ConfigTest.class.getPackage().getName().replace('.', '/');
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(configPath + "/demo-provider.xml", configPath + "/demo-provider-properties.xml");
providerContext.start();
try {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(configPath + "/init-reference.xml");
ctx.start();
try {
ReferenceBean referenceBean = ctx.getBean("&demoService", ReferenceBean.class);
Assertions.assertEquals("demo_tag", referenceBean.getTag());
DemoService demoService = (DemoService) ctx.getBean("demoService");
assertEquals("say:world", demoService.sayName("world"));
} finally {
ctx.stop();
ctx.close();
}
} finally {
providerContext.stop();
providerContext.close();
}
}
Aggregations