From 2f5ec047ddd2528f565302158bb7b9d1133cd0d9 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Wed, 14 Sep 2011 23:41:42 +0000 Subject: [PATCH] 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 --- .../activemq/transport/stomp/StompTest.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java index 6fb33f3624..de2779a779 100644 --- a/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java @@ -380,6 +380,7 @@ public class StompTest extends CombinationTestSupport { public void testSubscriptionReceipts() throws Exception { final int done = 500; int count = 0; + int receiptId = 0; URI connectUri = new URI(bindAddress); @@ -393,8 +394,10 @@ public class StompTest extends CombinationTestSupport { frame = sender.receiveFrame(); 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); + frame = sender.receiveFrame(); + assertTrue("" + frame, frame.startsWith("RECEIPT")); sender.disconnect(); @@ -407,15 +410,21 @@ public class StompTest extends CombinationTestSupport { frame = receiver.receiveFrame(); 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); frame = receiver.receiveFrame(); assertTrue("" + frame, frame.startsWith("RECEIPT")); 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(); 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(); } while (count < done);