Search in sources :

Example 1 with ConsumerConfig

use of org.apache.dubbo.config.ConsumerConfig in project dubbo by alibaba.

the class ReferenceBuilderTest method build.

@Test
void build() {
    ConsumerConfig consumer = new ConsumerConfig();
    MethodConfig method = new MethodConfig();
    ReferenceBuilder<DemoService> builder = new ReferenceBuilder<>();
    builder.id("id").interfaceClass(DemoService.class).protocol("protocol").client("client").url("url").consumer(consumer).addMethod(method).services("test-service", "test-service2");
    ReferenceConfig config = builder.build();
    ReferenceConfig config2 = builder.build();
    Assertions.assertEquals("org.apache.dubbo.config.api.DemoService", config.getInterface());
    Assertions.assertEquals(DemoService.class, config.getInterfaceClass());
    Assertions.assertEquals("protocol", config.getProtocol());
    Assertions.assertEquals("client", config.getClient());
    Assertions.assertEquals("url", config.getUrl());
    Assertions.assertEquals(consumer, config.getConsumer());
    Assertions.assertEquals("test-service,test-service2", config.getServices());
    Assertions.assertEquals(ofSet("test-service", "test-service2"), config.getSubscribedServices());
    Assertions.assertTrue(config.getMethods().contains(method));
    Assertions.assertEquals(1, config.getMethods().size());
    Assertions.assertNotSame(config, config2);
}
Also used : MethodConfig(org.apache.dubbo.config.MethodConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) DemoService(org.apache.dubbo.config.api.DemoService) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) Test(org.junit.jupiter.api.Test)

Example 2 with ConsumerConfig

use of org.apache.dubbo.config.ConsumerConfig in project dubbo by alibaba.

the class ConfigManagerTest method testConsumerConfig.

// Test ConsumerConfig correlative methods
@Test
public void testConsumerConfig() {
    ConsumerConfig config = new ConsumerConfig();
    configManager.addConsumers(asList(config, null));
    Collection<ConsumerConfig> configs = configManager.getConsumers();
    assertEquals(1, configs.size());
    assertEquals(config, configs.iterator().next());
    assertTrue(configManager.getDefaultConsumer().isPresent());
    config.setId(DEFAULT_KEY);
    configManager.addConsumer(config);
    assertTrue(configManager.getDefaultConsumer().isPresent());
    configs = configManager.getConsumers();
    assertEquals(2, configs.size());
}
Also used : ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) Test(org.junit.jupiter.api.Test)

Example 3 with ConsumerConfig

use of org.apache.dubbo.config.ConsumerConfig 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 4 with ConsumerConfig

use of org.apache.dubbo.config.ConsumerConfig in project dubbo by alibaba.

the class ConfigTest method testRmiTimeout.

@Test
public void testRmiTimeout() throws Exception {
    if (System.getProperty("sun.rmi.transport.tcp.responseTimeout") != null) {
        System.setProperty("sun.rmi.transport.tcp.responseTimeout", "");
    }
    ConsumerConfig consumer = new ConsumerConfig();
    consumer.setTimeout(1000);
    assertEquals("1000", System.getProperty("sun.rmi.transport.tcp.responseTimeout"));
    consumer.setTimeout(2000);
    assertEquals("1000", System.getProperty("sun.rmi.transport.tcp.responseTimeout"));
}
Also used : ConsumerConfig(org.apache.dubbo.config.ConsumerConfig) Test(org.junit.jupiter.api.Test)

Example 5 with ConsumerConfig

use of org.apache.dubbo.config.ConsumerConfig in project dubbo by alibaba.

the class ConfigValidationUtils method validateReferenceConfig.

public static void validateReferenceConfig(ReferenceConfig config) {
    checkMultiExtension(InvokerListener.class, LISTENER_KEY, config.getListener());
    checkKey(VERSION_KEY, config.getVersion());
    checkKey(GROUP_KEY, config.getGroup());
    checkName(CLIENT_KEY, config.getClient());
    validateAbstractInterfaceConfig(config);
    List<RegistryConfig> registries = config.getRegistries();
    if (registries != null) {
        for (RegistryConfig registry : registries) {
            validateRegistryConfig(registry);
        }
    }
    ConsumerConfig consumerConfig = config.getConsumer();
    if (consumerConfig != null) {
        validateConsumerConfig(consumerConfig);
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig)

Aggregations

ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)12 Test (org.junit.jupiter.api.Test)7 RegistryConfig (org.apache.dubbo.config.RegistryConfig)4 ProviderConfig (org.apache.dubbo.config.ProviderConfig)3 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)2 MethodConfig (org.apache.dubbo.config.MethodConfig)2 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)2 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)2 DemoService (org.apache.dubbo.config.api.DemoService)2 URL (org.apache.dubbo.common.URL)1 MetadataReportConfig (org.apache.dubbo.config.MetadataReportConfig)1 ModuleConfig (org.apache.dubbo.config.ModuleConfig)1 MonitorConfig (org.apache.dubbo.config.MonitorConfig)1 ServiceConfig (org.apache.dubbo.config.ServiceConfig)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 DemoService (org.apache.dubbo.config.spring.api.DemoService)1 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1