Search in sources :

Example 6 with DemoService

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

the class ConfigTest method testAppendFilter.

@Test
public void testAppendFilter() throws Exception {
    ApplicationConfig application = new ApplicationConfig("provider");
    ProviderConfig provider = new ProviderConfig();
    provider.setFilter("classloader,monitor");
    ConsumerConfig consumer = new ConsumerConfig();
    consumer.setFilter("classloader,monitor");
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setFilter("accesslog,trace");
    service.setProvider(provider);
    service.setProtocol(new ProtocolConfig("dubbo", 20880));
    service.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    service.setInterface(DemoService.class);
    service.setRef(new DemoServiceImpl());
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setFilter("accesslog,trace");
    reference.setConsumer(consumer);
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl("dubbo://" + NetUtils.getLocalHost() + ":20880?" + DemoService.class.getName() + "?check=false");
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).provider(provider).service(service).reference(reference).start();
    try {
        List<URL> urls = service.getExportedUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("service.filter"));
        urls = reference.getExportedUrls();
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("classloader,monitor,accesslog,trace", urls.get(0).getParameter("reference.filter"));
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ProviderConfig(org.apache.dubbo.config.ProviderConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) URL(org.apache.dubbo.common.URL) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 7 with DemoService

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

the class ConfigTest method refer.

private DemoService refer(String url) {
    ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
    reference.setRegistry(new RegistryConfig(RegistryConfig.NO_AVAILABLE));
    reference.setInterface(DemoService.class);
    reference.setUrl(url);
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(new ApplicationConfig("consumer")).reference(reference).start();
    return bootstrap.getCache().get(reference);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) 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)

Example 8 with DemoService

use of org.apache.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());
        ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setInterface(DemoService.class);
        reference.setInjvm(true);
        reference.setRetries(2);
        DubboBootstrap.getInstance().application(new ApplicationConfig("testSystemPropertyOverrideReferenceConfig")).registry(new RegistryConfig(RegistryConfig.NO_AVAILABLE)).protocol(protocolConfig).service(service).reference(reference).start();
        assertEquals(Integer.valueOf(5), reference.getRetries());
    } finally {
        System.setProperty("dubbo.reference.retries", "");
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) 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) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 9 with DemoService

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

the class ConfigTest method test_retrySettingFail.

// BUG: DUBBO-846 in version 2.0.9, config retry="false" on provider's method doesn't work
@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(org.apache.dubbo.rpc.RpcException) DemoService(org.apache.dubbo.config.spring.api.DemoService) Test(org.junit.jupiter.api.Test)

Example 10 with DemoService

use of org.apache.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);
    DubboBootstrap bootstrap = DubboBootstrap.getInstance().application(application).registry(registry).protocol(protocol).service(demoService).service(helloService);
    try {
        bootstrap.start();
        Assertions.assertEquals(demoService.getExportedUrls().get(0).getPort(), helloService.getExportedUrls().get(0).getPort());
    } finally {
        bootstrap.stop();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DemoService(org.apache.dubbo.config.spring.api.DemoService) HelloService(org.apache.dubbo.config.spring.api.HelloService) DubboBootstrap(org.apache.dubbo.config.bootstrap.DubboBootstrap) HelloServiceImpl(org.apache.dubbo.config.spring.impl.HelloServiceImpl) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) DemoServiceImpl(org.apache.dubbo.config.spring.impl.DemoServiceImpl) 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