https://issues.apache.org/jira/browse/AMQ-3497 - make test case more deterministic using receipts on unsub such that a sub only gets one message

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1170901 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2011-09-14 23:41:42 +00:00
parent b65626689d
commit 2f5ec047dd
1 changed files with 12 additions and 3 deletions

View File

@ -380,6 +380,7 @@ public class StompTest extends CombinationTestSupport {
public void testSubscriptionReceipts() throws Exception { public void testSubscriptionReceipts() throws Exception {
final int done = 500; final int done = 500;
int count = 0; int count = 0;
int receiptId = 0;
URI connectUri = new URI(bindAddress); URI connectUri = new URI(bindAddress);
@ -393,8 +394,10 @@ public class StompTest extends CombinationTestSupport {
frame = sender.receiveFrame(); frame = sender.receiveFrame();
assertTrue(frame.startsWith("CONNECTED")); assertTrue(frame.startsWith("CONNECTED"));
frame = "SEND\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World:" + count + Stomp.NULL; frame = "SEND\n" + "destination:/queue/" + getQueueName() + "\n" + "receipt: " + (receiptId++) + "\n\n" + "Hello World:" + (count++) + Stomp.NULL;
sender.sendFrame(frame); sender.sendFrame(frame);
frame = sender.receiveFrame();
assertTrue("" + frame, frame.startsWith("RECEIPT"));
sender.disconnect(); sender.disconnect();
@ -407,15 +410,21 @@ public class StompTest extends CombinationTestSupport {
frame = receiver.receiveFrame(); frame = receiver.receiveFrame();
assertTrue(frame.startsWith("CONNECTED")); assertTrue(frame.startsWith("CONNECTED"));
frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "receipt: " + (count++) + "\n\n" + Stomp.NULL; frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "receipt: " + (receiptId++) + "\n\n" + Stomp.NULL;
receiver.sendFrame(frame); receiver.sendFrame(frame);
frame = receiver.receiveFrame(); frame = receiver.receiveFrame();
assertTrue("" + frame, frame.startsWith("RECEIPT")); assertTrue("" + frame, frame.startsWith("RECEIPT"));
assertTrue("Receipt contains receipt-id", frame.indexOf(Stomp.Headers.Response.RECEIPT_ID) >= 0); assertTrue("Receipt contains receipt-id", frame.indexOf(Stomp.Headers.Response.RECEIPT_ID) >= 0);
LOG.info("received: " + frame.substring(frame.indexOf(Stomp.Headers.Response.RECEIPT_ID)));
frame = receiver.receiveFrame(); frame = receiver.receiveFrame();
assertTrue("" + frame, frame.startsWith("MESSAGE")); assertTrue("" + frame, frame.startsWith("MESSAGE"));
// remove suscription so we don't hang about and get next message
frame = "UNSUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "receipt: " + (receiptId++) + "\n\n" + Stomp.NULL;
receiver.sendFrame(frame);
frame = receiver.receiveFrame();
assertTrue("" + frame, frame.startsWith("RECEIPT"));
receiver.disconnect(); receiver.disconnect();
} while (count < done); } while (count < done);