Java Code Examples for com.alipay.sofa.rpc.config.ConsumerConfig#unRefer()
The following examples show how to use
com.alipay.sofa.rpc.config.ConsumerConfig#unRefer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllConnectConnectionHolderTest.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Test public void getAvailableClientTransport2() throws Exception { ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setDirectUrl("bolt://127.0.0.1:22223,bolt://127.0.0.1:22224") .setConnectionHolder("all") .setRegister(false) .setLazy(true) .setTimeout(3000); HelloService helloService = consumerConfig.refer(); ClientProxyInvoker invoker = (ClientProxyInvoker) ProxyFactory.getInvoker(helloService, consumerConfig.getProxy()); Cluster cluster = invoker.getCluster(); Assert.assertTrue(cluster.getConnectionHolder() instanceof AllConnectConnectionHolder); AllConnectConnectionHolder holder = (AllConnectConnectionHolder) cluster.getConnectionHolder(); Assert.assertTrue(holder.isAvailableEmpty()); Assert.assertNotNull(holder.getAvailableClientTransport( ProviderHelper.toProviderInfo("bolt://127.0.0.1:22223"))); Assert.assertNotNull(holder.getAvailableClientTransport( ProviderHelper.toProviderInfo("bolt://127.0.0.1:22224"))); consumerConfig.unRefer(); }
Example 2
Source File: ConsumerConfigContainer.java From sofa-rpc-boot-projects with Apache License 2.0 | 5 votes |
/** * 移除对应的 ConsumerConfig,并进行unRefer。 * * @param binding the {@link Binding} */ public void removeAndUnReferConsumerConfig(Binding binding) { if (binding != null) { ConsumerConfig consumerConfig = consumerConfigMap.remove(binding); if (consumerConfig != null) { consumerConfig.unRefer(); } } }
Example 3
Source File: FailoverClusterTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void testRpcDirectInvokeFromContext() { ServerConfig serverConfig = new ServerConfig() .setProtocol("bolt") .setHost("0.0.0.0") .setPort(13900); ProviderConfig<HelloService> provider = new ProviderConfig(); provider.setInterfaceId(HelloService.class.getName()) .setRef(new HelloServiceImpl("x-demo-invoke")) .setApplication(new ApplicationConfig().setAppName("x-test-server")) .setProxy("javassist") .setSerialization("hessian2") .setServer(serverConfig) .setTimeout(3000); provider.export(); ConsumerConfig<HelloService> consumer = new ConsumerConfig(); consumer.setInterfaceId(HelloService.class.getName()) .setApplication(new ApplicationConfig().setAppName("x-test-client")) .setProxy("javassist"); HelloService proxy = consumer.refer(); for (int i = 0; i < 3; i++) { RpcInvokeContext.getContext().setTargetURL("127.0.0.1:13900"); Assert.assertEquals("x-demo-invoke", proxy.sayHello("x-demo-invoke", 1)); } provider.unExport(); consumer.unRefer(); }
Example 4
Source File: FailoverClusterTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void testRpcDirectInvokeFromContextWithAvailableProviders() { ServerConfig serverConfig = new ServerConfig() .setProtocol("bolt") .setHost("0.0.0.0") .setPort(13900); ProviderConfig<HelloService> provider = new ProviderConfig(); provider.setInterfaceId(HelloService.class.getName()) .setRef(new HelloServiceImpl("x-demo-invoke")) .setApplication(new ApplicationConfig().setAppName("x-test-server")) .setProxy("javassist") .setSerialization("hessian2") .setServer(serverConfig) .setTimeout(3000); provider.export(); ConsumerConfig<HelloService> consumer = new ConsumerConfig(); consumer.setInterfaceId(HelloService.class.getName()) .setApplication(new ApplicationConfig().setAppName("x-test-client")) // 模拟有可用服务 .setDirectUrl("bolt://127.0.0.1:65534") .setProxy("javassist"); HelloService proxy = consumer.refer(); for (int i = 0; i < 3; i++) { RpcInvokeContext.getContext().setTargetURL("127.0.0.1:13900"); Assert.assertEquals("x-demo-invoke", proxy.sayHello("x-demo-invoke", 1)); } provider.unExport(); consumer.unRefer(); }
Example 5
Source File: AllConnectConnectionHolderTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void getAvailableClientTransport3() throws Exception { ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setDirectUrl("bolt://127.0.0.1:22223,bolt://127.0.0.1:22224") .setConnectionHolder("all") .setRegister(false) .setLazy(true) .setTimeout(3000); HelloService helloService = consumerConfig.refer(); ClientProxyInvoker invoker = (ClientProxyInvoker) ProxyFactory.getInvoker(helloService, consumerConfig.getProxy()); Cluster cluster = invoker.getCluster(); Assert.assertTrue(cluster.getConnectionHolder() instanceof AllConnectConnectionHolder); AllConnectConnectionHolder holder = (AllConnectConnectionHolder) cluster.getConnectionHolder(); ProviderGroup providerGroups = new ProviderGroup(); providerGroups.add(ProviderHelper.toProviderInfo("bolt://127.0.0.1:22223")); providerGroups.add(ProviderHelper.toProviderInfo("bolt://127.0.0.1:22224")); holder.updateProviders(providerGroups); Set<ProviderInfo> last = holder.currentProviderList(); Assert.assertEquals(2, last.size()); ProviderGroup providerGroups2 = new ProviderGroup(); providerGroups2.add(ProviderHelper.toProviderInfo("bolt://127.0.0.1:22223")); providerGroups2.add(ProviderHelper.toProviderInfo("bolt://127.0.0.1:22224")); providerGroups2.add(ProviderHelper.toProviderInfo("bolt://127.0.0.1:22225")); holder.updateProviders(providerGroups2); Set<ProviderInfo> current = holder.currentProviderList(); Assert.assertEquals(3, current.size()); consumerConfig.unRefer(); }
Example 6
Source File: AllConnectConnectionHolderTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Test public void getAvailableClientTransport4() throws Exception { ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setDirectUrl("bolt://127.0.0.1:22223,bolt://127.0.0.1:22224") .setConnectionHolder("all") .setRegister(false) .setLazy(true) .setTimeout(3000); HelloService helloService = consumerConfig.refer(); ClientProxyInvoker invoker = (ClientProxyInvoker) ProxyFactory.getInvoker(helloService, consumerConfig.getProxy()); Cluster cluster = invoker.getCluster(); Assert.assertTrue(cluster.getConnectionHolder() instanceof AllConnectConnectionHolder); AllConnectConnectionHolder holder = (AllConnectConnectionHolder) cluster.getConnectionHolder(); ProviderGroup providerGroups = new ProviderGroup(); providerGroups.add(ProviderHelper.toProviderInfo("bolt://127.0.0.1:22223")); providerGroups.add(ProviderHelper.toProviderInfo("bolt://127.0.0.1:22224")); holder.updateProviders(providerGroups); Set<ProviderInfo> last = holder.currentProviderList(); Assert.assertEquals(2, last.size()); ProviderGroup providerGroups2 = new ProviderGroup(); holder.updateProviders(providerGroups2); Set<ProviderInfo> current = holder.currentProviderList(); Assert.assertEquals(0, current.size()); consumerConfig.unRefer(); }
Example 7
Source File: FailoverClusterTest.java From sofa-rpc with Apache License 2.0 | 4 votes |
@Test(expected = SofaRouteException.class) public void testRpcDirectInvokeFromContextNotAllowed() { boolean prev = RpcConfigs.getBooleanValue(RpcOptions.RPC_CREATE_CONN_WHEN_ABSENT); // disable create connection from context RpcConfigs.putValue(RpcOptions.RPC_CREATE_CONN_WHEN_ABSENT, false); try { ServerConfig serverConfig = new ServerConfig() .setProtocol("bolt") .setHost("0.0.0.0") .setPort(13900); ProviderConfig<HelloService> provider = new ProviderConfig(); provider.setInterfaceId(HelloService.class.getName()) .setRef(new HelloServiceImpl("x-demo-invoke")) .setApplication(new ApplicationConfig().setAppName("x-test-server")) .setProxy("javassist") .setSerialization("hessian2") .setServer(serverConfig) .setTimeout(3000); provider.export(); ConsumerConfig<HelloService> consumer = new ConsumerConfig(); consumer.setInterfaceId(HelloService.class.getName()) .setApplication(new ApplicationConfig().setAppName("x-test-client")) .setProxy("javassist"); HelloService proxy = consumer.refer(); RpcInvokeContext.getContext().setTargetURL("127.0.0.1:13900"); proxy.sayHello("x-demo-invoke", 1); provider.unExport(); consumer.unRefer(); } finally { RpcConfigs.putValue(RpcOptions.RPC_CREATE_CONN_WHEN_ABSENT, prev); } }
Example 8
Source File: BoltConsumerBootstrapTest.java From sofa-rpc with Apache License 2.0 | 4 votes |
@Test public void testSubscribe() throws Exception { RegistryConfig registryConfig = new RegistryConfig().setProtocol("mocktest"); RegistryConfig registryConfig2 = new RegistryConfig().setProtocol("mocktestslow"); ConsumerConfig<HelloService> consumerConfig3 = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setUniqueId("mock") .setRegistry(Arrays.asList(registryConfig, registryConfig2)) .setTimeout(3000).setAddressWait(-1); long start = System.currentTimeMillis(); consumerConfig3.refer(); long end = System.currentTimeMillis(); LOGGER.info("elapsed time " + (end - start) + "ms"); Assert.assertTrue((end - start) > 2000 && (end - start) < 4000); Assert.assertTrue(consumerConfig3.getConsumerBootstrap().isSubscribed()); Assert.assertTrue(consumerConfig3.getConsumerBootstrap().getCluster() .getAddressHolder().getAllProviderSize() == 0); // 发布一个服务,每个请求要执行2秒 ServerConfig serverConfig0 = new ServerConfig() .setStopTimeout(0) .setPort(22222) .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT) .setQueues(100).setCoreThreads(5).setMaxThreads(5); ProviderConfig<HelloService> providerConfig0 = new ProviderConfig<HelloService>() .setId("p-0") .setInterfaceId(HelloService.class.getName()) .setUniqueId("mock") .setRef(new HelloServiceImpl(2000)) .setServer(serverConfig0) .setRepeatedExportLimit(5) .setRegistry(registryConfig); providerConfig0.export(); // 发布一个服务,每个请求要执行2秒 ServerConfig serverConfig1 = new ServerConfig() .setStopTimeout(0) .setPort(22223) .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT) .setQueues(100).setCoreThreads(5).setMaxThreads(5); ProviderConfig<HelloService> providerConfig1 = new ProviderConfig<HelloService>() .setId("p-1") .setInterfaceId(HelloService.class.getName()) .setUniqueId("mock") .setRef(new HelloServiceImpl(2000)) .setServer(serverConfig1) .setRepeatedExportLimit(5) .setRegistry(registryConfig2); providerConfig1.export(); ConsumerConfig<HelloService> consumerConfig0 = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setUniqueId("mock") .setDirectUrl("bolt://127.0.0.1:22222") .setTimeout(3000); consumerConfig0.refer(); Assert.assertTrue(consumerConfig0.getConsumerBootstrap().isSubscribed()); consumerConfig0.refer(); consumerConfig0.unRefer(); consumerConfig0.unRefer(); ConsumerConfig<HelloService> consumerConfig1 = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setUniqueId("mock") .setRegistry(Arrays.asList(registryConfig, registryConfig2)) .setTimeout(3000).setAddressWait(-1); start = System.currentTimeMillis(); consumerConfig1.refer(); end = System.currentTimeMillis(); LOGGER.info("elapsed time " + (end - start) + "ms"); Assert.assertTrue((end - start) > 2000 && (end - start) < 4000); Assert.assertTrue(consumerConfig1.getConsumerBootstrap().isSubscribed()); Assert.assertTrue(consumerConfig1.getConsumerBootstrap().getCluster() .getAddressHolder().getAllProviderSize() > 0); Assert.assertTrue(consumerConfig3.getConsumerBootstrap().getCluster() .getAddressHolder().getAllProviderSize() > 0); ConsumerConfig<HelloService> consumerConfig2 = new ConsumerConfig<HelloService>() .setInterfaceId(HelloService.class.getName()) .setUniqueId("mock") .setRegistry(Arrays.asList(registryConfig, registryConfig2)) .setTimeout(3000).setAddressWait(1000); start = System.currentTimeMillis(); consumerConfig2.refer(); end = System.currentTimeMillis(); LOGGER.info("elapsed time " + (end - start) + "ms"); Assert.assertTrue((end - start) > 1000 && (end - start) < 3000); Assert.assertFalse(consumerConfig2.getConsumerBootstrap().isSubscribed()); try { Thread.sleep(1500); } catch (Exception e) { } Assert.assertTrue(consumerConfig2.getConsumerBootstrap().getCluster() .getAddressHolder().getAllProviderSize() > 0); }