@@ -562,9 +562,13 @@ MockSession::Call::Call(Method method, bslma::Allocator* allocator)
562562, d_openQueueCallback(bsl::allocator_arg, allocator)
563563, d_configureQueueCallback(bsl::allocator_arg, allocator)
564564, d_closeQueueCallback(bsl::allocator_arg, allocator)
565+ , d_startCallback(bsl::allocator_arg, allocator)
566+ , d_stopCallback(bsl::allocator_arg, allocator)
565567, d_openQueueResult(allocator)
566568, d_configureQueueResult(allocator)
567569, d_closeQueueResult(allocator)
570+ , d_startResult(allocator)
571+ , d_stopResult(allocator)
568572, d_emittedEvents(allocator)
569573, d_returnEvent()
570574, d_messageEvent()
@@ -590,9 +594,13 @@ MockSession::Call::Call(const Call& other, bslma::Allocator* allocator)
590594, d_closeQueueCallback(bsl::allocator_arg,
591595 allocator,
592596 other.d_closeQueueCallback)
597+ , d_startCallback(bsl::allocator_arg, allocator, other.d_startCallback)
598+ , d_stopCallback(bsl::allocator_arg, allocator, other.d_stopCallback)
593599, d_openQueueResult(other.d_openQueueResult)
594600, d_configureQueueResult(other.d_configureQueueResult, allocator)
595601, d_closeQueueResult(other.d_closeQueueResult, allocator)
602+ , d_startResult(other.d_startResult, allocator)
603+ , d_stopResult(other.d_stopResult, allocator)
596604, d_emittedEvents(other.d_emittedEvents, allocator)
597605, d_returnEvent(other.d_returnEvent)
598606, d_messageEvent(other.d_messageEvent)
@@ -745,6 +753,56 @@ MockSession::Call::emitting(const CloseQueueStatus& closeQueueResult)
745753 return *this ;
746754}
747755
756+ MockSession::Call& MockSession::Call::emitting (const StartStatus& startResult)
757+ {
758+ // PRECONDITIONS
759+ BSLS_ASSERT_SAFE (d_method = e_START_ASYNC_CALLBACK);
760+ BSLS_ASSERT_SAFE (d_startCallback);
761+
762+ d_startResult = startResult;
763+
764+ const CallbackFn callbackFn = bdlf::BindUtil::bindS (d_allocator_p,
765+ d_startCallback,
766+ startResult);
767+
768+ // Start is a session-level operation with no associated queue, so
769+ // 'processIfQueueJob' will ignore this job (it only acts on queue events).
770+ Job job;
771+ job.d_callback = callbackFn;
772+ job.d_type = bmqt::SessionEventType::e_CONNECTED;
773+ job.d_status = startResult.result ();
774+
775+ EventOrJob eventOrJob (job, d_allocator_p);
776+ d_emittedEvents.push_back (eventOrJob);
777+
778+ return *this ;
779+ }
780+
781+ MockSession::Call& MockSession::Call::emitting (const StopStatus& stopResult)
782+ {
783+ // PRECONDITIONS
784+ BSLS_ASSERT_SAFE (d_method = e_STOP_ASYNC_CALLBACK);
785+ BSLS_ASSERT_SAFE (d_stopCallback);
786+
787+ d_stopResult = stopResult;
788+
789+ const CallbackFn callbackFn = bdlf::BindUtil::bindS (d_allocator_p,
790+ d_stopCallback,
791+ stopResult);
792+
793+ // Stop is a session-level operation with no associated queue, so
794+ // 'processIfQueueJob' will ignore this job (it only acts on queue events).
795+ Job job;
796+ job.d_callback = callbackFn;
797+ job.d_type = bmqt::SessionEventType::e_DISCONNECTED;
798+ job.d_status = stopResult.result ();
799+
800+ EventOrJob eventOrJob (job, d_allocator_p);
801+ d_emittedEvents.push_back (eventOrJob);
802+
803+ return *this ;
804+ }
805+
748806const char * MockSession::Call::methodName () const
749807{
750808 return MockSession::toAscii (d_method);
@@ -792,8 +850,13 @@ const char* MockSession::toAscii(const Method method)
792850 switch (method) {
793851 case e_START: return " start()" ;
794852 case e_START_ASYNC: return " startAsync()" ;
853+ case e_START_ASYNC_CALLBACK:
854+ return " int startAsync(const StartCallback& callback,"
855+ " const bsls::TimeInterval& timeout)" ;
795856 case e_STOP: return " stop()" ;
796857 case e_STOP_ASYNC: return " stopAsync()" ;
858+ case e_STOP_ASYNC_CALLBACK:
859+ return " void stopAsync(const StopCallback& callback)" ;
797860 case e_FINALIZE_STOP: return " finalizeStop()" ;
798861 case e_OPEN_QUEUE:
799862 return " int openQueue(QueueId *queueId,"
@@ -1227,6 +1290,21 @@ MockSession::expect_startAsync(const bsls::TimeInterval& timeout)
12271290 return call;
12281291}
12291292
1293+ MockSession::Call&
1294+ MockSession::expect_startAsync (const StartCallback& callback,
1295+ const bsls::TimeInterval& timeout)
1296+ {
1297+ bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
1298+
1299+ d_calls.emplace_back (e_START_ASYNC_CALLBACK);
1300+ Call& call = d_calls.back ();
1301+ call.d_startCallback = callback;
1302+ call.d_timeout = timeout;
1303+ call.d_allocator_p = d_allocator_p;
1304+
1305+ return call;
1306+ }
1307+
12301308MockSession::Call& MockSession::expect_stop ()
12311309{
12321310 bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
@@ -1243,6 +1321,18 @@ MockSession::Call& MockSession::expect_stopAsync()
12431321 return d_calls.back ();
12441322}
12451323
1324+ MockSession::Call& MockSession::expect_stopAsync (const StopCallback& callback)
1325+ {
1326+ bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
1327+
1328+ d_calls.emplace_back (e_STOP_ASYNC_CALLBACK);
1329+ Call& call = d_calls.back ();
1330+ call.d_stopCallback = callback;
1331+ call.d_allocator_p = d_allocator_p;
1332+
1333+ return call;
1334+ }
1335+
12461336MockSession::Call& MockSession::expect_finalizeStop ()
12471337{
12481338 bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
@@ -1584,6 +1674,27 @@ int MockSession::startAsync(const bsls::TimeInterval& timeout)
15841674 return rc;
15851675}
15861676
1677+ int MockSession::startAsync (BSLA_MAYBE_UNUSED const StartCallback& callback,
1678+ const bsls::TimeInterval& timeout)
1679+ {
1680+ bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
1681+
1682+ BMQA_CHECK_CALL (e_START_ASYNC_CALLBACK, { return 0 ; });
1683+ BMQA_CHECK_ARG (e_START_ASYNC_CALLBACK,
1684+ " timeout" ,
1685+ call.d_timeout ,
1686+ timeout,
1687+ call);
1688+
1689+ d_eventsAndJobs.insert (d_eventsAndJobs.end (),
1690+ call.d_emittedEvents .begin (),
1691+ call.d_emittedEvents .end ());
1692+
1693+ const int rc = call.d_rc ;
1694+ BMQA_ASSERT_AND_POP_FRONT ();
1695+ return rc;
1696+ }
1697+
15871698void MockSession::stop ()
15881699{
15891700 bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
@@ -1628,6 +1739,28 @@ void MockSession::stopAsync()
16281739 BMQA_ASSERT_AND_POP_FRONT ();
16291740}
16301741
1742+ void MockSession::stopAsync (BSLA_MAYBE_UNUSED const StopCallback& callback)
1743+ {
1744+ bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
1745+
1746+ BMQA_CHECK_CALL (e_STOP_ASYNC_CALLBACK, {});
1747+
1748+ d_eventsAndJobs.insert (d_eventsAndJobs.end (),
1749+ call.d_emittedEvents .begin (),
1750+ call.d_emittedEvents .end ());
1751+
1752+ // Reset all queue's state to 'closed' to mimic the real implementation
1753+ UriCorrIdToQueueMap& queueMap = uriCorrIdToQueues (d_twoKeyHashMapBuffer);
1754+ UriCorrIdToQueueMap::iterator qIt = queueMap.begin ();
1755+ while (qIt != queueMap.end ()) {
1756+ QueueImplSp& queueImpl = reinterpret_cast <QueueImplSp&>(qIt->value ());
1757+ queueImpl->setState (bmqimp::QueueState::e_CLOSED);
1758+ ++qIt;
1759+ }
1760+
1761+ BMQA_ASSERT_AND_POP_FRONT ();
1762+ }
1763+
16311764void MockSession::finalizeStop ()
16321765{
16331766 bslmt::LockGuard<bslmt::Mutex> guard (&d_mutex); // LOCKED
0 commit comments