use of org.apache.dubbo.config.spring.impl.DemoServiceImpl 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.impl.DemoServiceImpl in project dubbo by alibaba.
the class ConfigTest method testAppendFilter.
@Test
public void testAppendFilter() throws Exception {
ApplicationConfig application = new ApplicationConfig("provider");
ProviderConfig provider = new ProviderConfig();
provider.setFilter("classloader,monitor");
ConsumerConfig consumer = new ConsumerConfig();
consumer.setFilter("classloader,monitor");
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setFilter("accesslog,trace");
service.setProvider(provider);
service.setProtocol(new ProtocolConfig("dubbo", 20880));
service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setFilter("accesslog,trace");
reference.setConsumer(consumer);
reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
reference.setInterface(DemoService.class);
reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).provider(provider).service(service).reference(reference).start();
try {
List<URL> urls = service.getExportedUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
urls = reference.getExportedUrls();
assertNotNull(urls);
assertEquals(1, urls.size());
assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
} finally {
bootstrap.stop();
}
}
use of org.apache.dubbo.config.spring.impl.DemoServiceImpl 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());
ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setInterface(DemoService.class);
reference.setInjvm(true);
reference.setRetries(2);
DubboBootstrap.getInstance().application(new ApplicationConfig("testSystemPropertyOverrideReferenceConfig")).registry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)).protocol(protocolConfig).service(service).reference(reference).start();
assertEquals(Integer.valueOf(5), reference.getRetries());
} finally {
System.setProperty("dubbo.reference.retries", "");
}
}
use of org.apache.dubbo.config.spring.impl.DemoServiceImpl 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);
DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(demoService).service(helloService);
try {
bootstrap.start();
Assertions.assertEquals(demoService.getExportedUrls().get(0).getPort(), helloService.getExportedUrls().get(0).getPort());
} finally {
bootstrap.stop();
}
}
use of org.apache.dubbo.config.spring.impl.DemoServiceImpl 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);
}
}
}
Aggregations