Added first implementation for topic tree subscriptions.

This commit is contained in:
selva.andre
2012-08-07 00:17:47 +02:00
parent f8d75bf004
commit fdedfecfba
2 changed files with 154 additions and 11 deletions
@@ -4,6 +4,7 @@ import java.text.ParseException;
import java.util.Arrays;
import java.util.List;
import org.dna.mqtt.moquette.messaging.spi.impl.SubscriptionsStore.Token;
import org.dna.mqtt.moquette.proto.messages.AbstractMessage;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
@@ -31,6 +32,9 @@ public class SubscriptionsStoreTest {
tokens = store.splitTopic("/finance/stock/ibm");
assertEqualsSeq(asArray(Token.EMPTY, "finance", "stock", "ibm"), tokens);
tokens = store.splitTopic("/");
assertEqualsSeq(asArray(Token.EMPTY), tokens);
}
@@ -77,6 +81,24 @@ public class SubscriptionsStoreTest {
store.splitTopic("finance+");
}
@Test
public void testMatchSimple() {
store.add(new Subscription(null, "/", AbstractMessage.QOSType.MOST_ONE));
assertTrue(store.matches("finance").isEmpty());
store.add(new Subscription(null, "/finance", AbstractMessage.QOSType.MOST_ONE));
assertTrue(store.matches("finance").isEmpty());
}
@Test
public void testMatchSimpleMulti() {
store.add(new Subscription(null, "#", AbstractMessage.QOSType.MOST_ONE));
assertFalse(store.matches("finance").isEmpty());
store.add(new Subscription(null, "finance/#", AbstractMessage.QOSType.MOST_ONE));
assertFalse(store.matches("finance").isEmpty());
}
private static Token[] asArray(Object... l) {
Token[] tokens = new Token[l.length];