diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AMQ6477Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AMQ6477Test.java index 02d94259b1..50292c1e8c 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AMQ6477Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/AMQ6477Test.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.lang.reflect.Field; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -174,15 +175,22 @@ public class AMQ6477Test { @SuppressWarnings("unchecked") protected List getSubscriptionMessages(Subscription sub) throws Exception { - Field f = null; + Field dispatchedField = null; + Field dispatchLockField = null; if (sub instanceof TopicSubscription) { - f = TopicSubscription.class.getDeclaredField("dispatched"); + dispatchedField = TopicSubscription.class.getDeclaredField("dispatched"); + dispatchLockField = TopicSubscription.class.getDeclaredField("dispatchLock"); } else { - f = PrefetchSubscription.class.getDeclaredField("dispatched"); + dispatchedField = PrefetchSubscription.class.getDeclaredField("dispatched"); + dispatchLockField = PrefetchSubscription.class.getDeclaredField("dispatchLock"); + } + dispatchedField.setAccessible(true); + dispatchLockField.setAccessible(true); + + synchronized (dispatchLockField.get(sub)) { + return new ArrayList((List)dispatchedField.get(sub)); } - f.setAccessible(true); - return (List) f.get(sub); } } \ No newline at end of file