NacosConfigWatcherRegister extends ConfigWatcherRegister { @Override public Optional<ConfigTable> readConfig(Set<String> keys) { removeUninterestedKeys(keys); registerKeyListeners(keys); final ConfigTable table = new ConfigTable(); for (Map.Entry<String, Optional<String>> entry : configItemKeyedByName.entrySet()) { final String key = entry.getKey(); final Optional<String> value = entry.getValue(); if (value.isPresent()) { table.add(new ConfigTable.ConfigItem(key, value.get())); } else { table.add(new ConfigTable.ConfigItem(key, null)); } } return Optional.of(table); } NacosConfigWatcherRegister(NacosServerSettings settings); @Override Optional<ConfigTable> readConfig(Set<String> keys);  }
@Test public void shouldReadConfigs() throws NacosException { final String group = "skywalking"; final String testKey1 = "receiver-trace.default.slowDBAccessThreshold"; final String testVal1 = "test"; final String testKey2 = "testKey"; final String testVal2 = "testVal"; final NacosServerSettings mockSettings = mock(NacosServerSettings.class); when(mockSettings.getGroup()).thenReturn(group); when(mockSettings.getNamespace()).thenReturn(""); final NacosConfigWatcherRegister mockRegister = spy(new NacosConfigWatcherRegister(mockSettings)); final ConfigService mockConfigService = mock(ConfigService.class); when(mockConfigService.getConfig(testKey1, group, 1000)).thenReturn(testVal1); when(mockConfigService.getConfig(testKey2, group, 1000)).thenReturn(testVal2); Whitebox.setInternalState(mockRegister, "configService", mockConfigService); final ConfigTable configTable = mockRegister.readConfig(Sets.newHashSet(testKey1, testKey2)).get(); assertEquals(2, configTable.getItems().size()); Map<String, String> kvs = new HashMap<>(); for (ConfigTable.ConfigItem item : configTable.getItems()) { kvs.put(item.getName(), item.getValue()); } assertEquals(testVal1, kvs.get(testKey1)); assertEquals(testVal2, kvs.get(testKey2)); }