### Question:
AbstractMetadataReport implements MetadataReport { void publishAll() { this.doHandleMetadataCollection(allMetadataReports); } AbstractMetadataReport(URL reportServerURL); URL getUrl(); @Override String toString(); @Override void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition); @Override void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, Map<String, String> serviceParameterMap); void storeConsumerMetadataTask(MetadataIdentifier consumerMetadataIdentifier, Map<String, String> serviceParameterMap); boolean retry(); public MetadataReportRetry metadataReportRetry; }### Answer:
@Test public void testPublishAll() throws ClassNotFoundException, InterruptedException { Assertions.assertTrue(abstractMetadataReport.store.isEmpty()); Assertions.assertTrue(abstractMetadataReport.allMetadataReports.isEmpty()); String interfaceName = "org.apache.dubbo.metadata.integration.InterfaceNameTestService"; String version = "1.0.0"; String group = null; String application = "vic"; MetadataIdentifier providerMetadataIdentifier1 = storePrivider(abstractMetadataReport, interfaceName, version, group, application); Thread.sleep(1000); Assertions.assertEquals(abstractMetadataReport.allMetadataReports.size(), 1); Assertions.assertTrue(((FullServiceDefinition) abstractMetadataReport.allMetadataReports.get(providerMetadataIdentifier1)).getParameters().containsKey("testPKey")); MetadataIdentifier providerMetadataIdentifier2 = storePrivider(abstractMetadataReport, interfaceName, version + "_2", group + "_2", application); Thread.sleep(1000); Assertions.assertEquals(abstractMetadataReport.allMetadataReports.size(), 2); Assertions.assertTrue(((FullServiceDefinition) abstractMetadataReport.allMetadataReports.get(providerMetadataIdentifier2)).getParameters().containsKey("testPKey")); Assertions.assertEquals(((FullServiceDefinition) abstractMetadataReport.allMetadataReports.get(providerMetadataIdentifier2)).getParameters().get("version"), version + "_2"); Map<String, String> tmpMap = new HashMap<>(); tmpMap.put("testKey", "value"); MetadataIdentifier consumerMetadataIdentifier = storeConsumer(abstractMetadataReport, interfaceName, version + "_3", group + "_3", application, tmpMap); Thread.sleep(1000); Assertions.assertEquals(abstractMetadataReport.allMetadataReports.size(), 3); Map tmpMapResult = (Map) abstractMetadataReport.allMetadataReports.get(consumerMetadataIdentifier); Assertions.assertEquals(tmpMapResult.get("testPKey"), "9090"); Assertions.assertEquals(tmpMapResult.get("testKey"), "value"); Assertions.assertTrue(abstractMetadataReport.store.size() == 3); abstractMetadataReport.store.clear(); Assertions.assertTrue(abstractMetadataReport.store.size() == 0); abstractMetadataReport.publishAll(); Thread.sleep(200); Assertions.assertTrue(abstractMetadataReport.store.size() == 3); String v = abstractMetadataReport.store.get(providerMetadataIdentifier1.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY)); Gson gson = new Gson(); FullServiceDefinition data = gson.fromJson(v, FullServiceDefinition.class); checkParam(data.getParameters(), application, version); String v2 = abstractMetadataReport.store.get(providerMetadataIdentifier2.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY)); gson = new Gson(); data = gson.fromJson(v2, FullServiceDefinition.class); checkParam(data.getParameters(), application, version + "_2"); String v3 = abstractMetadataReport.store.get(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY)); gson = new Gson(); Map v3Map = gson.fromJson(v3, Map.class); checkParam(v3Map, application, version + "_3"); }