Search in sources :

Example 36 with ProtocolConfig

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

the class PublishingServiceDefinitionListenerTest method testOnServiceConfigExportedEvent.

/**
 * Test {@link ServiceConfigExportedEvent} arising
 */
@Test
public void testOnServiceConfigExportedEvent() {
    ServiceConfig<EchoService> serviceConfig = new ServiceConfig<>();
    serviceConfig.setInterface(EchoService.class);
    serviceConfig.setRef(new EchoServiceImpl());
    serviceConfig.setRegistry(new RegistryConfig("N/A"));
    serviceConfig.setProtocol(new ProtocolConfig("dubbo", NetUtils.getAvailablePort(20880 + new Random().nextInt(10000))));
    serviceConfig.export();
    String serviceDefinition = writableMetadataService.getServiceDefinition(EchoService.class.getName());
    ServiceDefinition serviceDefinitionBuild = ServiceDefinitionBuilder.build(serviceConfig.getInterfaceClass());
    assertEquals(serviceDefinition, JSON.toJSONString(serviceDefinitionBuild));
    serviceConfig.unexport();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Random(java.util.Random) ServiceConfig(org.apache.dubbo.config.ServiceConfig) EchoService(org.apache.dubbo.config.bootstrap.EchoService) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) EchoServiceImpl(org.apache.dubbo.config.bootstrap.EchoServiceImpl) ServiceDefinition(org.apache.dubbo.metadata.definition.model.ServiceDefinition) Test(org.junit.jupiter.api.Test)

Example 37 with ProtocolConfig

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

the class ConfigTest method testXmlOverrideProperties.

@Test
public void testXmlOverrideProperties() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/xml-override-properties.xml");
    providerContext.start();
    try {
        ApplicationConfig application = (ApplicationConfig) providerContext.getBean("application");
        assertEquals("demo-provider", application.getName());
        assertEquals("world", application.getOwner());
        RegistryConfig registry = (RegistryConfig) providerContext.getBean("registry");
        assertEquals("N/A", registry.getAddress());
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20813, dubbo.getPort().intValue());
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test)

Example 38 with ProtocolConfig

use of org.apache.dubbo.config.ProtocolConfig 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 39 with ProtocolConfig

use of org.apache.dubbo.config.ProtocolConfig 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 40 with ProtocolConfig

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

the class MetadataServiceExporterTest method init.

@BeforeAll
public static void init() {
    ApplicationModel.reset();
    ApplicationModel.getConfigManager().setApplication(new ApplicationConfig("Test"));
    ApplicationModel.getConfigManager().addRegistry(new RegistryConfig("test://1.2.3.4"));
    ApplicationModel.getConfigManager().addProtocol(new ProtocolConfig("injvm"));
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)52 Test (org.junit.jupiter.api.Test)30 RegistryConfig (org.apache.dubbo.config.RegistryConfig)29 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)27 ServiceConfig (org.apache.dubbo.config.ServiceConfig)14 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)11 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)8 DemoService (org.apache.dubbo.config.spring.api.DemoService)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ArrayList (java.util.ArrayList)6 ProviderConfig (org.apache.dubbo.config.ProviderConfig)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 GenericService (org.apache.dubbo.rpc.service.GenericService)5 Map (java.util.Map)4 URL (org.apache.dubbo.common.URL)4 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)3 ConfigTest (org.apache.dubbo.config.spring.ConfigTest)3 Test (org.junit.Test)3