17 #ifndef INCLUDED_BMQA_MOCKSESSION
18 #define INCLUDED_BMQA_MOCKSESSION
555 #include <ball_log.h>
556 #include <bdlb_variant.h>
557 #include <bdlbb_blob.h>
558 #include <bdlbb_pooledblobbufferfactory.h>
559 #include <bsl_cstddef.h>
560 #include <bsl_deque.h>
561 #include <bsl_functional.h>
562 #include <bsl_memory.h>
563 #include <bsl_string.h>
564 #include <bsl_unordered_map.h>
565 #include <bsl_unordered_set.h>
566 #include <bslma_allocator.h>
567 #include <bslma_managedptr.h>
568 #include <bslma_usesbslmaallocator.h>
569 #include <bslmf_nestedtraitdeclaration.h>
570 #include <bslmt_mutex.h>
571 #include <bsls_alignedbuffer.h>
572 #include <bsls_assert.h>
573 #include <bsls_timeinterval.h>
574 #include <bsls_types.h>
583 class MessageCorrelationIdContainer;
595 class ConfirmEventBuilder;
598 #define BMQA_EXPECT_CALL(OBJ, CALL) \
599 (((OBJ).expect_##CALL).fromLocation(__FILE__, __LINE__))
612 typedef bsl::shared_ptr<bmqimp::Event> EventImplSp;
616 typedef bsl::shared_ptr<bmqimp::Queue> QueueImplSp;
681 bdlbb::BlobBufferFactory* bufferFactory,
682 bslma::Allocator* allocator);
690 bdlbb::BlobBufferFactory* bufferFactory,
691 bslma::Allocator* allocator);
703 const bslstl::StringRef& errorDescription,
704 bslma::Allocator* allocator);
714 const bslstl::StringRef& errorDescription,
715 bslma::Allocator* allocator);
723 const bsl::string& errorDescription,
724 bslma::Allocator* allocator = 0);
732 const bsl::string& errorDescription,
733 bslma::Allocator* allocator = 0);
741 const bsl::string& errorDescription,
742 bslma::Allocator* allocator = 0);
782 typedef bsl::function<
783 void(
const char* description,
const char* file,
int line)>
788 BALL_LOG_SET_CLASS_CATEGORY(
"BMQA.MOCKSESSION");
797 static const int k_MAX_SIZEOF_BMQC_TWOKEYHASHMAP = 256;
802 typedef bsls::AlignedBuffer<k_MAX_SIZEOF_BMQC_TWOKEYHASHMAP>
806 typedef bsl::shared_ptr<bmqimp::Queue> QueueImplSp;
809 typedef bsl::shared_ptr<bmqimp::Event> EventImplSp;
812 typedef bsl::shared_ptr<bmqimp::Stat> StatImplSp;
815 typedef bsl::shared_ptr<bmqimp::MessageCorrelationIdContainer>
816 CorrelationIdContainerSp;
818 typedef bsl::function<void()> CallbackFn;
826 CallbackFn d_callback;
839 typedef bdlb::Variant<Event, Job> EventOrJob;
852 e_OPEN_QUEUE_ASYNC_CALLBACK,
856 e_CLOSE_QUEUE_ASYNC_CALLBACK,
858 e_CONFIGURE_QUEUE_SYNC,
859 e_CONFIGURE_QUEUE_ASYNC,
860 e_CONFIGURE_QUEUE_ASYNC_CALLBACK,
871 typedef bsl::vector<EventOrJob> EventsAndJobs;
891 bsls::Types::Uint64 d_flags;
897 bsls::TimeInterval d_timeout;
921 EventsAndJobs d_emittedEvents;
927 MessageEvent d_messageEvent;
930 MessageConfirmationCookie d_cookie;
933 bslma::Allocator* d_allocator_p;
936 BSLMF_NESTED_TRAIT_DECLARATION(Call, bslma::UsesBslmaAllocator)
942 Call(Method method, bslma::Allocator* allocator);
944 Call(
const Call& other, bslma::Allocator* allocator);
952 Call& fromLocation(
const char* file,
int line);
956 Call& returning(
int rc);
975 Call& returning(
const Event& event);
979 Call& emitting(
const Event& event);
984 Call& emitting(
const OpenQueueStatus& openQueueResult);
989 Call& emitting(
const ConfigureQueueStatus& configureQueueResutl);
994 Call& emitting(
const CloseQueueStatus& closeQueueResult);
999 const char* methodName()
const;
1003 typedef bsl::deque<Call> CallQueue;
1006 typedef bsl::deque<bmqa::MessageEvent> PostedEvents;
1011 bdlbb::PooledBlobBufferFactory d_blobBufferFactory;
1014 bslma::ManagedPtr<SessionEventHandler> d_eventHandler_mp;
1017 mutable CallQueue d_calls;
1020 mutable bsl::deque<EventOrJob> d_eventsAndJobs;
1023 bsl::unordered_set<bmqt::MessageGUID> d_unconfirmedGUIDs;
1026 TwoKeyHashMapBuffer d_twoKeyHashMapBuffer;
1036 CorrelationIdContainerSp d_corrIdContainer_sp;
1039 PostedEvents d_postedEvents;
1042 mutable bslmt::Mutex d_mutex;
1045 bslma::ManagedPtr<bmqst::StatContext> d_rootStatContext_mp;
1048 StatImplSp d_queuesStats_sp;
1051 bmqt::SessionOptions d_sessionOptions;
1054 bslma::Allocator* d_allocator_p;
1060 static const char* toAscii(
const Method method);
1065 void initializeStats();
1074 void openQueueImp(QueueId* queueId,
1075 const bmqt::QueueOptions& options,
1076 const bmqt::Uri& uri,
1077 bsls::Types::Uint64 flags,
1083 void processIfQueueEvent(Event* event);
1088 void processIfQueueJob(Job* job);
1092 void processIfPushEvent(
const Event& event);
1098 void assertWrongCall(
const Method method)
const;
1102 void assertWrongCall(
const Method method,
const Call& expectedCall)
const;
1108 template <
class T,
class U>
1109 void assertWrongArg(
const T& expected,
1111 const Method method,
1113 const Call& call)
const;
1117 BSLMF_NESTED_TRAIT_DECLARATION(
MockSession, bslma::UsesBslmaAllocator)
1127 const bmqt::SessionOptions& options = bmqt::SessionOptions(),
1128 bslma::Allocator* allocator = 0);
1137 const bmqt::SessionOptions& options = bmqt::SessionOptions(),
1138 bslma::Allocator* allocator = 0);
1161 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1167 const bmqt::Uri& uri,
1168 bsls::Types::Uint64 flags,
1169 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1170 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1173 const bmqt::Uri& uri,
1174 bsls::Types::Uint64 flags,
1175 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1176 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1180 const bmqt::Uri& uri,
1181 bsls::Types::Uint64 flags,
1182 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1183 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1186 const bmqt::Uri& uri,
1187 bsls::Types::Uint64 flags,
1189 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1190 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1194 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1197 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1201 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1205 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1208 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1209 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1212 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1213 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1216 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1217 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1221 const bmqt::QueueOptions& options,
1223 const bsls::TimeInterval& timeout = bsls::TimeInterval());
1240 int start(const bsls::TimeInterval& timeout = bsls::TimeInterval())
1241 BSLS_KEYWORD_OVERRIDE;
1247 int startAsync(const bsls::TimeInterval& timeout = bsls::TimeInterval())
1248 BSLS_KEYWORD_OVERRIDE;
1265 BSLS_KEYWORD_OVERRIDE;
1270 BSLS_KEYWORD_OVERRIDE;
1283 const bmqt::Uri& uri) BSLS_KEYWORD_OVERRIDE;
1288 BSLS_KEYWORD_OVERRIDE;
1295 const bmqt::Uri& uri,
1296 bsls::Types::Uint64 flags,
1297 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1298 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1299 BSLS_KEYWORD_OVERRIDE;
1311 const bmqt::Uri& uri,
1312 bsls::Types::Uint64 flags,
1313 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1314 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1315 BSLS_KEYWORD_OVERRIDE;
1323 const bmqt::Uri& uri,
1324 bsls::Types::Uint64 flags,
1325 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1326 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1327 BSLS_KEYWORD_OVERRIDE;
1347 const bmqt::Uri& uri,
1348 bsls::Types::Uint64 flags,
1350 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1351 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1352 BSLS_KEYWORD_OVERRIDE;
1360 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1361 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1362 BSLS_KEYWORD_OVERRIDE;
1369 const bmqt::QueueOptions& options,
1370 const bsls::TimeInterval& timeout)
1371 BSLS_KEYWORD_OVERRIDE;
1379 const bmqt::QueueOptions& options = bmqt::QueueOptions(),
1380 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1381 BSLS_KEYWORD_OVERRIDE;
1392 const bmqt::QueueOptions& options,
1394 const bsls::TimeInterval& timeout =
1395 bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1402 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1403 BSLS_KEYWORD_OVERRIDE;
1412 const bsls::TimeInterval& timeout = bsls::TimeInterval())
1413 BSLS_KEYWORD_OVERRIDE;
1420 const bsls::TimeInterval& timeout =
1421 bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1432 const bsls::TimeInterval& timeout =
1433 bsls::TimeInterval()) BSLS_KEYWORD_OVERRIDE;
1442 BSLS_KEYWORD_OVERRIDE;
1452 BSLS_KEYWORD_OVERRIDE;
1460 BSLS_KEYWORD_OVERRIDE;
1491 d_failureCb = failureCb;
1496 return d_unconfirmedGUIDs.size();
1504 bslmt::LockGuard<bslmt::Mutex> guard(&d_mutex);
1506 if (d_postedEvents.empty()) {
1510 *
event = d_postedEvents.front();
1511 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:750
void loadMessageProperties(MessageProperties *buffer) BSLS_KEYWORD_OVERRIDE
int confirmMessages(ConfirmEventBuilder *builder) BSLS_KEYWORD_OVERRIDE
size_t unconfirmedMessages() const
Definition: bmqa_mocksession.h:1494
void finalizeStop() BSLS_KEYWORD_OVERRIDE
void setFailureCallback(const FailureCb &failureCb)
Definition: bmqa_mocksession.h:1489
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:1499
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:784
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:622
QueueId d_queueId
QueueId for message being referred to.
Definition: bmqa_mocksession.h:635
bmqt::MessageGUID d_guid
Message GUID of confirmed message.
Definition: bmqa_mocksession.h:632
bmqt::CorrelationId d_correlationId
CorrelationId.
Definition: bmqa_mocksession.h:629
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:626
Struct representing parameters for a push message.
Definition: bmqa_mocksession.h:650
MessageProperties d_properties
Optionally specified properties for message.
Definition: bmqa_mocksession.h:663
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:657
bdlbb::Blob d_payload
Payload of message.
Definition: bmqa_mocksession.h:654
bmqt::MessageGUID d_guid
GUID for message.
Definition: bmqa_mocksession.h:660
Utility methods to create bmqa events.
Definition: bmqa_mocksession.h:606
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