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/09 22:50:58 UTC
[5/6] qpid-jms git commit: Enforce the use of known Ack modes for
createSession calls.
Enforce the use of known Ack modes for createSession calls.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/6ff14aff
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/6ff14aff
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/6ff14aff
Branch: refs/heads/master
Commit: 6ff14afff8e6d3ea426489e49c2b7df7314090c7
Parents: c3b6d6a
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Feb 9 16:35:13 2015 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Feb 9 16:35:13 2015 -0500
----------------------------------------------------------------------
.../java/org/apache/qpid/jms/JmsConnection.java | 3 +++
.../org/apache/qpid/jms/JmsConnectionTest.java | 26 ++++++++++++++++++++
2 files changed, 29 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6ff14aff/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
index b986ae8..9f69e90 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnection.java
@@ -485,8 +485,11 @@ public class JmsConnection implements Connection, TopicConnection, QueueConnecti
if (!transacted && acknowledgeMode == Session.SESSION_TRANSACTED) {
throw new JMSException("acknowledgeMode SESSION_TRANSACTED cannot be used for an non-transacted Session");
}
+
if (transacted) {
result = Session.SESSION_TRANSACTED;
+ } else if (acknowledgeMode < Session.SESSION_TRANSACTED || acknowledgeMode > Session.DUPS_OK_ACKNOWLEDGE){
+ throw new JMSException("acknowledgeMode " + acknowledgeMode + " cannot be used for an non-transacted Session");
}
return result;
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6ff14aff/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 331809b..a2058c7 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
@@ -19,6 +19,7 @@ package org.apache.qpid.jms;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.URI;
@@ -26,6 +27,7 @@ import java.net.URI;
import javax.jms.IllegalStateException;
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
+import javax.jms.Session;
import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
import org.apache.qpid.jms.provider.mock.MockProvider;
@@ -136,6 +138,30 @@ public class JmsConnectionTest {
connection.setClientID("");
}
+ @Test(timeout=30000)
+ public void testCreateNonTXSessionWithTXAckMode() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+ connection.start();
+
+ try {
+ connection.createSession(false, Session.SESSION_TRANSACTED);
+ fail("Should not allow non-TX session with mode SESSION_TRANSACTED");
+ } catch (JMSException ex) {
+ }
+ }
+
+ @Test(timeout=30000)
+ public void testCreateNonTXSessionWithUnknownAckMode() throws JMSException, IOException {
+ connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
+ connection.start();
+
+ try {
+ connection.createSession(false, 99);
+ fail("Should not allow unkown Ack modes.");
+ } catch (JMSException ex) {
+ }
+ }
+
@Test(timeout=30000, expected=InvalidClientIDException.class)
public void testSetClientIDFromEmptyString() throws JMSException, IOException {
connection = new JmsConnection("ID:TEST:1", provider, clientIdGenerator);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org