ServiceConfig extends ServiceConfigBase<T> { public synchronized void export() { if (bootstrap == null) { bootstrap = DubboBootstrap.getInstance(); bootstrap.initialize(); } checkAndUpdateSubConfigs(); serviceMetadata.setVersion(getVersion()); serviceMetadata.setGroup(getGroup()); serviceMetadata.setDefaultGroup(getGroup()); serviceMetadata.setServiceType(getInterfaceClass()); serviceMetadata.setServiceInterfaceName(getInterface()); serviceMetadata.setTarget(getRef()); if (!shouldExport()) { return; } if (shouldDelay()) { DELAY_EXPORT_EXECUTOR.schedule(this::doExport, getDelay(), TimeUnit.MILLISECONDS); } else { doExport(); } exported(); } ServiceConfig();  ServiceConfig(Service service); @Parameter(excluded = true) boolean isExported(); @Parameter(excluded = true) boolean isUnexported(); void unexport(); synchronized void export(); void exported(); DubboBootstrap getBootstrap(); void setBootstrap(DubboBootstrap bootstrap); static final Logger logger; }
@Test public void testExport() throws Exception { service.export(); assertThat(service.getExportedUrls(), hasSize(1)); URL url = service.toUrl(); assertThat(url.getProtocol(), equalTo("mockprotocol2")); assertThat(url.getPath(), equalTo(DemoService.class.getName())); assertThat(url.getParameters(), hasEntry(ANYHOST_KEY, "true")); assertThat(url.getParameters(), hasEntry(APPLICATION_KEY, "app")); assertThat(url.getParameters(), hasKey(BIND_IP_KEY)); assertThat(url.getParameters(), hasKey(BIND_PORT_KEY)); assertThat(url.getParameters(), hasEntry(EXPORT_KEY, "true")); assertThat(url.getParameters(), hasEntry("echo.0.callback", "false")); assertThat(url.getParameters(), hasEntry(GENERIC_KEY, "false")); assertThat(url.getParameters(), hasEntry(INTERFACE_KEY, DemoService.class.getName())); assertThat(url.getParameters(), hasKey(METHODS_KEY)); assertThat(url.getParameters().get(METHODS_KEY), containsString("echo")); assertThat(url.getParameters(), hasEntry(SIDE_KEY, PROVIDER)); Mockito.verify(protocolDelegate).export(Mockito.any(Invoker.class)); }
@Test public void testProxy() throws Exception { service2.export(); assertThat(service2.getExportedUrls(), hasSize(1)); assertEquals(2, TestProxyFactory.count); }
@Test public void testDelayExport() throws Exception { delayService.export(); assertTrue(delayService.getExportedUrls().isEmpty()); TimeUnit.MILLISECONDS.sleep(delayService.getDelay() + 300); assertThat(delayService.getExportedUrls(), hasSize(1)); }
@Test public void testApplicationInUrl() { service.export(); Assertions.assertNotNull(service.toUrl().getParameter(APPLICATION_KEY)); Assertions.assertEquals("app", service.toUrl().getParameter(APPLICATION_KEY)); }