qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject qpid-jms git commit: Don't require a MockProviderContext for the simpler MockProvider to operate.
Date Thu, 12 Feb 2015 19:50:26 GMT
Repository: qpid-jms
Updated Branches:
  refs/heads/master fc9dd8dc3 -> 244b2d87e


Don't require a MockProviderContext for the simpler MockProvider to
operate. 

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

Branch: refs/heads/master
Commit: 244b2d87e354de34b50837848ccaa6b580ec1875
Parents: fc9dd8d
Author: Timothy Bish <tabish121@gmail.com>
Authored: Thu Feb 12 14:50:20 2015 -0500
Committer: Timothy Bish <tabish121@gmail.com>
Committed: Thu Feb 12 14:50:20 2015 -0500

----------------------------------------------------------------------
 .../provider/failover/FailoverProviderTest.java | 43 ++++++++++----------
 .../failover/FailoverProviderTestSupport.java   | 15 +++++--
 .../qpid/jms/provider/mock/MockProvider.java    | 15 +++++--
 .../jms/provider/mock/MockProviderContext.java  | 20 +++++----
 .../jms/provider/mock/MockProviderFactory.java  |  7 +++-
 5 files changed, 59 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/244b2d87/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 833d962..719f348 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
@@ -43,7 +43,6 @@ import org.apache.qpid.jms.meta.JmsProducerInfo;
 import org.apache.qpid.jms.meta.JmsSessionInfo;
 import org.apache.qpid.jms.provider.DefaultProviderListener;
 import org.apache.qpid.jms.provider.ProviderFuture;
-import org.apache.qpid.jms.provider.mock.MockProviderContext;
 import org.apache.qpid.jms.test.Wait;
 import org.junit.Before;
 import org.junit.Test;
@@ -68,7 +67,7 @@ public class FailoverProviderTest extends FailoverProviderTestSupport {
         uris.add(new URI("mock://192.168.2.2:5672"));
         uris.add(new URI("mock://192.168.2.3:5672"));
         uris.add(new URI("mock://192.168.2.4:5672"));
-        
+
         super.setUp();
     }
 
@@ -169,8 +168,8 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
 
         provider.close();
 
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getProvidersCreated());
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getConnectionAttempts());
+        assertEquals(1, context.getContextStats().getProvidersCreated());
+        assertEquals(1, context.getContextStats().getConnectionAttempts());
     }
 
     @Test(timeout = 30000)
@@ -206,9 +205,9 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
             connection.close();
         }
 
-        assertEquals(5, MockProviderContext.INSTANCE.getContextStats().getProvidersCreated());
-        assertEquals(5, MockProviderContext.INSTANCE.getContextStats().getConnectionAttempts());
-        assertEquals(5, MockProviderContext.INSTANCE.getContextStats().getCloseAttempts());
+        assertEquals(5, context.getContextStats().getProvidersCreated());
+        assertEquals(5, context.getContextStats().getConnectionAttempts());
+        assertEquals(5, context.getContextStats().getCloseAttempts());
     }
 
     @Test(timeout = 30000)
@@ -228,9 +227,9 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
             connection.close();
         }
 
-        assertEquals(5, MockProviderContext.INSTANCE.getContextStats().getProvidersCreated());
-        assertEquals(5, MockProviderContext.INSTANCE.getContextStats().getConnectionAttempts());
-        assertEquals(5, MockProviderContext.INSTANCE.getContextStats().getCloseAttempts());
+        assertEquals(5, context.getContextStats().getProvidersCreated());
+        assertEquals(5, context.getContextStats().getConnectionAttempts());
+        assertEquals(5, context.getContextStats().getCloseAttempts());
     }
 
     @Test(timeout = 30000)
@@ -242,9 +241,9 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
         connection.start();
         connection.close();
 
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getProvidersCreated());
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getConnectionAttempts());
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getCloseAttempts());
+        assertEquals(1, context.getContextStats().getProvidersCreated());
+        assertEquals(1, context.getContextStats().getConnectionAttempts());
+        assertEquals(1, context.getContextStats().getCloseAttempts());
     }
 
     @Test(timeout = 30000)
@@ -257,8 +256,8 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
         connection.createSession(false, Session.AUTO_ACKNOWLEDGE).close();
         connection.close();
 
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getCreateResourceCalls(JmsSessionInfo.class));
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getDestroyResourceCalls(JmsSessionInfo.class));
+        assertEquals(1, context.getContextStats().getCreateResourceCalls(JmsSessionInfo.class));
+        assertEquals(1, context.getContextStats().getDestroyResourceCalls(JmsSessionInfo.class));
     }
 
     @Test(timeout = 30000)
@@ -273,9 +272,9 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
         session.createConsumer(destination).close();
         connection.close();
 
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getCreateResourceCalls(JmsConsumerInfo.class));
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getStartResourceCalls(JmsConsumerInfo.class));
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getDestroyResourceCalls(JmsConsumerInfo.class));
+        assertEquals(1, context.getContextStats().getCreateResourceCalls(JmsConsumerInfo.class));
+        assertEquals(1, context.getContextStats().getStartResourceCalls(JmsConsumerInfo.class));
+        assertEquals(1, context.getContextStats().getDestroyResourceCalls(JmsConsumerInfo.class));
     }
 
     @Test(timeout = 30000)
@@ -290,8 +289,8 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
         session.createProducer(destination).close();
         connection.close();
 
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getCreateResourceCalls(JmsProducerInfo.class));
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getDestroyResourceCalls(JmsProducerInfo.class));
+        assertEquals(1, context.getContextStats().getCreateResourceCalls(JmsProducerInfo.class));
+        assertEquals(1, context.getContextStats().getDestroyResourceCalls(JmsProducerInfo.class));
     }
 
     @Test(timeout = 30000)
@@ -305,7 +304,7 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
         session.recover();
         connection.close();
 
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getRecoverCalls());
+        assertEquals(1, context.getContextStats().getRecoverCalls());
     }
 
     @Test(timeout = 30000)
@@ -319,6 +318,6 @@ public class FailoverProviderTest extends FailoverProviderTestSupport
{
         session.unsubscribe("some-subscription");
         connection.close();
 
-        assertEquals(1, MockProviderContext.INSTANCE.getContextStats().getUnsubscribeCalls());
+        assertEquals(1, context.getContextStats().getUnsubscribeCalls());
     }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/244b2d87/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTestSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTestSupport.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTestSupport.java
index 5542910..879b807 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTestSupport.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/failover/FailoverProviderTestSupport.java
@@ -39,21 +39,28 @@ public class FailoverProviderTestSupport extends QpidJmsTestCase {
     private final AtomicLong nextSessionId = new AtomicLong();
     private final AtomicLong nextConsumerId = new AtomicLong();
 
+    protected MockProviderContext context;
+
     @Override
     @Before
     public void setUp() throws Exception {
-        super.setUp();
-
         nextSessionId.set(0);
         nextConsumerId.set(0);
 
-        MockProviderContext.INSTANCE.reset();
+        context = new MockProviderContext();
+        context.start();
+
+        super.setUp();
     }
 
     @Override
     @After
     public void tearDown() throws Exception {
-        MockProviderContext.INSTANCE.reset();
+        if (context != null) {
+            context.shutdown();
+            context = null;
+        }
+
         super.tearDown();
     }
 

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/244b2d87/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 3d32509..3872302 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
@@ -62,6 +62,7 @@ public class MockProvider implements Provider {
     private final MockProviderConfiguration configuration;
     private final ScheduledExecutorService serializer;
     private final AtomicBoolean closed = new AtomicBoolean();
+    private final MockProviderContext context;
 
     private long connectTimeout = JmsConnectionInfo.DEFAULT_CONNECT_TIMEOUT;
     private long closeTimeout = JmsConnectionInfo.DEFAULT_CLOSE_TIMEOUT;
@@ -69,10 +70,12 @@ public class MockProvider implements Provider {
     private MockProviderListener eventListener;
     private ProviderListener listener;
 
-    public MockProvider(URI remoteURI, MockProviderConfiguration configuration, MockProviderStats
global) {
+    public MockProvider(URI remoteURI, MockProviderConfiguration configuration, MockProviderContext
context) {
         this.remoteURI = remoteURI;
         this.configuration = configuration;
-        this.stats = new MockProviderStats(global);
+        this.context = context;
+        this.stats = new MockProviderStats(context != null ? context.getContextStats() :
null);
+
         this.serializer = Executors.newSingleThreadScheduledExecutor(new ThreadFactory()
{
 
             @Override
@@ -97,7 +100,9 @@ public class MockProvider implements Provider {
             throw new IOException("Failed to connect to: " + remoteURI);
         }
 
-        MockProviderContext.INSTANCE.connect(this);
+        if (context != null) {
+            context.connect(this);
+        }
     }
 
     @Override
@@ -125,7 +130,9 @@ public class MockProvider implements Provider {
                 public void run() {
                     try {
 
-                        MockProviderContext.INSTANCE.disconnect(MockProvider.this);
+                        if (context != null) {
+                            context.disconnect(MockProvider.this);
+                        }
 
                         if (configuration.isFailOnClose()) {
                             request.onFailure(new RuntimeException());

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/244b2d87/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderContext.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderContext.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderContext.java
index 905599f..5b55532 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderContext.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderContext.java
@@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 public class MockProviderContext {
 
-    public static final MockProviderContext INSTANCE = new MockProviderContext();
+    public static MockProviderContext INSTANCE;
 
     private final Map<String, MockProvider> activeProviders = new ConcurrentHashMap<String,
MockProvider>();
     private final MockProviderStats contextStats = new MockProviderStats();
@@ -52,6 +52,15 @@ public class MockProviderContext {
         }
     }
 
+    public void start() {
+        contextStats.reset();
+        activeProviders.clear();
+        lastRegistered = null;
+        offline = false;
+
+        MockProviderContext.INSTANCE = this;
+    }
+
     public void shutdown() {
         offline = true;
         List<MockProvider> active = new ArrayList<MockProvider>(activeProviders.values());
@@ -60,13 +69,8 @@ public class MockProviderContext {
         }
         activeProviders.clear();
         lastRegistered = null;
-    }
 
-    public void reset() {
-        contextStats.reset();
-        activeProviders.clear();
-        lastRegistered = null;
-        offline = false;
+        MockProviderContext.INSTANCE = null;
     }
 
     public MockProvider getProvider(String providerId) {
@@ -80,6 +84,4 @@ public class MockProviderContext {
     public MockProviderStats getContextStats() {
         return contextStats;
     }
-
-    private MockProviderContext() {}
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/244b2d87/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderFactory.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderFactory.java
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderFactory.java
index 9e60223..979aaf8 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderFactory.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/mock/MockProviderFactory.java
@@ -36,7 +36,10 @@ public class MockProviderFactory extends ProviderFactory {
         remoteURI = PropertyUtil.replaceQuery(remoteURI, map);
 
         MockProviderConfiguration configuration = new MockProviderConfiguration();
-        MockProviderContext.INSTANCE.getContextStats().recordProviderCreated();
+        MockProviderContext context = MockProviderContext.INSTANCE;
+        if (context != null) {
+            context.getContextStats().recordProviderCreated();
+        }
 
         Map<String, String> unused = PropertyUtil.setProperties(configuration, providerOptions);
         if (!unused.isEmpty()) {
@@ -48,7 +51,7 @@ public class MockProviderFactory extends ProviderFactory {
             throw new IllegalArgumentException(msg);
         }
 
-        return new MockProvider(remoteURI, configuration, MockProviderContext.INSTANCE.getContextStats());
+        return new MockProvider(remoteURI, configuration, context);
     }
 
     @Override


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


Mime
View raw message