Skip to content

Commit

Permalink
fix referenceBean initialization issue (#1999)
Browse files Browse the repository at this point in the history
  • Loading branch information
ATAKing1023 authored and zonghaishang committed Aug 1, 2018
1 parent 7f48cd0 commit adafee0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ private T createProxy(Map<String, String> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DemoService> rc = new ReferenceConfig<DemoService>();
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<DemoService> sc = new ServiceConfig<DemoService>();
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);

}
}

0 comments on commit adafee0

Please sign in to comment.