Search in sources :

Example 21 with RegistryConfig

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

Example 22 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig 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);
        }
    }
}
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) Matchers.containsString(org.hamcrest.Matchers.containsString) 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 23 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ConfigTest method testReferGenericExport.

@Test
public void testReferGenericExport() throws Exception {
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);
    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef((method, parameterTypes, args) -> null);
    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("test-refer-generic-export")).service(sc).reference(ref);
    try {
        bootstrap.start();
        Assertions.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        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) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) BeanCreationException(org.springframework.beans.factory.BeanCreationException) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 24 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class UrlTestBase method initServConf.

@SuppressWarnings("deprecation")
protected void initServConf() {
    regConfForProvider = new RegistryConfig();
    regConfForService = new RegistryConfig();
    provConf = new ProviderConfig();
    protoConfForProvider = new ProtocolConfig("mockprotocol");
    protoConfForService = new ProtocolConfig("mockprotocol");
    methodConfForService = new MethodConfig();
    servConf = new ServiceConfig<DemoService>();
    // provConf.setApplication(appConfForProvider);
    servConf.setApplication(application);
    provConf.setRegistry(regConfForProvider);
    servConf.setRegistry(regConfForService);
    provConf.setProtocols(new ArrayList<>(Arrays.asList(protoConfForProvider)));
    servConf.setProtocols(new ArrayList<>(Arrays.asList(protoConfForService)));
    servConf.setMethods(Arrays.asList(new MethodConfig[] { methodConfForService }));
    servConf.setProvider(provConf);
    servConf.setRef(demoService);
    servConf.setInterfaceClass(DemoService.class);
    methodConfForService.setName("sayName");
    regConfForService.setAddress("127.0.0.1:9090");
    regConfForService.setProtocol("mockregistry");
    application.setName("ConfigTests");
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) MethodConfig(org.apache.dubbo.config.MethodConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) DemoService(org.apache.dubbo.config.api.DemoService) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 25 with RegistryConfig

use of org.apache.dubbo.config.RegistryConfig in project dubbo by alibaba.

the class ReferenceConfigCacheTest method buildMockReferenceConfig.

private MockReferenceConfig buildMockReferenceConfig(String service, String group, String version) {
    MockReferenceConfig config = new MockReferenceConfig();
    config.setApplication(new ApplicationConfig("cache"));
    config.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
    config.setCheck(false);
    config.setInterface(service);
    config.setGroup(group);
    config.setVersion(version);
    return config;
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig)

Aggregations

RegistryConfig (org.apache.dubbo.config.RegistryConfig)68 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)42 Test (org.junit.jupiter.api.Test)34 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)29 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)20 ServiceConfig (org.apache.dubbo.config.ServiceConfig)19 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)16 DemoService (org.apache.dubbo.config.spring.api.DemoService)13 GenericService (org.apache.dubbo.rpc.service.GenericService)8 ArrayList (java.util.ArrayList)7 URL (org.apache.dubbo.common.URL)7 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ModuleConfig (org.apache.dubbo.config.ModuleConfig)4 MonitorConfig (org.apache.dubbo.config.MonitorConfig)4 ProviderConfig (org.apache.dubbo.config.ProviderConfig)4 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 MethodConfig (org.apache.dubbo.config.MethodConfig)3