@@ -67,6 +67,40 @@ public void testQueuePurge() throws IOException {
6767 deleteExchangeAndQueue (binding );
6868 }
6969
70+ /**
71+ * See bug 21854:
72+ * "When Queue.Purge is called, sent-but-unacknowledged messages are no
73+ * longer purged, even if the channel they were sent down is not
74+ * (Tx-)transacted."
75+ */
76+ public void testUnackedPurge () throws IOException {
77+ Binding binding = setupExchangeBindings (false );
78+ channel .basicPublish (binding .x , binding .k , null , payload );
79+
80+ GetResponse response = channel .basicGet (binding .q , false );
81+ assertFalse (response .getEnvelope ().isRedeliver ());
82+ assertNotNull ("The response SHOULD NOT BE null" , response );
83+
84+ // If we purge the queue the unacked message should still be there on
85+ // recover.
86+ channel .queuePurge (binding .q );
87+ response = channel .basicGet (binding .q , true );
88+ assertNull ("The response SHOULD BE null" , response );
89+
90+ channel .basicRecoverAsync (true );
91+ response = channel .basicGet (binding .q , false );
92+ assertTrue (response .getEnvelope ().isRedeliver ());
93+ assertNotNull ("The response SHOULD NOT BE null" , response );
94+
95+ // If we recover then purge the message should go away
96+ channel .basicRecoverAsync (true );
97+ channel .queuePurge (binding .q );
98+ response = channel .basicGet (binding .q , true );
99+ assertNull ("The response SHOULD BE null" , response );
100+
101+ deleteExchangeAndQueue (binding );
102+ }
103+
70104 /**
71105 * This tests whether when you delete an exchange, that any
72106 * bindings attached to it are deleted as well.
0 commit comments