Search in sources :

Example 1 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testDubboProtocolPortOverride.

@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;
    DubboBootstrap bootstrap = 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);
        DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(service).start();
        Assertions.assertEquals(port, service.getExportedUrls().get(0).getPort());
    } finally {
        if (StringUtils.isNotEmpty(dubboPort)) {
            System.setProperty("dubbo.protocol.dubbo.port", dubboPort);
        }
        if (bootstrap != null) {
            bootstrap.stop();
        }
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) 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) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 2 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method test_RpcContext_getUrls.

// DUBBO-147 find all invoker instances which have been tried from RpcContext
@Test
public void test_RpcContext_getUrls() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-long-waiting.xml");
    providerContext.start();
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference-getUrls.xml");
        ctx.start();
        try {
            DemoService demoService = (DemoService) ctx.getBean("demoService");
            try {
                demoService.sayName("Haha");
                fail();
            } catch (RpcException expected) {
                assertThat(expected.getMessage(), containsString("Tried 3 times"));
            }
            assertEquals(3, RpcContext.getContext().getUrls().size());
        } finally {
            ctx.stop();
            ctx.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RpcException(org.apache.dubbo.rpc.RpcException) DemoService(org.apache.dubbo.config.spring.api.DemoService) Test(org.junit.jupiter.api.Test)

Example 3 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testSystemPropertyOverrideXml.

@SuppressWarnings("unchecked")
@Test
public void testSystemPropertyOverrideXml() 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", "20819");
    System.setProperty("dubbo.service.register", "false");
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override.xml");
    providerContext.start();
    try {
        ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig");
        URL url = service.getExportedUrls().get(0);
        assertEquals("sysover", url.getParameter("application"));
        assertEquals("sysowner", url.getParameter("owner"));
        assertEquals("dubbo", url.getProtocol());
        assertEquals(20819, url.getPort());
        String register = url.getParameter("register");
        assertTrue(register != null && !"".equals(register));
        assertEquals(false, Boolean.valueOf(register));
    } 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", "");
        System.setProperty("dubbo.service.register", "");
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ServiceConfig(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) Matchers.containsString(org.hamcrest.Matchers.containsString) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 4 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testForks.

@Test
public void testForks() {
    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:20881");
    int forks = 10;
    reference.setForks(forks);
    String str = reference.toString();
    assertTrue(str.contains("forks=\"" + forks + "\""));
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 5 with DemoService

use of org.apache.dubbo.config.spring.api.DemoService in project dubbo by alibaba.

the class ConfigTest method testInitReference.

@Test
public void testInitReference() throws Exception {
    String configPath = ConfigTest.class.getPackage().getName().replace('.', '/');
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(configPath + "/demo-provider.xml", configPath + "/demo-provider-properties.xml");
    providerContext.start();
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(configPath + "/init-reference.xml");
        ctx.start();
        try {
            ReferenceBean referenceBean = ctx.getBean("&demoService", ReferenceBean.class);
            Assertions.assertEquals("demo_tag", referenceBean.getTag());
            DemoService demoService = (DemoService) ctx.getBean("demoService");
            assertEquals("say:world", demoService.sayName("world"));
        } finally {
            ctx.stop();
            ctx.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(org.apache.dubbo.config.spring.api.DemoService) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

DemoService (org.apache.dubbo.config.spring.api.DemoService)30 Test (org.junit.jupiter.api.Test)27 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)12 RegistryConfig (org.apache.dubbo.config.RegistryConfig)12 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)12 ServiceConfig (org.apache.dubbo.config.ServiceConfig)10 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)8 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)8 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)7 URL (org.apache.dubbo.common.URL)6 RpcException (org.apache.dubbo.rpc.RpcException)4 HelloService (org.apache.dubbo.config.spring.api.HelloService)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)1 ProviderConfig (org.apache.dubbo.config.ProviderConfig)1 ConsumerConfiguration (org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration)1 TestConsumerConfiguration (org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration)1 HelloServiceImpl (org.apache.dubbo.config.spring.impl.HelloServiceImpl)1