Fixed bug #143 avoid publication try to disconnected clients

This commit is contained in:
andsel
2016-01-25 22:21:38 +01:00
parent 43f7223a15
commit dfa75e145f
2 changed files with 18 additions and 0 deletions
@@ -214,6 +214,10 @@ public class SubscriptionsStore {
for (ClientTopicCouple matchingCouple : matchingSubs) {
Subscription existingSub = subsForClient.get(matchingCouple.clientID);
Subscription sub = m_sessionsStore.getSubscription(matchingCouple);
if (sub == null) {
//if the m_sessionStore hasn't the sub because the client disconnected
continue;
}
//update the selected subscriptions if not present or if has a greater qos
if (existingSub == null || existingSub.getRequestedQos().byteValue() < sub.getRequestedQos().byteValue()) {
subsForClient.put(matchingCouple.clientID, sub);
@@ -26,6 +26,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Properties;
@@ -255,4 +256,17 @@ public class ServerIntegrationEmbeddedPublishTest {
//Verify
verifyMessageIsReceivedSuccessfully();
}
@Test(expected = EOFException.class)
public void testClientSubscribeAfterDisconnected() throws Exception {
LOG.info("*** testClientSubscribeAfterDisconnected ***");
subscribeToWithQos("foo", QoS.AT_MOST_ONCE);
m_subscriber.disconnect();
internalPublishToWithQosAndRetained("foo", QOSType.MOST_ONE, false);
//verifyMessageIsReceivedSuccessfully();
m_subscriber.receive(2, TimeUnit.MILLISECONDS);
}
}