1818
1919import static org .junit .jupiter .api .Assertions .assertNotNull ;
2020import static org .junit .jupiter .api .Assertions .assertNull ;
21- import static org .junit .jupiter .api .Assertions .assertTrue ;
2221
2322import java .util .ArrayList ;
2423import java .util .Arrays ;
2524import java .util .List ;
2625import java .util .concurrent .CountDownLatch ;
27- import java .util .concurrent .TimeUnit ;
2826
2927import org .apache .activemq .artemis .api .core .QueueConfiguration ;
3028import org .apache .activemq .artemis .api .core .RoutingType ;
3129import org .apache .activemq .artemis .api .core .SimpleString ;
3230import org .apache .activemq .artemis .api .core .client .ClientConsumer ;
31+ import org .apache .activemq .artemis .api .core .client .ClientMessage ;
3332import org .apache .activemq .artemis .api .core .client .ClientProducer ;
3433import org .apache .activemq .artemis .api .core .client .ClientSession ;
3534import org .apache .activemq .artemis .api .core .client .ClientSessionFactory ;
@@ -122,13 +121,11 @@ public void testAutoDeleteAddressWithWildcardAddress() throws Exception {
122121 String wildcardAddress = prefix + ".#" ;
123122 String queue = RandomUtil .randomUUIDString ();
124123 final int MESSAGE_COUNT = 10 ;
125- final CountDownLatch latch = new CountDownLatch (MESSAGE_COUNT );
126124
127125 server .createQueue (QueueConfiguration .of (queue ).setAddress (wildcardAddress ).setRoutingType (RoutingType .ANYCAST ).setAutoCreated (true ));
128126
129127 ClientSession consumerSession = cf .createSession ();
130128 ClientConsumer consumer = consumerSession .createConsumer (queue );
131- consumer .setMessageHandler (message -> latch .countDown ());
132129 consumerSession .start ();
133130
134131 ClientSession producerSession = cf .createSession ();
@@ -143,7 +140,19 @@ public void testAutoDeleteAddressWithWildcardAddress() throws Exception {
143140 }
144141 producerSession .close ();
145142
146- assertTrue (latch .await (2 , TimeUnit .SECONDS ));
143+ PostOfficeTestAccessor .sweepAndReapAddresses ((PostOfficeImpl ) server .getPostOffice ());
144+
145+ for (String address : addresses ) {
146+ assertNotNull (server .getAddressInfo (SimpleString .of (address )));
147+ Wait .assertTrue (() -> Arrays .asList (server .getPagingManager ().getStoreNames ()).contains (SimpleString .of (address )), 2000 , 100 );
148+ }
149+
150+ for (int i = 0 ; i < MESSAGE_COUNT ; i ++) {
151+ ClientMessage message = consumer .receive (3000 );
152+ assertNotNull (message );
153+ message .acknowledge ();
154+ }
155+ consumerSession .commit ();
147156
148157 for (String address : addresses ) {
149158 assertNotNull (server .getAddressInfo (SimpleString .of (address )));
0 commit comments