ApolloDynamicConfiguration implements DynamicConfiguration { @Override public void addListener(String key, String group, ConfigurationListener listener) { ApolloListener apolloListener = listeners.computeIfAbsent(group + key, k -> createTargetListener(key, group)); apolloListener.addListener(listener); dubboConfig.addChangeListener(apolloListener, Collections.singleton(key)); } ApolloDynamicConfiguration(URL url); @Override void addListener(String key, String group, ConfigurationListener listener); @Override void removeListener(String key, String group, ConfigurationListener listener); @Override String getConfig(String key, String group, long timeout); @Override String getProperties(String key, String group, long timeout); @Override String getInternalProperty(String key);  }
@Test public void testAddListener() throws Exception { String mockKey = "mockKey3"; String mockValue = String.valueOf(new Random().nextInt()); final SettableFuture<org.apache.dubbo.common.config.configcenter.ConfigChangedEvent> future = SettableFuture.create(); apolloDynamicConfiguration = new ApolloDynamicConfiguration(url); apolloDynamicConfiguration.addListener(mockKey, DEFAULT_NAMESPACE, new ConfigurationListener() { @Override public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent event) { future.set(event); } }); putData(mockKey, mockValue); org.apache.dubbo.common.config.configcenter.ConfigChangedEvent result = future.get(3000, TimeUnit.MILLISECONDS); assertEquals(mockValue, result.getContent()); assertEquals(mockKey, result.getKey()); assertEquals(ConfigChangeType.MODIFIED, result.getChangeType()); }