Repository: qpid-jms Updated Branches: refs/heads/master 47348747d -> 6d5a52a0e
Just use collections and always return empty ones to avoid any NPE issues Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/d0ccd408 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/d0ccd408 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/d0ccd408 Branch: refs/heads/master Commit: d0ccd408be0a3921bf2b0db77ccd1b310d2d9512 Parents: 4734874 Author: Timothy Bish <tabish...@gmail.com> Authored: Fri Feb 6 17:21:05 2015 -0500 Committer: Timothy Bish <tabish...@gmail.com> Committed: Fri Feb 6 17:21:05 2015 -0500 ---------------------------------------------------------------------- .../jms/provider/failover/FailoverProvider.java | 4 ++-- .../jms/provider/failover/FailoverUriPool.java | 3 ++- .../org/apache/qpid/jms/util/URISupport.java | 15 ++++++------- .../provider/failover/FailoverUriPoolTest.java | 16 +++++++------- .../failover/FiloverProviderFactoryTest.java | 1 + .../apache/qpid/jms/util/URISupportTest.java | 22 +++++++++----------- .../discovery/DiscoveryProviderFactory.java | 2 +- 7 files changed, 32 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d0ccd408/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java index 160455f..a080fb1 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverProvider.java @@ -113,11 +113,11 @@ public class FailoverProvider extends DefaultProviderListener implements Provide this(null, nestedOptions); } - public FailoverProvider(URI[] uris) { + public FailoverProvider(List<URI> uris) { this(uris, null); } - public FailoverProvider(URI[] uris, Map<String, String> nestedOptions) { + public FailoverProvider(List<URI> uris, Map<String, String> nestedOptions) { this.uris = new FailoverUriPool(uris, nestedOptions); this.serializer = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d0ccd408/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverUriPool.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverUriPool.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverUriPool.java index eaf6a2d..624c05a 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverUriPool.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/failover/FailoverUriPool.java @@ -22,6 +22,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Collections; import java.util.LinkedList; +import java.util.List; import java.util.Map; import org.apache.qpid.jms.util.URISupport; @@ -47,7 +48,7 @@ public class FailoverUriPool { this.nestedOptions = Collections.emptyMap(); } - public FailoverUriPool(URI[] uris, Map<String, String> nestedOptions) { + public FailoverUriPool(List<URI> uris, Map<String, String> nestedOptions) { this.uris = new LinkedList<URI>(); if (nestedOptions != null) { this.nestedOptions = nestedOptions; http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d0ccd408/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/URISupport.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/URISupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/URISupport.java index 0a649f3..e2aaaa0 100644 --- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/URISupport.java +++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/util/URISupport.java @@ -34,14 +34,15 @@ public class URISupport { * the individual URIs that comprise the composite one. */ public static class CompositeData { + private String host; private String scheme; private String path; - private URI components[]; - private Map<String, String> parameters; + private List<URI> components = Collections.emptyList(); + private Map<String, String> parameters = Collections.emptyMap(); private String fragment; - public URI[] getComponents() { + public List<URI> getComponents() { return components; } @@ -76,11 +77,11 @@ public class URISupport { sb.append(host); } else { sb.append('('); - for (int i = 0; i < components.length; i++) { + for (int i = 0; i < components.size(); i++) { if (i != 0) { sb.append(','); } - sb.append(components[i].toString()); + sb.append(components.get(i).toString()); } sb.append(')'); } @@ -173,9 +174,9 @@ public class URISupport { } String components[] = splitComponents(componentString); - rc.components = new URI[components.length]; + rc.components = new ArrayList<URI>(components.length); for (int i = 0; i < components.length; i++) { - rc.components[i] = new URI(components[i].trim()); + rc.components.add(new URI(components[i].trim())); } p = params.indexOf("?"); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d0ccd408/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverUriPoolTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverUriPoolTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverUriPoolTest.java index de395eb..2636830 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverUriPoolTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverUriPoolTest.java @@ -71,7 +71,7 @@ public class FailoverUriPoolTest { @Test public void testCreateEmptyPoolWithURIs() throws URISyntaxException { - FailoverUriPool pool = new FailoverUriPool(uris.toArray(new URI[0]), null); + FailoverUriPool pool = new FailoverUriPool(uris, null); assertEquals(FailoverUriPool.DEFAULT_RANDOMIZE_ENABLED, pool.isRandomize()); assertNotNull(pool.getNestedOptions()); @@ -88,7 +88,7 @@ public class FailoverUriPoolTest { @Test public void testGetNextFromSingleValuePool() { - FailoverUriPool pool = new FailoverUriPool(new URI[] {uris.get(0) }, null); + FailoverUriPool pool = new FailoverUriPool(uris.subList(0, 1), null); assertEquals(uris.get(0), pool.getNext()); assertEquals(uris.get(0), pool.getNext()); @@ -106,7 +106,7 @@ public class FailoverUriPoolTest { @Test public void testDuplicatesNotAdded() { - FailoverUriPool pool = new FailoverUriPool(uris.toArray(new URI[0]), null); + FailoverUriPool pool = new FailoverUriPool(uris, null); assertEquals(uris.size(), pool.size()); pool.add(uris.get(0)); @@ -195,7 +195,7 @@ public class FailoverUriPoolTest { public void testAddUriToPoolRandomized() throws URISyntaxException { URI newUri = new URI("tcp://192.168.2." + (uris.size() + 1) + ":5672"); - FailoverUriPool pool = new FailoverUriPool(uris.toArray(new URI[0]), null); + FailoverUriPool pool = new FailoverUriPool(uris, null); pool.setRandomize(true); pool.add(newUri); @@ -217,7 +217,7 @@ public class FailoverUriPoolTest { public void testAddUriToPoolNotRandomized() throws URISyntaxException { URI newUri = new URI("tcp://192.168.2." + (uris.size() + 1) + ":5672"); - FailoverUriPool pool = new FailoverUriPool(uris.toArray(new URI[0]), null); + FailoverUriPool pool = new FailoverUriPool(uris, null); pool.setRandomize(false); pool.add(newUri); @@ -230,7 +230,7 @@ public class FailoverUriPoolTest { @Test public void testRemoveURIFromPool() throws URISyntaxException { - FailoverUriPool pool = new FailoverUriPool(uris.toArray(new URI[0]), null); + FailoverUriPool pool = new FailoverUriPool(uris, null); pool.setRandomize(false); URI removed = uris.get(0); @@ -256,7 +256,7 @@ public class FailoverUriPoolTest { private void assertConnectedEffectOnPool(boolean randomize, boolean shouldShuffle) { - FailoverUriPool pool = new FailoverUriPool(uris.toArray(new URI[0]), null); + FailoverUriPool pool = new FailoverUriPool(uris, null); pool.setRandomize(randomize); List<URI> current = new ArrayList<URI>(); @@ -291,7 +291,7 @@ public class FailoverUriPoolTest { @Test public void testAddOrRemoveNullHasNoAffect() throws URISyntaxException { - FailoverUriPool pool = new FailoverUriPool(uris.toArray(new URI[0]), null); + FailoverUriPool pool = new FailoverUriPool(uris, null); assertEquals(uris.size(), pool.size()); pool.add(null); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d0ccd408/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FiloverProviderFactoryTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FiloverProviderFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FiloverProviderFactoryTest.java index 4b43ef3..d2db7c2 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FiloverProviderFactoryTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FiloverProviderFactoryTest.java @@ -44,6 +44,7 @@ public class FiloverProviderFactoryTest { @Test(timeout = 60000) public void testCreateProvider() throws Exception { + assertNotNull(factory.getName()); Provider provider = factory.createProvider(baseURI); assertNotNull(provider); assertTrue(provider instanceof FailoverProvider); http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d0ccd408/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java index 7459e82..a858758 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java @@ -21,17 +21,15 @@ import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; -import org.apache.qpid.jms.util.PropertyUtil; -import org.apache.qpid.jms.util.URISupport; -import org.apache.qpid.jms.util.URISupport.CompositeData; - import junit.framework.TestCase; +import org.apache.qpid.jms.util.URISupport.CompositeData; + public class URISupportTest extends TestCase { public void testEmptyCompositePath() throws Exception { CompositeData data = URISupport.parseComposite(new URI("broker:()/localhost?persistent=false")); - assertEquals(0, data.getComponents().length); + assertEquals(0, data.getComponents().size()); } public void testCompositePath() throws Exception { @@ -43,19 +41,19 @@ public class URISupportTest extends TestCase { public void testSimpleComposite() throws Exception { CompositeData data = URISupport.parseComposite(new URI("test:part1")); - assertEquals(1, data.getComponents().length); + assertEquals(1, data.getComponents().size()); } public void testComposite() throws Exception { URI uri = new URI("test:(part1://host,part2://(sub1://part,sube2:part))"); CompositeData data = URISupport.parseComposite(uri); - assertEquals(2, data.getComponents().length); + assertEquals(2, data.getComponents().size()); } public void testEmptyCompositeWithParenthesisInParam() throws Exception { URI uri = new URI("failover://()?updateURIsURL=file:/C:/Dir(1)/a.csv"); CompositeData data = URISupport.parseComposite(uri); - assertEquals(0, data.getComponents().length); + assertEquals(0, data.getComponents().size()); assertEquals(1, data.getParameters().size()); assertTrue(data.getParameters().containsKey("updateURIsURL")); assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL")); @@ -64,7 +62,7 @@ public class URISupportTest extends TestCase { public void testCompositeWithParenthesisInParam() throws Exception { URI uri = new URI("failover://(test)?updateURIsURL=file:/C:/Dir(1)/a.csv"); CompositeData data = URISupport.parseComposite(uri); - assertEquals(1, data.getComponents().length); + assertEquals(1, data.getComponents().size()); assertEquals(1, data.getParameters().size()); assertTrue(data.getParameters().containsKey("updateURIsURL")); assertEquals("file:/C:/Dir(1)/a.csv", data.getParameters().get("updateURIsURL")); @@ -72,9 +70,9 @@ public class URISupportTest extends TestCase { public void testCompositeWithComponentParam() throws Exception { CompositeData data = URISupport.parseComposite(new URI("test:(part1://host?part1=true)?outside=true")); - assertEquals(1, data.getComponents().length); + assertEquals(1, data.getComponents().size()); assertEquals(1, data.getParameters().size()); - Map<String, String> part1Params = URISupport.parseParameters(data.getComponents()[0]); + Map<String, String> part1Params = URISupport.parseParameters(data.getComponents().get(0)); assertEquals(1, part1Params.size()); assertTrue(part1Params.containsKey("part1")); } @@ -99,7 +97,7 @@ public class URISupportTest extends TestCase { public void testParsingCompositeURI() throws URISyntaxException { CompositeData data = URISupport.parseComposite(new URI("broker://(tcp://localhost:61616)?name=foo")); - assertEquals("one component", 1, data.getComponents().length); + assertEquals("one component", 1, data.getComponents().size()); assertEquals("Size: " + data.getParameters(), 1, data.getParameters().size()); } http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d0ccd408/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/DiscoveryProviderFactory.java ---------------------------------------------------------------------- diff --git a/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/DiscoveryProviderFactory.java b/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/DiscoveryProviderFactory.java index 179571e..1015e33 100644 --- a/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/DiscoveryProviderFactory.java +++ b/qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/DiscoveryProviderFactory.java @@ -52,7 +52,7 @@ public class DiscoveryProviderFactory extends ProviderFactory { DiscoveryProvider discovery = new DiscoveryProvider(remoteURI, failover); PropertyUtil.setProperties(discovery, options); - DiscoveryAgent agent = DiscoveryAgentFactory.createAgent(composite.getComponents()[0]); + DiscoveryAgent agent = DiscoveryAgentFactory.createAgent(composite.getComponents().get(0)); discovery.setDiscoveryAgent(agent); return discovery; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org