Refactored the part of move from inFlight to second stage rel ack, this driven to missed notification to the interceptors

This commit is contained in:
andsel
2016-06-16 23:01:48 +02:00
parent d5399995c3
commit 0c4f7fa393
8 changed files with 106 additions and 66 deletions
@@ -139,8 +139,6 @@ public class ServerIntegrationEmbeddedPublishTest {
LOG.info("*** testClientSubscribeBeforeRetainedQoS0IsSent ***");
subscribeToWithQos("/topic", 0);
//super ugly but we need the MQTT client lib finish it's job before us
Thread.sleep(1000);
//Exercise
internalPublishToWithQosAndRetained("/topic", QOSType.MOST_ONE, true);
@@ -155,6 +153,7 @@ public class ServerIntegrationEmbeddedPublishTest {
//Exercise
internalPublishToWithQosAndRetained("/topic", QOSType.MOST_ONE, true);
//LOG.info("** post internalPublish **");
subscribeToWithQos("/topic", 0);
//Verify
@@ -166,8 +165,6 @@ public class ServerIntegrationEmbeddedPublishTest {
LOG.info("*** testClientSubscribeBeforeNotRetainedQoS1IsSent ***");
subscribeToWithQos("/topic", 1);
//super ugly but we need the MQTT client lib finish it's job before us
Thread.sleep(1000);
//Exercise
internalPublishToWithQosAndRetained("/topic", QOSType.LEAST_ONE, false);
@@ -193,8 +190,6 @@ public class ServerIntegrationEmbeddedPublishTest {
LOG.info("*** testClientSubscribeBeforeRetainedQoS1IsSent ***");
subscribeToWithQos("/topic", 1);
//super ugly but we need the MQTT client lib finish it's job before us
Thread.sleep(1000);
//Exercise
internalPublishToWithQosAndRetained("/topic", QOSType.LEAST_ONE, true);
@@ -210,9 +205,11 @@ public class ServerIntegrationEmbeddedPublishTest {
//Exercise
internalPublishToWithQosAndRetained("/topic", QOSType.LEAST_ONE, true);
subscribeToWithQos("/topic", 1);
LOG.info("** After subscribe **");
//Verify
verifyMessageIsReceivedSuccessfully();
LOG.info("** Post verify **");
}
@Test
@@ -220,8 +217,6 @@ public class ServerIntegrationEmbeddedPublishTest {
LOG.info("*** testClientSubscribeBeforeNotRetainedQoS2IsSent ***");
subscribeToWithQos("/topic", 2);
//super ugly but we need the MQTT client lib finish it's job before us
Thread.sleep(1000);
//Exercise
internalPublishToWithQosAndRetained("/topic", QOSType.EXACTLY_ONCE, false);
@@ -247,8 +242,6 @@ public class ServerIntegrationEmbeddedPublishTest {
LOG.info("*** testClientSubscribeBeforeRetainedQoS2IsSent ***");
subscribeToWithQos("/topic", 2);
//super ugly but we need the MQTT client lib finish it's job before us
Thread.sleep(1000);
//Exercise
internalPublishToWithQosAndRetained("/topic", QOSType.EXACTLY_ONCE, true);
@@ -43,8 +43,8 @@ public class MemorySessionStore implements ISessionsStore {
// private Map<String, Set<Integer>> m_inflightIDs = new HashMap<>();
//maps clientID->[guid*]
private Map<String, Set<String>> m_enqueuedStore = new HashMap<>();
//maps clientID->[messageID*]
private Map<String, Set<Integer>> m_secondPhaseStore = new HashMap<>();
//maps clientID->[MessageId -> guid]
private Map<String, Map<Integer, String>> m_secondPhaseStore = new HashMap<>();
private Map<String, Map<Integer, String>> m_messageToGuids;
private final IMessagesStore m_messagesStore;
@@ -214,17 +214,27 @@ public class MemorySessionStore implements ISessionsStore {
}
@Override
public void secondPhaseAcknowledged(String clientID, int messageID) {
Set<Integer> messageIDs = Utils.defaultGet(m_secondPhaseStore, clientID, new HashSet<Integer>());
messageIDs.remove(messageID);
public void moveInFlightToSecondPhaseAckWaiting(String clientID, int messageID) {
LOG.info("acknowledging inflight clientID <{}> messageID {}", clientID, messageID);
Map<Integer, String> m = this.m_inflightStore.get(clientID);
if (m == null) {
LOG.error("Can't find the inFlight record for client <{}>", clientID);
return;
}
String guid = m.remove(messageID);
LOG.info("Moving to second phase store");
Map<Integer, String> messageIDs = Utils.defaultGet(m_secondPhaseStore, clientID, new HashMap<Integer, String>());
messageIDs.put(messageID, guid);
m_secondPhaseStore.put(clientID, messageIDs);
}
@Override
public void secondPhaseAckWaiting(String clientID, int messageID) {
Set<Integer> messageIDs = Utils.defaultGet(m_secondPhaseStore, clientID, new HashSet<Integer>());
messageIDs.add(messageID);
public String secondPhaseAcknowledged(String clientID, int messageID) {
Map<Integer, String> messageIDs = Utils.defaultGet(m_secondPhaseStore, clientID, new HashMap<Integer, String>());
String guid = messageIDs.remove(messageID);
m_secondPhaseStore.put(clientID, messageIDs);
return guid;
}
@Override