Added tests suite used by Roger Light to check SubscriptionStore.matches

This commit is contained in:
andrea
2013-11-06 12:35:10 +01:00
parent 136b7e25c3
commit 2c18ee92c7
3 changed files with 51 additions and 8 deletions
@@ -2,6 +2,7 @@ package org.dna.mqtt.moquette.messaging.spi.impl.subscriptions;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingDeque;
@@ -181,6 +182,7 @@ public class SubscriptionsStore {
} catch (ParseException ex) {
//TODO handle the parse exception
LOG.error(null, ex);
return Collections.EMPTY_LIST;
}
Queue<Token> tokenQueue = new LinkedBlockingDeque<Token>(tokens);
@@ -255,9 +257,9 @@ public class SubscriptionsStore {
for (int i = 0; i < splitted.length; i++) {
String s = splitted[i];
if (s.isEmpty()) {
if (i != 0) {
throw new ParseException("Bad format of topic, expetec topic name between separators", i);
}
// if (i != 0) {
// throw new ParseException("Bad format of topic, expetec topic name between separators", i);
// }
res.add(Token.EMPTY);
} else if (s.equals("#")) {
//check that multi is the last symbol
@@ -66,7 +66,7 @@ class TreeNode {
matchingSubs.addAll(m_subscriptions);
//check if it has got a MULTI child and add its subscriptions
for (TreeNode n : m_children) {
if (n.getToken() == Token.MULTI) {
if (n.getToken() == Token.MULTI || n.getToken() == Token.SINGLE) {
matchingSubs.addAll(n.subscriptions());
}
}
@@ -85,6 +85,7 @@ class TreeNode {
//Create a copy of token, else if navigate 2 sibling it
//consumes 2 elements on the queue instead of one
n.matches(new LinkedBlockingQueue<Token>(tokens), matchingSubs);
//TODO don't create a copy n.matches(tokens, matchingSubs);
}
}
}