Search in sources :

Example 11 with DemoService

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

the class ConfigTest method testMultiProtocolDefault.

@Test
public void testMultiProtocolDefault() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-default.xml");
    ctx.start();
    try {
        DemoService demoService = refer("rmi://127.0.0.1:10991");
        String hello = demoService.sayName("hello");
        assertEquals("say:hello", hello);
    } finally {
        ctx.stop();
        ctx.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)

Example 12 with DemoService

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

the class ConfigTest method testSystemPropertyOverrideProperties.

@Test
public void testSystemPropertyOverrideProperties() throws Exception {
    String portString = System.getProperty("dubbo.protocol.port");
    System.clearProperty("dubbo.protocol.port");
    try {
        int port = 1234;
        System.setProperty("dubbo.protocol.port", String.valueOf(port));
        ApplicationConfig application = new ApplicationConfig();
        application.setName("aaa");
        RegistryConfig registry = new RegistryConfig();
        registry.setAddress("N/A");
        ProtocolConfig protocol = new ProtocolConfig();
        protocol.setName("rmi");
        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);
            // from api
            assertEquals("aaa", url.getParameter("application"));
            // from dubbo-binder.properties
            assertEquals("world", url.getParameter("owner"));
            // from system property
            assertEquals(1234, url.getPort());
        } finally {
            bootstrap.stop();
        }
    } finally {
        if (portString != null) {
            System.setProperty("dubbo.protocol.port", portString);
        }
    }
}
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) Matchers.containsString(org.hamcrest.Matchers.containsString) 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 13 with DemoService

use of org.apache.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:30887");
        String hello = demoService.sayName("hello");
        assertEquals("welcome:hello", hello);
    } finally {
        ctx.stop();
        ctx.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)

Example 14 with DemoService

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

the class ConfigTest method testReferGenericExport.

@Test
public void testReferGenericExport() throws Exception {
    RegistryConfig rc = new RegistryConfig();
    rc.setAddress(RegistryConfig.NO_AVAILABLE);
    ServiceConfig<GenericService> sc = new ServiceConfig<GenericService>();
    sc.setRegistry(rc);
    sc.setInterface(DemoService.class.getName());
    sc.setRef((method, parameterTypes, args) -> null);
    ReferenceConfig<DemoService> ref = new ReferenceConfig<DemoService>();
    ref.setRegistry(rc);
    ref.setInterface(DemoService.class.getName());
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("test-refer-generic-export")).service(sc).reference(ref);
    try {
        bootstrap.start();
        Assertions.fail();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) GenericService(org.apache.dubbo.rpc.service.GenericService) 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) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) BeanCreationException(org.springframework.beans.factory.BeanCreationException) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Example 15 with DemoService

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

the class ConfigTest method test_returnSerializationFail.

// BuG: DUBBO-146 Provider doesn't have exception output, and consumer has timeout error when serialization fails
// for example, object transported on the wire doesn't implement Serializable
@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(org.apache.dubbo.rpc.RpcException) DemoService(org.apache.dubbo.config.spring.api.DemoService) 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