Minor, moved tests from ServerIntegrationFuseTest to ServerIntegrationPahoTest to limit the usage of fusesource mqtt client

This commit is contained in:
andsel
2016-03-06 19:50:47 +01:00
parent 7bb02d9a2a
commit efbfab7914
4 changed files with 283 additions and 207 deletions
@@ -71,22 +71,7 @@ public class ServerIntegrationFuseTest {
m_server.stopServer();
IntegrationUtils.cleanPersistenceFile(m_config);
}
@Test
public void connectWithCredentials() throws Exception {
LOG.info("*** connectWithCredetials ***");
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
mqtt.setClientId("Publisher");
mqtt.setUserName("testuser");
mqtt.setPassword("passwd");
m_publisher = mqtt.blockingConnection();
m_publisher.connect();
assertTrue(true);
}
@Test
public void checkWillTestamentIsPublishedOnConnectionKill_noRetain() throws Exception {
LOG.info("checkWillTestamentIsPublishedOnConnectionKill");
@@ -121,163 +106,4 @@ public class ServerIntegrationFuseTest {
msg.ack();
assertEquals(willTestamentMsg, new String(msg.getPayload()));
}
@Test
public void checkReplayofStoredPublishResumeAfter_a_disconnect_cleanSessionFalseQoS1() throws Exception {
LOG.info("*** checkReplayofStoredPublishResumeAfter_a_disconnect_cleanSessionFalseQoS1 ***");
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
mqtt.setClientId("Publisher");
m_publisher = mqtt.blockingConnection();
m_publisher.connect();
m_mqtt.setHost("localhost", 1883);
m_mqtt.setCleanSession(false);
m_mqtt.setClientId("Subscriber");
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
Topic[] topics = new Topic[]{new Topic("/topic", QoS.AT_LEAST_ONCE)};
m_subscriber.subscribe(topics);
//force the publisher to send
m_publisher.publish("/topic", "Hello world MQTT!!-1".getBytes(), QoS.AT_LEAST_ONCE, false);
//read the first message and drop the connection
Message msg = m_subscriber.receive();
msg.ack();
assertEquals("Hello world MQTT!!-1", new String(msg.getPayload()));
m_subscriber.disconnect();
m_publisher.publish("/topic", "Hello world MQTT!!-2".getBytes(), QoS.AT_LEAST_ONCE, false);
m_publisher.publish("/topic", "Hello world MQTT!!-3".getBytes(), QoS.AT_LEAST_ONCE, false);
//reconnect and expect to receive the hello 2 message
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
//topics = new Topic[]{new Topic("/topic", QoS.AT_LEAST_ONCE)};
//m_subscriber.subscribe(topics);
msg = m_subscriber.receive();
msg.ack();
assertEquals("Hello world MQTT!!-2", new String(msg.getPayload()));
msg = m_subscriber.receive();
assertEquals("Hello world MQTT!!-3", new String(msg.getPayload()));
msg.ack();
m_subscriber.disconnect();
}
@Test
public void checkReplayStoredPublish_forNoCleanSession_qos1() throws Exception {
LOG.info("*** checkReplayStoredPublish_forNoCleanSession_qos1 ***");
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
mqtt.setClientId("Publisher");
m_publisher = mqtt.blockingConnection();
m_publisher.connect();
m_mqtt.setHost("localhost", 1883);
m_mqtt.setCleanSession(false);
m_mqtt.setClientId("Subscriber");
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
Topic[] topics = new Topic[]{new Topic("/topic", QoS.AT_LEAST_ONCE)};
m_subscriber.subscribe(topics);
m_subscriber.disconnect();
//force the publisher to send
m_publisher.publish("/topic", "Hello world MQTT!!-1".getBytes(), QoS.AT_LEAST_ONCE, false);
//reconnect and expect to receive the hello 2 message
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
topics = new Topic[]{new Topic("/topic", QoS.AT_LEAST_ONCE)};
m_subscriber.subscribe(topics);
Message msg = m_subscriber.receive(1, TimeUnit.SECONDS);
assertNotNull(msg);
msg.ack();
assertEquals("Hello world MQTT!!-1", new String(msg.getPayload()));
// m_subscriber.disconnect();
}
/**
* subscriber connect and subscribe on "topic"
* subscriber disconnects
* publisher connects and send two message "hello1" "hello2" to "topic"
* subscriber connects again and receive "hello1" "hello2"
*/
@Test
public void checkQoS2SubscriberDisconnectReceivePersistedPublishes() throws Exception {
LOG.info("*** checkQoS2SubscriberDisconnectReceivePersistedPublishes ***");
m_mqtt.setHost("localhost", 1883);
m_mqtt.setCleanSession(false);
m_mqtt.setClientId("Subscriber");
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
Topic[] topics = new Topic[]{new Topic("topic", QoS.EXACTLY_ONCE)};
m_subscriber.subscribe(topics);
m_subscriber.disconnect();
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
mqtt.setClientId("Publisher");
m_publisher = mqtt.blockingConnection();
m_publisher.connect();
m_publisher.publish("topic", "Hello1".getBytes(), QoS.EXACTLY_ONCE, true);
m_publisher.publish("topic", "Hello2".getBytes(), QoS.EXACTLY_ONCE, true);
m_publisher.disconnect();
//subscriber reconnects
m_mqtt = new MQTT();
m_mqtt.setHost("localhost", 1883);
m_mqtt.setClientId("Subscriber");
m_mqtt.setCleanSession(false);
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
//subscriber should receive the 2 messages missed
Message msg = m_subscriber.receive(1, TimeUnit.SECONDS);
assertNotNull(msg);
msg.ack();
assertEquals("Hello1", new String(msg.getPayload()));
msg = m_subscriber.receive(1, TimeUnit.SECONDS);
assertNotNull(msg);
msg.ack();
assertEquals("Hello2", new String(msg.getPayload()));
}
/**
* subscriber connect and subscribe on "a/b" QoS 1 and "a/+" QoS 2
* publisher connects and send a message "hello" on "a/b"
* subscriber must receive only a single message not twice
*/
@Test
public void checkSinglePublishOnOverlappingSubscriptions() throws Exception {
LOG.info("*** checkSinglePublishOnOverlappingSubscriptions ***");
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
mqtt.setClientId("Publisher");
m_publisher = mqtt.blockingConnection();
m_publisher.connect();
m_mqtt.setHost("localhost", 1883);
m_mqtt.setCleanSession(false);
m_mqtt.setClientId("Subscriber");
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
Topic[] topics = new Topic[]{
new Topic("a/+", QoS.EXACTLY_ONCE),
new Topic("a/b", QoS.AT_LEAST_ONCE)};
m_subscriber.subscribe(topics);
//force the publisher to send
m_publisher.publish("a/b", "Hello world MQTT!!".getBytes(), QoS.AT_LEAST_ONCE, false);
//reconnect and expect to receive the hello 2 message
Message msg = m_subscriber.receive(1, TimeUnit.SECONDS);
assertNotNull(msg);
msg.ack();
assertEquals("Hello world MQTT!!", new String(msg.getPayload()));
//try to listen a second publish
msg = m_subscriber.receive(1, TimeUnit.SECONDS);
assertNull(msg);
}
}