Java Code Examples for com.alibaba.dubbo.config.spring.api.DemoService#sayName()

The following examples show how to use com.alibaba.dubbo.config.spring.api.DemoService#sayName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 2
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 3
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiProtocol() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml");
    ctx.start();
    try {
        DemoService demoService = refer("dubbo://127.0.0.1:20881");
        String hello = demoService.sayName("hello");
        assertEquals("say:hello", hello);
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example 4
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 5
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 6
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 7
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 8
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiProtocol() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml");
    ctx.start();
    try {
        DemoService demoService = refer("dubbo://127.0.0.1:20881");
        String hello = demoService.sayName("hello");
        assertEquals("say:hello", hello);
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example 9
Source File: ConfigTest.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 10
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 11
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultiProtocol() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol.xml");
    ctx.start();
    try {
        DemoService demoService = refer("dubbo://127.0.0.1:20881");
        String hello = demoService.sayName("hello");
        assertEquals("say:hello", hello);
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example 12
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 13
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 14
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 15
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 16
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 17
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 18
Source File: ConfigTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example 19
Source File: DubboComponentScanRegistrarTest.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
@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");

    Assert.assertEquals("Hello,Mercy", value);

    Class<?> beanClass = AopUtils.getTargetClass(demoService);

    // DemoServiceImpl with @Transactional
    Assert.assertEquals(DemoServiceImpl.class, beanClass);

    // Test @Transactional is present or not
    Assert.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");

    Assert.assertEquals("Hello,Mercy", value);

    ConsumerConfiguration.Child child = consumerContext.getBean(ConsumerConfiguration.Child.class);

    // From Child

    demoService = child.getDemoServiceFromChild();

    Assert.assertNotNull(demoService);

    value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    // From Parent

    demoService = child.getDemoServiceFromParent();

    Assert.assertNotNull(demoService);

    value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    // From Ancestor

    demoService = child.getDemoServiceFromAncestor();

    Assert.assertNotNull(demoService);

    value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    providerContext.close();
    consumerContext.close();


}
 
Example 20
Source File: EnableDubboTest.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
@Test
public void test() {

    AnnotationConfigApplicationContext providerContext = new AnnotationConfigApplicationContext();

    providerContext.register(TestProviderConfiguration.class);

    providerContext.refresh();

    DemoService demoService = providerContext.getBean(DemoService.class);

    String value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    Class<?> beanClass = AopUtils.getTargetClass(demoService);

    // DemoServiceImpl with @Transactional
    Assert.assertEquals(DemoServiceImpl.class, beanClass);

    // Test @Transactional is present or not
    Assert.assertNotNull(findAnnotation(beanClass, Transactional.class));

    AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();

    consumerContext.register(TestConsumerConfiguration.class);

    consumerContext.refresh();

    TestConsumerConfiguration consumerConfiguration = consumerContext.getBean(TestConsumerConfiguration.class);

    demoService = consumerConfiguration.getDemoService();

    value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    TestConsumerConfiguration.Child child = consumerContext.getBean(TestConsumerConfiguration.Child.class);

    // From Child

    demoService = child.getDemoServiceFromChild();

    Assert.assertNotNull(demoService);

    value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    // From Parent

    demoService = child.getDemoServiceFromParent();

    Assert.assertNotNull(demoService);

    value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    // From Ancestor

    demoService = child.getDemoServiceFromAncestor();

    Assert.assertNotNull(demoService);

    value = demoService.sayName("Mercy");

    Assert.assertEquals("Hello,Mercy", value);

    // Test dubbo-annotation-consumer2 bean presentation

    ApplicationConfig applicationConfig = consumerContext.getBean("dubbo-annotation-consumer2", ApplicationConfig.class);

    // Test multiple binding
    Assert.assertEquals("dubbo-consumer2", applicationConfig.getName());

    // Test dubbo-annotation-consumer2 bean presentation
    RegistryConfig registryConfig = consumerContext.getBean("my-registry2", RegistryConfig.class);

    // Test multiple binding
    Assert.assertEquals("N/A", registryConfig.getAddress());

    providerContext.close();
    consumerContext.close();


}