From 39d6482eaee51f5074e7df7ede5ea3f95c5ffb47 Mon Sep 17 00:00:00 2001 From: vdisk Date: Sat, 3 Jul 2021 20:46:13 +0800 Subject: [PATCH] fix the unit test NullPointerException --- .../apollo/spring/JavaConfigAnnotationTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java index c125afcc538..668f2a4f80a 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java @@ -36,6 +36,7 @@ import java.util.Queue; import java.util.UUID; import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Test; @@ -383,7 +384,8 @@ public void testApolloConfigChangeListenerWithInterestedKeyPrefixes() { } @Test - public void testApolloConfigChangeListenerWithInterestedKeyPrefixes_fire() { + public void testApolloConfigChangeListenerWithInterestedKeyPrefixes_fire() + throws InterruptedException { // default mock, useless here // just for speed up test without waiting mockConfig(ConfigConsts.NAMESPACE_APPLICATION, mock(Config.class)); @@ -946,7 +948,7 @@ private static class TestApolloConfigChangeListenerWithInterestedKeyPrefixesBean static final String SPECIAL_NAMESPACE = "special-namespace-2021"; - private final Queue configChangeEventQueue = new ArrayBlockingQueue<>(100); + private final BlockingQueue configChangeEventQueue = new ArrayBlockingQueue<>(100); @ApolloConfigChangeListener(value = SPECIAL_NAMESPACE, interestedKeyPrefixes = {"number", "logging.level"}) @@ -954,8 +956,8 @@ private void onChange(ConfigChangeEvent changeEvent) { this.configChangeEventQueue.add(changeEvent); } - public ConfigChangeEvent getConfigChangeEvent() { - return this.configChangeEventQueue.poll(); + public ConfigChangeEvent getConfigChangeEvent() throws InterruptedException { + return this.configChangeEventQueue.take(); } }