Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ public void shouldSupportAnnotationAndMultipleConfig() throws Exception {
assertNotNull(anotherAppChange);
assertNotNull(anotherAppChange.getChange("compat.origin"));

String namespace = apolloEventListenerProbe.pollNamespace(10, TimeUnit.SECONDS);
assertEquals("application", namespace);
// config change listeners are notified asynchronously, so events from different
// namespaces may arrive in any order
SpringCompatibilityTestSupport.waitForCondition(
"ApplicationListener should receive namespace updates",
() -> apolloEventListenerProbe.hasNamespace("application")
&& apolloEventListenerProbe.hasNamespace("TEST1.apollo")
&& apolloEventListenerProbe.hasNamespace("application.yaml"));

SpringCompatibilityTestSupport.waitForCondition("public value should be updated",
() -> "from-public-updated".equals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
package com.ctrip.framework.apollo.compat.spring;

import com.ctrip.framework.apollo.spring.events.ApolloConfigChangeEvent;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

public class SpringApolloEventListenerProbe implements ApplicationListener {

private final BlockingQueue<String> namespaces = new LinkedBlockingQueue<String>();
private final Set<String> namespaces = Collections.synchronizedSet(new HashSet<String>());

@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ApolloConfigChangeEvent) {
namespaces.offer(((ApolloConfigChangeEvent) event).getConfigChangeEvent().getNamespace());
namespaces.add(((ApolloConfigChangeEvent) event).getConfigChangeEvent().getNamespace());
}
}

public String pollNamespace(long timeout, TimeUnit unit) throws InterruptedException {
return namespaces.poll(timeout, unit);
public boolean hasNamespace(String namespace) {
return namespaces.contains(namespace);
}
}
Loading