Fixed issue #49, duplication of subscription with different QoS

This commit is contained in:
andrea
2015-06-21 15:55:39 +02:00
parent 3deb903f3c
commit 932d2fb4cb
3 changed files with 28 additions and 3 deletions
+1
View File
@@ -16,6 +16,7 @@ Version 0.7:
Removed cause of leakage of Netty Sessions (fix issue #39)
Cleaned Netty's stuff reference from Events used in Disruptor (fix issue #40)
Bad assignment of PacketID during publish to subscribed QoS0 topics (fix issue #38)
Fixed duplicated subscription with different QoS same client and topic (fix issue #
Version 0.6:
Fix issue #42, bad password file path composition
@@ -30,8 +30,8 @@ class TreeNode {
TreeNode m_parent;
Token m_token;
List<TreeNode> m_children = new ArrayList<TreeNode>();
List<Subscription> m_subscriptions = new ArrayList<Subscription>();
List<TreeNode> m_children = new ArrayList<>();
List<Subscription> m_subscriptions = new ArrayList<>();
TreeNode(TreeNode parent) {
this.m_parent = parent;
@@ -51,7 +51,9 @@ class TreeNode {
return;
}
//remove existing subscription for same client and topic but different QoS
int existingSubIdx = Collections.binarySearch(m_subscriptions, s, new ClientIDComparator());
Comparator<Subscription> comparator = new ClientIDComparator();
Collections.sort(m_subscriptions, comparator);
int existingSubIdx = Collections.binarySearch(m_subscriptions, s, comparator);
if (existingSubIdx >= 0) {
m_subscriptions.remove(existingSubIdx);
}
@@ -356,6 +356,28 @@ public class SubscriptionsStoreTest {
assertEquals(overrindingSubscription.getRequestedQos(), sub.getRequestedQos());
}
/*
Test for Issue #49
* */
@Test
public void duplicatedSubscriptionsWithDifferentQos() {
Subscription client2Sub = new Subscription("client2", "client/test/b", AbstractMessage.QOSType.MOST_ONE, true);
store.add(client2Sub);
Subscription client1SubQoS0 = new Subscription("client1", "client/test/b", AbstractMessage.QOSType.MOST_ONE, true);
store.add(client1SubQoS0);
Subscription client1SubQoS2 = new Subscription("client1", "client/test/b", AbstractMessage.QOSType.EXACTLY_ONCE, true);
store.add(client1SubQoS2);
System.out.println(store.dumpTree());
//Verify
List<Subscription> subscriptions = store.matches("client/test/b");
assertTrue(subscriptions.contains(client1SubQoS2));
assertTrue(subscriptions.contains(client2Sub));
assertFalse(subscriptions.contains(client1SubQoS0)); //client1SubQoS2 should override client1SubQoS0
}
private static Token[] asArray(Object... l) {
Token[] tokens = new Token[l.length];
for (int i = 0; i < l.length; i++) {