Skip to content

Commit bcb1899

Browse files
YoungHubeiwei30
authored andcommitted
fix referenceBean initialization issue (#2719)
1 parent 4cd9619 commit bcb1899

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

dubbo-config/dubbo-config-api/src/main/java/com/alibaba/dubbo/config/ReferenceConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ private T createProxy(Map<String, String> map) {
419419
c = true; // default true
420420
}
421421
if (c && !invoker.isAvailable()) {
422+
// make it possible for consumer to retry later if provider is temporarily unavailable
423+
initialized = false;
422424
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());
423425
}
424426
if (logger.isInfoEnabled()) {

dubbo-config/dubbo-config-api/src/test/java/com/alibaba/dubbo/config/ReferenceConfigTest.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,45 @@ public void testInjvm() throws Exception {
5959
demoService.unexport();
6060
}
6161
}
62-
63-
}
62+
/**
63+
* unit test for dubbo-1765
64+
*/
65+
@Test
66+
public void testReferenceRetry() {
67+
ApplicationConfig application = new ApplicationConfig();
68+
application.setName("test-reference-retry");
69+
RegistryConfig registry = new RegistryConfig();
70+
registry.setAddress("multicast://224.5.6.7:1234");
71+
ProtocolConfig protocol = new ProtocolConfig();
72+
protocol.setName("dubbo");
73+
ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
74+
rc.setApplication(application);
75+
rc.setRegistry(registry);
76+
rc.setInterface(DemoService.class.getName());
77+
boolean success = false;
78+
DemoService demoService = null;
79+
try {
80+
demoService = rc.get();
81+
success = true;
82+
} catch (Exception e) {
83+
e.printStackTrace();
84+
}
85+
Assert.assertFalse(success);
86+
Assert.assertNull(demoService);
87+
ServiceConfig<DemoService> sc = new ServiceConfig<DemoService>();
88+
sc.setInterface(DemoService.class);
89+
sc.setRef(new DemoServiceImpl());
90+
sc.setApplication(application);
91+
sc.setRegistry(registry);
92+
sc.setProtocol(protocol);
93+
try {
94+
sc.export();
95+
demoService = rc.get();
96+
success = true;
97+
} catch (Exception e) {
98+
e.printStackTrace();
99+
}
100+
Assert.assertTrue(success);
101+
Assert.assertNotNull(demoService);
102+
}
103+
}

0 commit comments

Comments
 (0)