Search in sources :

Example 11 with ProtocolConfig

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

the class ConfigTest method testSystemPropertyOverrideProtocol.

@Test
public void testSystemPropertyOverrideProtocol() throws Exception {
    System.setProperty("dubbo.protocol.port", "20812");
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/override-protocol.xml");
    providerContext.start();
    try {
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20812, dubbo.getPort().intValue());
    } finally {
        System.setProperty("dubbo.protocol.port", "");
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test)

Example 12 with ProtocolConfig

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

the class ConfigTest method testAppendFilter.

@Test
public void testAppendFilter() throws Exception {
    ApplicationConfig application = new ApplicationConfig("provider");
    ProviderConfig provider = new ProviderConfig();
    provider.setFilter("classloader,monitor");
    ConsumerConfig consumer = new ConsumerConfig();
    consumer.setFilter("classloader,monitor");
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setFilter("accesslog,trace");
    service.setProvider(provider);
    service.setProtocol(new ProtocolConfig("dubbo", 20880));
    service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setFilter("accesslog,trace");
    reference.setConsumer(consumer);
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).provider(provider).service(service).reference(reference).start();
    try {
        List<URL> urls = service.getExportedUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
        urls = reference.getExportedUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) URL(org.apache.dubbo.common.URL) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 13 with ProtocolConfig

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

the class ConfigTest method testSystemPropertyOverrideMultiProtocol.

@Test
public void testSystemPropertyOverrideMultiProtocol() throws Exception {
    System.setProperty("dubbo.protocol.dubbo.port", "20814");
    System.setProperty("dubbo.protocol.rmi.port", "10914");
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/override-multi-protocol.xml");
    providerContext.start();
    try {
        ProtocolConfig dubbo = (ProtocolConfig) providerContext.getBean("dubbo");
        assertEquals(20814, dubbo.getPort().intValue());
        ProtocolConfig rmi = (ProtocolConfig) providerContext.getBean("rmi");
        assertEquals(10914, rmi.getPort().intValue());
    } finally {
        System.setProperty("dubbo.protocol.dubbo.port", "");
        System.setProperty("dubbo.protocol.rmi.port", "");
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) Test(org.junit.jupiter.api.Test)

Example 14 with ProtocolConfig

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

the class ConfigTest method testSystemPropertyOverrideReferenceConfig.

@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());
        ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setInterface(DemoService.class);
        reference.setInjvm(true);
        reference.setRetries(2);
        DubboBootstrap.getInstance().application(new ApplicationConfig("testSystemPropertyOverrideReferenceConfig")).registry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)).protocol(protocolConfig).service(service).reference(reference).start();
        assertEquals(Integer.valueOf(5), reference.getRetries());
    } finally {
        System.setProperty("dubbo.reference.retries", "");
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) 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) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 15 with ProtocolConfig

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

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