Search in sources :

Example 16 with DemoService

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

the class ConfigTest method testToString.

@Test
public void testToString() {
    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");
    String str = reference.toString();
    assertTrue(str.startsWith("<dubbo:reference "));
    assertTrue(str.contains(" url=\"dubbo://127.0.0.1:20881\" "));
    assertTrue(str.contains(" interface=\"com.alibaba.dubbo.config.spring.api.DemoService\" "));
    assertTrue(str.endsWith(" />"));
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Test(org.junit.Test)

Example 17 with DemoService

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

the class ConfigTest method testCustomizeParameter.

@Test
@SuppressWarnings("unchecked")
public void testCustomizeParameter() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/customize-parameter.xml");
    context.start();
    ServiceBean<DemoService> serviceBean = (ServiceBean<DemoService>) context.getBean("demoServiceExport");
    URL url = (URL) serviceBean.toUrls().get(0);
    assertEquals("protocol-paramA", url.getParameter("protocol.paramA"));
    assertEquals("service-paramA", url.getParameter("service.paramA"));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) URL(com.alibaba.dubbo.common.URL) Test(org.junit.Test)

Example 18 with DemoService

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

the class ConfigTest method test_retrySettingFail.

// BUG: DUBBO-846 2.0.9中,服务方法上的retry="false"设置失效
@Test
public void test_retrySettingFail() 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-retry-false.xml");
        ctx.start();
        try {
            DemoService demoService = (DemoService) ctx.getBean("demoService");
            try {
                demoService.sayName("Haha");
                fail();
            } catch (RpcException expected) {
                assertThat(expected.getMessage(), containsString("Tried 1 times"));
            }
            assertEquals(1, RpcContext.getContext().getUrls().size());
        } finally {
            ctx.stop();
            ctx.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RpcException(com.alibaba.dubbo.rpc.RpcException) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) Test(org.junit.Test)

Example 19 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService 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());
        serviceConfig.export();
        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 {
            serviceConfig.unexport();
        }
    } 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(com.alibaba.dubbo.config.ServiceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) DemoServiceImpl(com.alibaba.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.Test)

Example 20 with DemoService

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

the class ConfigTest method testInitReference.

@Test
public void testInitReference() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider.xml");
    providerContext.start();
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml");
        ctx.start();
        try {
            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(com.alibaba.dubbo.config.spring.api.DemoService) Test(org.junit.Test)

Aggregations

DemoService (com.alibaba.dubbo.config.spring.api.DemoService)22 Test (org.junit.Test)21 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)11 RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)10 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)10 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)9 DemoServiceImpl (com.alibaba.dubbo.config.spring.impl.DemoServiceImpl)8 JUnitMatchers.containsString (org.junit.matchers.JUnitMatchers.containsString)8 ProtocolConfig (com.alibaba.dubbo.config.ProtocolConfig)7 URL (com.alibaba.dubbo.common.URL)6 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)6 RpcException (com.alibaba.dubbo.rpc.RpcException)4 ConsumerConfig (com.alibaba.dubbo.config.ConsumerConfig)1 ProviderConfig (com.alibaba.dubbo.config.ProviderConfig)1 HelloService (com.alibaba.dubbo.config.spring.api.HelloService)1 HelloServiceImpl (com.alibaba.dubbo.config.spring.impl.HelloServiceImpl)1 GenericException (com.alibaba.dubbo.rpc.service.GenericException)1 GenericService (com.alibaba.dubbo.rpc.service.GenericService)1 BeansException (org.springframework.beans.BeansException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1