Search in sources :

Example 41 with RegistryConfig

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

the class ModuleBuilderTest method addRegistries.

@Test
void addRegistries() {
    RegistryConfig registry = new RegistryConfig();
    ModuleBuilder builder = new ModuleBuilder();
    builder.addRegistries(Collections.singletonList(registry));
    Assertions.assertTrue(builder.build().getRegistries().contains(registry));
    Assertions.assertEquals(1, builder.build().getRegistries().size());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Test(org.junit.jupiter.api.Test)

Example 42 with RegistryConfig

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

the class ApplicationBuilderTest method addRegistries.

@Test
void addRegistries() {
    RegistryConfig registry = new RegistryConfig();
    ApplicationBuilder builder = new ApplicationBuilder();
    builder.addRegistries(Collections.singletonList(registry));
    Assertions.assertNotNull(builder.build().getRegistry());
    Assertions.assertEquals(1, builder.build().getRegistries().size());
    Assertions.assertSame(registry, builder.build().getRegistry());
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Test(org.junit.jupiter.api.Test)

Example 43 with RegistryConfig

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

the class CacheTest method testCache.

private void testCache(String type) throws Exception {
    ApplicationConfig applicationConfig = new ApplicationConfig("cache-test");
    RegistryConfig registryConfig = new RegistryConfig("N/A");
    ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
    ServiceConfig<CacheService> service = new ServiceConfig<CacheService>();
    service.setApplication(applicationConfig);
    service.setRegistry(registryConfig);
    service.setProtocol(protocolConfig);
    service.setInterface(CacheService.class.getName());
    service.setRef(new CacheServiceImpl());
    service.export();
    try {
        ReferenceConfig<CacheService> reference = new ReferenceConfig<CacheService>();
        reference.setApplication(applicationConfig);
        reference.setInterface(CacheService.class);
        reference.setUrl("injvm://127.0.0.1?scope=remote&cache=true");
        MethodConfig method = new MethodConfig();
        method.setName("findCache");
        method.setCache(type);
        reference.setMethods(Arrays.asList(method));
        CacheService cacheService = reference.get();
        try {
            // verify cache, same result is returned for multiple invocations (in fact, the return value increases
            // on every invocation on the server side)
            String fix = null;
            cacheService.findCache("0");
            for (int i = 0; i < 3; i++) {
                String result = cacheService.findCache("0");
                assertTrue(fix == null || fix.equals(result));
                fix = result;
                Thread.sleep(100);
            }
            if ("lru".equals(type)) {
                // default cache.size is 1000 for LRU, should have cache expired if invoke more than 1001 times
                for (int n = 0; n < 1001; n++) {
                    String pre = null;
                    cacheService.findCache(String.valueOf(n));
                    for (int i = 0; i < 10; i++) {
                        String result = cacheService.findCache(String.valueOf(n));
                        assertTrue(pre == null || pre.equals(result));
                        pre = result;
                    }
                }
                // verify if the first cache item is expired in LRU cache
                String result = cacheService.findCache("0");
                assertFalse(fix == null || fix.equals(result));
            }
        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) MethodConfig(org.apache.dubbo.config.MethodConfig) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) ServiceConfig(org.apache.dubbo.config.ServiceConfig) ReferenceConfig(org.apache.dubbo.config.ReferenceConfig) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig)

Example 44 with RegistryConfig

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

the class RegistryBuilderTest method build.

@Test
void build() {
    RegistryBuilder builder = new RegistryBuilder();
    builder.address("address").username("username").password("password").port(8080).protocol("protocol").transporter("transporter").server("server").client("client").cluster("cluster").group("group").version("version").timeout(1000).session(2000).file("file").wait(Integer.valueOf(10)).isCheck(true).isDynamic(false).register(true).subscribe(false).isDefault(true).simplified(false).extraKeys("A").parameter("default.num", "one").id("id").prefix("prefix");
    RegistryConfig config = builder.build();
    RegistryConfig config2 = builder.build();
    Assertions.assertEquals(8080, config.getPort());
    Assertions.assertEquals(1000, config.getTimeout());
    Assertions.assertEquals(2000, config.getSession());
    Assertions.assertEquals(10, config.getWait());
    Assertions.assertTrue(config.isCheck());
    Assertions.assertFalse(config.isDynamic());
    Assertions.assertTrue(config.isRegister());
    Assertions.assertFalse(config.isSubscribe());
    Assertions.assertTrue(config.isDefault());
    Assertions.assertFalse(config.getSimplified());
    Assertions.assertEquals("address", config.getAddress());
    Assertions.assertEquals("username", config.getUsername());
    Assertions.assertEquals("password", config.getPassword());
    Assertions.assertEquals("protocol", config.getProtocol());
    Assertions.assertEquals("transporter", config.getTransporter());
    Assertions.assertEquals("server", config.getServer());
    Assertions.assertEquals("client", config.getClient());
    Assertions.assertEquals("cluster", config.getCluster());
    Assertions.assertEquals("group", config.getGroup());
    Assertions.assertEquals("version", config.getVersion());
    Assertions.assertEquals("file", config.getFile());
    Assertions.assertEquals("A", config.getExtraKeys());
    Assertions.assertTrue(config.getParameters().containsKey("default.num"));
    Assertions.assertEquals("one", config.getParameters().get("default.num"));
    Assertions.assertEquals("id", config.getId());
    Assertions.assertEquals("prefix", config.getPrefix());
    Assertions.assertNotSame(config, config2);
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Test(org.junit.jupiter.api.Test)

Example 45 with RegistryConfig

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

the class PublishingServiceDefinitionListenerTest method testOnServiceConfigExportedEvent.

/**
 * Test {@link ServiceConfigExportedEvent} arising
 */
@Test
public void testOnServiceConfigExportedEvent() {
    ServiceConfig<EchoService> serviceConfig = new ServiceConfig<>();
    serviceConfig.setInterface(EchoService.class);
    serviceConfig.setRef(new EchoServiceImpl());
    serviceConfig.setRegistry(new RegistryConfig("N/A"));
    serviceConfig.setProtocol(new ProtocolConfig("dubbo", NetUtils.getAvailablePort(20880 + new Random().nextInt(10000))));
    serviceConfig.export();
    String serviceDefinition = writableMetadataService.getServiceDefinition(EchoService.class.getName());
    ServiceDefinition serviceDefinitionBuild = ServiceDefinitionBuilder.build(serviceConfig.getInterfaceClass());
    assertEquals(serviceDefinition, JSON.toJSONString(serviceDefinitionBuild));
    serviceConfig.unexport();
}
Also used : RegistryConfig(org.apache.dubbo.config.RegistryConfig) Random(java.util.Random) ServiceConfig(org.apache.dubbo.config.ServiceConfig) EchoService(org.apache.dubbo.config.bootstrap.EchoService) ProtocolConfig(org.apache.dubbo.config.ProtocolConfig) EchoServiceImpl(org.apache.dubbo.config.bootstrap.EchoServiceImpl) ServiceDefinition(org.apache.dubbo.metadata.definition.model.ServiceDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

RegistryConfig (org.apache.dubbo.config.RegistryConfig)68 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)42 Test (org.junit.jupiter.api.Test)34 ProtocolConfig (org.apache.dubbo.config.ProtocolConfig)29 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)20 ServiceConfig (org.apache.dubbo.config.ServiceConfig)19 ReferenceConfig (org.apache.dubbo.config.ReferenceConfig)16 DemoService (org.apache.dubbo.config.spring.api.DemoService)13 GenericService (org.apache.dubbo.rpc.service.GenericService)8 ArrayList (java.util.ArrayList)7 URL (org.apache.dubbo.common.URL)7 DemoServiceImpl (org.apache.dubbo.config.spring.impl.DemoServiceImpl)7 ConsumerConfig (org.apache.dubbo.config.ConsumerConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 ModuleConfig (org.apache.dubbo.config.ModuleConfig)4 MonitorConfig (org.apache.dubbo.config.MonitorConfig)4 ProviderConfig (org.apache.dubbo.config.ProviderConfig)4 Bean (org.springframework.context.annotation.Bean)4 List (java.util.List)3 MethodConfig (org.apache.dubbo.config.MethodConfig)3