You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2007/08/15 19:33:06 UTC

svn commit: r566277 - /activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java

Author: chirino
Date: Wed Aug 15 10:33:05 2007
New Revision: 566277

URL: http://svn.apache.org/viewvc?view=rev&rev=566277
Log:
Improved the STOMP test case a little to verify that killed stomp clients redeliver un acked messages

Modified:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java?view=diff&rev=566277&r1=566276&r2=566277
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java Wed Aug 15 10:33:05 2007
@@ -20,6 +20,8 @@
 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 @@
         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 @@
         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 @@
 
     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 @@
         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 @@
         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 @@
         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);