Search in sources :

Example 6 with AddressHolder

use of com.alipay.sofa.rpc.client.AddressHolder in project sofa-rpc by sofastack.

the class ZookeeperSubscribeObserverTest method testAll.

@Test
public void testAll() throws Exception {
    RegistryConfig registryConfig = new RegistryConfig().setProtocol(RpcConstants.REGISTRY_PROTOCOL_ZK).setAddress("127.0.0.1:2181");
    ZookeeperRegistry registry = (ZookeeperRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.start();
    ServerConfig serverConfig = new ServerConfig().setPort(22222).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(22222)).setServer(serverConfig).setRegistry(registryConfig).setParameter(ProviderInfoAttrs.ATTR_WARMUP_TIME, "2000").setParameter(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT, "100").setUniqueId("uniqueIdA").setRepeatedExportLimit(-1).setWeight(0);
    ServerConfig serverConfig2 = new ServerConfig().setPort(22111).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
    ProviderConfig<HelloService> providerConfig2 = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(22111)).setServer(serverConfig2).setRegistry(registryConfig).setUniqueId("uniqueIdB").setRepeatedExportLimit(-1).setWeight(0);
    providerConfig.export();
    providerConfig2.export();
    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRegistry(registryConfig).setTimeout(3333).setUniqueId("uniqueIdA").setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
    HelloService helloService = consumerConfig.refer();
    AddressHolder addressHolder = consumerConfig.getConsumerBootstrap().getCluster().getAddressHolder();
    Assert.assertTrue(addressHolder.getAllProviderSize() == 1);
    ServerConfig serverConfig3 = new ServerConfig().setPort(22133).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
    ProviderConfig<HelloService> providerConfig3 = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(22133)).setServer(serverConfig3).setRegistry(registryConfig).setRepeatedExportLimit(-1).setUniqueId("uniqueIdB").setRepeatedExportLimit(-1).setWeight(0);
    providerConfig3.export();
    Assert.assertTrue(delayGetSize(addressHolder, 1, 100) == 1);
    ServerConfig serverConfig4 = new ServerConfig().setPort(22244).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
    ProviderConfig<HelloService> providerConfig4 = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl(22244)).setServer(serverConfig4).setRegistry(registryConfig).setUniqueId("uniqueIdA").setRepeatedExportLimit(-1).setWeight(0);
    providerConfig4.export();
    Assert.assertTrue(delayGetSize(addressHolder, 1, 100) == 2);
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) AddressHolder(com.alipay.sofa.rpc.client.AddressHolder) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) HelloService(com.alipay.sofa.rpc.test.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.test.HelloServiceImpl) Test(org.junit.Test) BaseZkTest(com.alipay.sofa.rpc.registry.base.BaseZkTest)

Aggregations

AddressHolder (com.alipay.sofa.rpc.client.AddressHolder)6 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)5 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)2 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)2 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)2 BaseZkTest (com.alipay.sofa.rpc.registry.base.BaseZkTest)2 Test (org.junit.Test)2 ConsumerBootstrap (com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap)1 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 HelloService (com.alipay.sofa.rpc.test.HelloService)1 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)1