* Reimplemented the Fuse integration tests into Paho client lib

* Extracted common pom properties
This commit is contained in:
selva.andre
2013-09-19 20:14:07 +02:00
parent f09fcd6cd5
commit 81b6516cac
7 changed files with 701 additions and 323 deletions
+1 -1
View File
@@ -22,7 +22,7 @@
<!-- <dependency> <!-- <dependency>
<groupId>org.apache.mina</groupId> <groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId> <artifactId>mina-core</artifactId>
<version>2.0.4</version> <version>${mina-version}</version>
</dependency>--> </dependency>-->
<!-- <dependency> <!-- <dependency>
+167 -153
View File
@@ -1,153 +1,167 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
<artifactId>moquette-parent</artifactId> <artifactId>moquette-parent</artifactId>
<groupId>org.dna.mqtt</groupId> <groupId>org.dna.mqtt</groupId>
<version>0.2</version> <version>0.2</version>
</parent> </parent>
<artifactId>moquette-broker</artifactId> <artifactId>moquette-broker</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.2</version> <version>0.2</version>
<name>Moquette - broker</name> <name>Moquette - broker</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.dna.mqtt</groupId> <groupId>org.dna.mqtt</groupId>
<artifactId>moquette-mina-parser</artifactId> <artifactId>moquette-mina-parser</artifactId>
<version>0.2</version> <version>0.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.dna.mqtt</groupId> <groupId>org.dna.mqtt</groupId>
<artifactId>moquette-netty-parser</artifactId> <artifactId>moquette-netty-parser</artifactId>
<version>0.2</version> <version>0.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.mina</groupId> <groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId> <artifactId>mina-core</artifactId>
<version>2.0.4</version> <version>${mina-version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.googlecode.disruptor</groupId> <groupId>com.googlecode.disruptor</groupId>
<artifactId>disruptor</artifactId> <artifactId>disruptor</artifactId>
<version>2.7.1</version> <version>2.7.1</version>
</dependency> </dependency>
<!-- <dependency> <!-- <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId> <artifactId>slf4j-jdk14</artifactId>
<version>1.6.4</version> <version>1.6.4</version>
</dependency>--> </dependency>-->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version> <version>1.6.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.fusesource.hawtdb</groupId> <groupId>org.fusesource.hawtdb</groupId>
<artifactId>hawtdb</artifactId> <artifactId>hawtdb</artifactId>
<version>1.6</version> <version>1.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.8.2</version> <version>4.8.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- needs extra dependencies: objenesis & hamcrest --> <!-- needs extra dependencies: objenesis & hamcrest -->
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>1.9.0</version> <version>1.9.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.fusesource.mqtt-client</groupId> <groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId> <artifactId>mqtt-client</artifactId>
<!-- <version>1.4-SNAPSHOT</version>--> <!-- <version>1.4-SNAPSHOT</version>-->
<version>1.3</version> <version>1.5</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.fusesource.hawtbuf</groupId> <groupId>org.fusesource.hawtbuf</groupId>
<artifactId>hawtbuf</artifactId> <artifactId>hawtbuf</artifactId>
<version>1.9</version> <version>1.9</version>
</dependency> </dependency>
</dependencies>
<dependency>
<build> <groupId>org.eclipse.paho</groupId>
<plugins> <artifactId>mqtt-client</artifactId>
<plugin> <version>0.4.0</version>
<groupId>org.apache.maven.plugins</groupId> </dependency>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target> </dependencies>
</configuration>
</plugin> <build>
<plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<excludes> <source>1.5</source>
<exclude>org/dna/mqtt/moquette/proto/TestUtils.java</exclude> <target>1.5</target>
<exclude>org/dna/mqtt/moquette/proto/TestUtils$*</exclude> </configuration>
</excludes> </plugin>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<plugin> <configuration>
<artifactId>maven-assembly-plugin</artifactId> <excludes>
<configuration> <exclude>org/dna/mqtt/moquette/proto/TestUtils.java</exclude>
<archive> <exclude>org/dna/mqtt/moquette/proto/TestUtils$*</exclude>
<manifest> </excludes>
<mainClass>org.dna.mqtt.moquette.server.Server</mainClass> </configuration>
</manifest> </plugin>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef> <plugin>
</descriptorRefs> <artifactId>maven-assembly-plugin</artifactId>
</configuration> <configuration>
</plugin> <archive>
<manifest>
<mainClass>org.dna.mqtt.moquette.server.Server</mainClass>
</plugins> </manifest>
</build> </archive>
<descriptorRefs>
<repositories> <descriptorRef>jar-with-dependencies</descriptorRef>
<!-- <repository> </descriptorRefs>
<id>Fusesource Releases</id> </configuration>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url> </plugin>
</repository>-->
<!-- <repository>
<id>fusesource.snapshots</id> </plugins>
<name>FuseSource Snapshot Repository</name> </build>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots> <repositories>
<enabled>true</enabled> <!-- <repository>
</snapshots> <id>Fusesource Releases</id>
<releases> <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<enabled>false</enabled> </repository>-->
</releases> <!-- <repository>
</repository>--> <id>fusesource.snapshots</id>
</repositories> <name>FuseSource Snapshot Repository</name>
</project> <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>-->
<repository>
<id>Paho Releases</id>
<url>https://repo.eclipse.org/content/repositories/paho-releases/</url>
</repository>
</repositories>
</project>
@@ -0,0 +1,21 @@
# Set root logger level to DEBUG and its only appender to A1.
#log4j.rootLogger=ERROR, A1
log4j.rootLogger=ERROR, A1
#log4j.rootLogger=WARN, A1
#log4j.logger.org.dna.mqtt.moquette.client=WARN
#log4j.logger.org.mina=WARN
#log4j.logger.org.dna.mqtt.moquette.server=DEBUG
#log4j.logger.org.dna.mqtt.moquette.messaging=DEBUG
#log4j.logger.org.dna.mqtt.moquette.proto.MQTTLoggingFilter=DEBUG
#log4j.logger.org.dna.mqtt.moquette.proto.PublishDecoder=DEBUG
log4j.logger.org.dna.mqtt=INFO
log4j.logger.org.dna.mqtt.moquette.server.ServerIntegrationFuseTest=DEBUG
log4j.logger.org.dna.mqtt.moquette.messaging.spi.impl.ProtocolProcessor=DEBUG
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c{1} %x - %m%n
@@ -5,6 +5,8 @@ import org.dna.mqtt.commons.Constants;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -17,7 +19,9 @@ import static org.junit.Assert.*;
* Test the broker using the widely used FuseSource libraries * Test the broker using the widely used FuseSource libraries
* */ * */
public class ServerIntegrationFuseTest { public class ServerIntegrationFuseTest {
private static final Logger LOG = LoggerFactory.getLogger(ServerIntegrationFuseTest.class);
Server m_server; Server m_server;
MQTT m_mqtt; MQTT m_mqtt;
BlockingConnection m_connection; BlockingConnection m_connection;
@@ -34,6 +38,20 @@ public class ServerIntegrationFuseTest {
m_mqtt = new MQTT(); m_mqtt = new MQTT();
m_mqtt.setHost("localhost", Constants.PORT); m_mqtt.setHost("localhost", Constants.PORT);
m_mqtt.setClientId("TestClient"); m_mqtt.setClientId("TestClient");
m_mqtt.setTracer(new Tracer() {
public void debug(String message, Object...args) {
StringBuilder sb = new StringBuilder("[");
for (Object o : args) {
sb.append(o.toString());
}
sb.append("]");
if (args.length > 0) {
LOG.debug(message + sb);
} else {
LOG.debug(message);
}
}
});
} }
@After @After
@@ -51,7 +69,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testSubscribe() throws Exception { public void testSubscribe() throws Exception {
System.out.println("*** testSubscribe ***"); LOG.info("*** testSubscribe ***");
m_connection = m_mqtt.blockingConnection(); m_connection = m_mqtt.blockingConnection();
m_connection.connect(); m_connection.connect();
@@ -67,7 +85,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testCleanSession_maintainClientSubscriptions() throws Exception { public void testCleanSession_maintainClientSubscriptions() throws Exception {
System.out.println("*** testCleanSession_maintainClientSubscriptions ***"); LOG.info("*** testCleanSession_maintainClientSubscriptions ***");
MQTT localMqtt = new MQTT(m_mqtt); MQTT localMqtt = new MQTT(m_mqtt);
localMqtt.setCleanSession(false); localMqtt.setCleanSession(false);
BlockingConnection connection = localMqtt.blockingConnection(); BlockingConnection connection = localMqtt.blockingConnection();
@@ -89,7 +107,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testCleanSession_maintainClientSubscriptions_againstClientDestruction() throws Exception { public void testCleanSession_maintainClientSubscriptions_againstClientDestruction() throws Exception {
System.out.println("*** testCleanSession_maintainClientSubscriptions_againstClientDestruction ***"); LOG.info("*** testCleanSession_maintainClientSubscriptions_againstClientDestruction ***");
MQTT localMqtt = new MQTT(m_mqtt); MQTT localMqtt = new MQTT(m_mqtt);
localMqtt.setCleanSession(false); localMqtt.setCleanSession(false);
BlockingConnection connection = localMqtt.blockingConnection(); BlockingConnection connection = localMqtt.blockingConnection();
@@ -117,7 +135,7 @@ public class ServerIntegrationFuseTest {
*/ */
@Test @Test
public void testCleanSession_correctlyClientSubscriptions() throws Exception { public void testCleanSession_correctlyClientSubscriptions() throws Exception {
System.out.println("*** testCleanSession_correctlyClientSubscriptions ***"); LOG.info("*** testCleanSession_correctlyClientSubscriptions ***");
MQTT localMqtt = new MQTT(m_mqtt); MQTT localMqtt = new MQTT(m_mqtt);
localMqtt.setCleanSession(false); localMqtt.setCleanSession(false);
BlockingConnection connection = localMqtt.blockingConnection(); BlockingConnection connection = localMqtt.blockingConnection();
@@ -138,7 +156,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testCleanSession_maintainClientSubscriptions_withServerRestart() throws Exception { public void testCleanSession_maintainClientSubscriptions_withServerRestart() throws Exception {
System.out.println("*** testCleanSession_maintainClientSubscriptions_withServerRestart ***"); LOG.info("*** testCleanSession_maintainClientSubscriptions_withServerRestart ***");
MQTT localMqtt = new MQTT(m_mqtt); MQTT localMqtt = new MQTT(m_mqtt);
localMqtt.setCleanSession(false); localMqtt.setCleanSession(false);
BlockingConnection connection = localMqtt.blockingConnection(); BlockingConnection connection = localMqtt.blockingConnection();
@@ -160,12 +178,13 @@ public class ServerIntegrationFuseTest {
//Verify that the message is published due to prevoius subscription //Verify that the message is published due to prevoius subscription
Message msg = anotherconnection.receive(1, TimeUnit.SECONDS); Message msg = anotherconnection.receive(1, TimeUnit.SECONDS);
msg.ack();
assertEquals("/topic", msg.getTopic()); assertEquals("/topic", msg.getTopic());
} }
@Test @Test
public void testRetain_maintainMessage_againstClientDestruction() throws Exception { public void testRetain_maintainMessage_againstClientDestruction() throws Exception {
System.out.println("*** testRetain_maintainMessage_againstClientDestruction ***"); LOG.info("*** testRetain_maintainMessage_againstClientDestruction ***");
m_connection = m_mqtt.blockingConnection(); m_connection = m_mqtt.blockingConnection();
m_connection.connect(); m_connection.connect();
m_connection.publish("/topic", "Test my payload".getBytes(), QoS.AT_MOST_ONCE, true); m_connection.publish("/topic", "Test my payload".getBytes(), QoS.AT_MOST_ONCE, true);
@@ -182,7 +201,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testUnsubscribe_do_not_notify_anymore_same_session() throws Exception { public void testUnsubscribe_do_not_notify_anymore_same_session() throws Exception {
System.out.println("*** testUnsubscribe_do_not_notify_anymore_same_session ***"); LOG.info("*** testUnsubscribe_do_not_notify_anymore_same_session ***");
m_connection = m_mqtt.blockingConnection(); m_connection = m_mqtt.blockingConnection();
m_connection.connect(); m_connection.connect();
m_connection.subscribe(new Topic[] {new Topic("/topic", QoS.AT_MOST_ONCE)}); m_connection.subscribe(new Topic[] {new Topic("/topic", QoS.AT_MOST_ONCE)});
@@ -202,7 +221,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testUnsubscribe_do_not_notify_anymore_new_session() throws Exception { public void testUnsubscribe_do_not_notify_anymore_new_session() throws Exception {
System.out.println("*** testUnsubscribe_do_not_notify_anymore_new_session ***"); LOG.info("*** testUnsubscribe_do_not_notify_anymore_new_session ***");
m_connection = m_mqtt.blockingConnection(); m_connection = m_mqtt.blockingConnection();
m_connection.connect(); m_connection.connect();
m_connection.subscribe(new Topic[] {new Topic("/topic", QoS.AT_MOST_ONCE)}); m_connection.subscribe(new Topic[] {new Topic("/topic", QoS.AT_MOST_ONCE)});
@@ -225,7 +244,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testPublishWithQoS1() throws Exception { public void testPublishWithQoS1() throws Exception {
System.out.println("*** testPublishWithQoS1 ***"); LOG.info("*** testPublishWithQoS1 ***");
m_connection = m_mqtt.blockingConnection(); m_connection = m_mqtt.blockingConnection();
m_connection.connect(); m_connection.connect();
@@ -245,7 +264,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testPublishWithQoS1_notCleanSession() throws Exception { public void testPublishWithQoS1_notCleanSession() throws Exception {
System.out.println("*** testPublishWithQoS1_notCleanSession ***"); LOG.info("*** testPublishWithQoS1_notCleanSession ***");
MQTT mqtt = new MQTT(m_mqtt); MQTT mqtt = new MQTT(m_mqtt);
mqtt.setCleanSession(false); mqtt.setCleanSession(false);
m_connection = mqtt.blockingConnection(); m_connection = mqtt.blockingConnection();
@@ -285,7 +304,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testPublishWithQoS2() throws Exception { public void testPublishWithQoS2() throws Exception {
System.out.println("*** testPublishWithQoS2 ***"); LOG.info("*** testPublishWithQoS2 ***");
m_mqtt.setClientId("TestClient"); m_mqtt.setClientId("TestClient");
m_connection = m_mqtt.blockingConnection(); m_connection = m_mqtt.blockingConnection();
m_connection.connect(); m_connection.connect();
@@ -306,7 +325,7 @@ public class ServerIntegrationFuseTest {
@Test @Test
public void testPublishReceiveWithQoS2() throws Exception { public void testPublishReceiveWithQoS2() throws Exception {
System.out.println("*** testPublishReceiveWithQoS2 ***"); LOG.info("*** testPublishReceiveWithQoS2 ***");
m_mqtt.setCleanSession(false); m_mqtt.setCleanSession(false);
m_connection = m_mqtt.blockingConnection(); m_connection = m_mqtt.blockingConnection();
m_connection.connect(); m_connection.connect();
@@ -0,0 +1,323 @@
package org.dna.mqtt.moquette.server;
import org.eclipse.paho.client.mqttv3.*;
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
public class ServerIntegrationPahoTest {
static class TestCallback implements MqttCallback {
private MqttMessage m_message;
private String m_topic;
private CountDownLatch m_latch = new CountDownLatch(1);
public MqttMessage getMessage() {
try {
m_latch.await(1, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return m_message;
}
public String getTopic() {
try {
m_latch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return m_topic;
}
void reinit() {
m_latch = new CountDownLatch(1);
m_message = null;
m_topic = null;
}
public void connectionLost(Throwable cause) {
//To change body of implemented methods use File | Settings | File Templates.
}
public void messageArrived(String topic, MqttMessage message) throws Exception {
m_message = message;
m_topic = topic;
m_latch.countDown();
}
public void deliveryComplete(IMqttDeliveryToken token) {
//To change body of implemented methods use File | Settings | File Templates.
}
}
private static final Logger LOG = LoggerFactory.getLogger(ServerIntegrationPahoTest.class);
static MqttClientPersistence s_dataStore;
Server m_server;
IMqttClient m_client;
TestCallback m_callback;
@BeforeClass
public static void beforeTests() {
String tmpDir = System.getProperty("java.io.tmpdir");
s_dataStore = new MqttDefaultFilePersistence(tmpDir);
}
protected void startServer() throws IOException {
m_server = new Server();
m_server.startServer();
}
@Before
public void setUp() throws Exception {
startServer();
m_client = new MqttClient("tcp://localhost:1883", "TestClient", s_dataStore);
m_callback = new TestCallback();
m_client.setCallback(m_callback);
}
@After
public void tearDown() throws Exception {
if (m_client.isConnected()) {
m_client.disconnect();
}
m_server.stopServer();
File dbFile = new File(Server.STORAGE_FILE_PATH);
if (dbFile.exists()) {
dbFile.delete();
}
}
@Test
public void testSubscribe() throws Exception {
LOG.info("*** testSubscribe ***");
m_client.connect();
m_client.subscribe("/topic", 0);
MqttMessage message = new MqttMessage("Hello world!!".getBytes());
message.setQos(0);
message.setRetained(false);
m_client.publish("/topic", message);
assertEquals("/topic", m_callback.getTopic());
}
@Test
public void testCleanSession_maintainClientSubscriptions() throws Exception {
LOG.info("*** testCleanSession_maintainClientSubscriptions ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 0);
m_client.disconnect();
//reconnect and publish
MqttClient anotherClient = new MqttClient("tcp://localhost:1883", "TestClient", s_dataStore);
m_callback = new TestCallback();
anotherClient.setCallback(m_callback);
anotherClient.connect(options);
anotherClient.publish("/topic", "Test my payload".getBytes(), 0, false);
assertEquals("/topic", m_callback.getTopic());
}
@Test
public void testCleanSession_maintainClientSubscriptions_againstClientDestruction() throws Exception {
LOG.info("*** testCleanSession_maintainClientSubscriptions_againstClientDestruction ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 0);
m_client.disconnect();
//reconnect and publish
m_client.connect(options);
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
assertEquals("/topic", m_callback.getTopic());
}
/**
* Check that after a client has connected with clean session false, subscribed
* to some topic and exited, if it reconnect with clean session true, the m_server
* correctly cleanup every previous subscription
*/
@Test
public void testCleanSession_correctlyClientSubscriptions() throws Exception {
LOG.info("*** testCleanSession_correctlyClientSubscriptions ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 0);
m_client.disconnect();
//reconnect and publish
m_client.connect();
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
assertNull(m_callback.getMessage());
}
@Test
public void testCleanSession_maintainClientSubscriptions_withServerRestart() throws Exception {
LOG.info("*** testCleanSession_maintainClientSubscriptions_withServerRestart ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 0);
m_client.disconnect();
m_server.stopServer();
m_server.startServer();
//reconnect and publish
m_client.connect(options);
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
assertEquals("/topic", m_callback.getTopic());
}
@Test
public void testRetain_maintainMessage_againstClientDestruction() throws Exception {
LOG.info("*** testRetain_maintainMessage_againstClientDestruction ***");
m_client.connect();
m_client.publish("/topic", "Test my payload".getBytes(), 0, true);
m_client.disconnect();
//reconnect and publish
m_client.connect();
m_client.subscribe("/topic", 0);
assertEquals("/topic", m_callback.getTopic());
}
@Test
public void testUnsubscribe_do_not_notify_anymore_same_session() throws Exception {
LOG.info("*** testUnsubscribe_do_not_notify_anymore_same_session ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 0);
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
//m_client.disconnect();
assertEquals("/topic", m_callback.getTopic());
m_client.unsubscribe("/topic");
m_callback.reinit();
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
assertNull(m_callback.getMessage());
}
@Test
public void testUnsubscribe_do_not_notify_anymore_new_session() throws Exception {
LOG.info("*** testUnsubscribe_do_not_notify_anymore_new_session ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 0);
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
//m_client.disconnect();
assertEquals("/topic", m_callback.getTopic());
m_client.unsubscribe("/topic");
m_client.disconnect();
m_callback.reinit();
m_client.connect(options);
m_client.publish("/topic", "Test my payload".getBytes(), 0, false);
assertNull(m_callback.getMessage());
}
@Test
public void testPublishWithQoS1() throws Exception {
LOG.info("*** testPublishWithQoS1 ***");
m_client.connect();
m_client.subscribe("/topic", 1);
m_client.publish("/topic", "Hello MQTT".getBytes(), 1, false);
m_client.disconnect();
//reconnect and publish
assertEquals("Hello MQTT", m_callback.getMessage().toString());
assertEquals(1, m_callback.getMessage().getQos());
}
@Test
public void testPublishWithQoS1_notCleanSession() throws Exception {
LOG.info("*** testPublishWithQoS1_notCleanSession ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 1);
m_client.disconnect();
//publish a QoS 1 message another client publish a message on the topic
publishFromAnotherClient("/topic", "Hello MQTT".getBytes(), 1);
m_client.connect(options);
assertEquals("Hello MQTT", m_callback.getMessage().toString());
}
private void publishFromAnotherClient(String topic, byte[] payload, int qos) throws Exception {
IMqttClient anotherClient = new MqttClient("tcp://localhost:1883", "TestClientPUB", s_dataStore);
anotherClient.connect();
anotherClient.publish(topic, payload, qos, false);
anotherClient.disconnect();
}
@Test
public void testPublishWithQoS2() throws Exception {
LOG.info("*** testPublishWithQoS2 ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 2);
m_client.disconnect();
//publish a QoS 1 message another client publish a message on the topic
publishFromAnotherClient("/topic", "Hello MQTT".getBytes(), 2);
m_client.connect(options);
assertEquals("Hello MQTT", m_callback.getMessage().toString());
assertEquals(2, m_callback.getMessage().getQos());
}
@Test
public void testPublishReceiveWithQoS2() throws Exception {
LOG.info("*** testPublishReceiveWithQoS2 ***");
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
m_client.connect(options);
m_client.subscribe("/topic", 2);
m_client.disconnect();
//publish a QoS 1 message another client publish a message on the topic
publishFromAnotherClient("/topic", "Hello MQTT".getBytes(), 2);
m_client.connect(options);
assertEquals("Hello MQTT", m_callback.getMessage().toString());
}
}
+130 -130
View File
@@ -1,130 +1,130 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
<artifactId>moquette-parent</artifactId> <artifactId>moquette-parent</artifactId>
<groupId>org.dna.mqtt</groupId> <groupId>org.dna.mqtt</groupId>
<version>0.2</version> <version>0.2</version>
</parent> </parent>
<artifactId>moquette-mina-parser</artifactId> <artifactId>moquette-mina-parser</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.2</version> <version>0.2</version>
<name>Moquette - MINA Parser</name> <name>Moquette - MINA Parser</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.mina</groupId> <groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId> <artifactId>mina-core</artifactId>
<version>2.0.4</version> <version>${mina-version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.dna.mqtt</groupId> <groupId>org.dna.mqtt</groupId>
<artifactId>moquette-parser-commons</artifactId> <artifactId>moquette-parser-commons</artifactId>
<version>0.2</version> <version>0.2</version>
</dependency> </dependency>
<!--dependency> <!--dependency>
<groupId>com.googlecode.disruptor</groupId> <groupId>com.googlecode.disruptor</groupId>
<artifactId>disruptor</artifactId> <artifactId>disruptor</artifactId>
<version>2.7.1</version> <version>2.7.1</version>
</dependency --> </dependency -->
<!-- <dependency> <!-- <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId> <artifactId>slf4j-jdk14</artifactId>
<version>1.6.4</version> <version>1.6.4</version>
</dependency>--> </dependency>-->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version> <version>1.6.4</version>
</dependency> </dependency>
<!--dependency> <!--dependency>
<groupId>org.fusesource.hawtdb</groupId> <groupId>org.fusesource.hawtdb</groupId>
<artifactId>hawtdb</artifactId> <artifactId>hawtdb</artifactId>
<version>1.6</version> <version>1.6</version>
</dependency--> </dependency-->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.8.2</version> <version>4.8.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- needs extra dependencies: objenesis & hamcrest --> <!-- needs extra dependencies: objenesis & hamcrest -->
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>1.9.0</version> <version>1.9.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!--dependency> <!--dependency>
<groupId>org.fusesource.mqtt-client</groupId> <groupId>org.fusesource.mqtt-client</groupId>
<artifactId>mqtt-client</artifactId> <artifactId>mqtt-client</artifactId>
<version>1.3</version> <version>1.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.fusesource.hawtbuf</groupId> <groupId>org.fusesource.hawtbuf</groupId>
<artifactId>hawtbuf</artifactId> <artifactId>hawtbuf</artifactId>
<version>1.9</version> <version>1.9</version>
</dependency--> </dependency-->
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>1.5</source> <source>1.5</source>
<target>1.5</target> <target>1.5</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<excludes> <excludes>
<exclude>org/dna/mqtt/moquette/proto/TestUtils.java</exclude> <exclude>org/dna/mqtt/moquette/proto/TestUtils.java</exclude>
<exclude>org/dna/mqtt/moquette/proto/TestUtils$*</exclude> <exclude>org/dna/mqtt/moquette/proto/TestUtils$*</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<repositories> <repositories>
<!-- <repository> <!-- <repository>
<id>Fusesource Releases</id> <id>Fusesource Releases</id>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url> <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
</repository>--> </repository>-->
<!-- <repository> <!-- <repository>
<id>fusesource.snapshots</id> <id>fusesource.snapshots</id>
<name>FuseSource Snapshot Repository</name> <name>FuseSource Snapshot Repository</name>
<url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url> <url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
</snapshots> </snapshots>
<releases> <releases>
<enabled>false</enabled> <enabled>false</enabled>
</releases> </releases>
</repository>--> </repository>-->
</repositories> </repositories>
</project> </project>
+27 -26
View File
@@ -1,26 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties> <properties>
<moquette.version>0.2</moquette.version> <moquette.version>0.2</moquette.version>
</properties> <mina-version>2.0.7</mina-version>
</properties>
<groupId>org.dna.mqtt</groupId>
<artifactId>moquette-parent</artifactId> <groupId>org.dna.mqtt</groupId>
<artifactId>moquette-parent</artifactId>
<packaging>pom</packaging>
<version>0.2</version> <packaging>pom</packaging>
<name>Moquette MQTT library</name> <version>0.2</version>
<url>http://code.google.com/p/moquette-mqtt/</url> <name>Moquette MQTT library</name>
<url>http://code.google.com/p/moquette-mqtt/</url>
<modules>
<module>parser_commons</module> <modules>
<module>parser</module> <module>parser_commons</module>
<module>netty_parser</module> <module>parser</module>
<module>broker</module> <module>netty_parser</module>
<module>benchmarking</module> <module>broker</module>
</modules> <module>benchmarking</module>
</modules>
</project>
</project>