Added tests suite used by Roger Light to check SubscriptionStore.matches
This commit is contained in:
+5
-3
@@ -2,6 +2,7 @@ package org.dna.mqtt.moquette.messaging.spi.impl.subscriptions;
|
|||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
@@ -181,6 +182,7 @@ public class SubscriptionsStore {
|
|||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
//TODO handle the parse exception
|
//TODO handle the parse exception
|
||||||
LOG.error(null, ex);
|
LOG.error(null, ex);
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
Queue<Token> tokenQueue = new LinkedBlockingDeque<Token>(tokens);
|
Queue<Token> tokenQueue = new LinkedBlockingDeque<Token>(tokens);
|
||||||
@@ -255,9 +257,9 @@ public class SubscriptionsStore {
|
|||||||
for (int i = 0; i < splitted.length; i++) {
|
for (int i = 0; i < splitted.length; i++) {
|
||||||
String s = splitted[i];
|
String s = splitted[i];
|
||||||
if (s.isEmpty()) {
|
if (s.isEmpty()) {
|
||||||
if (i != 0) {
|
// if (i != 0) {
|
||||||
throw new ParseException("Bad format of topic, expetec topic name between separators", i);
|
// throw new ParseException("Bad format of topic, expetec topic name between separators", i);
|
||||||
}
|
// }
|
||||||
res.add(Token.EMPTY);
|
res.add(Token.EMPTY);
|
||||||
} else if (s.equals("#")) {
|
} else if (s.equals("#")) {
|
||||||
//check that multi is the last symbol
|
//check that multi is the last symbol
|
||||||
|
|||||||
+2
-1
@@ -66,7 +66,7 @@ class TreeNode {
|
|||||||
matchingSubs.addAll(m_subscriptions);
|
matchingSubs.addAll(m_subscriptions);
|
||||||
//check if it has got a MULTI child and add its subscriptions
|
//check if it has got a MULTI child and add its subscriptions
|
||||||
for (TreeNode n : m_children) {
|
for (TreeNode n : m_children) {
|
||||||
if (n.getToken() == Token.MULTI) {
|
if (n.getToken() == Token.MULTI || n.getToken() == Token.SINGLE) {
|
||||||
matchingSubs.addAll(n.subscriptions());
|
matchingSubs.addAll(n.subscriptions());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +85,7 @@ class TreeNode {
|
|||||||
//Create a copy of token, else if navigate 2 sibling it
|
//Create a copy of token, else if navigate 2 sibling it
|
||||||
//consumes 2 elements on the queue instead of one
|
//consumes 2 elements on the queue instead of one
|
||||||
n.matches(new LinkedBlockingQueue<Token>(tokens), matchingSubs);
|
n.matches(new LinkedBlockingQueue<Token>(tokens), matchingSubs);
|
||||||
|
//TODO don't create a copy n.matches(tokens, matchingSubs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-4
@@ -62,10 +62,10 @@ public class SubscriptionsStoreTest {
|
|||||||
assertEqualsSeq(asArray(Token.EMPTY), tokens);
|
assertEqualsSeq(asArray(Token.EMPTY), tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ParseException.class)
|
// @Test(expected = ParseException.class)
|
||||||
public void testSplitTopicTwinsSlashAvoided() throws ParseException {
|
// public void testSplitTopicTwinsSlashAvoided() throws ParseException {
|
||||||
store.splitTopic("/finance//stock/ibm");
|
// store.splitTopic("/finance//stock/ibm");
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSplitTopicMultiValid() throws ParseException {
|
public void testSplitTopicMultiValid() throws ParseException {
|
||||||
@@ -211,6 +211,46 @@ public class SubscriptionsStoreTest {
|
|||||||
assertFalse(store.matches("finance").isEmpty());
|
assertFalse(store.matches("finance").isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rogerLightTopicMatches() {
|
||||||
|
assertMatch("foo/bar", "foo/bar");
|
||||||
|
assertMatch("foo/bar", "foo/bar");
|
||||||
|
assertMatch("foo/+", "foo/bar");
|
||||||
|
assertMatch("foo/+/baz", "foo/bar/baz");
|
||||||
|
assertMatch("foo/+/#", "foo/bar/baz");
|
||||||
|
assertMatch("#", "foo/bar/baz");
|
||||||
|
|
||||||
|
assertNotMatch("foo/bar", "foo");
|
||||||
|
assertNotMatch("foo/+", "foo/bar/baz");
|
||||||
|
assertNotMatch("foo/+/baz", "foo/bar/bar");
|
||||||
|
assertNotMatch("foo/+/#", "fo2/bar/baz");
|
||||||
|
|
||||||
|
assertMatch("#", "/foo/bar");
|
||||||
|
assertMatch("/#", "/foo/bar");
|
||||||
|
assertNotMatch("/#", "foo/bar");
|
||||||
|
|
||||||
|
assertMatch("foo//bar", "foo//bar");
|
||||||
|
assertMatch("foo//+", "foo//bar");
|
||||||
|
assertMatch("foo/+/+/baz", "foo///baz");
|
||||||
|
assertMatch("foo/bar/+", "foo/bar/");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertMatch(String subscription, String topic) {
|
||||||
|
store = new SubscriptionsStore();
|
||||||
|
store.init(new MemoryStorageService());
|
||||||
|
Subscription sub = new Subscription("FAKE_CLI_ID_1", subscription, AbstractMessage.QOSType.MOST_ONE, false);
|
||||||
|
store.add(sub);
|
||||||
|
assertFalse(store.matches(topic).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertNotMatch(String subscription, String topic) {
|
||||||
|
store = new SubscriptionsStore();
|
||||||
|
store.init(new MemoryStorageService());
|
||||||
|
Subscription sub = new Subscription("FAKE_CLI_ID_1", subscription, AbstractMessage.QOSType.MOST_ONE, false);
|
||||||
|
store.add(sub);
|
||||||
|
assertTrue(store.matches(topic).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveClientSubscriptions_existingClientID() {
|
public void testRemoveClientSubscriptions_existingClientID() {
|
||||||
|
|||||||
Reference in New Issue
Block a user