ReferenceConfig extends ReferenceConfigBase<T> { public synchronized T get() { if (destroyed) { throw new IllegalStateException("The invoker of ReferenceConfig(" + url + ") has already destroyed!"); } if (ref == null) { init(); } return ref; } ReferenceConfig();  ReferenceConfig(Reference reference); @Parameter(key = SUBSCRIBED_SERVICE_NAMES_KEY) String getServices(); @Parameter(excluded = true) Set<String> getSubscribedServices(); void setServices(String services); synchronized T get(); synchronized void destroy(); synchronized void init(); void checkAndUpdateSubConfigs(); DubboBootstrap getBootstrap(); void setBootstrap(DubboBootstrap bootstrap); static final Logger logger; }
@Test public void testReferenceRetry() { ApplicationConfig application = new ApplicationConfig(); application.setName("test-reference-retry"); RegistryConfig registry = new RegistryConfig(); registry.setAddress("multicast: ProtocolConfig protocol = new ProtocolConfig(); protocol.setName("mockprotocol"); 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(); } Assertions.assertFalse(success); Assertions.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 { System.setProperty("java.net.preferIPv4Stack", "true"); sc.export(); demoService = rc.get(); success = true; } catch (Exception e) { e.printStackTrace(); } finally { System.clearProperty("java.net.preferIPv4Stack"); } Assertions.assertTrue(success); Assertions.assertNotNull(demoService); }
@Test public void testConstructWithReferenceAnnotation() throws NoSuchFieldException { Reference reference = getClass().getDeclaredField("innerTest").getAnnotation(Reference.class); ReferenceConfig referenceConfig = new ReferenceConfig(reference); Assertions.assertEquals(1, referenceConfig.getMethods().size()); Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getName(), "sayHello"); Assertions.assertEquals(1300, (int) ((MethodConfig) referenceConfig.getMethods().get(0)).getTimeout()); Assertions.assertEquals(4, (int) ((MethodConfig) referenceConfig.getMethods().get(0)).getRetries()); Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getLoadbalance(), "random"); Assertions.assertEquals(3, (int) ((MethodConfig) referenceConfig.getMethods().get(0)).getActives()); Assertions.assertEquals(5, (int) ((MethodConfig) referenceConfig.getMethods().get(0)).getExecutes()); Assertions.assertTrue(((MethodConfig) referenceConfig.getMethods().get(0)).isAsync()); Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOninvoke(), "i"); Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnreturn(), "r"); Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getOnthrow(), "t"); Assertions.assertEquals(((MethodConfig) referenceConfig.getMethods().get(0)).getCache(), "c"); }