Fixed a bug in store remove subscription that doesn't check the clientID but just the topic match
This commit is contained in:
@@ -10,3 +10,4 @@ Version 0.4:
|
|||||||
Dropped support for MINA
|
Dropped support for MINA
|
||||||
Fix Issue 15 (bad re-activation of client's subscriptions after a recconection)
|
Fix Issue 15 (bad re-activation of client's subscriptions after a recconection)
|
||||||
Fix Issue 16 (bad re-publish of stored messages after a client reconnection)
|
Fix Issue 16 (bad re-publish of stored messages after a client reconnection)
|
||||||
|
Fixed a bug in unsubscribe due to missed clientID check
|
||||||
+2
-2
@@ -124,10 +124,10 @@ public class SubscriptionsStore {
|
|||||||
public void removeSubscription(String topic, String clientID) {
|
public void removeSubscription(String topic, String clientID) {
|
||||||
TreeNode matchNode = findMatchingNode(topic);
|
TreeNode matchNode = findMatchingNode(topic);
|
||||||
|
|
||||||
//search fr the subscription to remove
|
//search for the subscription to remove
|
||||||
Subscription toBeRemoved = null;
|
Subscription toBeRemoved = null;
|
||||||
for (Subscription sub : matchNode.subscriptions()) {
|
for (Subscription sub : matchNode.subscriptions()) {
|
||||||
if (sub.topic.equals(topic)) {
|
if (sub.topic.equals(topic) && sub.getClientId().equals(clientID)) {
|
||||||
toBeRemoved = sub;
|
toBeRemoved = sub;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
@@ -324,6 +324,27 @@ public class SubscriptionsStoreTest {
|
|||||||
assertTrue(SubscriptionsStore.matchTopics("foo///baz", "foo/+/+/baz"));
|
assertTrue(SubscriptionsStore.matchTopics("foo///baz", "foo/+/+/baz"));
|
||||||
assertTrue(SubscriptionsStore.matchTopics("foo/bar/", "foo/bar/+"));
|
assertTrue(SubscriptionsStore.matchTopics("foo/bar/", "foo/bar/+"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeSubscription_withDifferentClients_subscribedSameTopic() {
|
||||||
|
SubscriptionsStore aStore = new SubscriptionsStore();
|
||||||
|
aStore.init(new MemoryStorageService());
|
||||||
|
//subscribe a not active clientID1 to /topic
|
||||||
|
Subscription slashSub = new Subscription("FAKE_CLI_ID_1", "/topic", AbstractMessage.QOSType.MOST_ONE, false);
|
||||||
|
aStore.add(slashSub);
|
||||||
|
aStore.deactivate(slashSub.getClientId());
|
||||||
|
|
||||||
|
//subscribe an active clientID2 to /topic
|
||||||
|
Subscription slashSub2 = new Subscription("FAKE_CLI_ID_2", "/topic", AbstractMessage.QOSType.MOST_ONE, false);
|
||||||
|
aStore.add(slashSub2);
|
||||||
|
|
||||||
|
//Exercise
|
||||||
|
aStore.removeSubscription("/topic", slashSub2.getClientId());
|
||||||
|
|
||||||
|
//Verify
|
||||||
|
Subscription remainedSubscription = aStore.matches("/topic").get(0);
|
||||||
|
assertEquals(slashSub.getClientId(), remainedSubscription.getClientId());
|
||||||
|
}
|
||||||
|
|
||||||
private static Token[] asArray(Object... l) {
|
private static Token[] asArray(Object... l) {
|
||||||
Token[] tokens = new Token[l.length];
|
Token[] tokens = new Token[l.length];
|
||||||
|
|||||||
Reference in New Issue
Block a user