summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2010-01-20 15:54:59 +0000
committerGordon Sim <gsim@apache.org>2010-01-20 15:54:59 +0000
commit84dff8ce35a6d8bdee54b2182a1b7f03ab3ca9dd (patch)
tree4fc1c43e57b1fd74e80ed4b81f9cdc0eb92518c4
parent7af2422349b111e5207045fc509649a8fe3f878b (diff)
downloadqpid-python-84dff8ce35a6d8bdee54b2182a1b7f03ab3ca9dd.tar.gz
Provide access to a sessions connection.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@901247 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/include/qpid/client/SessionBase_0_10.h2
-rw-r--r--qpid/cpp/src/qpid/client/ConnectionAccess.h1
-rw-r--r--qpid/cpp/src/qpid/client/SessionBase_0_10.cpp8
-rw-r--r--qpid/cpp/src/tests/ClientSessionTest.cpp22
4 files changed, 33 insertions, 0 deletions
diff --git a/qpid/cpp/include/qpid/client/SessionBase_0_10.h b/qpid/cpp/include/qpid/client/SessionBase_0_10.h
index afa458bcee..e76019dd4d 100644
--- a/qpid/cpp/include/qpid/client/SessionBase_0_10.h
+++ b/qpid/cpp/include/qpid/client/SessionBase_0_10.h
@@ -99,6 +99,8 @@ class SessionBase_0_10 {
QPID_CLIENT_EXTERN bool isValid() const;
+ QPID_CLIENT_EXTERN Connection getConnection();
+
protected:
boost::shared_ptr<SessionImpl> impl;
friend class SessionBase_0_10Access;
diff --git a/qpid/cpp/src/qpid/client/ConnectionAccess.h b/qpid/cpp/src/qpid/client/ConnectionAccess.h
index b662fd5d8b..3a763f692f 100644
--- a/qpid/cpp/src/qpid/client/ConnectionAccess.h
+++ b/qpid/cpp/src/qpid/client/ConnectionAccess.h
@@ -34,6 +34,7 @@ namespace client {
struct ConnectionAccess {
static void setVersion(Connection& c, const framing::ProtocolVersion& v) { c.version = v; }
static boost::shared_ptr<ConnectionImpl> getImpl(Connection& c) { return c.impl; }
+ static void setImpl(Connection& c, boost::shared_ptr<ConnectionImpl> i) { c.impl = i; }
};
}} // namespace qpid::client
diff --git a/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp b/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp
index 1a345d534e..e114b7aacc 100644
--- a/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp
+++ b/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp
@@ -20,6 +20,7 @@
*/
#include "qpid/client/SessionBase_0_10.h"
#include "qpid/client/Connection.h"
+#include "qpid/client/ConnectionAccess.h"
#include "qpid/client/SessionImpl.h"
#include "qpid/client/Future.h"
#include "qpid/framing/all_method_bodies.h"
@@ -74,4 +75,11 @@ SessionId SessionBase_0_10::getId() const { return impl->getId(); }
bool SessionBase_0_10::isValid() const { return impl; }
+Connection SessionBase_0_10::getConnection()
+{
+ Connection c;
+ ConnectionAccess::setImpl(c, impl->getConnection());
+ return c;
+}
+
}} // namespace qpid::client
diff --git a/qpid/cpp/src/tests/ClientSessionTest.cpp b/qpid/cpp/src/tests/ClientSessionTest.cpp
index 6ca0aa6d44..8ce5d85632 100644
--- a/qpid/cpp/src/tests/ClientSessionTest.cpp
+++ b/qpid/cpp/src/tests/ClientSessionTest.cpp
@@ -607,6 +607,28 @@ QPID_AUTO_TEST_CASE(testExpirationNotAltered) {
BOOST_CHECK_EQUAL(12345u, got.getDeliveryProperties().getExpiration());
}
+QPID_AUTO_TEST_CASE(testGetConnectionFromSession) {
+ ClientSessionFixture fix;
+ FieldTable options;
+ options.setInt("no-local", 1);
+ fix.session.queueDeclare(arg::queue="a", arg::exclusive=true, arg::autoDelete=true, arg::arguments=options);
+ fix.session.queueDeclare(arg::queue="b", arg::exclusive=true, arg::autoDelete=true);
+
+ Connection c = fix.session.getConnection();
+ Session s = c.newSession();
+ //If this new session was created as expected on the same connection as
+ //fix.session, then the no-local behaviour means that queue 'a'
+ //will not enqueue messages from this new session but queue 'b'
+ //will.
+ s.messageTransfer(arg::content=Message("a", "a"));
+ s.messageTransfer(arg::content=Message("b", "b"));
+
+ Message got;
+ BOOST_CHECK(fix.subs.get(got, "b"));
+ BOOST_CHECK_EQUAL("b", got.getData());
+ BOOST_CHECK(!fix.subs.get(got, "a"));
+}
+
QPID_AUTO_TEST_SUITE_END()
}} // namespace qpid::tests