3434import org .apache .activemq .artemis .api .core .ActiveMQException ;
3535import org .apache .activemq .artemis .api .core .Message ;
3636import org .apache .activemq .artemis .api .core .QueueConfiguration ;
37+ import org .apache .activemq .artemis .api .core .RoutingType ;
3738import org .apache .activemq .artemis .api .core .SimpleString ;
3839import org .apache .activemq .artemis .api .core .TransportConfiguration ;
3940import org .apache .activemq .artemis .api .core .client .ActiveMQClient ;
5253import org .apache .activemq .artemis .tests .extensions .parameterized .ParameterizedTestExtension ;
5354import org .apache .activemq .artemis .tests .extensions .parameterized .Parameters ;
5455import org .apache .activemq .artemis .tests .util .ActiveMQTestBase ;
56+ import org .apache .activemq .artemis .utils .RandomUtil ;
5557import org .apache .activemq .artemis .utils .UUIDGenerator ;
5658import org .junit .jupiter .api .BeforeEach ;
5759import org .junit .jupiter .api .TestTemplate ;
@@ -1346,6 +1348,36 @@ private ClientMessage createMessage(final ClientSession session, final int i) {
13461348 return message ;
13471349 }
13481350
1351+ @ TestTemplate
1352+ public void testDuplicateCacheCleanupWhenAddressRemoved () throws Exception {
1353+ final SimpleString addressName = SimpleString .of ("DuplicateDetectionTestQueue" );
1354+
1355+ // send a message to create a cache
1356+ sf = createSessionFactory (locator );
1357+ ClientSession session = sf .createSession (false , true , true );
1358+ session .createAddress (addressName , RoutingType .MULTICAST , false );
1359+ ClientProducer producer = session .createProducer (addressName );
1360+ ClientMessage message = createMessage (session , 1 );
1361+ message .putBytesProperty (Message .HDR_DUPLICATE_DETECTION_ID , RandomUtil .randomBytes (10 ));
1362+ producer .send (message );
1363+ session .close ();
1364+ sf .close ();
1365+
1366+ assertNotNull (((PostOfficeImpl ) server .getPostOffice ()).getDuplicateIDCaches ().get (addressName ));
1367+
1368+ server .removeAddressInfo (addressName , null );
1369+
1370+ assertNull (((PostOfficeImpl ) server .getPostOffice ()).getDuplicateIDCaches ().get (addressName ));
1371+
1372+ server .stop ();
1373+
1374+ waitForServerToStop (server );
1375+
1376+ server .start ();
1377+
1378+ assertNull (((PostOfficeImpl ) server .getPostOffice ()).getDuplicateIDCaches ().get (addressName ));
1379+ }
1380+
13491381 @ TestTemplate
13501382 public void testDuplicateCachePersisted () throws Exception {
13511383 server .stop ();
@@ -1364,7 +1396,7 @@ public void testDuplicateCachePersisted() throws Exception {
13641396
13651397 final SimpleString queueName = SimpleString .of ("DuplicateDetectionTestQueue" );
13661398
1367- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1399+ session .createQueue (QueueConfiguration .of (queueName ).setDurable (true ));
13681400
13691401 ClientProducer producer = session .createProducer (queueName );
13701402
@@ -1400,8 +1432,6 @@ public void testDuplicateCachePersisted() throws Exception {
14001432
14011433 session .start ();
14021434
1403- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1404-
14051435 producer = session .createProducer (queueName );
14061436
14071437 consumer = session .createConsumer (queueName );
@@ -1439,7 +1469,7 @@ public void testDuplicateCachePersisted2() throws Exception {
14391469
14401470 final SimpleString queueName = SimpleString .of ("DuplicateDetectionTestQueue" );
14411471
1442- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1472+ session .createQueue (QueueConfiguration .of (queueName ).setDurable (true ));
14431473
14441474 ClientProducer producer = session .createProducer (queueName );
14451475
@@ -1470,8 +1500,6 @@ public void testDuplicateCachePersisted2() throws Exception {
14701500
14711501 session .start ();
14721502
1473- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1474-
14751503 producer = session .createProducer (queueName );
14761504
14771505 consumer = session .createConsumer (queueName );
@@ -1645,7 +1673,7 @@ public void testPersistTransactional() throws Exception {
16451673
16461674 final SimpleString queueName = SimpleString .of ("DuplicateDetectionTestQueue" );
16471675
1648- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1676+ session .createQueue (QueueConfiguration .of (queueName ).setDurable (true ));
16491677
16501678 ClientProducer producer = session .createProducer (queueName );
16511679
@@ -1687,8 +1715,6 @@ public void testPersistTransactional() throws Exception {
16871715
16881716 session .start ();
16891717
1690- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1691-
16921718 producer = session .createProducer (queueName );
16931719
16941720 consumer = session .createConsumer (queueName );
@@ -1906,7 +1932,7 @@ public void testPersistXA1() throws Exception {
19061932
19071933 final SimpleString queueName = SimpleString .of ("DuplicateDetectionTestQueue" );
19081934
1909- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1935+ session .createQueue (QueueConfiguration .of (queueName ).setDurable (true ));
19101936
19111937 ClientProducer producer = session .createProducer (queueName );
19121938
@@ -1946,8 +1972,6 @@ public void testPersistXA1() throws Exception {
19461972
19471973 session .start ();
19481974
1949- session .createQueue (QueueConfiguration .of (queueName ).setDurable (false ));
1950-
19511975 producer = session .createProducer (queueName );
19521976
19531977 consumer = session .createConsumer (queueName );
0 commit comments