Search in sources :

Example 6 with ProviderConfig

use of org.apache.dubbo.config.ProviderConfig 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 ProviderConfig

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

the class ProviderBuilderTest method build.

@Test
void build() {
    ProviderBuilder builder = new ProviderBuilder();
    builder.host("host").port(8080).contextPath("contextpath").threadPool("mockthreadpool").threads(2).ioThreads(3).queues(4).accepts(5).codec("mockcodec").charset("utf-8").payload(6).buffer(1024).transporter("mocktransporter").exchanger("mockexchanger").dispatcher("mockdispatcher").networker("networker").server("server").client("client").telnet("mocktelnethandler").prompt("prompt").status("mockstatuschecker").wait(Integer.valueOf(1000)).isDefault(true).id("id").prefix("prefix");
    ProviderConfig config = builder.build();
    ProviderConfig config2 = builder.build();
    Assertions.assertEquals(8080, config.getPort());
    Assertions.assertEquals(2, config.getThreads());
    Assertions.assertEquals(3, config.getIothreads());
    Assertions.assertEquals(4, config.getQueues());
    Assertions.assertEquals(5, config.getAccepts());
    Assertions.assertEquals(6, config.getPayload());
    Assertions.assertEquals(1024, config.getBuffer());
    Assertions.assertEquals(1000, config.getWait());
    Assertions.assertEquals("host", config.getHost());
    Assertions.assertEquals("contextpath", config.getContextpath());
    Assertions.assertEquals("mockthreadpool", config.getThreadpool());
    Assertions.assertEquals("mockcodec", config.getCodec());
    Assertions.assertEquals("utf-8", config.getCharset());
    Assertions.assertEquals("mocktransporter", config.getTransporter());
    Assertions.assertEquals("mockexchanger", config.getExchanger());
    Assertions.assertEquals("mockdispatcher", config.getDispatcher());
    Assertions.assertEquals("networker", config.getNetworker());
    Assertions.assertEquals("server", config.getServer());
    Assertions.assertEquals("client", config.getClient());
    Assertions.assertEquals("mocktelnethandler", config.getTelnet());
    Assertions.assertEquals("prompt", config.getPrompt());
    Assertions.assertEquals("mockstatuschecker", config.getStatus());
    Assertions.assertTrue(config.isDefault());
    Assertions.assertEquals("id", config.getId());
    Assertions.assertEquals("prefix", config.getPrefix());
    Assertions.assertNotSame(config, config2);
}
Also used : ProviderConfig(org.apache.dubbo.config.ProviderConfig) Test(org.junit.jupiter.api.Test)

Example 8 with ProviderConfig

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

the class DubboNamespaceHandlerTest method testTimeoutConfig.

@Test
public void testTimeoutConfig() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/provider-nested-service.xml");
    ctx.start();
    Map<String, ProviderConfig> providerConfigMap = ctx.getBeansOfType(ProviderConfig.class);
    assertThat(providerConfigMap.get("org.apache.dubbo.config.ProviderConfig").getTimeout(), is(2000));
    ctx.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ProviderConfig(org.apache.dubbo.config.ProviderConfig) Test(org.junit.jupiter.api.Test) ConfigTest(org.apache.dubbo.config.spring.ConfigTest)

Example 9 with ProviderConfig

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

the class DubboBootstrap method checkGlobalConfigs.

private void checkGlobalConfigs() {
    // check Application
    ConfigValidationUtils.validateApplicationConfig(getApplication());
    // check Metadata
    Collection<MetadataReportConfig> metadatas = configManager.getMetadataConfigs();
    if (CollectionUtils.isEmpty(metadatas)) {
        MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
        metadataReportConfig.refresh();
        if (metadataReportConfig.isValid()) {
            configManager.addMetadataReport(metadataReportConfig);
            metadatas = configManager.getMetadataConfigs();
        }
    }
    if (CollectionUtils.isNotEmpty(metadatas)) {
        for (MetadataReportConfig metadataReportConfig : metadatas) {
            metadataReportConfig.refresh();
            ConfigValidationUtils.validateMetadataConfig(metadataReportConfig);
        }
    }
    // check Provider
    Collection<ProviderConfig> providers = configManager.getProviders();
    if (CollectionUtils.isEmpty(providers)) {
        configManager.getDefaultProvider().orElseGet(() -> {
            ProviderConfig providerConfig = new ProviderConfig();
            configManager.addProvider(providerConfig);
            providerConfig.refresh();
            return providerConfig;
        });
    }
    for (ProviderConfig providerConfig : configManager.getProviders()) {
        ConfigValidationUtils.validateProviderConfig(providerConfig);
    }
    // check Consumer
    Collection<ConsumerConfig> consumers = configManager.getConsumers();
    if (CollectionUtils.isEmpty(consumers)) {
        configManager.getDefaultConsumer().orElseGet(() -> {
            ConsumerConfig consumerConfig = new ConsumerConfig();
            configManager.addConsumer(consumerConfig);
            consumerConfig.refresh();
            return consumerConfig;
        });
    }
    for (ConsumerConfig consumerConfig : configManager.getConsumers()) {
        ConfigValidationUtils.validateConsumerConfig(consumerConfig);
    }
    // check Monitor
    ConfigValidationUtils.validateMonitorConfig(getMonitor());
    // check Metrics
    ConfigValidationUtils.validateMetricsConfig(getMetrics());
    // check Module
    ConfigValidationUtils.validateModuleConfig(getModule());
    // check Ssl
    ConfigValidationUtils.validateSslConfig(getSsl());
}
Also used : ProviderConfig(org.apache.dubbo.config.ProviderConfig) MetadataReportConfig(org.apache.dubbo.config.MetadataReportConfig) ConsumerConfig(org.apache.dubbo.config.ConsumerConfig)

Example 10 with ProviderConfig

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

the class ProviderBuilder method build.

public ProviderConfig build() {
    ProviderConfig provider = new ProviderConfig();
    super.build(provider);
    provider.setHost(host);
    provider.setPort(port);
    provider.setContextpath(contextpath);
    provider.setThreadpool(threadpool);
    provider.setThreads(threads);
    provider.setIothreads(iothreads);
    provider.setQueues(queues);
    provider.setAccepts(accepts);
    provider.setCodec(codec);
    provider.setPayload(payload);
    provider.setCharset(charset);
    provider.setBuffer(buffer);
    provider.setTransporter(transporter);
    provider.setExchanger(exchanger);
    provider.setDispatcher(dispatcher);
    provider.setNetworker(networker);
    provider.setServer(server);
    provider.setClient(client);
    provider.setTelnet(telnet);
    provider.setPrompt(prompt);
    provider.setStatus(status);
    provider.setWait(wait);
    provider.setDefault(isDefault);
    return provider;
}
Also used : ProviderConfig(org.apache.dubbo.config.ProviderConfig)

Aggregations

ProviderConfig (org.apache.dubbo.config.ProviderConfig)14 Test (org.junit.jupiter.api.Test)9 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)6 RegistryConfig (org.apache.dubbo.config.RegistryConfig)4 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)3 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)3 MethodConfig (org.apache.dubbo.config.MethodConfig)2 ServiceConfig (org.apache.dubbo.config.ServiceConfig)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 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 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)1 DemoService (org.apache.dubbo.config.api.DemoService)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 ConfigTest (org.apache.dubbo.config.spring.ConfigTest)1 DemoService (org.apache.dubbo.config.spring.api.DemoService)1 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)1