You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by js...@apache.org on 2006/03/07 20:52:51 UTC

svn commit: r383984 - in /incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp: ./ UdpTestSupport.java UdpTransportTest.java

Author: jstrachan
Date: Tue Mar  7 11:52:50 2006
New Revision: 383984

URL: http://svn.apache.org/viewcvs?rev=383984&view=rev
Log:
Added test case for UDP

Added:
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java   (with props)
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java   (with props)

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java?rev=383984&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java Tue Mar  7 11:52:50 2006
@@ -0,0 +1,128 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.transport.udp;
+
+import org.apache.activemq.command.Command;
+import org.apache.activemq.command.ConsumerInfo;
+import org.apache.activemq.transport.Transport;
+import org.apache.activemq.transport.TransportListener;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @version $Revision$
+ */
+public abstract class UdpTestSupport extends TestCase implements TransportListener  {
+
+    protected abstract Transport createConsumer() throws Exception;
+
+    protected abstract Transport createProducer() throws Exception;
+
+    protected Transport producer;
+    protected Transport consumer;
+
+    protected Object lock = new Object();
+    protected Command receivedCommand;
+    
+    public void testSendingSmallMessage() throws Exception {
+        ConsumerInfo expected = new ConsumerInfo();
+        expected.setSelector("Cheese");
+        try {
+            producer.oneway(expected);
+            
+            Command received = assertCommandReceived();
+            assertTrue("Should have received a ConsumerInfo but was: " + received, received instanceof ConsumerInfo);
+            ConsumerInfo actual = (ConsumerInfo) received;
+            assertEquals("Selector", expected.getSelector(), actual.getSelector());
+        }
+        catch (Exception e) {
+            System.out.println("Caught: " + e);
+            e.printStackTrace();
+            fail("Failed to send to transport: " + e);
+        }
+    }
+
+    protected void setUp() throws Exception {
+        consumer = createConsumer();
+        producer = createProducer();
+    
+        consumer.setTransportListener(this);
+        producer.setTransportListener(new TransportListener() {
+            public void onCommand(Command command) {
+            }
+    
+            public void onException(IOException error) {
+            }
+    
+            public void transportInterupted() {
+            }
+    
+            public void transportResumed() {
+            }
+        });
+    
+        consumer.start();
+        producer.start();
+    
+    }
+
+    protected void tearDown() throws Exception {
+        if (producer != null) {
+            producer.stop();
+        }
+        if (consumer != null) {
+            consumer.stop();
+        }
+    }
+
+    public void onCommand(Command command) {
+        System.out.println("### Received command: " + command);
+        
+        synchronized (lock) {
+            receivedCommand = command;
+            lock.notifyAll();
+        }
+    }
+
+    public void onException(IOException error) {
+        System.out.println("### Received error: " + error);
+    }
+
+    public void transportInterupted() {
+        System.out.println("### Transport interrupted");
+    }
+
+    public void transportResumed() {
+        System.out.println("### Transport resumed");
+    }
+
+
+    protected Command assertCommandReceived() throws InterruptedException {
+        Command answer = null;
+        synchronized (lock) {
+            lock.wait(5000);
+            answer = receivedCommand;
+        }
+        
+        assertNotNull("Should have received a Command by now!", answer);
+        return answer;
+    }
+
+}

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTestSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java?rev=383984&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java (added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java Tue Mar  7 11:52:50 2006
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.transport.udp;
+
+import org.apache.activemq.transport.Transport;
+import org.apache.activemq.transport.TransportFactory;
+
+import java.net.URI;
+
+/**
+ * 
+ * @version $Revision$
+ */
+public class UdpTransportTest extends UdpTestSupport {
+
+    protected String producerURI = "udp://localhost:8830";
+    protected String consumerURI = "udp://localhost:8831?port=8830";
+
+    protected Transport createProducer() throws Exception {
+        System.out.println("Producer using URI: " + producerURI);
+        return TransportFactory.connect(new URI(producerURI));
+    }
+
+    protected Transport createConsumer() throws Exception {
+        System.out.println("Consumer using URI: " + consumerURI);
+        return TransportFactory.connect(new URI(consumerURI));
+    }
+
+}

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/udp/UdpTransportTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain