You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2015/01/29 22:23:38 UTC
[3/3] qpid-jms git commit: Move these to the client and use a Mock'd
provider as we are just testing the contract of the methods based on state.
Move these to the client and use a Mock'd provider as we are just
testing the contract of the methods based on state.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/d76e0afd
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/d76e0afd
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/d76e0afd
Branch: refs/heads/master
Commit: d76e0afd3cb160b0c06527ecfae9fec75d85fb14
Parents: f33aba2
Author: Timothy Bish <ta...@gmail.com>
Authored: Thu Jan 29 16:23:22 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Thu Jan 29 16:23:22 2015 -0500
----------------------------------------------------------------------
.../qpid/jms/JmsConnectionClosedTest.java | 175 +++++++++++++++++++
.../qpid/jms/JmsConnectionFailedTest.java | 58 ++++++
.../java/org/apache/qpid/jms/test/Wait.java | 4 +-
.../qpid/jms/JmsConnectionClosedTest.java | 107 ------------
.../qpid/jms/JmsConnectionFailedTest.java | 60 -------
5 files changed, 235 insertions(+), 169 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d76e0afd/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java
new file mode 100644
index 0000000..1be9605
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java
@@ -0,0 +1,175 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms;
+
+import javax.jms.Destination;
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+
+import org.apache.qpid.jms.meta.JmsResource;
+import org.apache.qpid.jms.provider.Provider;
+import org.apache.qpid.jms.provider.ProviderFuture;
+import org.apache.qpid.jms.provider.ProviderListener;
+import org.apache.qpid.jms.test.QpidJmsTestCase;
+import org.apache.qpid.jms.util.IdGenerator;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test Connection methods contracts when state is closed.
+ */
+public class JmsConnectionClosedTest extends QpidJmsTestCase {
+
+ private static final Logger LOG = LoggerFactory.getLogger(JmsConnectionClosedTest.class);
+
+ protected Destination destination;
+
+ private final Provider provider = Mockito.mock(Provider.class);
+ private final IdGenerator clientIdGenerator = new IdGenerator();
+
+ protected JmsConnection connection;
+ protected ProviderListener providerListener;
+
+ protected JmsConnection createConnectionToMockProvider() throws Exception {
+
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ if (args[0] instanceof JmsResource) {
+ LOG.debug("Handling provider create resource: {}", args[0]);
+ ProviderFuture request = (ProviderFuture) args[1];
+ request.onSuccess();
+ }
+ return null;
+ }
+ }).when(provider).create(Mockito.any(JmsResource.class), Mockito.any(ProviderFuture.class));
+
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ if (args[0] instanceof JmsResource) {
+ LOG.debug("Handling provider destroy resource: {}", args[0]);
+ ProviderFuture request = (ProviderFuture) args[1];
+ request.onSuccess();
+ }
+ return null;
+ }
+ }).when(provider).destroy(Mockito.any(JmsResource.class), Mockito.any(ProviderFuture.class));
+
+ Mockito.doAnswer(new Answer<Object>() {
+ @Override
+ public Object answer(InvocationOnMock invocation) throws Throwable {
+ Object[] args = invocation.getArguments();
+ if (args[0] instanceof ProviderListener) {
+ providerListener = (ProviderListener) args[0];
+ }
+ return null;
+ }
+ }).when(provider).setProviderListener(Mockito.any(ProviderListener.class));
+
+ JmsConnection connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+ return connection;
+ }
+
+ protected JmsConnection createConnection() throws Exception {
+ connection = createConnectionToMockProvider();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ destination = session.createTopic("test");
+ connection.close();
+ return connection;
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ connection = createConnection();
+ }
+
+ @Override
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testGetClientIdFails() throws Exception {
+ connection.getClientID();
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testSetClientIdFails() throws Exception {
+ connection.setClientID("test");
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testGetMetaData() throws Exception {
+ connection.getMetaData();
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testGetExceptionListener() throws Exception {
+ connection.getExceptionListener();
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testSetExceptionListener() throws Exception {
+ connection.setExceptionListener(new ExceptionListener() {
+ @Override
+ public void onException(JMSException exception) {
+ }
+ });
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testStartFails() throws Exception {
+ connection.start();
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testStopFails() throws Exception {
+ connection.stop();
+ }
+
+ @Test(timeout=30000)
+ public void testClose() throws Exception {
+ connection.close();
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testCreateConnectionConsumerFails() throws Exception {
+ connection.createConnectionConsumer(destination, "", null, 1);
+ }
+
+ @Test(timeout=30000, expected=JMSException.class)
+ public void testCreateDurableConnectionConsumerFails() throws Exception {
+ connection.createDurableConnectionConsumer((Topic) destination, "id", "", null, 1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d76e0afd/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java
new file mode 100644
index 0000000..809cf97
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.qpid.jms;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+import javax.jms.ExceptionListener;
+import javax.jms.JMSException;
+
+import org.apache.qpid.jms.test.Wait;
+
+/**
+ * Test Connection methods contracts when connection has failed.
+ */
+public class JmsConnectionFailedTest extends JmsConnectionClosedTest {
+
+ @Override
+ protected JmsConnection createConnection() throws Exception {
+ connection = createConnectionToMockProvider();
+ connection.setExceptionListener(new ExceptionListener() {
+
+ @Override
+ public void onException(JMSException exception) {
+ }
+ });
+ connection.start();
+
+ providerListener.onConnectionFailure(new IOException());
+
+ final JmsConnection jmsConnection = connection;
+ assertTrue(Wait.waitFor(new Wait.Condition() {
+
+ @Override
+ public boolean isSatisified() throws Exception {
+ return !jmsConnection.isConnected();
+ }
+ }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(10)));
+
+ return connection;
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d76e0afd/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/Wait.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/Wait.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/Wait.java
index e95a2a9..bfb6053 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/Wait.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/Wait.java
@@ -21,7 +21,7 @@ import java.util.concurrent.TimeUnit;
public class Wait {
public static final long MAX_WAIT_MILLIS = 30 * 1000;
- public static final int SLEEP_MILLIS = 1000;
+ public static final long SLEEP_MILLIS = 1000;
public interface Condition {
boolean isSatisified() throws Exception;
@@ -35,7 +35,7 @@ public class Wait {
return waitFor(condition, duration, SLEEP_MILLIS);
}
- public static boolean waitFor(final Condition condition, final long duration, final int sleepMillis) throws Exception {
+ public static boolean waitFor(final Condition condition, final long duration, final long sleepMillis) throws Exception {
final long expiry = System.currentTimeMillis() + duration;
boolean conditionSatisified = condition.isSatisified();
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d76e0afd/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java
deleted file mode 100644
index f5d2892..0000000
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionClosedTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.qpid.jms;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-import javax.jms.Session;
-import javax.jms.Topic;
-
-import org.apache.qpid.jms.support.AmqpTestSupport;
-import org.junit.Test;
-
-/**
- * Test Connection methods contracts when state is closed.
- */
-public class JmsConnectionClosedTest extends AmqpTestSupport {
-
- protected Destination destination;
-
- protected Connection createConnection() throws Exception {
- connection = createAmqpConnection();
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- destination = session.createTopic("test");
- connection.close();
- return connection;
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testGetClientIdFails() throws Exception {
- createConnection();
- connection.getClientID();
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testSetClientIdFails() throws Exception {
- createConnection();
- connection.setClientID("test");
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testGetMetaData() throws Exception {
- createConnection();
- connection.getMetaData();
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testGetExceptionListener() throws Exception {
- createConnection();
- connection.getExceptionListener();
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testSetExceptionListener() throws Exception {
- createConnection();
- connection.setExceptionListener(new ExceptionListener() {
- @Override
- public void onException(JMSException exception) {
- }
- });
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testStartFails() throws Exception {
- createConnection();
- connection.start();
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testStopFails() throws Exception {
- createConnection();
- connection.stop();
- }
-
- @Test(timeout=30000)
- public void testClose() throws Exception {
- createConnection();
- connection.close();
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testCreateConnectionConsumerFails() throws Exception {
- createConnection();
- connection.createConnectionConsumer(destination, "", null, 1);
- }
-
- @Test(timeout=30000, expected=JMSException.class)
- public void testCreateDurableConnectionConsumerFails() throws Exception {
- createConnection();
- connection.createDurableConnectionConsumer((Topic) destination, "id", "", null, 1);
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d76e0afd/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java b/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java
deleted file mode 100644
index b14792e..0000000
--- a/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/JmsConnectionFailedTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.qpid.jms;
-
-import static org.junit.Assert.assertTrue;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.jms.Connection;
-import javax.jms.ExceptionListener;
-import javax.jms.JMSException;
-
-import org.apache.qpid.jms.JmsConnection;
-import org.apache.qpid.jms.support.Wait;
-
-/**
- * Test Connection methods contracts when connection has failed.
- */
-public class JmsConnectionFailedTest extends JmsConnectionClosedTest {
-
- @Override
- protected Connection createConnection() throws Exception {
- final CountDownLatch latch = new CountDownLatch(1);
- connection = createAmqpConnection();
- connection.setExceptionListener(new ExceptionListener() {
-
- @Override
- public void onException(JMSException exception) {
- latch.countDown();
- }
- });
- connection.start();
- stopPrimaryBroker();
- assertTrue(latch.await(20, TimeUnit.SECONDS));
- final JmsConnection jmsConnection = (JmsConnection) connection;
- assertTrue(Wait.waitFor(new Wait.Condition() {
-
- @Override
- public boolean isSatisified() throws Exception {
- return !jmsConnection.isConnected();
- }
- }));
- return connection;
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org