diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2009-06-18 21:03:12 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2009-06-18 21:03:12 +0000 |
| commit | 0ac0ba5e1d146a133abbd1ea0ddcabe6d25ab987 (patch) | |
| tree | 0d65318b1d4b1ff9eef825c31e6113d334146871 | |
| parent | c2e8e0f59377b04019decbe2eb6c6f3db634b988 (diff) | |
| download | qpid-python-0ac0ba5e1d146a133abbd1ea0ddcabe6d25ab987.tar.gz | |
made test ports configurable; this required adding variable expansion to PropertiesFileInitialContextFactory
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@786269 13f79535-47bb-0310-9956-ffa450edef68
7 files changed, 174 insertions, 13 deletions
diff --git a/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java b/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java index 4b92d972b2..39176cd8dd 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactory.java @@ -48,6 +48,7 @@ import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.url.AMQBindingURL; import org.apache.qpid.url.BindingURL; import org.apache.qpid.url.URLSyntaxException; +import org.apache.qpid.util.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,9 +85,20 @@ public class PropertiesFileInitialContextFactory implements InitialContextFactor Properties p = new Properties(); p.load(new BufferedInputStream(new FileInputStream(file))); + Strings.Resolver resolver = new Strings.ChainedResolver + (Strings.SYSTEM_RESOLVER, new Strings.PropertiesResolver(p)); - environment.putAll(p); - System.getProperties().putAll(p); + for (Map.Entry me : p.entrySet()) + { + String key = (String) me.getKey(); + String value = (String) me.getValue(); + String expanded = Strings.expand(value, resolver); + environment.put(key, expanded); + if (System.getProperty(key) == null) + { + System.setProperty(key, expanded); + } + } _logger.info("Loaded Context Properties:" + environment.toString()); } else diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java b/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java index a0bbbb22de..04bf174ff0 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/util/Strings.java @@ -22,6 +22,12 @@ package org.apache.qpid.util; import java.io.UnsupportedEncodingException; +import java.util.Map; +import java.util.Properties; +import java.util.Stack; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Strings @@ -91,4 +97,142 @@ public final class Strings } } + private static final Pattern VAR = Pattern.compile("(?:\\$\\{([^\\}]*)\\})|(?:\\$(\\$))"); + + public static interface Resolver + { + String resolve(String variable); + } + + public static class MapResolver implements Resolver + { + + private final Map<String,String> map; + + public MapResolver(Map<String,String> map) + { + this.map = map; + } + + public String resolve(String variable) + { + return map.get(variable); + } + } + + public static class PropertiesResolver implements Resolver + { + + private final Properties properties; + + public PropertiesResolver(Properties properties) + { + this.properties = properties; + } + + public String resolve(String variable) + { + return properties.getProperty(variable); + } + } + + public static class ChainedResolver implements Resolver + { + private final Resolver primary; + private final Resolver secondary; + + public ChainedResolver(Resolver primary, Resolver secondary) + { + this.primary = primary; + this.secondary = secondary; + } + + public String resolve(String variable) + { + String result = primary.resolve(variable); + if (result == null) + { + result = secondary.resolve(variable); + } + return result; + } + } + + public static final Resolver SYSTEM_RESOLVER = new Resolver() + { + public String resolve(String variable) + { + String result = System.getProperty(variable); + if (result == null) + { + result = System.getenv(variable); + } + return result; + } + }; + + public static final String expand(String input) + { + return expand(input, SYSTEM_RESOLVER); + } + + public static final String expand(String input, Resolver resolver) + { + return expand(input, resolver, new Stack()); + } + + private static final String expand(String input, Resolver resolver, Stack<String> stack) + { + Matcher m = VAR.matcher(input); + StringBuffer result = new StringBuffer(); + while (m.find()) + { + String var = m.group(1); + if (var == null) + { + String esc = m.group(2); + if ("$".equals(esc)) + { + m.appendReplacement(result, Matcher.quoteReplacement("$")); + } + else + { + throw new IllegalArgumentException(esc); + } + } + else + { + m.appendReplacement(result, Matcher.quoteReplacement(resolve(var, resolver, stack))); + } + } + m.appendTail(result); + return result.toString(); + } + + private static final String resolve(String var, Resolver resolver, Stack<String> stack) + { + if (stack.contains(var)) + { + throw new IllegalArgumentException + (String.format("recursively defined variable: %s stack=%s", var, + stack)); + } + + String result = resolver.resolve(var); + if (result == null) + { + throw new IllegalArgumentException("no such variable: " + var); + } + + stack.push(var); + try + { + return expand(result, resolver, stack); + } + finally + { + stack.pop(); + } + } + } diff --git a/qpid/java/module.xml b/qpid/java/module.xml index 33238c295e..6ff2e01e83 100644 --- a/qpid/java/module.xml +++ b/qpid/java/module.xml @@ -236,10 +236,11 @@ <sysproperty key="broker.clean" value="${broker.clean}"/> <sysproperty key="broker.version" value="${broker.version}"/> <sysproperty key="broker.ready" value="${broker.ready}" /> - <sysproperty key="test.excludes" value="${test.excludes}"/> - <sysproperty key="test.excludesfile" value="${test.excludesfile}"/> <sysproperty key="test.output" value="${module.results}"/> <syspropertyset> + <propertyref prefix="test"/> + </syspropertyset> + <syspropertyset> <propertyref prefix="profile"/> </syspropertyset> <syspropertyset> diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/UTF8Test.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/UTF8Test.java index 39ecf0a209..8a9aee94dd 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/UTF8Test.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/message/UTF8Test.java @@ -92,7 +92,7 @@ public class UTF8Test extends QpidTestCase Connection conn = new Connection(); if (!_broker.equals(QpidTestCase.EXTERNAL) && !isBroker08()) { - conn.connect("localhost", 5672, "test", "guest", "guest",false); + conn.connect("localhost", QpidTestCase.DEFAULT_PORT, "test", "guest", "guest",false); } else { diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java index b185ec60a2..1e172be855 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/FailoverBaseCase.java @@ -26,7 +26,7 @@ public class FailoverBaseCase extends QpidTestCase { public static int FAILING_VM_PORT = 2; - public static int FAILING_PORT = 5673; + public static int FAILING_PORT = DEFAULT_PORT + 1; protected int failingPort; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java index bd481df8a0..a28e1181fe 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java @@ -148,8 +148,8 @@ public class QpidTestCase extends TestCase private static final String QPID_HOME = "QPID_HOME"; - protected int DEFAULT_VM_PORT = 1; - protected int DEFAULT_PORT = 5672; + protected static int DEFAULT_VM_PORT = 1; + protected static int DEFAULT_PORT = Integer.getInteger("test.port", 5672); protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA); protected String _broker = System.getProperty(BROKER, VM); diff --git a/qpid/java/test-provider.properties b/qpid/java/test-provider.properties index bcbe4866f3..2479b5a5f0 100644 --- a/qpid/java/test-provider.properties +++ b/qpid/java/test-provider.properties @@ -19,14 +19,18 @@ # # -connectionfactory.default = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5672' +test.port=5672 +test.port.ssl=5671 +test.port.alt=5673 + +connectionfactory.default = amqp://username:password@clientid/test?brokerlist='tcp://localhost:${test.port}' connectionfactory.default.vm = amqp://username:password@clientid/test?brokerlist='vm://:1' -connectionfactory.ssl = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5671?ssl='true'' +connectionfactory.ssl = amqp://username:password@clientid/test?brokerlist='tcp://localhost:${test.port.ssl}?ssl='true'' -connectionfactory.failover = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5673;tcp://localhost:5672'&sync_ack='true'&sync_publish='all'&failover='roundrobin?cyclecount='20'' +connectionfactory.failover = amqp://username:password@clientid/test?brokerlist='tcp://localhost:${test.port.alt};tcp://localhost:${test.port}'&sync_ack='true'&sync_publish='all'&failover='roundrobin?cyclecount='20'' connectionfactory.failover.vm = amqp://username:password@clientid/test?brokerlist='vm://:2;vm://:1' -connectionfactory.connection1 = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5672' -connectionfactory.connection2 = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5673' +connectionfactory.connection1 = amqp://username:password@clientid/test?brokerlist='tcp://localhost:${test.port}' +connectionfactory.connection2 = amqp://username:password@clientid/test?brokerlist='tcp://localhost:${test.port.alt}' connectionfactory.connection1.vm = amqp://username:password@clientid/test?brokerlist='vm://:1' connectionfactory.connection2.vm = amqp://username:password@clientid/test?brokerlist='vm://:2' |
