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/02/12 00:46:03 UTC
[1/2] qpid-jms git commit: Make the mock provider behave more like
the real thing.
Repository: qpid-jms
Updated Branches:
refs/heads/master 1cc00eef8 -> e5ed52ec0
Make the mock provider behave more like the real thing.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/d8766377
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/d8766377
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/d8766377
Branch: refs/heads/master
Commit: d876637764b1171e5b3eb30f395c64420f0726f0
Parents: 1cc00ee
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Feb 11 16:13:59 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Feb 11 16:13:59 2015 -0500
----------------------------------------------------------------------
.../qpid/jms/provider/mock/MockProvider.java | 341 ++++++++++++++++---
1 file changed, 290 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d8766377/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 7b64799..90146d7 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
@@ -19,6 +19,12 @@ package org.apache.qpid.jms.provider.mock;
import java.io.IOException;
import java.net.URI;
import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.jms.JMSException;
@@ -32,8 +38,13 @@ import org.apache.qpid.jms.meta.JmsResource;
import org.apache.qpid.jms.meta.JmsSessionId;
import org.apache.qpid.jms.provider.AsyncResult;
import org.apache.qpid.jms.provider.Provider;
+import org.apache.qpid.jms.provider.ProviderClosedException;
import org.apache.qpid.jms.provider.ProviderConstants.ACK_TYPE;
+import org.apache.qpid.jms.provider.ProviderFuture;
import org.apache.qpid.jms.provider.ProviderListener;
+import org.apache.qpid.jms.provider.amqp.AmqpProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Mock Provider instance used in testing higher level classes that interact
@@ -41,11 +52,19 @@ import org.apache.qpid.jms.provider.ProviderListener;
*/
public class MockProvider implements Provider {
+ private static final Logger LOG = LoggerFactory.getLogger(AmqpProvider.class);
+
+ private static final AtomicInteger PROVIDER_SEQUENCE = new AtomicInteger();
+
private final JmsMessageFactory messageFactory = new JmsDefaultMessageFactory();
private final MockProviderStats stats;
private final URI remoteURI;
private final MockProviderConfiguration configuration;
+ private final ScheduledExecutorService serializer;
+ private final AtomicBoolean closed = new AtomicBoolean();
+ private long connectTimeout = JmsConnectionInfo.DEFAULT_CONNECT_TIMEOUT;
+ private long closeTimeout = JmsConnectionInfo.DEFAULT_CLOSE_TIMEOUT;
private String providerId = UUID.randomUUID().toString();
private MockProviderListener eventListener;
private ProviderListener listener;
@@ -54,10 +73,24 @@ public class MockProvider implements Provider {
this.remoteURI = remoteURI;
this.configuration = configuration;
this.stats = new MockProviderStats(global);
+ this.serializer = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
+
+ @Override
+ public Thread newThread(Runnable runner) {
+ Thread serial = new Thread(runner);
+ serial.setDaemon(true);
+ serial.setName(MockProvider.this.getClass().getSimpleName() + ":(" +
+ PROVIDER_SEQUENCE.incrementAndGet() + "):[" +
+ getRemoteURI() + "]");
+ return serial;
+ }
+ });
}
@Override
public void connect() throws IOException {
+ checkClosed();
+
stats.recordConnectAttempt();
if (configuration.isFailOnConnect()) {
@@ -69,6 +102,7 @@ public class MockProvider implements Provider {
@Override
public void start() throws IOException, IllegalStateException {
+ checkClosed();
if (listener == null) {
throw new IllegalStateException("Must set a provider listener prior to calling start.");
@@ -81,12 +115,41 @@ public class MockProvider implements Provider {
@Override
public void close() {
- stats.recordCloseAttempt();
-
- MockProviderContext.INSTANCE.disconnect(this);
-
- if (configuration.isFailOnClose()) {
- throw new RuntimeException();
+ if (closed.compareAndSet(false, true)) {
+ stats.recordCloseAttempt();
+
+ final ProviderFuture request = new ProviderFuture();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+
+ MockProviderContext.INSTANCE.disconnect(MockProvider.this);
+
+ if (configuration.isFailOnClose()) {
+ request.onFailure(new RuntimeException());
+ } else {
+ request.onSuccess();
+ }
+ } catch (Exception e) {
+ LOG.debug("Caught exception while closing the MockProvider");
+ request.onFailure(e);
+ }
+ }
+ });
+
+ try {
+ if (closeTimeout < 0) {
+ request.sync();
+ } else {
+ request.sync(closeTimeout, TimeUnit.MILLISECONDS);
+ }
+ } catch (IOException e) {
+ LOG.warn("Error caught while closing Provider: ", e.getMessage());
+ } finally {
+ serializer.shutdown();
+ }
}
}
@@ -96,93 +159,245 @@ public class MockProvider implements Provider {
}
@Override
- public void create(JmsResource resource, AsyncResult request) throws IOException, JMSException {
- stats.recordCreateResourceCall(resource);
-
- if (resource instanceof JmsConnectionInfo) {
- if (listener != null) {
- listener.onConnectionEstablished(remoteURI);
+ public void create(final JmsResource resource, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordCreateResourceCall(resource);
+
+ if (resource instanceof JmsConnectionInfo) {
+ if (listener != null) {
+ listener.onConnectionEstablished(remoteURI);
+ }
+ }
+
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
}
- }
+ });
+ }
- request.onSuccess();
+ @Override
+ public void start(final JmsResource resource, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordStartResourceCall(resource);
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void start(JmsResource resource, AsyncResult request) throws IOException, JMSException {
- stats.recordStartResourceCall(resource);
- request.onSuccess();
+ public void stop(final JmsResource resource, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordStopResourceCall(resource);
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void stop(JmsResource resource, AsyncResult request) throws IOException, JMSException {
- stats.recordStopResourceCall(resource);
- request.onSuccess();
+ public void destroy(final JmsResource resource, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordDestroyResourceCall(resource);
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void destroy(JmsResource resource, AsyncResult request) throws IOException, JMSException {
- stats.recordDestroyResourceCall(resource);
- request.onSuccess();
+ public void send(final JmsOutboundMessageDispatch envelope, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordSendCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void send(JmsOutboundMessageDispatch envelope, AsyncResult request) throws IOException, JMSException {
- stats.recordSendCall();
- request.onSuccess();
+ public void acknowledge(final JmsSessionId sessionId, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recoordSessionAcknowledgeCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void acknowledge(JmsSessionId sessionId, AsyncResult request) throws IOException, JMSException {
- stats.recoordSessionAcknowledgeCall();
- request.onSuccess();
+ public void acknowledge(final JmsInboundMessageDispatch envelope, final ACK_TYPE ackType, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recoordAcknowledgeCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void acknowledge(JmsInboundMessageDispatch envelope, ACK_TYPE ackType, AsyncResult request) throws IOException, JMSException {
- stats.recoordAcknowledgeCall();
- request.onSuccess();
+ public void commit(final JmsSessionId sessionId, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordCommitCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void commit(JmsSessionId sessionId, AsyncResult request) throws IOException, JMSException {
- stats.recordCommitCall();
- request.onSuccess();
+ public void rollback(final JmsSessionId sessionId, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordRollbackCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void rollback(JmsSessionId sessionId, AsyncResult request) throws IOException, JMSException {
- stats.recordRollbackCall();
- request.onSuccess();
+ public void recover(final JmsSessionId sessionId, final AsyncResult request) throws IOException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordRecoverCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void recover(JmsSessionId sessionId, AsyncResult request) throws IOException {
- stats.recordRecoverCall();
- request.onSuccess();
+ public void unsubscribe(final String subscription, final AsyncResult request) throws IOException, JMSException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordUnsubscribeCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
@Override
- public void unsubscribe(String subscription, AsyncResult request) throws IOException, JMSException {
- stats.recordUnsubscribeCall();
- request.onSuccess();
+ public void pull(final JmsConsumerId consumerId, final long timeout, final AsyncResult request) throws IOException {
+ checkClosed();
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ checkClosed();
+ stats.recordPullCall();
+ request.onSuccess();
+ } catch (Exception error) {
+ request.onFailure(error);
+ }
+ }
+ });
}
//----- API for generating provider events to a connection ---------------//
public void signalConnectionFailed() {
- listener.onConnectionFailure(new IOException("Connection lost"));
+ serializer.execute(new Runnable() {
+
+ @Override
+ public void run() {
+ if (!closed.get()) {
+ listener.onConnectionFailure(new IOException("Connection lost"));
+ }
+ }
+ });
}
//----- Property getters and setters -------------------------------------//
@Override
- public void pull(JmsConsumerId consumerId, long timeout, AsyncResult request) throws IOException {
- stats.recordPullCall();
- request.onSuccess();
- }
-
- @Override
public JmsMessageFactory getMessageFactory() {
return messageFactory;
}
@@ -220,4 +435,28 @@ public class MockProvider implements Provider {
public String getProviderId() {
return this.providerId;
}
+
+ public long getCloseTimeout() {
+ return this.closeTimeout;
+ }
+
+ public void setCloseTimeout(long closeTimeout) {
+ this.closeTimeout = closeTimeout;
+ }
+
+ public long getConnectTimeout() {
+ return connectTimeout;
+ }
+
+ public void setConnectTimeout(long connectTimeout) {
+ this.connectTimeout = connectTimeout;
+ }
+
+ //----- Implementation deatils -------------------------------------------//
+
+ private void checkClosed() throws ProviderClosedException {
+ if (closed.get()) {
+ throw new ProviderClosedException("This Provider is already closed");
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[2/2] qpid-jms git commit: Additional test coverage
Posted by ta...@apache.org.
Additional test coverage
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/e5ed52ec
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e5ed52ec
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e5ed52ec
Branch: refs/heads/master
Commit: e5ed52ec002562944b9479394fe24226e7ee7545
Parents: d876637
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Feb 11 18:45:56 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Feb 11 18:45:56 2015 -0500
----------------------------------------------------------------------
.../qpid/jms/JmsConnectionFactoryTest.java | 74 ++++++++++++++++
.../org/apache/qpid/jms/JmsConnectionTest.java | 91 ++++++++++++++++++--
.../qpid/jms/provider/mock/MockProvider.java | 2 +-
3 files changed, 160 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e5ed52ec/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
index baae401..3527db2 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
@@ -24,13 +24,16 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import javax.jms.Connection;
import javax.jms.ExceptionListener;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
@@ -42,6 +45,7 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase {
private static final String CLIENT_ID_PROP = "clientID";
private static final String QUEUE_PREFIX_PROP = "queuePrefix";
+ private static final String TOPIC_PREFIX_PROP = "topicPrefix";
private static final String USER = "USER";
private static final String PASSWORD = "PASSWORD";
@@ -62,6 +66,76 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase {
}
@Test
+ public void testConnectionFactoryOptionsAreAppliedToConnection() throws JMSException {
+ JmsConnectionFactory factory = new JmsConnectionFactory(USER, PASSWORD, "mock://localhost");
+
+ factory.setTopicPrefix(TOPIC_PREFIX_PROP);
+ factory.setQueuePrefix(QUEUE_PREFIX_PROP);
+ factory.setClientID(CLIENT_ID_PROP);
+
+ factory.setAlwaysSyncSend(!factory.isAlwaysSyncSend());
+ factory.setForceAsyncSend(!factory.isForceAsyncSend());
+ factory.setLocalMessagePriority(!factory.isLocalMessagePriority());
+ factory.setSendAcksAsync(!factory.isSendAcksAsync());
+ factory.setConnectTimeout(TimeUnit.SECONDS.toMillis(30));
+ factory.setCloseTimeout(TimeUnit.SECONDS.toMillis(45));
+
+ factory.getPrefetchPolicy().setAll(1);
+
+ JmsConnection connection = (JmsConnection) factory.createConnection();
+ assertNotNull(connection);
+
+ assertEquals(USER, connection.getUsername());
+ assertEquals(PASSWORD, connection.getPassword());
+ assertEquals(CLIENT_ID_PROP, connection.getClientID());
+ assertEquals(TOPIC_PREFIX_PROP, connection.getTopicPrefix());
+ assertEquals(QUEUE_PREFIX_PROP, connection.getQueuePrefix());
+
+ assertEquals(factory.isAlwaysSyncSend(), connection.isAlwaysSyncSend());
+ assertEquals(factory.isForceAsyncSend(), connection.isForceAsyncSend());
+ assertEquals(factory.isLocalMessagePriority(), connection.isLocalMessagePriority());
+ assertEquals(factory.isSendAcksAsync(), connection.isSendAcksAsync());
+
+ assertEquals(TimeUnit.SECONDS.toMillis(30), connection.getConnectTimeout());
+ assertEquals(TimeUnit.SECONDS.toMillis(45), connection.getCloseTimeout());
+
+ assertEquals(1, connection.getPrefetchPolicy().getTopicPrefetch());
+ assertEquals(1, connection.getPrefetchPolicy().getQueuePrefetch());
+ assertEquals(1, connection.getPrefetchPolicy().getQueueBrowserPrefetch());
+ assertEquals(1, connection.getPrefetchPolicy().getDurableTopicPrefetch());
+ }
+
+ @Test
+ public void testConnectionGetConfiguredURIApplied() throws Exception {
+ URI mock = new URI("mock://localhost");
+
+ JmsConnectionFactory factory = new JmsConnectionFactory(mock);
+
+ JmsConnection connection = (JmsConnection) factory.createConnection();
+ assertEquals(mock, connection.getConfiguredURI());
+ connection.start();
+ assertEquals(mock, connection.getConnectedURI());
+ }
+
+ @Test
+ public void testGlobalExceptionListenerIsAppliedToCreatedConnection() throws Exception {
+ JmsConnectionFactory factory = new JmsConnectionFactory(new URI("mock://127.0.0.1:5763"));
+
+ ExceptionListener listener = new ExceptionListener() {
+
+ @Override
+ public void onException(JMSException exception) {
+ }
+ };
+
+ factory.setExceptionListener(listener);
+ Connection connection = factory.createConnection();
+ assertNotNull(connection);
+ assertNotNull(connection.getExceptionListener());
+ assertSame(listener, connection.getExceptionListener());
+ }
+
+ @Test
public void testCreateConnectionBadProviderURI() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(new URI("bad://127.0.0.1:5763"));
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e5ed52ec/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java
index a2058c7..231a8de 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionTest.java
@@ -18,16 +18,23 @@ package org.apache.qpid.jms;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.URI;
+import javax.jms.ExceptionListener;
import javax.jms.IllegalStateException;
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
import org.apache.qpid.jms.provider.mock.MockProvider;
@@ -59,13 +66,13 @@ public class JmsConnectionTest {
}
}
- @Test(expected=JMSException.class)
+ @Test(timeout=30000, expected=JMSException.class)
public void testJmsConnectionThrowsJMSExceptionProviderStartFails() throws JMSException, IllegalStateException, IOException {
provider.getConfiguration().setFailOnStart(true);
new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
}
- @Test
+ @Test(timeout=30000)
public void testStateAfterCreate() throws JMSException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
@@ -74,13 +81,40 @@ public class JmsConnectionTest {
assertFalse(connection.isConnected());
}
- @Test
+ @Test(timeout=30000)
+ public void testGetExceptionListener() throws JMSException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+
+ assertNull(connection.getExceptionListener());
+ connection.setExceptionListener(new ExceptionListener() {
+
+ @Override
+ public void onException(JMSException exception) {
+ }
+ });
+
+ assertNotNull(connection.getExceptionListener());
+ }
+
+ @Test(timeout=30000)
+ public void testReplacePrefetchPolicy() throws JMSException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+
+ JmsPrefetchPolicy newPolicy = new JmsPrefetchPolicy();
+ newPolicy.setAll(1);
+
+ assertNotSame(newPolicy, connection.getPrefetchPolicy());
+ connection.setPrefetchPolicy(newPolicy);
+ assertSame(newPolicy, connection.getPrefetchPolicy());
+ }
+
+ @Test(timeout=30000)
public void testGetConnectionId() throws JMSException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
assertEquals("ID:TEST:1", connection.getConnectionId().toString());
}
- @Test
+ @Test(timeout=30000)
public void testAddConnectionListener() throws JMSException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
JmsConnectionListener listener = new JmsConnectionListener() {
@@ -111,7 +145,7 @@ public class JmsConnectionTest {
assertTrue(connection.removeConnectionListener(listener));
}
- @Test
+ @Test(timeout=30000)
public void testConnectionStart() throws JMSException, IOException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
@@ -120,7 +154,18 @@ public class JmsConnectionTest {
assertTrue(connection.isConnected());
}
- @Test
+ @Test(timeout=30000)
+ public void testConnectionMulitpleStartCalls() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+
+ assertFalse(connection.isConnected());
+ connection.start();
+ assertTrue(connection.isConnected());
+ connection.start();
+ assertTrue(connection.isConnected());
+ }
+
+ @Test(timeout=30000)
public void testConnectionStartAndStop() throws JMSException, IOException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
@@ -189,6 +234,40 @@ public class JmsConnectionTest {
connection.setClientID("TEST-ID");
}
+ @Test(timeout=30000)
+ public void testDeleteOfTempQueueOnClosedConnection() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+ connection.start();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryQueue tempQueue = session.createTemporaryQueue();
+ assertNotNull(tempQueue);
+
+ connection.close();
+ try {
+ tempQueue.delete();
+ fail("Should have thrown an IllegalStateException");
+ } catch (IllegalStateException ex) {
+ }
+ }
+
+ @Test(timeout=30000)
+ public void testDeleteOfTempTopicOnClosedConnection() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+ connection.start();
+
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ TemporaryTopic tempTopic = session.createTemporaryTopic();
+ assertNotNull(tempTopic);
+
+ connection.close();
+ try {
+ tempTopic.delete();
+ fail("Should have thrown an IllegalStateException");
+ } catch (IllegalStateException ex) {
+ }
+ }
+
//----- Currently these are unimplemented, these will fail after that ----//
@Test(timeout=30000, expected=JMSException.class)
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e5ed52ec/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 90146d7..3d32509 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
@@ -452,7 +452,7 @@ public class MockProvider implements Provider {
this.connectTimeout = connectTimeout;
}
- //----- Implementation deatils -------------------------------------------//
+ //----- Implementation details -------------------------------------------//
private void checkClosed() throws ProviderClosedException {
if (closed.get()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org