Java Code Examples for com.alibaba.dubbo.config.ServiceConfig#setInterface()

The following examples show how to use com.alibaba.dubbo.config.ServiceConfig#setInterface() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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", "");
    }
}
 
Example 2
Source File: ConfigTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenericServiceConfig() throws Exception {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setApplication(new ApplicationConfig("test"));
    service.setRegistry(new RegistryConfig("mock://localhost"));
    service.setInterface(DemoService.class.getName());
    service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
    service.setRef(new GenericService(){

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });
    try {
        service.export();
        Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
        MockRegistry registry = (MockRegistry)collection.iterator().next();
        URL url = registry.getRegistered().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        MockRegistryFactory.cleanCachedRegistry();
        service.unexport();
    }
}
 
Example 3
Source File: DubboServiceConfig.java    From dubbo-mock with Apache License 2.0 6 votes vote down vote up
public ServiceConfig<GenericService> fillDubboService(MockService mockService, com.tony.test.mock.po.RegistryConfig registryConfig,
        com.tony.test.mock.po.ProtocolConfig protocolConfig, MockGenericService tmpMockservice) {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setInterface(mockService.getServiceInterface());
    service.setRef(tmpMockservice); // 指向一个通用服务实现 
    RegistryConfig registry = createRegistry(registryConfig.getRegistryAddress(), registryConfig.getRegistryTimeout());
    service.setRegistry(registry);
    service.setProtocols(Lists.newArrayList(new ProtocolConfig(protocolConfig.getProtocolName(), protocolConfig.getProtocolPort())));
    if (!StringUtils.isBlank(mockService.getGroupName())) {
        service.setGroup(mockService.getGroupName());
    }
    service.setTimeout(mockService.getTimeout());
    service.setRetries(mockService.getRetries());
    service.setApplication(new ApplicationConfig(mockService.getApplicationName()));
    return service;
}
 
Example 4
Source File: APIConfigurationLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Before
public void initProvider() {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("demo-provider");
    application.setVersion("1.0");

    RegistryConfig registryConfig = new RegistryConfig();
    registryConfig.setAddress("multicast://224.1.1.1:9090");

    ServiceConfig<GreetingsService> service = new ServiceConfig<>();
    service.setApplication(application);
    service.setRegistry(registryConfig);
    service.setInterface(GreetingsService.class);
    service.setRef(new GreetingsServiceImpl());

    service.export();
}
 
Example 5
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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", "");
    }
}
 
Example 6
Source File: Dubbo26ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static ServiceConfig<GreeterService> getService() {
  final ServiceConfig<GreeterService> service = new ServiceConfig<>();
  service.setApplication(new ApplicationConfig("test"));
  service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
  service.setProtocol(new ProtocolConfig("dubbo", TestUtil.nextFreePort()));
  service.setInterface(GreeterService.class);
  service.setRef(new GreeterServiceImpl());
  return service;
}
 
Example 7
Source File: DubboConfiguration.java    From cicada with MIT License 5 votes vote down vote up
@Bean
public ServiceConfig<DemoService> dubboDemoSerive() {
  final ServiceConfig<DemoService> dubboService = new ServiceConfig<>();// 该类很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
  dubboService.setApplication(this.dubboApplication());
  dubboService.setRegistries(this.dubboRegistries()); // 多个注册中心可以用setRegistries()
  dubboService.setProvider(dubboProvider());
  dubboService.setInterface(DemoService.class);
  dubboService.setRef(demoService);    
  dubboService.export();

  return dubboService;
}
 
Example 8
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferGenericExport() throws Exception {
    ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export");
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);

    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setApplication(ac);
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });

    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setApplication(ac);
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());

    try {
        sc.export();
        ref.get();
        Assert.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sc.unexport();
        ref.destroy();
    }
}
 
Example 9
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 10
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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;
    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);
        service.export();

        Assert.assertEquals(port, service.getExportedUrls().get(0).getPort());
    } finally {
        if (StringUtils.isNotEmpty(dubboPort)) {
            System.setProperty("dubbo.protocol.dubbo.port", dubboPort);
        }
        if (service != null) {
            service.unexport();
        }
    }
}
 
Example 11
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferGenericExport() throws Exception {
    ApplicationConfig ac = new ApplicationConfig("test-refer-generic-export");
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);

    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setApplication(ac);
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });

    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setApplication(ac);
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());

    try {
        sc.export();
        ref.get();
        Assert.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sc.unexport();
        ref.destroy();
    }
}
 
Example 12
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
@Test
public void testApiOverrideProperties() throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("api-override-properties");
    
    RegistryConfig registry = new RegistryConfig();
    registry.setAddress("N/A");
    
    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("dubbo");
    protocol.setPort(13123);
    
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    service.setApplication(application);
    service.setRegistry(registry);
    service.setProtocol(protocol);
    service.export();
    
    try {
        URL url = service.toUrls().get(0);
        assertEquals("api-override-properties", url.getParameter("application"));
        assertEquals("world", url.getParameter("owner"));
        assertEquals(13123, url.getPort());
        
        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:13123");
        reference.get();
        try {
            url = reference.toUrls().get(0);
            assertEquals("2000", url.getParameter("timeout"));
        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
 
Example 13
Source File: ConfigTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@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);
        service.export();

        try {
            URL url = service.toUrls().get(0);
            // from api
            assertEquals("aaa", url.getParameter("application"));
            // from dubbo.properties
            assertEquals("world", url.getParameter("owner"));
            // from system property
            assertEquals(1234, url.getPort());
        } finally {
            service.unexport();
        }
    } finally {
        if (portString != null) {
            System.setProperty("dubbo.protocol.port", portString);
        }
    }
}
 
Example 14
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
@Test
public void testAppendFilter() throws Exception {
    ProviderConfig provider = new ProviderConfig();
    provider.setFilter("classloader,monitor");
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setFilter("accesslog,trace");
    service.setProvider(provider);
    service.setProtocol(new ProtocolConfig("dubbo", 20880));
    service.setApplication(new ApplicationConfig("provider"));
    service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    try {
        service.export();
        List<URL> urls = service.toUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
        
        ConsumerConfig consumer = new ConsumerConfig();
        consumer.setFilter("classloader,monitor");
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setFilter("accesslog,trace");
        reference.setConsumer(consumer);
        reference.setApplication(new ApplicationConfig("consumer"));
        reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
        reference.setInterface(DemoService.class);
        reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
        try {
            reference.get();
            urls = reference.toUrls();
            assertNotNull(urls);
            assertEquals(1, urls.size());
            assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
 
Example 15
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@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);
        service.export();

        try {
            URL url = service.toUrls().get(0);
            // from api
            assertEquals("aaa", url.getParameter("application"));
            // from dubbo.properties
            assertEquals("world", url.getParameter("owner"));
            // from system property
            assertEquals(1234, url.getPort());
        } finally {
            service.unexport();
        }
    } finally {
        if (portString != null) {
            System.setProperty("dubbo.protocol.port", portString);
        }
    }
}
 
Example 16
Source File: DubboEasyTransRpcProviderImpl.java    From EasyTransaction with Apache License 2.0 4 votes vote down vote up
@Override
public void startService(Class<?> businessInterface,Map<BusinessIdentifer, RpcBusinessProvider<?>> businessList) {
	
	for(Entry<BusinessIdentifer, RpcBusinessProvider<?>> entry :businessList.entrySet()){
		BusinessIdentifer key = entry.getKey();
		final RpcBusinessProvider<?> value = entry.getValue();
		
		GenericService genericService = new GenericService() {
			@Override
			public Object $invoke(String method, String[] parameterTypes, Object[] args)
					throws GenericException {

				//第一个参数类型为easytransRequest,第二个为map(业务外 框架用的元数据)
				Method callMethod = getMethod(value.getClass(),method,new String[]{parameterTypes[0]});
				try {
					Object invokeResult = callMethod.invoke(value, new Object[]{args[0]});
					logger.debug("EasyTrans rpc call recived, executed success:" + args[0]);
					return invokeResult;
				} catch (IllegalAccessException | IllegalArgumentException
						| InvocationTargetException e) {
					logger.info("EasyTrans rpc call recived,executed failed:" + args[0], e);
					throw new RuntimeException(e);
				}
			}
		};
		
		ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
		service.setInterface(businessInterface);
		service.setGroup(key.appId() + "-" + key.busCode());
		service.setVersion("1.0.0");
		service.setRef(genericService);
		service.setCluster("failfast");
		int rpcTimeOut = key.rpcTimeOut();
		if(rpcTimeOut != 0){
			service.setTimeout(key.rpcTimeOut());
		}
		service.setFilter("easyTransFilter");
		
		if(applicationConfig != null) {
			service.setApplication(applicationConfig);
		}
		
		if(registryConfig != null) {
			service.setRegistry(registryConfig);
		}
		
		if(protocolConfig != null) {
			service.setProtocol(protocolConfig);
		}
		
		if(monitorConfig != null) {
			service.setMonitor(monitorConfig);
		}
		
		if(moduleConfig != null) {
			service.setModule(moduleConfig);
		}
		
		if(providerConfig != null) {
			service.setProvider(providerConfig);
		}
		
		if(customizationer != null) {
			customizationer.customDubboService(key,service);
		}
		
		service.export();
	}
}
 
Example 17
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
@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);
        service.export();
        
        try {
            URL url = service.toUrls().get(0);
            assertEquals("sysover", url.getParameter("application"));
            assertEquals("sysowner", url.getParameter("owner"));
            assertEquals("dubbo", url.getProtocol());
            assertEquals(20834, url.getPort());
        } finally {
            service.unexport();
        }
    } 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", "");
    }
}
 
Example 18
Source File: ConfigTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@Test
public void testApiOverrideProperties() throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName("api-override-properties");
    
    RegistryConfig registry = new RegistryConfig();
    registry.setAddress("N/A");
    
    ProtocolConfig protocol = new ProtocolConfig();
    protocol.setName("dubbo");
    protocol.setPort(13123);
    
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    service.setApplication(application);
    service.setRegistry(registry);
    service.setProtocol(protocol);
    service.export();
    
    try {
        URL url = service.toUrls().get(0);
        assertEquals("api-override-properties", url.getParameter("application"));
        assertEquals("world", url.getParameter("owner"));
        assertEquals(13123, url.getPort());
        
        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:13123");
        reference.get();
        try {
            url = reference.toUrls().get(0);
            assertEquals("2000", url.getParameter("timeout"));
        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
 
Example 19
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
@Test
public void testAppendFilter() throws Exception {
    ProviderConfig provider = new ProviderConfig();
    provider.setFilter("classloader,monitor");
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setFilter("accesslog,trace");
    service.setProvider(provider);
    service.setProtocol(new ProtocolConfig("dubbo", 20880));
    service.setApplication(new ApplicationConfig("provider"));
    service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    try {
        service.export();
        List<URL> urls = service.toUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
        
        ConsumerConfig consumer = new ConsumerConfig();
        consumer.setFilter("classloader,monitor");
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setFilter("accesslog,trace");
        reference.setConsumer(consumer);
        reference.setApplication(new ApplicationConfig("consumer"));
        reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
        reference.setInterface(DemoService.class);
        reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
        try {
            reference.get();
            urls = reference.toUrls();
            assertNotNull(urls);
            assertEquals(1, urls.size());
            assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
 
Example 20
Source File: ConfigTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@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);
        service.export();
        
        try {
            URL url = service.toUrls().get(0);
            assertEquals("sysover", url.getParameter("application"));
            assertEquals("sysowner", url.getParameter("owner"));
            assertEquals("dubbo", url.getProtocol());
            assertEquals(20834, url.getPort());
        } finally {
            service.unexport();
        }
    } 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", "");
    }
}