17 #ifndef INCLUDED_BMQA_MOCKSESSION
18 #define INCLUDED_BMQA_MOCKSESSION
563 #include <ball_log.h>
564 #include <bdlb_variant.h>
565 #include <bdlbb_blob.h>
566 #include <bdlbb_pooledblobbufferfactory.h>
567 #include <bdlcc_sharedobjectpool.h>
568 #include <bsl_cstddef.h>
569 #include <bsl_deque.h>
570 #include <bsl_functional.h>
571 #include <bsl_memory.h>
572 #include <bsl_string.h>
573 #include <bsl_unordered_map.h>
574 #include <bsl_unordered_set.h>
575 #include <bslma_allocator.h>
576 #include <bslma_managedptr.h>
577 #include <bslma_usesbslmaallocator.h>
578 #include <bslmf_nestedtraitdeclaration.h>
579 #include <bslmt_mutex.h>
580 #include <bsls_alignedbuffer.h>
581 #include <bsls_assert.h>
582 #include <bsls_timeinterval.h>
583 #include <bsls_types.h>
592 class MessageCorrelationIdContainer;
604 class ConfirmEventBuilder;
607 #define BMQA_EXPECT_CALL(OBJ, CALL) \
608 (((OBJ).expect_##CALL).fromLocation(__FILE__, __LINE__))
620 typedef bdlcc::SharedObjectPool<
622 bdlcc::ObjectPoolFunctors::DefaultCreator,
623 bdlcc::ObjectPoolFunctors::RemoveAll<bdlbb::Blob> >
628 typedef bsl::shared_ptr<bmqimp::Event> EventImplSp;
632 typedef bsl::shared_ptr<bmqimp::Queue> QueueImplSp;
697 bdlbb::BlobBufferFactory* bufferFactory,
698 bslma::Allocator* allocator);
706 bdlbb::BlobBufferFactory* bufferFactory,
707 bslma::Allocator* allocator);
719 const bslstl::StringRef& errorDescription,
720 bslma::Allocator* allocator);
730 const bslstl::StringRef& errorDescription,
731 bslma::Allocator* allocator);
739 const bsl::string& errorDescription,
740 bslma::Allocator* allocator = 0);
748 const bsl::string& errorDescription,
749 bslma::Allocator* allocator = 0);
757 const bsl::string& errorDescription,
758 bslma::Allocator* allocator = 0);
800 typedef bsl::function<
801 void(
const char* description,
const char* file,
int line)>
806 BALL_LOG_SET_CLASS_CATEGORY(
"BMQA.MOCKSESSION");
815 static const int k_MAX_SIZEOF_BMQC_TWOKEYHASHMAP = 256;
820 typedef bdlcc::SharedObjectPool<
822 bdlcc::ObjectPoolFunctors::DefaultCreator,
823 bdlcc::ObjectPoolFunctors::RemoveAll<bdlbb::Blob> >
827 typedef bsl::shared_ptr<BlobSpPool> BlobSpPoolSp;
830 typedef bsls::AlignedBuffer<k_MAX_SIZEOF_BMQC_TWOKEYHASHMAP>
834 typedef bsl::shared_ptr<bmqimp::Queue> QueueImplSp;
837 typedef bsl::shared_ptr<bmqimp::Event> EventImplSp;
840 typedef bsl::shared_ptr<bmqimp::Stat> StatImplSp;
843 typedef bsl::shared_ptr<bmqimp::MessageCorrelationIdContainer>
844 CorrelationIdContainerSp;
846 typedef bsl::function<void()> CallbackFn;
854 CallbackFn d_callback;
867 typedef bdlb::Variant<Event, Job> EventOrJob;
880 e_OPEN_QUEUE_ASYNC_CALLBACK,
884 e_CLOSE_QUEUE_ASYNC_CALLBACK,
886 e_CONFIGURE_QUEUE_SYNC,
887 e_CONFIGURE_QUEUE_ASYNC,
888 e_CONFIGURE_QUEUE_ASYNC_CALLBACK,
899 typedef bsl::vector<EventOrJob> EventsAndJobs;
919 bsls::Types::Uint64 d_flags;
925 bsls::TimeInterval d_timeout;
949 EventsAndJobs d_emittedEvents;
955 MessageEvent d_messageEvent;
958 MessageConfirmationCookie d_cookie;
961 bslma::Allocator* d_allocator_p;
964 BSLMF_NESTED_TRAIT_DECLARATION(Call, bslma::UsesBslmaAllocator)
970 Call(Method method, bslma::Allocator* allocator);
972 Call(
const Call& other, bslma::Allocator* allocator);
980 Call& fromLocation(
const char* file,
int line);
984 Call& returning(
int rc);
1003 Call& returning(
const Event& event);
1007 Call& emitting(
const Event& event);
1012 Call& emitting(
const OpenQueueStatus& openQueueResult);
1017 Call& emitting(
const ConfigureQueueStatus& configureQueueResutl);
1022 Call& emitting(
const CloseQueueStatus& closeQueueResult);
1027 const char* methodName()
const;
1031 typedef bsl::deque<Call> CallQueue;
1034 typedef bsl::deque<bmqa::MessageEvent> PostedEvents;
1039 bdlbb::PooledBlobBufferFactory d_blobBufferFactory;
1042 BlobSpPoolSp d_blobSpPool_sp;
1045 bslma::ManagedPtr<SessionEventHandler> d_eventHandler_mp;
1048 mutable CallQueue d_calls;
1051 mutable bsl::deque<EventOrJob> d_eventsAndJobs;
1054 bsl::unordered_set<bmqt::MessageGUID> d_unconfirmedGUIDs;
1057 TwoKeyHashMapBuffer d_twoKeyHashMapBuffer;
1067 CorrelationIdContainerSp d_corrIdContainer_sp;
1070 PostedEvents d_postedEvents;
1073 mutable bslmt::Mutex d_mutex;
1076 bslma::ManagedPtr<bmqst::StatContext> d_rootStatContext_mp;
1079 StatImplSp d_queuesStats_sp;
1082 bmqt::SessionOptions d_sessionOptions;
1085 bslma::Allocator* d_allocator_p;
1091 static const char* toAscii(
const Method method);
1096 void initializeStats();
1105 void openQueueImp(QueueId* queueId,
1106 const bmqt::QueueOptions& options,
1107 const bmqt::Uri& uri,
1108 bsls::Types::Uint64 flags,
1114 void processIfQueueEvent(Event* event);
1119 void processIfQueueJob(Job* job);
1123 void processIfPushEvent(
const Event& event);
1129 void assertWrongCall(
const Method method)
const;
1133 void assertWrongCall(
const Method method,
const Call& expectedCall)
const;
1139 template <
class T,
class U>
1140 void assertWrongArg(
const T& expected,
1142 const Method method,
1144 const Call& call)
const;
1148 BSLMF_NESTED_TRAIT_DECLARATION(
MockSession, bslma::UsesBslmaAllocator)
1158 const bmqt::SessionOptions& options = bmqt::SessionOptions(),
1159 bslma::Allocator* allocator = 0);
1168 const bmqt::SessionOptions& options = bmqt::SessionOptions(),
1169 bslma::Allocator* allocator = 0);
1192 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1198 const bmqt::Uri& uri,
1199 bsls::Types::Uint64 flags,
1200 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1201 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1204 const bmqt::Uri& uri,
1205 bsls::Types::Uint64 flags,
1206 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1207 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1211 const bmqt::Uri& uri,
1212 bsls::Types::Uint64 flags,
1213 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1214 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1217 const bmqt::Uri& uri,
1218 bsls::Types::Uint64 flags,
1220 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1221 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1225 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1228 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1232 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1236 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1239 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1240 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1243 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1244 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1247 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1248 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1252 const bmqt::QueueOptions& options,
1254 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1271 int start(const bsls::TimeInterval& timeout = bsls::TimeInterval())
1272 BSLS_KEYWORD_OVERRIDE;
1278 int startAsync(const bsls::TimeInterval& timeout = bsls::TimeInterval())
1279 BSLS_KEYWORD_OVERRIDE;
1296 BSLS_KEYWORD_OVERRIDE;
1301 BSLS_KEYWORD_OVERRIDE;
1314 const bmqt::Uri& uri) BSLS_KEYWORD_OVERRIDE;
1319 BSLS_KEYWORD_OVERRIDE;
1326 const bmqt::Uri& uri,
1327 bsls::Types::Uint64 flags,
1328 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1329 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1330 BSLS_KEYWORD_OVERRIDE;
1342 const bmqt::Uri& uri,
1343 bsls::Types::Uint64 flags,
1344 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1345 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1346 BSLS_KEYWORD_OVERRIDE;
1354 const bmqt::Uri& uri,
1355 bsls::Types::Uint64 flags,
1356 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1357 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1358 BSLS_KEYWORD_OVERRIDE;
1378 const bmqt::Uri& uri,
1379 bsls::Types::Uint64 flags,
1381 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1382 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1383 BSLS_KEYWORD_OVERRIDE;
1391 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1392 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1393 BSLS_KEYWORD_OVERRIDE;
1400 const bmqt::QueueOptions& options,
1401 const bsls::TimeInterval& timeout)
1402 BSLS_KEYWORD_OVERRIDE;
1410 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1411 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1412 BSLS_KEYWORD_OVERRIDE;
1423 const bmqt::QueueOptions& options,
1425 const bsls::TimeInterval& timeout =
1426 bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1433 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1434 BSLS_KEYWORD_OVERRIDE;
1443 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1444 BSLS_KEYWORD_OVERRIDE;
1451 const bsls::TimeInterval& timeout =
1452 bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1463 const bsls::TimeInterval& timeout =
1464 bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1473 BSLS_KEYWORD_OVERRIDE;
1483 BSLS_KEYWORD_OVERRIDE;
1491 BSLS_KEYWORD_OVERRIDE;
1522 d_failureCb = failureCb;
1527 return d_unconfirmedGUIDs.size();
1535 bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex);
1537 if (d_postedEvents.empty()) {
1541 *
event = d_postedEvents.front();
1542 d_postedEvents.pop_front();
Provide a pure protocol for a BlazingMQ session.
Provide Value-Semantic Type for a close queue operation status.
Provide a builder for bmqa::MessageEvent objects.
Provide Value-Semantic Type for an open queue operation status.
Provide a value-semantic efficient identifier for a queue.
Provide access to the BlazingMQ broker.
Provide a value-semantic type for options related to a queue.
Provide a value-semantic type to configure session with the broker.
A pure protocol for a session.
Definition: bmqa_abstractsession.h:50
bsl::function< void(const bmqa::CloseQueueStatus &result)> CloseQueueCallback
Definition: bmqa_abstractsession.h:73
bsl::function< void(const bmqa::ConfigureQueueStatus &result)> ConfigureQueueCallback
Definition: bmqa_abstractsession.h:66
bsl::function< void(const bmqa::OpenQueueStatus &result)> OpenQueueCallback
Definition: bmqa_abstractsession.h:59
Definition: bmqa_closequeuestatus.h:62
Mechanism to build a batch of CONFIRM messages.
Definition: bmqa_confirmeventbuilder.h:157
A variant type encompassing all types of events.
Definition: bmqa_event.h:69
Cookie for async message confirmation.
Definition: bmqa_message.h:131
A builder for MessageEvent objects.
Definition: bmqa_messageeventbuilder.h:319
Definition: bmqa_messageevent.h:64
Provide a VST representing message properties.
Definition: bmqa_messageproperties.h:92
A message sent/received to/from the BlazingMQ broker.
Definition: bmqa_message.h:170
Mechanism to mock a bmqa::Session
Definition: bmqa_mocksession.h:766
void loadMessageProperties(MessageProperties *buffer) BSLS_KEYWORD_OVERRIDE
int confirmMessages(ConfirmEventBuilder *builder) BSLS_KEYWORD_OVERRIDE
size_t unconfirmedMessages() const
Definition: bmqa_mocksession.h:1525
void finalizeStop() BSLS_KEYWORD_OVERRIDE
void setFailureCallback(const FailureCb &failureCb)
Definition: bmqa_mocksession.h:1520
int closeQueueAsync(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
int configureQueue(QueueId *queueId, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
static void initialize(bslma::Allocator *allocator=0)
void stopAsync() BSLS_KEYWORD_OVERRIDE
int getQueueId(QueueId *queueId, const bmqt::Uri &uri) BSLS_KEYWORD_OVERRIDE
int openQueueAsync(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
Call & expect_start(const bsls::TimeInterval &timeout=bsls::TimeInterval())
int startAsync(const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
Call & expect_openQueue(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval())
bool popPostedEvent(bmqa::MessageEvent *event)
Definition: bmqa_mocksession.h:1530
MockSession(const bmqt::SessionOptions &options=bmqt::SessionOptions(), bslma::Allocator *allocator=0)
CloseQueueStatus closeQueueSync(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
int confirmMessage(const Message &message) BSLS_KEYWORD_OVERRIDE
Call & expect_stopAsync()
Call & expect_confirmMessage(const Message &message)
Call & expect_openQueueAsync(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval())
Call & expect_configureQueueAsync(QueueId *queueId, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval())
void stop() BSLS_KEYWORD_OVERRIDE
OpenQueueStatus openQueueSync(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
void loadConfirmEventBuilder(ConfirmEventBuilder *builder) BSLS_KEYWORD_OVERRIDE
int configureQueueAsync(QueueId *queueId, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
Call & expect_closeQueue(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval())
void loadMessageEventBuilder(MessageEventBuilder *builder) BSLS_KEYWORD_OVERRIDE
Call & expect_confirmMessages(ConfirmEventBuilder *builder)
Call & expect_post(const MessageEvent &messageEvent)
int start(const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
Call & expect_nextEvent(const bsls::TimeInterval &timeout=bsls::TimeInterval())
Call & expect_configureQueueSync(QueueId *queueId, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval())
int closeQueue(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
Call & expect_closeQueueSync(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval())
ConfigureQueueStatus configureQueueSync(QueueId *queueId, const bmqt::QueueOptions &options, const bsls::TimeInterval &timeout) BSLS_KEYWORD_OVERRIDE
Call & expect_configureQueue(QueueId *queueId, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval())
Event nextEvent(const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
void enqueueEvent(const bmqa::Event &event)
bool emitEvent(int numEvents=1)
bsl::function< void(const char *description, const char *file, int line)> FailureCb
Definition: bmqa_mocksession.h:802
int openQueue(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE
Call & expect_finalizeStop()
int configureMessageDumping(const bslstl::StringRef &command) BSLS_KEYWORD_OVERRIDE
Call & expect_closeQueueAsync(QueueId *queueId, const bsls::TimeInterval &timeout=bsls::TimeInterval())
int post(const MessageEvent &messageEvent) BSLS_KEYWORD_OVERRIDE
Call & expect_startAsync(const bsls::TimeInterval &timeout=bsls::TimeInterval())
Call & expect_openQueueSync(QueueId *queueId, const bmqt::Uri &uri, bsls::Types::Uint64 flags, const bmqt::QueueOptions &options=bmqt::QueueOptions(), const bsls::TimeInterval &timeout=bsls::TimeInterval())
Definition: bmqa_openqueuestatus.h:62
Value-semantic efficient identifier for a queue.
Definition: bmqa_queueid.h:59
Definition: bmqa_session.h:611
Definition: bmqt_correlationid.h:193
Definition: bmqt_messageguid.h:95
Value-semantic type for options related to a queue.
Definition: bmqt_queueoptions.h:66
Value semantic type representing a URI.
Definition: bmqt_uri.h:157
Definition: bmqa_abstractsession.h:42
Struct representing parameters for an ack message.
Definition: bmqa_mocksession.h:638
QueueId d_queueId
QueueId for message being referred to.
Definition: bmqa_mocksession.h:651
bmqt::MessageGUID d_guid
Message GUID of confirmed message.
Definition: bmqa_mocksession.h:648
bmqt::CorrelationId d_correlationId
CorrelationId.
Definition: bmqa_mocksession.h:645
AckParams(const bmqt::AckResult::Enum status, const bmqt::CorrelationId &correlationId, const bmqt::MessageGUID &guid, const bmqa::QueueId &queueId)
bmqt::AckResult::Enum d_status
Status code.
Definition: bmqa_mocksession.h:642
Struct representing parameters for a push message.
Definition: bmqa_mocksession.h:666
MessageProperties d_properties
Optionally specified properties for message.
Definition: bmqa_mocksession.h:679
PushMessageParams(const bdlbb::Blob &payload, const bmqa::QueueId &queueId, const bmqt::MessageGUID &guid, const MessageProperties &properties)
QueueId d_queueId
QueueId for this message.
Definition: bmqa_mocksession.h:673
bdlbb::Blob d_payload
Payload of message.
Definition: bmqa_mocksession.h:670
bmqt::MessageGUID d_guid
GUID for message.
Definition: bmqa_mocksession.h:676
Utility methods to create bmqa events.
Definition: bmqa_mocksession.h:615
static Event createSessionEvent(bmqt::SessionEventType::Enum sessionEventType, const bmqt::CorrelationId &correlationId, const int errorCode, const bslstl::StringRef &errorDescription, bslma::Allocator *allocator)
static CloseQueueStatus createCloseQueueStatus(const QueueId &queueId, bmqt::CloseQueueResult::Enum statusCode, const bsl::string &errorDescription, bslma::Allocator *allocator=0)
static OpenQueueStatus createOpenQueueStatus(const QueueId &queueId, bmqt::OpenQueueResult::Enum statusCode, const bsl::string &errorDescription, bslma::Allocator *allocator=0)
static Event createAckEvent(const bsl::vector< AckParams > &acks, bdlbb::BlobBufferFactory *bufferFactory, bslma::Allocator *allocator)
static ConfigureQueueStatus createConfigureQueueStatus(const QueueId &queueId, bmqt::ConfigureQueueResult::Enum statusCode, const bsl::string &errorDescription, bslma::Allocator *allocator=0)
static Event createQueueSessionEvent(bmqt::SessionEventType::Enum sessionEventType, QueueId *queueId, const bmqt::CorrelationId &correlationId, int errorCode, const bslstl::StringRef &errorDescription, bslma::Allocator *allocator)
static Event createPushEvent(const bsl::vector< PushMessageParams > &pushEventParams, bdlbb::BlobBufferFactory *bufferFactory, bslma::Allocator *allocator)
Enum
Definition: bmqt_resultcode.h:437
Enum
Definition: bmqt_resultcode.h:287
Enum
Definition: bmqt_resultcode.h:137
Enum
Definition: bmqt_sessioneventtype.h:116