2014-06-11 23:40:19 +02:00
|
|
|
/*
|
2017-03-19 22:01:23 +01:00
|
|
|
* Copyright (c) 2012-2017 The original author or authors
|
2014-06-11 23:40:19 +02:00
|
|
|
* ------------------------------------------------------
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
|
* and Apache License v2.0 which accompanies this distribution.
|
|
|
|
|
*
|
|
|
|
|
* The Eclipse Public License is available at
|
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
*
|
|
|
|
|
* The Apache License v2.0 is available at
|
|
|
|
|
* http://www.opensource.org/licenses/apache2.0.php
|
|
|
|
|
*
|
|
|
|
|
* You may elect to redistribute this code under either of these licenses.
|
|
|
|
|
*/
|
2017-02-01 16:15:18 +01:00
|
|
|
|
2015-11-20 20:54:27 +01:00
|
|
|
package io.moquette.server;
|
2013-09-19 20:14:07 +02:00
|
|
|
|
2015-11-20 20:54:27 +01:00
|
|
|
import io.moquette.server.config.IConfig;
|
|
|
|
|
import io.moquette.server.config.MemoryConfig;
|
2013-09-19 20:14:07 +02:00
|
|
|
import org.eclipse.paho.client.mqttv3.*;
|
|
|
|
|
import org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence;
|
2017-01-28 10:06:30 +01:00
|
|
|
import org.junit.*;
|
2013-09-19 20:14:07 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
2015-03-11 10:07:27 -04:00
|
|
|
import java.util.Properties;
|
2018-04-25 19:39:12 +02:00
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
2013-09-19 20:14:07 +02:00
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
public class ServerIntegrationPahoTest {
|
|
|
|
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(ServerIntegrationPahoTest.class);
|
|
|
|
|
|
|
|
|
|
static MqttClientPersistence s_dataStore;
|
2013-11-25 18:53:50 +01:00
|
|
|
static MqttClientPersistence s_pubDataStore;
|
2017-02-01 16:15:18 +01:00
|
|
|
|
2013-09-19 20:14:07 +02:00
|
|
|
Server m_server;
|
|
|
|
|
IMqttClient m_client;
|
2016-02-23 23:29:45 +01:00
|
|
|
IMqttClient m_publisher;
|
2016-03-06 19:03:01 +01:00
|
|
|
MessageCollector m_messagesCollector;
|
2015-08-22 15:35:11 +02:00
|
|
|
IConfig m_config;
|
2013-09-19 20:14:07 +02:00
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeTests() {
|
|
|
|
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
|
|
|
|
s_dataStore = new MqttDefaultFilePersistence(tmpDir);
|
2013-11-25 18:53:50 +01:00
|
|
|
s_pubDataStore = new MqttDefaultFilePersistence(tmpDir + File.separator + "publisher");
|
2013-09-19 20:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void startServer() throws IOException {
|
|
|
|
|
m_server = new Server();
|
2016-05-18 00:09:40 +02:00
|
|
|
final Properties configProps = IntegrationUtils.prepareTestProperties();
|
2015-08-22 15:35:11 +02:00
|
|
|
m_config = new MemoryConfig(configProps);
|
|
|
|
|
m_server.startServer(m_config);
|
2013-09-19 20:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
|
startServer();
|
|
|
|
|
|
|
|
|
|
m_client = new MqttClient("tcp://localhost:1883", "TestClient", s_dataStore);
|
2016-03-06 19:03:01 +01:00
|
|
|
m_messagesCollector = new MessageCollector();
|
|
|
|
|
m_client.setCallback(m_messagesCollector);
|
2016-02-23 23:29:45 +01:00
|
|
|
|
|
|
|
|
m_publisher = new MqttClient("tcp://localhost:1883", "Publisher", s_pubDataStore);
|
2013-09-19 20:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
public void tearDown() throws Exception {
|
2016-02-23 23:29:45 +01:00
|
|
|
if (m_client != null && m_client.isConnected()) {
|
2013-09-19 20:14:07 +02:00
|
|
|
m_client.disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 23:29:45 +01:00
|
|
|
if (m_publisher != null && m_publisher.isConnected()) {
|
|
|
|
|
m_publisher.disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-07 07:51:44 +02:00
|
|
|
stopServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stopServer() {
|
2013-09-19 20:14:07 +02:00
|
|
|
m_server.stopServer();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-25 16:05:45 +01:00
|
|
|
@Ignore("This test hasn't any meaning using in memory storage service")
|
2013-09-19 20:14:07 +02:00
|
|
|
@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();
|
|
|
|
|
|
2016-05-18 00:09:40 +02:00
|
|
|
m_server.startServer(IntegrationUtils.prepareTestProperties());
|
2013-09-19 20:14:07 +02:00
|
|
|
|
2017-02-01 16:15:18 +01:00
|
|
|
// reconnect and publish
|
2013-09-19 20:14:07 +02:00
|
|
|
m_client.connect(options);
|
2018-04-25 19:39:12 +02:00
|
|
|
m_client.publish("/topic", "Test my payload".getBytes(UTF_8), 0, false);
|
2013-09-19 20:14:07 +02:00
|
|
|
|
2016-03-06 19:03:01 +01:00
|
|
|
assertEquals("/topic", m_messagesCollector.getTopic());
|
2013-09-19 20:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-28 19:53:22 +02:00
|
|
|
/**
|
2017-02-01 16:15:18 +01:00
|
|
|
* subscriber A connect and subscribe on "a/b" QoS 1 subscriber B connect and subscribe on "a/+"
|
|
|
|
|
* BUT with QoS 2 publisher connects and send a message "hello" on "a/b" subscriber A must
|
|
|
|
|
* receive a notification with QoS1 subscriber B must receive a notification with QoS2
|
2015-06-28 19:53:22 +02:00
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void checkSubscribersGetCorrectQosNotifications() throws Exception {
|
|
|
|
|
LOG.info("*** checkSubscribersGetCorrectQosNotifications ***");
|
|
|
|
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
|
|
|
|
|
|
|
|
|
MqttClientPersistence dsSubscriberA = new MqttDefaultFilePersistence(tmpDir + File.separator + "subscriberA");
|
|
|
|
|
|
|
|
|
|
MqttClient subscriberA = new MqttClient("tcp://localhost:1883", "SubscriberA", dsSubscriberA);
|
2016-03-06 19:03:01 +01:00
|
|
|
MessageCollector cbSubscriberA = new MessageCollector();
|
2015-06-28 19:53:22 +02:00
|
|
|
subscriberA.setCallback(cbSubscriberA);
|
|
|
|
|
subscriberA.connect();
|
|
|
|
|
subscriberA.subscribe("a/b", 1);
|
|
|
|
|
|
|
|
|
|
MqttClientPersistence dsSubscriberB = new MqttDefaultFilePersistence(tmpDir + File.separator + "subscriberB");
|
|
|
|
|
|
|
|
|
|
MqttClient subscriberB = new MqttClient("tcp://localhost:1883", "SubscriberB", dsSubscriberB);
|
2016-03-06 19:03:01 +01:00
|
|
|
MessageCollector cbSubscriberB = new MessageCollector();
|
2015-06-28 19:53:22 +02:00
|
|
|
subscriberB.setCallback(cbSubscriberB);
|
|
|
|
|
subscriberB.connect();
|
|
|
|
|
subscriberB.subscribe("a/+", 2);
|
|
|
|
|
|
|
|
|
|
m_client.connect();
|
2018-04-25 19:39:12 +02:00
|
|
|
m_client.publish("a/b", "Hello world MQTT!!".getBytes(UTF_8), 2, false);
|
2015-06-28 19:53:22 +02:00
|
|
|
|
2017-01-28 10:06:30 +01:00
|
|
|
MqttMessage messageOnA = cbSubscriberA.waitMessage(1);
|
2018-04-25 19:39:12 +02:00
|
|
|
assertEquals("Hello world MQTT!!", new String(messageOnA.getPayload(), UTF_8));
|
2015-06-28 19:53:22 +02:00
|
|
|
assertEquals(1, messageOnA.getQos());
|
|
|
|
|
subscriberA.disconnect();
|
|
|
|
|
|
2017-01-28 10:06:30 +01:00
|
|
|
MqttMessage messageOnB = cbSubscriberB.waitMessage(1);
|
2018-04-25 19:39:12 +02:00
|
|
|
assertEquals("Hello world MQTT!!", new String(messageOnB.getPayload(), UTF_8));
|
2015-06-28 19:53:22 +02:00
|
|
|
assertEquals(2, messageOnB.getQos());
|
|
|
|
|
subscriberB.disconnect();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-19 18:01:54 +01:00
|
|
|
@Test
|
|
|
|
|
public void testSubcriptionDoesntStayActiveAfterARestart() throws Exception {
|
|
|
|
|
LOG.info("*** testSubcriptionDoesntStayActiveAfterARestart ***");
|
|
|
|
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
2017-02-01 16:15:18 +01:00
|
|
|
// clientForSubscribe1 connect and subscribe to /topic QoS2
|
|
|
|
|
MqttClientPersistence dsSubscriberA = new MqttDefaultFilePersistence(
|
|
|
|
|
tmpDir + File.separator + "clientForSubscribe1");
|
2015-12-19 18:01:54 +01:00
|
|
|
|
|
|
|
|
MqttClient clientForSubscribe1 = new MqttClient("tcp://localhost:1883", "clientForSubscribe1", dsSubscriberA);
|
2016-03-06 19:03:01 +01:00
|
|
|
MessageCollector cbSubscriber1 = new MessageCollector();
|
2015-12-19 18:01:54 +01:00
|
|
|
clientForSubscribe1.setCallback(cbSubscriber1);
|
|
|
|
|
clientForSubscribe1.connect();
|
|
|
|
|
clientForSubscribe1.subscribe("topic", 0);
|
|
|
|
|
|
2017-02-01 16:15:18 +01:00
|
|
|
// server stop
|
2015-12-19 18:01:54 +01:00
|
|
|
m_server.stopServer();
|
|
|
|
|
System.out.println("\n\n SEVER REBOOTING \n\n");
|
2017-02-01 16:15:18 +01:00
|
|
|
// server start
|
2015-12-19 18:01:54 +01:00
|
|
|
startServer();
|
|
|
|
|
|
2017-02-01 16:15:18 +01:00
|
|
|
// clientForSubscribe2 connect and subscribe to /topic QoS2
|
|
|
|
|
MqttClientPersistence dsSubscriberB = new MqttDefaultFilePersistence(
|
|
|
|
|
tmpDir + File.separator + "clientForSubscribe2");
|
2015-12-19 18:01:54 +01:00
|
|
|
MqttClient clientForSubscribe2 = new MqttClient("tcp://localhost:1883", "clientForSubscribe2", dsSubscriberB);
|
2016-03-06 19:03:01 +01:00
|
|
|
MessageCollector cbSubscriber2 = new MessageCollector();
|
2015-12-19 18:01:54 +01:00
|
|
|
clientForSubscribe2.setCallback(cbSubscriber2);
|
|
|
|
|
clientForSubscribe2.connect();
|
|
|
|
|
clientForSubscribe2.subscribe("topic", 0);
|
|
|
|
|
|
2017-02-01 16:15:18 +01:00
|
|
|
// clientForPublish publish on /topic with QoS2 a message
|
|
|
|
|
MqttClientPersistence dsSubscriberPUB = new MqttDefaultFilePersistence(
|
|
|
|
|
tmpDir + File.separator + "clientForPublish");
|
2015-12-19 18:01:54 +01:00
|
|
|
MqttClient clientForPublish = new MqttClient("tcp://localhost:1883", "clientForPublish", dsSubscriberPUB);
|
|
|
|
|
clientForPublish.connect();
|
2018-04-25 19:39:12 +02:00
|
|
|
clientForPublish.publish("topic", "Hello".getBytes(UTF_8), 2, true);
|
2015-12-19 18:01:54 +01:00
|
|
|
|
2017-02-01 16:15:18 +01:00
|
|
|
// verify clientForSubscribe1 doesn't receive a notification but clientForSubscribe2 yes
|
2018-04-25 19:39:12 +02:00
|
|
|
LOG.info("Before waiting to receive 1 sec from {}", clientForSubscribe1.getClientId());
|
2015-12-19 18:01:54 +01:00
|
|
|
assertFalse(clientForSubscribe1.isConnected());
|
|
|
|
|
assertTrue(clientForSubscribe2.isConnected());
|
2018-04-25 19:39:12 +02:00
|
|
|
LOG.info("Waiting to receive 1 sec from {}", clientForSubscribe2.getClientId());
|
2017-01-28 10:06:30 +01:00
|
|
|
MqttMessage messageOnB = cbSubscriber2.waitMessage(1);
|
2018-04-25 19:39:12 +02:00
|
|
|
assertEquals("Hello", new String(messageOnB.getPayload(), UTF_8));
|
2015-12-19 18:01:54 +01:00
|
|
|
}
|
|
|
|
|
|
2017-06-29 09:23:23 +02:00
|
|
|
// @Test
|
|
|
|
|
// public void testForceClientDisconnection_issue116() throws Exception {
|
|
|
|
|
// LOG.info("*** testForceClientDisconnection_issue118 ***");
|
|
|
|
|
// MessageCollector cbSubscriber1 = new MessageCollector();
|
|
|
|
|
// MqttClient clientXA = createClient("subscriber", "X", cbSubscriber1);
|
|
|
|
|
// LOG.info("Connected 'subscriber' first time");
|
|
|
|
|
// clientXA.subscribe("topic", 0);
|
|
|
|
|
// LOG.info("Subscribed 'topic' from 'subscriber' first time");
|
|
|
|
|
//
|
|
|
|
|
// MqttClient clientXB = createClient("publisher", "X");
|
|
|
|
|
// LOG.info("Connected 'publisher' first time");
|
|
|
|
|
// clientXB.publish("topic", "Hello".getBytes(), 2, false);
|
|
|
|
|
// LOG.info("Published on 'topic' from 'publisher' first time");
|
|
|
|
|
//
|
|
|
|
|
// LOG.info("Creating second new 'subscriber'");
|
|
|
|
|
// MessageCollector cbSubscriber2 = new MessageCollector();
|
|
|
|
|
// MqttClient clientYA = createClient("subscriber", "Y", cbSubscriber2);
|
|
|
|
|
// LOG.info("Connected 'subscriber' second time");
|
|
|
|
|
// clientYA.subscribe("topic", 0);
|
|
|
|
|
//
|
|
|
|
|
// MqttClient clientYB = createClient("publisher", "Y");
|
|
|
|
|
// clientYB.publish("topic", "Hello 2".getBytes(), 2, true);
|
|
|
|
|
//
|
|
|
|
|
// // Verify that the second subscriber client get notified and not the first.
|
|
|
|
|
// assertTrue(cbSubscriber1.connectionLost());
|
|
|
|
|
// assertEquals("Hello 2", new String(cbSubscriber2.waitMessage(1).getPayload()));
|
|
|
|
|
// }
|
2015-12-27 13:19:16 +01:00
|
|
|
|
2017-06-29 09:23:23 +02:00
|
|
|
// @Test
|
|
|
|
|
// public void testConnectSubPub_cycle_getTimeout_on_second_disconnect_issue142() throws Exception {
|
|
|
|
|
// LOG.info("*** testConnectSubPub_cycle_getTimeout_on_second_disconnect_issue142 ***");
|
|
|
|
|
// MqttConnectOptions options = new MqttConnectOptions();
|
|
|
|
|
// options.setCleanSession(false);
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// m_client.subscribe("/topic", 0);
|
|
|
|
|
// m_client.publish("/topic", "Hello".getBytes(), 0, true);
|
|
|
|
|
// m_client.disconnect();
|
|
|
|
|
//
|
|
|
|
|
// // second loop
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// m_client.subscribe("/topic", 0);
|
|
|
|
|
// m_client.publish("/topic", "Hello".getBytes(), 0, true);
|
|
|
|
|
// m_client.disconnect(); // this should give timeout
|
|
|
|
|
//
|
|
|
|
|
// assertFalse("after a disconnect the client should be disconnected", m_client.isConnected());
|
|
|
|
|
// }
|
2015-12-27 13:19:16 +01:00
|
|
|
|
2017-06-29 09:23:23 +02:00
|
|
|
// @Test
|
|
|
|
|
// public void checkReplayofStoredPublishResumeAfter_a_disconnect_cleanSessionFalseQoS1() throws Exception {
|
|
|
|
|
// LOG.info("*** checkReplayofStoredPublishResumeAfter_a_disconnect_cleanSessionFalseQoS1 ***");
|
|
|
|
|
// // MessageCollector m_messagesCollector = new MessageCollector();
|
|
|
|
|
// // m_client.setCallback(m_messagesCollector);
|
|
|
|
|
// m_publisher.connect();
|
|
|
|
|
//
|
|
|
|
|
// MqttConnectOptions options = new MqttConnectOptions();
|
|
|
|
|
// options.setCleanSession(false);
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// m_client.subscribe("/topic", 1);
|
|
|
|
|
//
|
|
|
|
|
// // force the publisher to send
|
|
|
|
|
// m_publisher.publish("/topic", "Hello world MQTT!!-1".getBytes(), 1, false);
|
|
|
|
|
//
|
|
|
|
|
// // read the first message and drop the connection
|
|
|
|
|
// MqttMessage msg = m_messagesCollector.waitMessage(1);
|
|
|
|
|
// assertEquals("Hello world MQTT!!-1", new String(msg.getPayload()));
|
|
|
|
|
// m_client.disconnect();
|
|
|
|
|
//
|
|
|
|
|
// m_publisher.publish("/topic", "Hello world MQTT!!-2".getBytes(), 1, false);
|
|
|
|
|
// m_publisher.publish("/topic", "Hello world MQTT!!-3".getBytes(), 1, false);
|
|
|
|
|
//
|
|
|
|
|
// // reconnect and expect to receive the hello 2 message
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// msg = m_messagesCollector.waitMessage(1);
|
|
|
|
|
// assertEquals("Hello world MQTT!!-2", new String(msg.getPayload()));
|
|
|
|
|
//
|
|
|
|
|
// msg = m_messagesCollector.waitMessage(1);
|
|
|
|
|
// assertEquals("Hello world MQTT!!-3", new String(msg.getPayload()));
|
|
|
|
|
// m_client.disconnect();
|
|
|
|
|
// }
|
2015-12-27 13:19:16 +01:00
|
|
|
|
2017-06-29 09:23:23 +02:00
|
|
|
// @Test
|
|
|
|
|
// public void checkReplayStoredPublish_forNoCleanSession_qos1() throws Exception {
|
|
|
|
|
// LOG.info("*** checkReplayStoredPublish_forNoCleanSession_qos1 ***");
|
|
|
|
|
// MessageCollector messagesCollector = new MessageCollector();
|
|
|
|
|
// m_client.setCallback(messagesCollector);
|
|
|
|
|
// m_publisher.connect();
|
|
|
|
|
//
|
|
|
|
|
// MqttConnectOptions options = new MqttConnectOptions();
|
|
|
|
|
// options.setCleanSession(false);
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// m_client.subscribe("/topic", 1);
|
|
|
|
|
// m_client.disconnect();
|
|
|
|
|
//
|
|
|
|
|
// // force the publisher to send
|
|
|
|
|
// m_publisher.publish("/topic", "Hello world MQTT!!-1".getBytes(), 1, false);
|
|
|
|
|
//
|
|
|
|
|
// // reconnect and expect to receive the hello 2 message
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// m_client.subscribe("/topic", 1);
|
|
|
|
|
// MqttMessage msg = messagesCollector.waitMessage(1);
|
|
|
|
|
// assertNotNull(msg);
|
|
|
|
|
// assertEquals("Hello world MQTT!!-1", new String(msg.getPayload()));
|
|
|
|
|
// }
|
2015-12-27 13:19:16 +01:00
|
|
|
|
2017-06-29 09:23:23 +02:00
|
|
|
// /**
|
|
|
|
|
// * 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 ***");
|
|
|
|
|
// MessageCollector messagesCollector = new MessageCollector();
|
|
|
|
|
// m_client.setCallback(messagesCollector);
|
|
|
|
|
// MqttConnectOptions options = new MqttConnectOptions();
|
|
|
|
|
// options.setCleanSession(false);
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// m_client.subscribe("topic", 2);
|
|
|
|
|
// m_client.disconnect();
|
|
|
|
|
//
|
|
|
|
|
// m_publisher.connect();
|
|
|
|
|
// m_publisher.publish("topic", "Hello1".getBytes(), 2, true);
|
|
|
|
|
// m_publisher.publish("topic", "Hello2".getBytes(), 2, true);
|
|
|
|
|
// m_publisher.disconnect();
|
|
|
|
|
//
|
|
|
|
|
// // subscriber reconnects
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// // subscriber should receive the 2 messages missed
|
|
|
|
|
// MqttMessage msg = messagesCollector.waitMessage(1);
|
|
|
|
|
// assertNotNull(msg);
|
|
|
|
|
// assertEquals("Hello1", new String(msg.getPayload()));
|
|
|
|
|
// msg = messagesCollector.waitMessage(1);
|
|
|
|
|
// assertNotNull(msg);
|
|
|
|
|
// 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 ***");
|
|
|
|
|
// MessageCollector messagesCollector = new MessageCollector();
|
|
|
|
|
// m_client.setCallback(messagesCollector);
|
|
|
|
|
// m_publisher.connect();
|
|
|
|
|
//
|
|
|
|
|
// MqttConnectOptions options = new MqttConnectOptions();
|
|
|
|
|
// options.setCleanSession(false);
|
|
|
|
|
// m_client.connect(options);
|
|
|
|
|
// m_client.subscribe("a/+", 2);
|
|
|
|
|
// m_client.subscribe("a/b", 1);
|
|
|
|
|
//
|
|
|
|
|
// // force the publisher to send
|
|
|
|
|
// m_publisher.publish("a/b", "Hello world MQTT!!".getBytes(), 1, false);
|
|
|
|
|
//
|
|
|
|
|
// // reconnect and expect to receive the hello 2 message
|
|
|
|
|
// MqttMessage msg = messagesCollector.waitMessage(1);
|
|
|
|
|
// assertEquals("Hello world MQTT!!", new String(msg.getPayload()));
|
|
|
|
|
//
|
|
|
|
|
// // try to listen a second publish
|
|
|
|
|
// msg = messagesCollector.waitMessage(1);
|
|
|
|
|
// assertNull(msg);
|
|
|
|
|
// }
|
2016-02-23 23:29:45 +01:00
|
|
|
|
2015-12-27 13:19:16 +01:00
|
|
|
protected MqttClient createClient(String clientName, String storeSuffix) throws MqttException {
|
|
|
|
|
return createClient(clientName, storeSuffix, null);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-06 19:03:01 +01:00
|
|
|
protected MqttClient createClient(String clientName, String storeSuffix, MessageCollector cb) throws MqttException {
|
2015-12-27 13:19:16 +01:00
|
|
|
String tmpDir = System.getProperty("java.io.tmpdir");
|
2017-02-01 16:15:18 +01:00
|
|
|
// clientX connect and subscribe to /topic QoS2
|
|
|
|
|
MqttClientPersistence dsClient = new MqttDefaultFilePersistence(
|
|
|
|
|
tmpDir + File.separator + storeSuffix + clientName);
|
2015-12-27 13:19:16 +01:00
|
|
|
MqttClient client = new MqttClient("tcp://localhost:1883", clientName, dsClient);
|
|
|
|
|
if (cb != null) {
|
|
|
|
|
client.setCallback(cb);
|
|
|
|
|
}
|
|
|
|
|
client.connect();
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-19 20:14:07 +02:00
|
|
|
}
|