Search in sources :

Example 16 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap in project dubbo by alibaba.

the class ConfigTest method testApiOverrideProperties.

@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.setRegistry(registry);
    service.setProtocol(protocol);
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://127.0.0.1:13123");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).reference(reference).start();
    try {
        URL url = service.getExportedUrls().get(0);
        assertEquals("api-override-properties", url.getParameter("application"));
        assertEquals("world", url.getParameter("owner"));
        assertEquals(13123, url.getPort());
        url = reference.getExportedUrls().get(0);
        assertEquals("2000", url.getParameter("timeout"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 17 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap in project dubbo by alibaba.

the class ConfigTest method testGenericServiceConfig.

@Test
public void testGenericServiceConfig() throws Exception {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setRegistry(new RegistryConfig("mock://localhost"));
    service.setInterface(DemoService.class.getName());
    service.setGeneric(GENERIC_SERIALIZATION_BEAN);
    service.setRef((method, parameterTypes, args) -> null);
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("test")).service(service).start();
    try {
        Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
        MockRegistry registry = (MockRegistry) collection.iterator().next();
        URL url = registry.getRegistered().get(0);
        Assertions.assertEquals(GENERIC_SERIALIZATION_BEAN, url.getParameter(GENERIC_KEY));
    } finally {
        MockRegistryFactory.cleanCachedRegistry();
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) MockRegistry(org.apache.dubbo.config.spring.registry.MockRegistry) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) MockRegistry(org.apache.dubbo.config.spring.registry.MockRegistry) Registry(org.apache.dubbo.registry.Registry) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 18 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap 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", "");
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 19 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap 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", "");
    }
}
Also used : ServiceConfig(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 20 with DubboBootstrap

use of org.apache.dubbo.config.bootstrap.DubboBootstrap 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();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap)

Aggregations

DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)22 RegistryConfig (org.apache.dubbo.config.RegistryConfig)20 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)19 Test (org.junit.jupiter.api.Test)16 ServiceConfig (org.apache.dubbo.config.ServiceConfig)14 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)11 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)11 DemoService (org.apache.dubbo.config.spring.api.DemoService)10 GenericService (org.apache.dubbo.rpc.service.GenericService)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)5 URL (org.apache.dubbo.common.URL)5 List (java.util.List)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JavaBeanDescriptor (org.apache.dubbo.common.beanutil.JavaBeanDescriptor)2 HelloService (org.apache.dubbo.config.spring.api.HelloService)2 GenericException (org.apache.dubbo.rpc.service.GenericException)2 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)1 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)1 GreetingsService (com.pinpoint.test.plugin.api.GreetingsService)1