From 4682575fa2c8c9b4f5e05068ef9a6f4856b5a222 Mon Sep 17 00:00:00 2001 From: Ankang Date: Wed, 27 Jun 2018 16:20:52 +0800 Subject: [PATCH] fix referenceBean initialization issue --- .../apache/dubbo/config/ReferenceConfig.java | 2 + .../dubbo/config/ReferenceConfigTest.java | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index da86ea0017a..7901c784150 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -422,6 +422,8 @@ private T createProxy(Map map) { c = true; // default true } if (c && !invoker.isAvailable()) { + // make it possible for consumer to retry later if provider is temporarily unavailable + initialized = false; throw new IllegalStateException("Failed to check the status of the service " + interfaceName + ". No provider available for the service " + (group == null ? "" : group + "/") + interfaceName + (version == null ? "" : ":" + version) + " from the url " + invoker.getUrl() + " to the consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion()); } if (logger.isInfoEnabled()) { diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java index 1bac760c209..c8cb048d89a 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java @@ -59,5 +59,50 @@ public void testInjvm() throws Exception { demoService.unexport(); } } + /** + * unit test for dubbo-1765 + */ + @Test + public void testReferenceRetry() { + ApplicationConfig application = new ApplicationConfig(); + application.setName("test-reference-retry"); + RegistryConfig registry = new RegistryConfig(); + registry.setAddress("multicast://224.5.6.7:1234"); + ProtocolConfig protocol = new ProtocolConfig(); + protocol.setName("dubbo"); + ReferenceConfig rc = new ReferenceConfig(); + rc.setApplication(application); + rc.setRegistry(registry); + rc.setInterface(DemoService.class.getName()); + + boolean success = false; + DemoService demoService = null; + try { + demoService = rc.get(); + success = true; + } catch (Exception e) { + e.printStackTrace(); + } + Assert.assertFalse(success); + Assert.assertNull(demoService); + + ServiceConfig sc = new ServiceConfig(); + sc.setInterface(DemoService.class); + sc.setRef(new DemoServiceImpl()); + sc.setApplication(application); + sc.setRegistry(registry); + sc.setProtocol(protocol); + + try { + sc.export(); + demoService = rc.get(); + success = true; + } catch (Exception e) { + e.printStackTrace(); + } + Assert.assertTrue(success); + Assert.assertNotNull(demoService); + + } } \ No newline at end of file