Fixed issue #49, duplication of subscription with different QoS
This commit is contained in:
@@ -16,6 +16,7 @@ Version 0.7:
|
|||||||
Removed cause of leakage of Netty Sessions (fix issue #39)
|
Removed cause of leakage of Netty Sessions (fix issue #39)
|
||||||
Cleaned Netty's stuff reference from Events used in Disruptor (fix issue #40)
|
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)
|
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:
|
Version 0.6:
|
||||||
Fix issue #42, bad password file path composition
|
Fix issue #42, bad password file path composition
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ class TreeNode {
|
|||||||
|
|
||||||
TreeNode m_parent;
|
TreeNode m_parent;
|
||||||
Token m_token;
|
Token m_token;
|
||||||
List<TreeNode> m_children = new ArrayList<TreeNode>();
|
List<TreeNode> m_children = new ArrayList<>();
|
||||||
List<Subscription> m_subscriptions = new ArrayList<Subscription>();
|
List<Subscription> m_subscriptions = new ArrayList<>();
|
||||||
|
|
||||||
TreeNode(TreeNode parent) {
|
TreeNode(TreeNode parent) {
|
||||||
this.m_parent = parent;
|
this.m_parent = parent;
|
||||||
@@ -51,7 +51,9 @@ class TreeNode {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//remove existing subscription for same client and topic but different QoS
|
//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) {
|
if (existingSubIdx >= 0) {
|
||||||
m_subscriptions.remove(existingSubIdx);
|
m_subscriptions.remove(existingSubIdx);
|
||||||
}
|
}
|
||||||
|
|||||||
+22
@@ -356,6 +356,28 @@ public class SubscriptionsStoreTest {
|
|||||||
assertEquals(overrindingSubscription.getRequestedQos(), sub.getRequestedQos());
|
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) {
|
private static Token[] asArray(Object... l) {
|
||||||
Token[] tokens = new Token[l.length];
|
Token[] tokens = new Token[l.length];
|
||||||
for (int i = 0; i < l.length; i++) {
|
for (int i = 0; i < l.length; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user