use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.
the class ConfigTest method testSystemPropertyOverrideApi.
@Test
public void testSystemPropertyOverrideApi() 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 {
ApplicationConfig application = new ApplicationConfig();
application.setName("aaa");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("127.0.0.1");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("rmi");
protocol.setPort(1099);
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);
assertEquals("sysover", url.getParameter("application"));
assertEquals("sysowner", url.getParameter("owner"));
assertEquals("dubbo", url.getProtocol());
assertEquals(20834, url.getPort());
} finally {
bootstrap.stop();
}
} 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 org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.
the class ConfigTest method testSystemPropertyOverrideXmlDefault.
@SuppressWarnings("unchecked")
@Test
public void testSystemPropertyOverrideXmlDefault() 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");
ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override-default.xml");
providerContext.start();
try {
ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig");
assertEquals("sysover", service.getApplication().getName());
assertEquals("sysowner", service.getApplication().getOwner());
assertEquals("N/A", service.getRegistry().getAddress());
assertEquals("dubbo", service.getProtocol().getName());
assertEquals(20819, service.getProtocol().getPort().intValue());
} 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", "");
providerContext.stop();
providerContext.close();
}
}
use of org.apache.dubbo.config.ServiceConfig 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());
DubboBootstrap bootstrap = DubboBootstrap.getInstance().service(serviceConfig).start();
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 {
bootstrap.stop();
}
} 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 org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.
the class Application method startWithBootstrap.
private static void startWithBootstrap() {
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider")).registry(new RegistryConfig("zookeeper://127.0.0.1:2181")).service(service).start().await();
}
use of org.apache.dubbo.config.ServiceConfig in project dubbo by alibaba.
the class GenericServiceTest method testGenericImplementationWithBeanSerialization.
@Test
public void testGenericImplementationWithBeanSerialization() throws Exception {
final AtomicReference reference = new AtomicReference();
ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
service.setInterface(DemoService.class.getName());
service.setRef(new GenericService() {
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
if ("getUsers".equals(method)) {
GenericParameter arg = new GenericParameter();
arg.method = method;
arg.parameterTypes = parameterTypes;
arg.arguments = args;
reference.set(arg);
return args[0];
}
if ("sayName".equals(method)) {
return null;
}
return args;
}
});
ReferenceConfig<DemoService> ref = null;
ref = new ReferenceConfig<DemoService>();
ref.setInterface(DemoService.class);
ref.setUrl("dubbo://127.0.0.1:29581?scope=remote&generic=bean&timeout=3000");
DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("generic-test")).registry(new RegistryConfig("N/A")).protocol(new ProtocolConfig("dubbo", 29581)).service(service).reference(ref);
bootstrap.start();
try {
DemoService demoService = bootstrap.getCache().get(ref);
User user = new User();
user.setName("zhangsan");
List<User> users = new ArrayList<User>();
users.add(user);
List<User> result = demoService.getUsers(users);
Assertions.assertEquals(users.size(), result.size());
Assertions.assertEquals(user.getName(), result.get(0).getName());
GenericParameter gp = (GenericParameter) reference.get();
Assertions.assertEquals("getUsers", gp.method);
Assertions.assertEquals(1, gp.parameterTypes.length);
Assertions.assertEquals(ReflectUtils.getName(List.class), gp.parameterTypes[0]);
Assertions.assertEquals(1, gp.arguments.length);
Assertions.assertTrue(gp.arguments[0] instanceof JavaBeanDescriptor);
JavaBeanDescriptor descriptor = (JavaBeanDescriptor) gp.arguments[0];
Assertions.assertTrue(descriptor.isCollectionType());
Assertions.assertEquals(ArrayList.class.getName(), descriptor.getClassName());
Assertions.assertEquals(1, descriptor.propertySize());
descriptor = (JavaBeanDescriptor) descriptor.getProperty(0);
Assertions.assertTrue(descriptor.isBeanType());
Assertions.assertEquals(User.class.getName(), descriptor.getClassName());
Assertions.assertEquals(user.getName(), ((JavaBeanDescriptor) descriptor.getProperty("name")).getPrimitiveProperty());
Assertions.assertNull(demoService.sayName("zhangsan"));
} finally {
bootstrap.stop();
}
}
Aggregations