mirror of https://github.com/apache/activemq.git
Adds a unit test that demonstrates how to properly unsubscribe and remove a durable subscription and what happen when there is an active subscriber.
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1501878 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
86e2426d1b
commit
9988a3c94f
|
@ -979,6 +979,82 @@ public class Stomp11Test extends StompTestSupport {
|
|||
stompConnection.sendFrame(frame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDurableSubAndUnSubFlow() throws Exception {
|
||||
stompConnection.setVersion(Stomp.V1_1);
|
||||
|
||||
String domain = "org.apache.activemq";
|
||||
ObjectName brokerName = new ObjectName(domain + ":type=Broker,brokerName=localhost");
|
||||
|
||||
BrokerViewMBean view = (BrokerViewMBean)brokerService.getManagementContext().newProxyInstance(brokerName, BrokerViewMBean.class, true);
|
||||
|
||||
String connectFrame = "STOMP\n" +
|
||||
"login:system\n" + "passcode:manager\n" + "accept-version:1.1\n" +
|
||||
"host:localhost\n" + "client-id:test\n" + "\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(connectFrame);
|
||||
|
||||
String frame = stompConnection.receiveFrame();
|
||||
LOG.debug("Broker sent: " + frame);
|
||||
|
||||
assertTrue(frame.startsWith("CONNECTED"));
|
||||
assertEquals(view.getDurableTopicSubscribers().length, 0);
|
||||
|
||||
// subscribe to first destination durably
|
||||
frame = "SUBSCRIBE\n" +
|
||||
"destination:/topic/" + getQueueName() + "1" + "\n" +
|
||||
"ack:auto\n" + "receipt:1\n" + "id:durablesub-1\n" +
|
||||
"activemq.subscriptionName:test1\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
StompFrame receipt = stompConnection.receive();
|
||||
LOG.debug("Broker sent: " + receipt);
|
||||
assertTrue(receipt.getAction().startsWith("RECEIPT"));
|
||||
assertEquals("1", receipt.getHeaders().get("receipt-id"));
|
||||
assertEquals(view.getDurableTopicSubscribers().length, 1);
|
||||
|
||||
// attempt to remove the durable subscription while there is an active subscription
|
||||
frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "1\n" +
|
||||
"id:durablesub-1\n" + "receipt:3\n" +
|
||||
"activemq.subscriptionName:test1\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
receipt = stompConnection.receive();
|
||||
LOG.debug("Broker sent: " + receipt);
|
||||
assertTrue(receipt.getAction().startsWith("ERROR"));
|
||||
assertEquals("3", receipt.getHeaders().get("receipt-id"));
|
||||
|
||||
assertEquals(view.getInactiveDurableTopicSubscribers().length, 0);
|
||||
assertEquals(view.getDurableTopicSubscribers().length, 1);
|
||||
|
||||
// attempt to remove the subscriber leaving the durable sub in place.
|
||||
frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "1\n" +
|
||||
"id:durablesub-1\n" + "receipt:4\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
receipt = stompConnection.receive();
|
||||
LOG.debug("Broker sent: " + receipt);
|
||||
assertTrue(receipt.getAction().startsWith("RECEIPT"));
|
||||
assertEquals("4", receipt.getHeaders().get("receipt-id"));
|
||||
|
||||
assertEquals(view.getInactiveDurableTopicSubscribers().length, 1);
|
||||
assertEquals(view.getDurableTopicSubscribers().length, 0);
|
||||
|
||||
// attempt to remove the durable subscription which should succeed since there are no
|
||||
// active durable subscribers
|
||||
frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "1\n" +
|
||||
"id:durablesub-1\n" + "receipt:5\n" +
|
||||
"activemq.subscriptionName:test1\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
receipt = stompConnection.receive();
|
||||
LOG.debug("Broker sent: " + receipt);
|
||||
assertTrue(receipt.getAction().startsWith("RECEIPT"));
|
||||
assertEquals("5", receipt.getHeaders().get("receipt-id"));
|
||||
|
||||
assertEquals(view.getInactiveDurableTopicSubscribers().length, 0);
|
||||
assertEquals(view.getDurableTopicSubscribers().length, 0);
|
||||
|
||||
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleDurableSubsWithOfflineMessages() throws Exception {
|
||||
stompConnection.setVersion(Stomp.V1_1);
|
||||
|
|
Loading…
Reference in New Issue