From 90deed42ccc3ce12a4ea911295e69913b44d0a61 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Wed, 15 Aug 2007 17:33:05 +0000 Subject: [PATCH] Improved the STOMP test case a little to verify that killed stomp clients redeliver un acked messages git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@566277 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/transport/stomp/StompTest.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 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 a33e2c08c0..d87f4c325b 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 @@ -20,6 +20,8 @@ import java.io.IOException; import java.net.Socket; import java.net.SocketTimeoutException; import java.net.URI; +import java.net.URISyntaxException; +import java.net.UnknownHostException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -60,8 +62,7 @@ public class StompTest extends CombinationTestSupport { connector = broker.addConnector(bindAddress); broker.start(); - URI connectUri = connector.getConnectUri(); - stompConnection.open("127.0.0.1", connectUri.getPort()); + stompConnect(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost"); connection = cf.createConnection(); @@ -70,6 +71,11 @@ public class StompTest extends CombinationTestSupport { connection.start(); } + private void stompConnect() throws IOException, URISyntaxException, UnknownHostException { + URI connectUri = connector.getConnectUri(); + stompConnection.open("127.0.0.1", connectUri.getPort()); + } + protected Socket createSocket(URI connectUri) throws IOException { return new Socket(); } @@ -80,10 +86,17 @@ public class StompTest extends CombinationTestSupport { protected void tearDown() throws Exception { connection.close(); - stompConnection.close(); + stompDisconnect(); broker.stop(); } + private void stompDisconnect() throws IOException { + if (stompConnection != null) { + stompConnection.close(); + stompConnection = null; + } + } + public void sendMessage(String msg) throws Exception { sendMessage(msg, "foo", "xyz"); } @@ -188,8 +201,8 @@ public class StompTest extends CombinationTestSupport { frame = stompConnection.receiveFrame(); assertTrue(frame.startsWith("CONNECTED")); - frame = "SEND\n" + "correlation-id:c123\n" + "priority:3\n" + "type:t345\n" + "JMSXGroupID:abc\n" + "foo:abc\n" + "bar:123\n" + "destination:/queue/" + getQueueName() - + "\n\n" + "Hello World" + Stomp.NULL; + frame = "SEND\n" + "correlation-id:c123\n" + "priority:3\n" + "type:t345\n" + "JMSXGroupID:abc\n" + "foo:abc\n" + "bar:123\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Hello World" + + Stomp.NULL; stompConnection.sendFrame(frame); @@ -238,7 +251,9 @@ public class StompTest extends CombinationTestSupport { frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "ack:auto\n\n" + Stomp.NULL; stompConnection.sendFrame(frame); - sendBytesMessage(new byte[] {1, 2, 3, 4, 5}); + sendBytesMessage(new byte[] { + 1, 2, 3, 4, 5 + }); frame = stompConnection.receiveFrame(); assertTrue(frame.startsWith("MESSAGE")); @@ -363,8 +378,7 @@ public class StompTest extends CombinationTestSupport { frame = stompConnection.receiveFrame(); assertTrue(frame.startsWith("MESSAGE")); - frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL; - stompConnection.sendFrame(frame); + stompDisconnect(); // message should be received since message was not acknowledged MessageConsumer consumer = session.createConsumer(queue);