activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r1499843 - in /activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt: AbstractMQTTTest.java FuseMQQTTClientProvider.java MQTTClientProvider.java MQTTTest.java
Date Thu, 04 Jul 2013 18:57:49 GMT
Author: rajdavies
Date: Thu Jul  4 18:57:49 2013
New Revision: 1499843

URL: http://svn.apache.org/r1499843
Log:
fixed some failing tests

Modified:
    activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/AbstractMQTTTest.java
    activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/FuseMQQTTClientProvider.java
    activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTClientProvider.java
    activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java

Modified: activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/AbstractMQTTTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/AbstractMQTTTest.java?rev=1499843&r1=1499842&r2=1499843&view=diff
==============================================================================
--- activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/AbstractMQTTTest.java
(original)
+++ activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/AbstractMQTTTest.java
Thu Jul  4 18:57:49 2013
@@ -16,20 +16,18 @@
  */
 package org.apache.activemq.transport.mqtt;
 
-import static org.junit.Assert.assertArrayEquals;
-
 import java.io.File;
 import java.io.IOException;
 import java.security.ProtectionDomain;
 import java.util.LinkedList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
-
 import org.apache.activemq.ActiveMQConnection;
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.AutoFailTestSupport;
@@ -40,6 +38,7 @@ import org.apache.activemq.util.ByteSequ
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import static org.junit.Assert.assertArrayEquals;
 
 public abstract class AbstractMQTTTest extends AutoFailTestSupport {
     protected TransportConnector mqttConnector;
@@ -79,6 +78,50 @@ public abstract class AbstractMQTTTest e
     }
 
     @Test(timeout=300000)
+    public void testWillNotSentOnClose() throws Exception {
+        addMQTTConnector();
+        brokerService.start();
+        final MQTTClientProvider subscriptionProvider = getMQTTClientProvider();
+        initializeConnection(subscriptionProvider);
+
+        String willTopic = "lastWillAndTestament";
+
+        subscriptionProvider.subscribe(willTopic,AT_MOST_ONCE);
+
+        final AtomicInteger count = new AtomicInteger();
+
+        Thread thread = new Thread(new Runnable() {
+            @Override
+            public void run() {
+                for (int i = 0; i < 1; i++){
+                    try {
+                        byte[] payload = subscriptionProvider.receive(10000);
+                        assertNull("Should get a message", payload);
+                        count.incrementAndGet();
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                        break;
+                    }
+
+                }
+            }
+        });
+        thread.start();
+
+        final MQTTClientProvider publishProvider = getMQTTClientProvider();
+        publishProvider.setWillTopic(willTopic);
+        publishProvider.setWillMessage("EverythingGoesToRob");
+        initializeConnection(publishProvider);
+
+        Thread.sleep(1000);
+        publishProvider.disconnect();
+
+        assertEquals(0, count.get());
+        subscriptionProvider.disconnect();
+        publishProvider.disconnect();
+    }
+
+    @Test(timeout=300000)
     public void testSendAndReceiveMQTT() throws Exception {
         addMQTTConnector();
         brokerService.start();

Modified: activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/FuseMQQTTClientProvider.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/FuseMQQTTClientProvider.java?rev=1499843&r1=1499842&r2=1499843&view=diff
==============================================================================
--- activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/FuseMQQTTClientProvider.java
(original)
+++ activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/FuseMQQTTClientProvider.java
Thu Jul  4 18:57:49 2013
@@ -72,4 +72,14 @@ class FuseMQQTTClientProvider implements
     public void setSslContext(SSLContext sslContext) {
         mqtt.setSslContext(sslContext);
     }
+
+    @Override
+    public void setWillMessage(String string) {
+        mqtt.setWillMessage(string);
+    }
+
+    @Override
+    public void setWillTopic(String topic) {
+        mqtt.setWillTopic(topic);
+    }
 }

Modified: activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTClientProvider.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTClientProvider.java?rev=1499843&r1=1499842&r2=1499843&view=diff
==============================================================================
--- activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTClientProvider.java
(original)
+++ activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTClientProvider.java
Thu Jul  4 18:57:49 2013
@@ -23,5 +23,7 @@ public interface  MQTTClientProvider {
     void subscribe(String topic,int qos) throws Exception;
     byte[] receive(int timeout) throws Exception;
     void setSslContext(javax.net.ssl.SSLContext sslContext);
+    void setWillMessage(String string);
+    void setWillTopic(String topic);
 
 }

Modified: activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java?rev=1499843&r1=1499842&r2=1499843&view=diff
==============================================================================
--- activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
(original)
+++ activemq/trunk/activemq-mqtt/src/test/java/org/apache/activemq/transport/mqtt/MQTTTest.java
Thu Jul  4 18:57:49 2013
@@ -39,6 +39,7 @@ public class MQTTTest extends AbstractMQ
         addMQTTConnector();
         brokerService.start();
         MQTT mqtt = createMQTTConnection();
+        mqtt.setClientId("foo");
         mqtt.setKeepAlive((short)2);
         final BlockingConnection connection = mqtt.blockingConnection();
         connection.connect();
@@ -59,6 +60,7 @@ public class MQTTTest extends AbstractMQ
         addMQTTConnector("transport.useInactivityMonitor=false");
         brokerService.start();
         MQTT mqtt = createMQTTConnection();
+        mqtt.setClientId("foo3");
         mqtt.setKeepAlive((short)2);
         final BlockingConnection connection = mqtt.blockingConnection();
         connection.connect();
@@ -192,6 +194,7 @@ public class MQTTTest extends AbstractMQ
         addMQTTConnector("transport.defaultKeepAlive=2000");
         brokerService.start();
         MQTT mqtt = createMQTTConnection();
+        mqtt.setClientId("foo");
         mqtt.setKeepAlive((short)0);
         final BlockingConnection connection = mqtt.blockingConnection();
         connection.connect();
@@ -232,10 +235,6 @@ public class MQTTTest extends AbstractMQ
         return "mqtt";
     }
 
-    @Override
-    protected void addMQTTConnector() throws Exception {
-        addMQTTConnector();
-    }
 
     @Override
     protected MQTTClientProvider getMQTTClientProvider() {



Mime
View raw message