Search in sources :

Example 26 with DemoService

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

the class ConfigTest method testSystemPropertyOverrideXmlDefault.

@SuppressWarnings("unchecked")
@Test
public void testSystemPropertyOverrideXmlDefault() 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");
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/system-properties-override-default.xml");
    providerContext.start();
    try {
        ServiceConfig<DemoService> service = (ServiceConfig<DemoService>) providerContext.getBean("demoServiceConfig");
        assertEquals("sysover", service.getApplication().getName());
        assertEquals("sysowner", service.getApplication().getOwner());
        assertEquals("N/A", service.getRegistry().getAddress());
        assertEquals("dubbo", service.getProtocol().getName());
        assertEquals(20819, service.getProtocol().getPort().intValue());
    } 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", "");
        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) Test(org.junit.jupiter.api.Test)

Example 27 with DemoService

use of org.apache.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());
        DubboBootstrap bootstrap = DubboBootstrap.getInstance().service(serviceConfig).start();
        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 {
            bootstrap.stop();
        }
    } 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(org.apache.dubbo.config.ServiceConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 28 with DemoService

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

the class DubboComponentScanRegistrarTest method test.

@Test
public void test() {
    AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext();
    providerContext.register(ProviderConfiguration.class);
    providerContext.refresh();
    DemoService demoService = providerContext.getBean(DemoService.class);
    String value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    Class<?> beanClass = AopUtils.getTargetClass(demoService);
    // DemoServiceImpl with @Transactional
    Assertions.assertEquals(DemoServiceImpl.class, beanClass);
    // Test @Transactional is present or not
    Assertions.assertNotNull(findAnnotation(beanClass, Transactional.class));
    AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
    consumerContext.register(ConsumerConfiguration.class);
    consumerContext.refresh();
    ConsumerConfiguration consumerConfiguration = consumerContext.getBean(ConsumerConfiguration.class);
    demoService = consumerConfiguration.getDemoService();
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    ConsumerConfiguration.Child child = consumerContext.getBean(ConsumerConfiguration.Child.class);
    // From Child
    demoService = child.getDemoServiceFromChild();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // From Parent
    demoService = child.getDemoServiceFromParent();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // From Ancestor
    demoService = child.getDemoServiceFromAncestor();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    providerContext.close();
    consumerContext.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ConsumerConfiguration(org.apache.dubbo.config.spring.context.annotation.consumer.ConsumerConfiguration) DemoService(org.apache.dubbo.config.spring.api.DemoService) Transactional(org.springframework.transaction.annotation.Transactional) Test(org.junit.jupiter.api.Test)

Example 29 with DemoService

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

the class ZookeeperDubboSpringConsumerXmlBootstrap method main.

public static void main(String[] args) throws Exception {
    String location = "classpath:/META-INF/service-introspection/zookeeper-dubbo-consumer.xml";
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(location);
    DemoService demoService = context.getBean("demoService", DemoService.class);
    for (int i = 0; i < 100; i++) {
        System.out.println(demoService.sayName("Hello"));
    }
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DemoService(org.apache.dubbo.config.spring.api.DemoService)

Example 30 with DemoService

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

the class EnableDubboTest method testConsumer.

@Test
public void testConsumer() {
    context.register(TestProviderConfiguration.class, TestConsumerConfiguration.class);
    context.refresh();
    TestConsumerConfiguration consumerConfiguration = context.getBean(TestConsumerConfiguration.class);
    DemoService demoService = consumerConfiguration.getDemoService();
    String value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    DemoService autowiredDemoService = consumerConfiguration.getAutowiredDemoService();
    Assertions.assertEquals("Hello,Mercy", autowiredDemoService.sayName("Mercy"));
    TestConsumerConfiguration.Child child = context.getBean(TestConsumerConfiguration.Child.class);
    // From Child
    demoService = child.getDemoServiceFromChild();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // From Parent
    demoService = child.getDemoServiceFromParent();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // From Ancestor
    demoService = child.getDemoServiceFromAncestor();
    Assertions.assertNotNull(demoService);
    value = demoService.sayName("Mercy");
    Assertions.assertEquals("Hello,Mercy", value);
    // Test my-registry2 bean presentation
    RegistryConfig registryConfig = context.getBean("my-registry2", RegistryConfig.class);
    // Test multiple binding
    Assertions.assertEquals("N/A", registryConfig.getAddress());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) TestConsumerConfiguration(org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration) 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