[jboss-cvs] JBoss Messaging SVN: r3657 - in trunk: src/main/org/jboss/messaging/util and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Feb 1 10:22:09 EST 2008
Author: ataylor
Date: 2008-02-01 10:22:09 -0500 (Fri, 01 Feb 2008)
New Revision: 3657
Added:
trunk/src/main/org/jboss/messaging/core/Mergeable.java
trunk/tests/src/org/jboss/messaging/core/test/
trunk/tests/src/org/jboss/messaging/core/test/unit/
trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java
Modified:
trunk/src/main/org/jboss/messaging/core/QueueSettings.java
trunk/src/main/org/jboss/messaging/util/HierarchicalObjectRepository.java
trunk/src/main/org/jboss/messaging/util/HierarchicalRepository.java
trunk/src/main/org/jboss/messaging/util/Match.java
trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java
trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java
Log:
added functionality to Hierarchy repository in the form of supporting word excapes ^ and wildcards and merging
Added: trunk/src/main/org/jboss/messaging/core/Mergeable.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Mergeable.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/Mergeable.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -0,0 +1,11 @@
+package org.jboss.messaging.core;
+
+/**
+ * Used when merging objects together.
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public interface Mergeable<T>
+{
+ void merge(T merged);
+}
Modified: trunk/src/main/org/jboss/messaging/core/QueueSettings.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/QueueSettings.java 2008-02-01 12:37:33 UTC (rev 3656)
+++ trunk/src/main/org/jboss/messaging/core/QueueSettings.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -29,66 +29,75 @@
*
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public class QueueSettings
+public class QueueSettings implements Mergeable<QueueSettings>
{
private static Logger log = Logger.getLogger(QueueSettings.class);
- private static final DistributionPolicy DEFAULT_DISTRIBUTION_POLICY = new RoundRobinDistributionPolicy();
- boolean clustered = false;
- int maxSize = -1;
- String distributionPolicyClass = null;
- int maxDeliveryAttempts = 10;
- int messageCounterHistoryDayLimit = 0;
- long redeliveryDelay = 500;
- private String DLQ;
- private String ExpiryQueue;
+ /**
+ * defaults used if null, this allows merging
+ */
+ public static final DistributionPolicy DEFAULT_DISTRIBUTION_POLICY = new RoundRobinDistributionPolicy();
+ public static final Boolean DEFAULT_CLUSTERED = false;
+ public static final Integer DEFAULT_MAX_SIZE = -1;
+ public static final Integer DEFAULT_MAX_DELIVERY_ATTEMPTS = 10;
+ public static final Integer DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT = 0;
+ public static final Long DEFAULT_REDELIVER_DELAY = (long) 500;
+ private Boolean clustered = false;
+ private Integer maxSize = null;
+ private String distributionPolicyClass = null;
+ private Integer maxDeliveryAttempts = null;
+ private Integer messageCounterHistoryDayLimit = null;
+ private Long redeliveryDelay = null;
+ private String DLQ = null;
+ private String ExpiryQueue = null;
- public boolean isClustered()
+
+ public Boolean isClustered()
{
- return clustered;
+ return clustered != null?clustered:DEFAULT_CLUSTERED;
}
- public void setClustered(boolean clustered)
+ public void setClustered(Boolean clustered)
{
this.clustered = clustered;
}
- public int getMaxSize()
+ public Integer getMaxSize()
{
- return maxSize;
+ return maxSize != null?maxSize:DEFAULT_MAX_SIZE;
}
- public void setMaxSize(int maxSize)
+ public void setMaxSize(Integer maxSize)
{
this.maxSize = maxSize;
}
- public int getMaxDeliveryAttempts()
+ public Integer getMaxDeliveryAttempts()
{
- return maxDeliveryAttempts;
+ return maxDeliveryAttempts != null?maxDeliveryAttempts:DEFAULT_MAX_DELIVERY_ATTEMPTS;
}
- public void setMaxDeliveryAttempts(int maxDeliveryAttempts)
+ public void setMaxDeliveryAttempts(Integer maxDeliveryAttempts)
{
this.maxDeliveryAttempts = maxDeliveryAttempts;
}
- public int getMessageCounterHistoryDayLimit()
+ public Integer getMessageCounterHistoryDayLimit()
{
- return messageCounterHistoryDayLimit;
+ return messageCounterHistoryDayLimit!=null?messageCounterHistoryDayLimit:DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT;
}
- public void setMessageCounterHistoryDayLimit(int messageCounterHistoryDayLimit)
+ public void setMessageCounterHistoryDayLimit(Integer messageCounterHistoryDayLimit)
{
this.messageCounterHistoryDayLimit = messageCounterHistoryDayLimit;
}
- public long getRedeliveryDelay()
+ public Long getRedeliveryDelay()
{
- return redeliveryDelay;
+ return redeliveryDelay!=null?redeliveryDelay:DEFAULT_REDELIVER_DELAY;
}
- public void setRedeliveryDelay(long redeliveryDelay)
+ public void setRedeliveryDelay(Long redeliveryDelay)
{
this.redeliveryDelay = redeliveryDelay;
}
@@ -174,4 +183,44 @@
result = 31 * result + (ExpiryQueue != null ? ExpiryQueue.hashCode() : 0);
return result;
}
+
+ /**
+ * merge 2 objects in to 1
+ * @param merged
+ */
+ public void merge(QueueSettings merged)
+ {
+ if(!DEFAULT_CLUSTERED.equals(merged.clustered))
+ {
+ clustered = merged.clustered;
+ }
+ if(!DEFAULT_MAX_DELIVERY_ATTEMPTS.equals(merged.maxDeliveryAttempts) && merged.maxDeliveryAttempts != null)
+ {
+ maxDeliveryAttempts = merged.maxDeliveryAttempts;
+ }
+ if(!DEFAULT_MAX_SIZE.equals(merged.maxSize) && merged.maxSize != null)
+ {
+ maxSize = merged.maxSize;
+ }
+ if(!DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT.equals(merged.messageCounterHistoryDayLimit) && merged.messageCounterHistoryDayLimit != null)
+ {
+ messageCounterHistoryDayLimit = merged.messageCounterHistoryDayLimit;
+ }
+ if(!DEFAULT_REDELIVER_DELAY.equals(merged.redeliveryDelay) && merged.redeliveryDelay != null && merged.redeliveryDelay != null)
+ {
+ redeliveryDelay = merged.redeliveryDelay;
+ }
+ if(merged.distributionPolicyClass != null)
+ {
+ distributionPolicyClass = merged.distributionPolicyClass;
+ }
+ if(merged.DLQ != null)
+ {
+ DLQ = merged.DLQ;
+ }
+ if(merged.ExpiryQueue != null)
+ {
+ ExpiryQueue = merged.ExpiryQueue;
+ }
+ }
}
Modified: trunk/src/main/org/jboss/messaging/util/HierarchicalObjectRepository.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/HierarchicalObjectRepository.java 2008-02-01 12:37:33 UTC (rev 3656)
+++ trunk/src/main/org/jboss/messaging/util/HierarchicalObjectRepository.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -21,59 +21,106 @@
*/
package org.jboss.messaging.util;
-import java.util.HashMap;
+import org.jboss.messaging.core.Mergeable;
+import java.util.*;
+import java.lang.reflect.ParameterizedType;
+
/**
* allows objects to be mapped against a regex pattern and held in order in a list
*
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public class HierarchicalObjectRepository<E> implements HierarchicalRepository<E>
+public class HierarchicalObjectRepository<T> implements HierarchicalRepository<T>
{
/**
* The default Match to fall back to
*/
- E defaultmatch;
+ T defaultmatch;
/**
* all the matches
*/
- HashMap<String, Match> matches = new HashMap<String, Match>();
+ HashMap<String, Match<T>> matches = new HashMap<String, Match<T>>();
/**
+ * a regex comparator
+ */
+ MatchComparator<String> matchComparator = new MatchComparator<String>();
+
+ /**
* Add a new match to the repository
+ *
* @param match The regex to use to match against
* @param value the value to hold agains the match
*/
- public void addMatch(String match, E value)
+ public void addMatch(String match, T value)
{
- //create a match and add it to the list
- if(match.equals("*"))
- {
- defaultmatch = value;
- }
- else
- {
- Match<E> match1 = new Match<E>(match);
- match1.setValue(value);
- matches.put(match, match1);
- }
+ Match.verify(match);
+ Match<T> match1 = new Match<T>(match);
+ match1.setValue(value);
+ matches.put(match, match1);
+
}
/**
* return the value held against the nearest match
+ *
* @param match the match to look for
* @return the value
*/
- public E getMatch(String match)
+ public T getMatch(String match)
{
- HashMap<String, Match<E>> possibleMatches = getPossibleMatches(match);
- E actualMatch = getActualMatch(match, possibleMatches);
- return actualMatch != null ? actualMatch:defaultmatch;
+ T actualMatch;
+ HashMap<String, Match<T>> possibleMatches = getPossibleMatches(match);
+ List<Match<T>> orderedMatches = sort(possibleMatches);
+ actualMatch = merge(orderedMatches);
+ return actualMatch != null ? actualMatch : defaultmatch;
}
/**
+ * merge all the possible matches, if the values implement Mergeable then a full merge is done
+ * @param orderedMatches
+ * @return
+ */
+ private T merge(List<Match<T>> orderedMatches)
+ {
+ T actualMatch = null;
+ for (Match<T> match : orderedMatches)
+ {
+ if (actualMatch == null || !Mergeable.class.isAssignableFrom(actualMatch.getClass()))
+ {
+ actualMatch = match.getValue();
+ }
+ else
+ {
+ ((Mergeable) actualMatch).merge(match.getValue());
+
+ }
+ }
+ return actualMatch;
+ }
+
+ /**
+ * sort the matches in order of precedence
+ * @param possibleMatches
+ * @return
+ */
+ private List<Match<T>> sort(HashMap<String, Match<T>> possibleMatches)
+ {
+ List<String> keys = new ArrayList<String>(possibleMatches.keySet());
+ Collections.sort(keys, matchComparator);
+ List<Match<T>> matches = new ArrayList<Match<T>>();
+ for (String key : keys)
+ {
+ matches.add(possibleMatches.get(key));
+ }
+ return matches;
+ }
+
+ /**
* remove a match from the repository
+ *
* @param match the match to remove
*/
public void removeMatch(String match)
@@ -83,83 +130,81 @@
/**
* set the default value to fallback to if none found
+ *
* @param defaultValue the value
*/
- public void setDefault(E defaultValue)
+ public void setDefault(T defaultValue)
{
defaultmatch = defaultValue;
}
- private HashMap<String, Match<E>> getPossibleMatches(String match)
+ /**
+ * return any possible matches
+ * @param match
+ * @return
+ */
+ private HashMap<String, Match<T>> getPossibleMatches(String match)
{
- HashMap<String, Match<E>> possibleMatches = new HashMap<String, Match<E>>();
- for(String key : matches.keySet())
+ HashMap<String, Match<T>> possibleMatches = new HashMap<String, Match<T>>();
+ for (String key : matches.keySet())
{
- if(matches.get(key).getPattern().matcher(match).matches())
+ if (matches.get(key).getPattern().matcher(match).matches())
{
- //noinspection unchecked
possibleMatches.put(key, matches.get(key));
}
}
return possibleMatches;
}
-
- private E getActualMatch(String match, HashMap<String, Match<E>> possibleMatches)
+ /**
+ * compares to matches to seew hich one is more specific
+ */
+ class MatchComparator<T extends String> implements Comparator<T>
{
- E value = null;
- Match<E> currentVal = null;
- for(String key : possibleMatches.keySet())
- {
- currentVal = compareMatches(match, currentVal, possibleMatches.get(key));
- }
- if(currentVal != null)
- {
- value = currentVal.getValue();
- }
- return value;
- }
- private Match<E> compareMatches(String match, Match<E> currentVal, Match<E> replacementVal)
- {
- boolean moreSpecific = false;
- if(currentVal == null)
+ public int compare(String o1, String o2)
{
- moreSpecific = true;
- }
- else
- {
- String[] parts = match.split("\\.");
- for(int i = 0; i < parts.length; i++)
+ if (o1.contains(Match.WILDCARD) && !o2.contains(Match.WILDCARD))
{
- String left = getPart(i, currentVal.getMatch());
- String right = getPart(i, replacementVal.getMatch());
- if(!left.equals(right) && parts[i].equals(right))
+ return -1;
+ }
+ else if (!o1.contains(Match.WILDCARD) && o2.contains(Match.WILDCARD))
+ {
+ return +1;
+ }
+ else if (o1.contains(Match.WILDCARD) && o2.contains(Match.WILDCARD))
+ {
+ return o1.length() - o2.length();
+ }
+ else if (o1.contains(Match.WORD_WILDCARD) && !o2.contains(Match.WORD_WILDCARD))
+ {
+ return -1;
+ }
+ else if (!o1.contains(Match.WORD_WILDCARD) && o2.contains(Match.WORD_WILDCARD))
+ {
+ return +1;
+ }
+ else if (o1.contains(Match.WORD_WILDCARD) && o2.contains(Match.WORD_WILDCARD))
+ {
+ String[] leftSplits = o1.split("\\.");
+ String[] rightSplits = o2.split("\\.");
+ for (int i = 0; i < leftSplits.length; i++)
{
- moreSpecific = true;
- if("*".equals(left))
+ String left = leftSplits[i];
+ if (left.equals(Match.WORD_WILDCARD))
{
- break;
+ if (rightSplits.length < i || !rightSplits[i].equals(Match.WORD_WILDCARD))
+ {
+ return +1;
+ }
+ else
+ {
+ return -1;
+ }
}
}
- else
- {
- moreSpecific = false;
- }
}
+ return o1.length() - o2.length();
}
- return moreSpecific? replacementVal : currentVal;
}
-
- private String getPart(int i, String match)
- {
- String[] parts = match.split("\\.");
- if(parts != null && parts.length > i)
- {
- return parts[i];
- }
- return null;
- }
-
-
}
Modified: trunk/src/main/org/jboss/messaging/util/HierarchicalRepository.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/HierarchicalRepository.java 2008-02-01 12:37:33 UTC (rev 3656)
+++ trunk/src/main/org/jboss/messaging/util/HierarchicalRepository.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -6,27 +6,27 @@
*
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
*/
-public interface HierarchicalRepository<E>
+public interface HierarchicalRepository<T>
{
/**
* Add a new match to the repository
* @param match The regex to use to match against
* @param value the value to hold agains the match
*/
- void addMatch(String match, E value);
+ void addMatch(String match, T value);
/**
* return the value held against the nearest match
* @param match the match to look for
* @return the value
*/
- E getMatch(String match);
+ T getMatch(String match);
/**
* set the default value to fallback to if none found
* @param defaultValue the value
*/
- void setDefault(E defaultValue);
+ void setDefault(T defaultValue);
/**
* remove a match from the repository
Modified: trunk/src/main/org/jboss/messaging/util/Match.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/Match.java 2008-02-01 12:37:33 UTC (rev 3656)
+++ trunk/src/main/org/jboss/messaging/util/Match.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -21,29 +21,46 @@
*/
package org.jboss.messaging.util;
+import org.jboss.messaging.core.Mergeable;
+
import java.util.regex.Pattern;
/**
* a Match is the holder for the match string and the object to hold against it.
*/
-public class Match<E>
+public class Match<T>
{
+
+ public static String WORD_WILDCARD = "^";
+ private static String WORD_WILDCARD_REPLACEMENT = "[*[^.]]";
+ public static String WILDCARD = "*";
+ private static String WILDCARD_REPLACEMENT = ".+";
+ private static final String DOT = ".";
+ private static final String DOT_REPLACEMENT = "\\.";
+
private String match;
private Pattern pattern;
- private E value;
+ private T value;
+
public Match(String match)
{
this.match = match;
- //compile in advance for performance reasons
- //check for dangling characters
- if(match.length() > 1)
- pattern = Pattern.compile(match);
+ String actMatch = match;
+ //replace any regex characters
+ if(WILDCARD.equals(match))
+ {
+ actMatch = WILDCARD_REPLACEMENT;
+ }
else
{
- pattern = Pattern.compile(new StringBuilder("[").append(match).append("]").toString());
+ actMatch = actMatch.replace(WORD_WILDCARD, WORD_WILDCARD_REPLACEMENT);
+ actMatch = actMatch.replace(DOT, DOT_REPLACEMENT);
+ actMatch = actMatch.replace(WILDCARD, WILDCARD_REPLACEMENT);
}
+ pattern = Pattern.compile(actMatch);
+
}
@@ -63,12 +80,12 @@
}
- public E getValue()
+ public T getValue()
{
return value;
}
- public void setValue(E value)
+ public void setValue(T value)
{
this.value = value;
}
@@ -89,4 +106,22 @@
{
return (match != null ? match.hashCode() : 0);
}
+
+ /**
+ * utility method to verify consistency of match
+ * @param match
+ * @throws IllegalArgumentException
+ */
+ public static void verify(String match) throws IllegalArgumentException
+ {
+ if(match == null)
+ {
+ throw new IllegalArgumentException("match can not be null");
+ }
+ if(match.contains("*") && match.indexOf("*") < match.length() - 1)
+ {
+ throw new IllegalArgumentException("* can only be at end of match");
+ }
+ }
+
}
Added: trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/core/test/unit/QueueSettingsTest.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.core.test.unit;
+
+import junit.framework.TestCase;
+import org.jboss.messaging.core.QueueSettings;
+import org.jboss.messaging.core.impl.RoundRobinDistributionPolicy;
+
+/**
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class QueueSettingsTest extends TestCase
+{
+ public void testDefaults()
+ {
+ QueueSettings queueSettings = new QueueSettings();
+ assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+ assertEquals(queueSettings.getDistributionPolicyClass(), null);
+ assertEquals(queueSettings.getDLQ(), null);
+ assertEquals(queueSettings.isClustered(), Boolean.valueOf(false));
+ assertEquals(queueSettings.getExpiryQueue(), null);
+ assertEquals(queueSettings.getMaxDeliveryAttempts(), QueueSettings.DEFAULT_MAX_DELIVERY_ATTEMPTS);
+ assertEquals(queueSettings.getMaxSize(), QueueSettings.DEFAULT_MAX_SIZE);
+ assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), QueueSettings.DEFAULT_MESSAGE_COUNTER_HISTORY_DAY_LIMIT);
+ assertEquals(queueSettings.getRedeliveryDelay(), QueueSettings.DEFAULT_REDELIVER_DELAY);
+
+ }
+
+ public void testSingleMerge()
+ {
+ QueueSettings queueSettings = new QueueSettings();
+ QueueSettings queueSettingsToMerge = new QueueSettings();
+ queueSettingsToMerge.setClustered(true);
+ queueSettingsToMerge.setDLQ("testDlq");
+ queueSettingsToMerge.setExpiryQueue("testExpiryQueue");
+ queueSettingsToMerge.setMaxDeliveryAttempts(1000);
+ queueSettingsToMerge.setMaxSize(1001);
+ queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
+ queueSettingsToMerge.setRedeliveryDelay((long)1003);
+ queueSettings.merge(queueSettingsToMerge);
+ assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+ assertEquals(queueSettings.getDistributionPolicyClass(), null);
+ assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
+ assertEquals(queueSettings.getDLQ(), "testDlq");
+ assertEquals(queueSettings.getExpiryQueue(), "testExpiryQueue");
+ assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(1000));
+ assertEquals(queueSettings.getMaxSize(), Integer.valueOf(1001));
+ assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(1002));
+ assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(1003));
+ }
+
+ public void testMultipleMerge()
+ {
+ QueueSettings queueSettings = new QueueSettings();
+ QueueSettings queueSettingsToMerge = new QueueSettings();
+ queueSettingsToMerge.setClustered(true);
+ queueSettingsToMerge.setDLQ("testDlq");
+ queueSettingsToMerge.setExpiryQueue("testExpiryQueue");
+ queueSettingsToMerge.setMaxDeliveryAttempts(1000);
+ queueSettingsToMerge.setMaxSize(1001);
+ queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
+ queueSettingsToMerge.setRedeliveryDelay((long)1003);
+ queueSettings.merge(queueSettingsToMerge);
+
+ QueueSettings queueSettingsToMerge2 = new QueueSettings();
+ queueSettingsToMerge2.setClustered(true);
+ queueSettingsToMerge2.setExpiryQueue("testExpiryQueue2");
+ queueSettingsToMerge2.setMaxSize(2001);
+ queueSettingsToMerge2.setRedeliveryDelay((long)2003);
+ queueSettings.merge(queueSettingsToMerge2);
+
+ assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+ assertEquals(queueSettings.getDistributionPolicyClass(), null);
+ assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
+ assertEquals(queueSettings.getDLQ(), "testDlq");
+ assertEquals(queueSettings.getExpiryQueue(), "testExpiryQueue2");
+ assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(1000));
+ assertEquals(queueSettings.getMaxSize(), Integer.valueOf(2001));
+ assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(1002));
+ assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(2003));
+ }
+
+ public void testMultipleMergeAll()
+ {
+ QueueSettings queueSettings = new QueueSettings();
+ QueueSettings queueSettingsToMerge = new QueueSettings();
+ queueSettingsToMerge.setClustered(true);
+ queueSettingsToMerge.setDLQ("testDlq");
+ queueSettingsToMerge.setExpiryQueue("testExpiryQueue");
+ queueSettingsToMerge.setMaxDeliveryAttempts(1000);
+ queueSettingsToMerge.setMaxSize(1001);
+ queueSettingsToMerge.setMessageCounterHistoryDayLimit(1002);
+ queueSettingsToMerge.setRedeliveryDelay((long)1003);
+ queueSettings.merge(queueSettingsToMerge);
+
+ QueueSettings queueSettingsToMerge2 = new QueueSettings();
+ queueSettingsToMerge2.setClustered(false);
+ queueSettingsToMerge2.setDLQ("testDlq2");
+ queueSettingsToMerge2.setExpiryQueue("testExpiryQueue2");
+ queueSettingsToMerge2.setMaxDeliveryAttempts(2000);
+ queueSettingsToMerge2.setMaxSize(2001);
+ queueSettingsToMerge2.setMessageCounterHistoryDayLimit(2002);
+ queueSettingsToMerge2.setRedeliveryDelay((long)2003);
+ queueSettings.merge(queueSettingsToMerge2);
+
+ assertEquals(queueSettings.getDistributionPolicy().getClass(), QueueSettings.DEFAULT_DISTRIBUTION_POLICY.getClass());
+ assertEquals(queueSettings.getDistributionPolicyClass(), null);
+ assertEquals(queueSettings.isClustered(), Boolean.valueOf(true));
+ assertEquals(queueSettings.getDLQ(), "testDlq2");
+ assertEquals(queueSettings.getExpiryQueue(), "testExpiryQueue2");
+ assertEquals(queueSettings.getMaxDeliveryAttempts(), Integer.valueOf(2000));
+ assertEquals(queueSettings.getMaxSize(), Integer.valueOf(2001));
+ assertEquals(queueSettings.getMessageCounterHistoryDayLimit(), Integer.valueOf(2002));
+ assertEquals(queueSettings.getRedeliveryDelay(), Long.valueOf(2003));
+ }
+}
Modified: trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java 2008-02-01 12:37:33 UTC (rev 3656)
+++ trunk/tests/src/org/jboss/messaging/deployers/queue/tests/unit/QueueSettingsDeployerTest.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -59,7 +59,7 @@
queueSettings.setClustered(false);
queueSettings.setDLQ("DLQtest");
queueSettings.setExpiryQueue("ExpiryQueueTest");
- queueSettings.setRedeliveryDelay(100);
+ queueSettings.setRedeliveryDelay((long)100);
queueSettings.setMaxSize(-100);
queueSettings.setDistributionPolicyClass("org.jboss.messaging.core.impl.RoundRobinDistributionPolicy");
queueSettings.setMessageCounterHistoryDayLimit(1000);
Modified: trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java 2008-02-01 12:37:33 UTC (rev 3656)
+++ trunk/tests/src/org/jboss/messaging/util/test/unit/RepositoryTest.java 2008-02-01 15:22:09 UTC (rev 3657)
@@ -25,8 +25,11 @@
import org.jboss.jms.server.security.Role;
import org.jboss.messaging.util.HierarchicalObjectRepository;
import org.jboss.messaging.util.HierarchicalRepository;
+import org.jboss.messaging.core.Mergeable;
import java.util.HashSet;
+import java.util.List;
+import java.util.ArrayList;
/**
* @author <a href="ataylor at redhat.com">Andy Taylor</a>
@@ -67,7 +70,8 @@
roles2.add(new Role("test1"));
roles2.add(new Role("test2"));
roles2.add(new Role("test3"));
- securityRepository.addMatch("queues.another.andanother.*", roles2);
+ securityRepository.addMatch("queues.another.andanother", roles2);
+
HashSet<Role> hashSet = securityRepository.getMatch("queues.another.andanother");
assertEquals(hashSet.size(), 3);
}
@@ -86,22 +90,25 @@
public void testMultipleWildcards()
{
HierarchicalRepository<String> repository = new HierarchicalObjectRepository<String>();
+ repository.addMatch("*", "*");
repository.addMatch("a", "a");
repository.addMatch("a.*", "a.*");
+ repository.addMatch("a.^", "a.^");
repository.addMatch("a.b.c", "a.b.c");
- repository.addMatch("a.*.c", "a.*.c");
+ repository.addMatch("a.^.c", "a.^.c");
repository.addMatch("a.d.c", "a.d.c");
repository.addMatch("a.b.*", "a.b.*");
repository.addMatch("a.b", "a.b");
-
repository.addMatch("a.b.c.*", "a.b.c.*");
repository.addMatch("a.b.c.d", "a.b.c.d");
- repository.addMatch("a.*.*.d", "a.*.*.d");
- repository.addMatch("a.*.d.*", "a.*.d.*");
- String val = repository.getMatch("a.b");
+ repository.addMatch("a.^.^.d", "a.^.^.d");
+ repository.addMatch("a.^.d.*", "a.^.d.*");
+ String val = repository.getMatch("a");
+ assertEquals("a", val);
+ val = repository.getMatch("a.b");
assertEquals("a.b", val);
val = repository.getMatch("a.x");
- assertEquals("a.*", val);
+ assertEquals("a.^", val);
val = repository.getMatch("a.b.x");
assertEquals("a.b.*", val);
val = repository.getMatch("a.b.c");
@@ -109,15 +116,98 @@
val = repository.getMatch("a.d.c");
assertEquals("a.d.c", val);
val = repository.getMatch("a.x.c");
- assertEquals("a.*.c", val);
+ assertEquals("a.^.c", val);
val = repository.getMatch("a.b.c.d");
assertEquals("a.b.c.d", val);
val = repository.getMatch("a.x.c.d");
- assertEquals("a.*.*.d", val);
+ assertEquals("a.^.^.d", val);
val = repository.getMatch("a.b.x.d");
- assertEquals("a.b.*", val);
+ assertEquals("a.^.^.d", val);
val = repository.getMatch("a.d.x.d");
- assertEquals("a.*.*.d", val);
+ assertEquals("a.^.^.d", val);
+ val = repository.getMatch("a.d.d.g");
+ assertEquals("a.^.d.*", val);
+ val = repository.getMatch("zzzz.z.z.z.d.r.g.f.sd.s.fsdfd.fsdfs");
+ assertEquals("*", val);
+ }
+ public void testRepositoryMerge()
+ {
+ HierarchicalRepository<DummyMergeable> repository = new HierarchicalObjectRepository<DummyMergeable>();
+ repository.addMatch("*", new DummyMergeable(1));
+ repository.addMatch("a.*", new DummyMergeable(2));
+ repository.addMatch("b.*", new DummyMergeable(3));
+ repository.addMatch("a.b.*", new DummyMergeable(4));
+ repository.addMatch("b.c.*", new DummyMergeable(5));
+ repository.addMatch("a.b.c.*", new DummyMergeable(6));
+ repository.addMatch("a.b.^.d", new DummyMergeable(7));
+ repository.addMatch("a.b.c.^", new DummyMergeable(8));
+ repository.getMatch("a.b.c.d");
+ assertEquals(5, DummyMergeable.timesMerged);
+ assertTrue(DummyMergeable.contains(1));
+ assertTrue(DummyMergeable.contains(2));
+ assertTrue(DummyMergeable.contains(4));
+ assertTrue(DummyMergeable.contains(7));
+ assertTrue(DummyMergeable.contains(8));
+ DummyMergeable.reset();
+ repository.getMatch("a.b.c");
+ assertEquals(2, DummyMergeable.timesMerged);
+ assertTrue(DummyMergeable.contains(1));
+ assertTrue(DummyMergeable.contains(2));
+ assertTrue(DummyMergeable.contains(4));
+ DummyMergeable.reset();
+ repository.getMatch("a");
+ assertEquals(0, DummyMergeable.timesMerged);
+ DummyMergeable.reset();
}
+
+ public void testIllegalMatches()
+ {
+ HierarchicalRepository<String> repository = new HierarchicalObjectRepository<String>();
+ try
+ {
+ repository.addMatch("hjhjhjhjh.*.hhh", "test");
+ }
+ catch (IllegalArgumentException e)
+ {
+ //pass
+ }
+ try
+ {
+ repository.addMatch(null, "test");
+ }
+ catch (IllegalArgumentException e)
+ {
+ //pass
+ }
+ }
+
+ static class DummyMergeable implements Mergeable
+ {
+ static int timesMerged = 0;
+ static ArrayList<Integer> merged = new ArrayList<Integer>();
+ private Integer id;
+
+ static void reset()
+ {
+ timesMerged = 0;
+ DummyMergeable.merged = new ArrayList<Integer>();
+ }
+
+ static boolean contains(Integer i)
+ {
+ return DummyMergeable.merged.contains(i);
+ }
+ public DummyMergeable(Integer id)
+ {
+ this.id = id;
+ }
+
+ public void merge(Object merged)
+ {
+ timesMerged++;
+ DummyMergeable.merged.add(id);
+ DummyMergeable.merged.add(((DummyMergeable)merged).id);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list