Repository: qpid-jms
Updated Branches:
  refs/heads/master 285f24e07 -> b07e61f46


Test error handling on close.

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/b07e61f4
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/b07e61f4
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/b07e61f4

Branch: refs/heads/master
Commit: b07e61f4671347de0f3a3fee53190acd1a705829
Parents: 285f24e
Author: Timothy Bish <tabish...@gmail.com>
Authored: Tue Feb 10 12:15:42 2015 -0500
Committer: Timothy Bish <tabish...@gmail.com>
Committed: Tue Feb 10 12:15:42 2015 -0500

----------------------------------------------------------------------
 .../provider/failover/FailoverProviderTest.java | 43 +++++++++++++++++++-
 .../qpid/jms/provider/mock/MockProvider.java    |  2 +
 .../jms/provider/mock/MockProviderStats.java    | 14 +++++++
 3 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b07e61f4/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTest.java
----------------------------------------------------------------------
diff --git 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTest.java
 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTest.java
index 3fece10..a66f6c8 100644
--- 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTest.java
+++ 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTest.java
@@ -17,6 +17,7 @@
 package org.apache.qpid.jms.provider.failover;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -25,7 +26,9 @@ import static org.junit.Assert.fail;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
@@ -67,10 +70,34 @@ public class FailoverProviderTest extends 
FailoverProviderTestSupport {
     }
 
     @Test(timeout = 30000)
-    public void testCreateProvider() {
+    public void testCreateProviderOnlyUris() {
+        FailoverProvider provider = new FailoverProvider(uris);
+        assertEquals(FailoverUriPool.DEFAULT_RANDOMIZE_ENABLED, 
provider.isRandomize());
+        assertNull(provider.getRemoteURI());
+        assertNotNull(provider.getNestedOptions());
+        assertTrue(provider.getNestedOptions().isEmpty());
+    }
+
+    @Test(timeout = 30000)
+    public void testCreateProviderOnlyNestedOptions() {
+        Map<String, String> options = new HashMap<String, String>();
+        options.put("transport.tcpNoDelay", "true");
+
+        FailoverProvider provider = new FailoverProvider(options);
+        assertEquals(FailoverUriPool.DEFAULT_RANDOMIZE_ENABLED, 
provider.isRandomize());
+        assertNull(provider.getRemoteURI());
+        assertNotNull(provider.getNestedOptions());
+        assertFalse(provider.getNestedOptions().isEmpty());
+        
assertTrue(provider.getNestedOptions().containsKey("transport.tcpNoDelay"));
+    }
+
+    @Test(timeout = 30000)
+    public void testCreateProviderWithNestedOptions() {
         FailoverProvider provider = new FailoverProvider(uris, 
Collections.<String, String>emptyMap());
         assertEquals(FailoverUriPool.DEFAULT_RANDOMIZE_ENABLED, 
provider.isRandomize());
         assertNull(provider.getRemoteURI());
+        assertNotNull(provider.getNestedOptions());
+        assertTrue(provider.getNestedOptions().isEmpty());
     }
 
     @Test(timeout = 30000)
@@ -200,4 +227,18 @@ public class FailoverProviderTest extends 
FailoverProviderTestSupport {
         assertEquals(5, 
MockProviderFactory.AGGRAGATED_PROVIDER_STATS.getProvidersCreated());
         assertEquals(5, 
MockProviderFactory.AGGRAGATED_PROVIDER_STATS.getConnectionAttempts());
     }
+
+    @Test(timeout = 30000)
+    public void testFailureOnCloseIsSwallowed() throws Exception {
+        JmsConnectionFactory factory = new JmsConnectionFactory(
+            "failover:(mock://localhost?mock.failOnClose=true)");
+
+        Connection connection = factory.createConnection();
+        connection.start();
+        connection.close();
+
+        assertEquals(1, 
MockProviderFactory.AGGRAGATED_PROVIDER_STATS.getProvidersCreated());
+        assertEquals(1, 
MockProviderFactory.AGGRAGATED_PROVIDER_STATS.getConnectionAttempts());
+        assertEquals(1, 
MockProviderFactory.AGGRAGATED_PROVIDER_STATS.getCloseAttempts());
+    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b07e61f4/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
----------------------------------------------------------------------
diff --git 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
index 70289cb..23c2d21 100644
--- 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
+++ 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProvider.java
@@ -77,6 +77,8 @@ public class MockProvider implements Provider {
 
     @Override
     public void close() {
+        stats.recordCloseAttempt();
+
         if (configuration.isFailOnClose()) {
             throw new RuntimeException();
         }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b07e61f4/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderStats.java
----------------------------------------------------------------------
diff --git 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderStats.java
 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderStats.java
index d682f82..18285e6 100644
--- 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderStats.java
+++ 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderStats.java
@@ -28,6 +28,7 @@ public class MockProviderStats {
 
     private final AtomicInteger providersCreated = new AtomicInteger();
     private final AtomicInteger connectionAttempts = new AtomicInteger();
+    private final AtomicInteger closeAttempts = new AtomicInteger();
     private final AtomicInteger createResourceCalls = new AtomicInteger();
     private final AtomicInteger startResourceCalls = new AtomicInteger();
     private final AtomicInteger stopResourceCalls = new AtomicInteger();
@@ -73,6 +74,18 @@ public class MockProviderStats {
         connectionAttempts.incrementAndGet();
     }
 
+    public int getCloseAttempts() {
+        return closeAttempts.get();
+    }
+
+    public void recordCloseAttempt() {
+        if (parent != null) {
+            parent.recordCloseAttempt();
+        }
+
+        closeAttempts.incrementAndGet();
+    }
+
     public int getCreateResourceCalls() {
         return createResourceCalls.get();
     }
@@ -220,6 +233,7 @@ public class MockProviderStats {
     public void reset() {
         providersCreated.set(0);
         connectionAttempts.set(0);
+        closeAttempts.set(0);
         createResourceCalls.set(0);
         startResourceCalls.set(0);
         stopResourceCalls.set(0);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to