Fixed NPE exception of inflight ACK because the publisher with clean=true removed all messages, also the published from message store

This commit is contained in:
andsel
2017-01-04 11:17:30 +01:00
parent 2c43c74fe3
commit 480e36579c
4 changed files with 15 additions and 11 deletions
@@ -43,6 +43,7 @@ import io.netty.channel.ChannelPipeline;
import io.netty.handler.timeout.IdleStateHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sun.misc.MessageUtils;
/**
* Class responsible to handle the logic of MQTT protocol it's the director of
@@ -424,13 +425,16 @@ public class ProtocolProcessor {
String username = NettyUtils.userName(channel);
LOG.trace("retrieving inflight for messageID <{}>", messageID);
//Remove the message from message store
ClientSession targetSession = m_sessionsStore.sessionForClient(clientID);
StoredMessage inflightMsg = targetSession.getInflightMessage(messageID);
targetSession.inFlightAcknowledged(messageID);
String topic = inflightMsg.getTopic();
MessageGUID guid = inflightMsg.getGuid();
//Remove the message from message store
m_messagesStore.decUsageCounter(guid);
m_interceptor.notifyMessageAcknowledged(new InterceptAcknowledgedMessage(inflightMsg, topic, username));
}
@@ -632,9 +636,12 @@ public class ProtocolProcessor {
}
if (descriptor.cleanSession) {
LOG.debug("Removing messages in session for client <{}>", clientID);
this.m_messagesStore.dropMessagesInSession(clientID);
LOG.debug("Removed messages in session for client <{}>", clientID);
LOG.debug("Removing messages in session's queue for client <{}>", clientID);
Collection<MessageGUID> queue = this.m_sessionsStore.enqueued(clientID);
for (MessageGUID guid : queue) {
this.m_sessionsStore.removeEnqueued(clientID, guid);
}
LOG.debug("Removed messages in session for client's queue <{}>", clientID);
}
return true;
}
@@ -227,9 +227,6 @@ class MapDBSessionsStore implements ISessionsStore {
List<MessageGUID> guids = Utils.defaultGet(m_enqueuedStore, clientID, new ArrayList<MessageGUID>());
guids.remove(guid);
m_enqueuedStore.put(clientID, guids);
m_messagesStore.decUsageCounter(guid);
//if counter gets to 0 then remove from storage
m_messagesStore.removeStoredMessage(guid);
}
@Override
@@ -74,7 +74,7 @@ public class ServerIntegrationFuseTest {
@Test
public void checkWillTestamentIsPublishedOnConnectionKill_noRetain() throws Exception {
LOG.info("checkWillTestamentIsPublishedOnConnectionKill");
LOG.info("checkWillTestamentIsPublishedOnConnectionKill_noRetain");
String willTestamentTopic = "/will/test";
String willTestamentMsg = "Bye bye";
@@ -93,7 +93,6 @@ public class ServerIntegrationFuseTest {
m_mqtt.setClientId("Subscriber");
m_subscriber = m_mqtt.blockingConnection();
m_subscriber.connect();
// Topic[] topics = new Topic[]{new Topic(willTestamentTopic, QoS.AT_LEAST_ONCE)};
Topic[] topics = new Topic[]{new Topic(willTestamentTopic, QoS.AT_MOST_ONCE)};
m_subscriber.subscribe(topics);
@@ -286,6 +286,7 @@ public class ServerIntegrationPahoTest {
assertEquals("Hello MQTT", m_messagesCollector.getMessage(true).toString());
}
@Test
public void checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession() throws Exception {
LOG.info("*** checkReceivePublishedMessage_after_a_reconnect_with_notCleanSession ***");
@@ -461,10 +462,10 @@ public class ServerIntegrationPahoTest {
clientForPublish.publish("topic", "Hello".getBytes(), 2, true);
//verify clientForSubscribe1 doesn't receive a notification but clientForSubscribe2 yes
System.out.println("Before waiting to receive 1 sec from " + clientForSubscribe1.getClientId());
LOG.info("Before waiting to receive 1 sec from " + clientForSubscribe1.getClientId());
assertFalse(clientForSubscribe1.isConnected());
assertTrue(clientForSubscribe2.isConnected());
System.out.println("Waiting to receive 1 sec from " + clientForSubscribe2.getClientId());
LOG.info("Waiting to receive 1 sec from " + clientForSubscribe2.getClientId());
MqttMessage messageOnB = cbSubscriber2.getMessage(true);
assertEquals("Hello", new String(messageOnB.getPayload()));
}