ApolloConfigWrapper { public void addChangeListener(final ConfigChangeListener listener, final Set<String> interestedKeys) { apolloConfig.addChangeListener(listener, interestedKeys); } ApolloConfigWrapper(final String namespace, final GovernanceCenterConfiguration config, final ApolloProperties props); String getProperty(final String key); void addChangeListener(final ConfigChangeListener listener, final Set<String> interestedKeys); void addChangeListener(final ConfigChangeListener listener, final Set<String> interestedKeys, final Set<String> interestedKeyPrefixes);  }
@Test public void assertAddChangeListener() throws InterruptedException, TimeoutException, ExecutionException { SettableFuture<ConfigChangeEvent> future = SettableFuture.create(); ConfigChangeListener listener = future::set; configWrapper.addChangeListener(listener, Collections.singleton("test.children.2")); embeddedApollo.addOrModifyProperty("governance", "test.children.2", "value3"); ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS); assertTrue(changeEvent.isChanged("test.children.2")); assertThat(changeEvent.getChange("test.children.2").getOldValue(), is("value2")); assertThat(changeEvent.getChange("test.children.2").getNewValue(), is("value3")); assertThat(changeEvent.getChange("test.children.2").getChangeType(), is(PropertyChangeType.MODIFIED)); }
@Test public void assertAddChangeListenerWithInterestedKeyPrefixes() throws InterruptedException, TimeoutException, ExecutionException { SettableFuture<ConfigChangeEvent> future = SettableFuture.create(); ConfigChangeListener listener = future::set; configWrapper.addChangeListener(listener, Collections.singleton("test.children.1"), Collections.singleton("test.children.2")); embeddedApollo.addOrModifyProperty("governance", "test.children.2.1", "value4"); ConfigChangeEvent changeEvent = future.get(5, TimeUnit.SECONDS); assertTrue(changeEvent.isChanged("test.children.2.1")); assertThat(changeEvent.getChange("test.children.2.1").getNewValue(), is("value4")); assertThat(changeEvent.getChange("test.children.2.1").getChangeType(), is(PropertyChangeType.ADDED)); }