Search in sources :

Example 6 with DemoService

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

the class ConfigTest method test_returnSerializationFail.

// BUG: DUBBO-146 Dubbo序列化失败(如传输对象没有实现Serialiable接口),Provider端也没有异常输出,Consumer端超时出错
@Test
public void test_returnSerializationFail() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-UnserializableBox.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");
            try {
                demoService.getBox();
                fail();
            } catch (RpcException expected) {
                assertThat(expected.getMessage(), containsString("must implement java.io.Serializable"));
            }
        } 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 7 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService 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());
        service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
        ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
        service.setProtocol(protocolConfig);
        service.export();
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setInterface(DemoService.class);
        reference.setInjvm(true);
        reference.setRetries(2);
        reference.get();
        assertEquals(Integer.valueOf(5), reference.getRetries());
    } finally {
        System.setProperty("dubbo.reference.retries", "");
    }
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) ProtocolConfig(com.alibaba.dubbo.config.ProtocolConfig) DemoServiceImpl(com.alibaba.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.Test)

Example 8 with DemoService

use of com.alibaba.dubbo.config.spring.api.DemoService 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);
    try {
        demoService.export();
        helloService.export();
        Assert.assertEquals(demoService.getExportedUrls().get(0).getPort(), helloService.getExportedUrls().get(0).getPort());
    } finally {
        unexportService(demoService);
        unexportService(helloService);
    }
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) HelloService(com.alibaba.dubbo.config.spring.api.HelloService) HelloServiceImpl(com.alibaba.dubbo.config.spring.impl.HelloServiceImpl) ProtocolConfig(com.alibaba.dubbo.config.ProtocolConfig) DemoServiceImpl(com.alibaba.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.Test)

Example 9 with DemoService

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

the class ConfigTest method testProviderNestedService.

@Test
@SuppressWarnings("unchecked")
public void testProviderNestedService() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/provider-nested-service.xml");
    ctx.start();
    try {
        ServiceConfig<DemoService> serviceConfig = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig");
        assertNotNull(serviceConfig.getProvider());
        assertEquals(2000, serviceConfig.getProvider().getTimeout().intValue());
        ServiceConfig<DemoService> serviceConfig2 = (ServiceConfig<DemoService>) ctx.getBean("serviceConfig2");
        assertNotNull(serviceConfig2.getProvider());
        assertEquals(1000, serviceConfig2.getProvider().getTimeout().intValue());
    } finally {
        ctx.stop();
        ctx.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) Test(org.junit.Test)

Example 10 with DemoService

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

the class ConfigTest method testServiceClass.

@Test
public void testServiceClass() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/service-class.xml");
    ctx.start();
    try {
        DemoService demoService = refer("dubbo://127.0.0.1:20887");
        String hello = demoService.sayName("hello");
        assertEquals("welcome:hello", hello);
    } finally {
        ctx.stop();
        ctx.close();
    }
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(com.alibaba.dubbo.config.spring.api.DemoService) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) 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