Skip to content

Commit 4f85cbe

Browse files
author
Emile Joubert
committed
Test durable message expiry with restart
1 parent 1b1dd60 commit 4f85cbe

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/src/com/rabbitmq/client/test/functional/PerMessageTTL.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
public class PerMessageTTL extends TTLHandling {
2727

2828
protected Object sessionTTL;
29+
private volatile String retrievedMsg = null;
2930

3031
@Override
3132
protected void publish(String msg) throws IOException {
@@ -58,4 +59,33 @@ public void testExpiryWhenConsumerIsLateToTheParty() throws Exception {
5859
assertNull("Message should have been expired!!", c.nextDelivery(100));
5960
}
6061

62+
public void testRestartingExpiry() throws Exception {
63+
final String restartDelay = "3000";
64+
declareDurableQueue(TTL_QUEUE_NAME);
65+
bindQueue();
66+
channel.basicPublish(TTL_EXCHANGE, TTL_QUEUE_NAME,
67+
MessageProperties.MINIMAL_PERSISTENT_BASIC
68+
.builder()
69+
.expiration(restartDelay)
70+
.build(), new byte[]{});
71+
72+
Thread delayedConsume =
73+
new Thread(new Runnable() {
74+
@Override
75+
public void run() {
76+
try {
77+
Thread.sleep(Integer.parseInt(restartDelay));
78+
retrievedMsg = get();
79+
} catch (IOException e) {
80+
} catch (InterruptedException e) {
81+
}
82+
83+
}
84+
});
85+
delayedConsume.start();
86+
restart();
87+
delayedConsume.join();
88+
assertNull("Message should have expired after broker restart", retrievedMsg);
89+
}
90+
6191
}

0 commit comments

Comments
 (0)