From 35451ff855b5a738e1c475d2a0df757a79848157 Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Fri, 6 Dec 2024 01:51:27 +0200 Subject: [PATCH 01/17] Refactor[BMQ,MQB]: remove redundant virtual, s_allocator_p (#538) Signed-off-by: Evgeny Malygin --- src/groups/bmq/bmqa/bmqa_mocksession.h | 44 +-- .../bmq/bmqeval/bmqeval_simpleevaluator.h | 11 +- src/groups/bmq/bmqu/bmqu_operationchain.h | 2 +- .../mqb/mqbblp/mqbblp_clusterqueuehelper.h | 25 +- .../mqb/mqbblp/mqbblp_clusterstatemanager.h | 118 ++++---- src/groups/mqb/mqbblp/mqbblp_domain.h | 13 +- .../mqb/mqbblp/mqbblp_queueenginetester.h | 2 +- .../mqb/mqbblp/mqbblp_relayqueueengine.h | 53 ++-- .../mqb/mqbblp/mqbblp_rootqueueengine.h | 70 +++-- src/groups/mqb/mqbblp/mqbblp_storagemanager.h | 173 ++++++----- .../mqb/mqbc/mqbc_clusterstatemanager.h | 198 ++++++------- .../mqbc_incoreclusterstateledgeriterator.h | 21 +- src/groups/mqb/mqbc/mqbc_storagemanager.h | 268 +++++++++--------- .../mqb/mqbmock/mqbmock_logidgenerator.h | 11 +- src/groups/mqb/mqbmock/mqbmock_queueengine.h | 47 ++- .../mqb/mqbmock/mqbmock_storagemanager.h | 159 ++++++----- src/groups/mqb/mqbs/mqbs_filebackedstorage.h | 115 ++++---- src/groups/mqb/mqbs/mqbs_filestore.h | 2 +- src/groups/mqb/mqbs/mqbs_inmemorystorage.h | 115 ++++---- src/groups/mqb/mqbsl/mqbsl_inmemorylog.h | 58 ++-- src/groups/mqb/mqbsl/mqbsl_ledger.h | 74 +++-- .../mqb/mqbsl/mqbsl_memorymappedondisklog.h | 60 ++-- .../mqb/mqbsl/mqbsl_readwriteondisklog.h | 60 ++-- 23 files changed, 816 insertions(+), 883 deletions(-) diff --git a/src/groups/bmq/bmqa/bmqa_mocksession.h b/src/groups/bmq/bmqa/bmqa_mocksession.h index b9ba02dd81..453f3b4d86 100644 --- a/src/groups/bmq/bmqa/bmqa_mocksession.h +++ b/src/groups/bmq/bmqa/bmqa_mocksession.h @@ -209,8 +209,10 @@ /// ``` /// void unitTest() /// { +/// bslma::Allocator* allocator = bmqtst::TestHelperUtil::allocator(); +/// /// // Create an event handler -/// EventHandler eventHandler(d_allocator_p); +/// EventHandler eventHandler(allocator); /// /// // The following static initializer method calls all the appropriate /// // static initializers of the underlying components needed for the @@ -218,16 +220,16 @@ /// // any case but if events need to be built outside the scope of the /// // creation of 'MockSession' you will need to explicitly invoke this /// // static initializer method. -/// bmqa::MockSession::initialize(s_allocator_p); +/// bmqa::MockSession::initialize(allocator); /// /// bslma::ManagedPtr handlerMp; /// handlerMp.load(&eventHandler, 0, bslma::ManagedPtrUtil::noOpDeleter); /// /// bmqa::MockSession mockSession(handlerMp, -/// bmqt::SessionOptions(d_allocator_p), -/// d_allocator_p); +/// bmqt::SessionOptions(allocator), +/// allocator); /// -/// bmqa::QueueId queueId(bmqt::CorrelationId(1), d_allocator_p); +/// bmqa::QueueId queueId(bmqt::CorrelationId(1), allocator); /// bmqt::CorrelationId corrId(1); /// /// // Expect a call to start and the call emits an 'e_CONNECTED' event. @@ -237,7 +239,7 @@ /// bmqt::SessionEventType::e_CONNECTED, /// 0, // statusCode /// "", // errorDescription -/// d_allocator_p)); +/// allocator)); /// /// // Make a call to startAsync and emit the event that is enqueued from /// // that call. @@ -292,7 +294,7 @@ /// queueId1, /// bmqt::OpenQueueResult::e_TIMEOUT, // statusCode /// "Local Timeout", // errorDescription -/// d_allocator_p); +/// allocator); /// mockSession.enqueueEvent(openQueueResult); /// /// // We just enqueued a 'bmqa::OpenQueueStatus' to be emitted. We can @@ -321,13 +323,13 @@ /// /// // Simply creating a blob buffer factory on the stack to be used by /// // 'createAckEvent'. Typically you would have one for the component. -/// bdlbb::PooledBlobBufferFactory bufferFactory(4 * 1024, d_allocator_p); +/// bdlbb::PooledBlobBufferFactory bufferFactory(4 * 1024, allocator); /// /// // The method 'createAckEvent' takes a vector of 'AckParams' to /// // specify multiple acks per event, but here we are only acknowledging /// // 1 message. Specify a positive ack with 'e_SUCCESS' here but you /// // can specify any from 'bmqt::AckResult::Enum'. -/// bsl::vector acks(d_allocator_p); +/// bsl::vector acks(allocator); /// acks.emplace_back(bmqt::AckResult::e_SUCCESS, /// bmqt::CorrelationId(1), /// bmqt::MessageGUID(), // Real GUID needed if you want @@ -339,7 +341,7 @@ /// mockSession.enqueueEvent(bmqa::MockSessionUtil::createAckEvent( /// acks, /// &bufferFactory, -/// d_allocator_p)); +/// allocator)); /// /// // Emit the enqueued ack event. /// ASSERT_EQ(mockSession.emitEvent(), true); @@ -365,7 +367,7 @@ /// bmqt::SessionEventType::e_DISCONNECTED, /// 0, // statusCode /// "", // errorDescription -/// d_allocator_p)); +/// allocator)); /// ASSERT_EQ(mockSession.emitEvent(), true); /// /// // Our event handler internally just stores the event emitted, so pop @@ -396,9 +398,11 @@ /// ``` /// void unitTest() /// { +/// bslma::Allocator* allocator = bmqtst::TestHelperUtil::allocator(); +/// /// // MockSession created without an eventHandler. -/// bmqa::MockSession mockSession(bmqt::SessionOptions(d_allocator_p), -/// d_allocator_p); +/// bmqa::MockSession mockSession(bmqt::SessionOptions(allocator), +/// allocator); /// /// // The following static initializer method calls all the appropriate /// // static initializers of the underlying components needed for the @@ -406,7 +410,7 @@ /// // any case but if events need to be built outside the scope of the /// // creation of 'MockSession' you will need to explicitly invoke this /// // static initializer method. -/// // bmqa::MockSession::initialize(s_allocator_p); +/// // bmqa::MockSession::initialize(allocator); /// /// // Create simple queueIds and corrIds /// bmqa::QueueId queueId(1); @@ -421,7 +425,7 @@ /// /// // Simply creating a blob buffer factory on the stack to be used by /// // 'createAckEvent'. Typically you would have one for the component. -/// bdlbb::PooledBlobBufferFactory bufferFactory(4 * 1024, d_allocator_p); +/// bdlbb::PooledBlobBufferFactory bufferFactory(4 * 1024, allocator); /// /// // We then expect that 'nextEvent' will be called to return the /// // 'e_CONNECTED' event from the broker @@ -431,7 +435,7 @@ /// bmqt::CorrelationId::autoValue(), /// 0, // errorCode /// "", // errorDescription -/// d_allocator_p)); +/// allocator)); /// // Note that we use an 'autoValue' for correlationId because it's /// // irrelevant for a 'CONNECTED' event. /// @@ -448,14 +452,14 @@ /// queueId, /// bmqt::OpenQueueResult::e_SUCCESS, // statusCode /// "", // errorDescription -/// d_allocator_p); +/// allocator); /// BMQA_EXPECT_CALL(mockSession, openQueueSync(&queueId, uri, flags)) /// .returning(expectedResult); /// /// // Build our incoming message event. /// bsl::vector pushMsgs( -/// d_allocator_p); -/// bdlbb::Blob payload(&bufferFactory, d_allocator_p); +/// allocator); +/// bdlbb::Blob payload(&bufferFactory, allocator); /// bdlbb::BlobUtil::append(&payload, "hello", 6); /// /// const char guidHex[] = "00000000000000000000000000000001"; @@ -473,7 +477,7 @@ /// bmqa::Event pushMsgEvent = bmqa::MockSessionUtil::createPushEvent( /// pushMsgs, /// &bufferFactory, -/// d_allocator_p); +/// allocator); /// BMQA_EXPECT_CALL(mockSession, nextEvent(bsls::TimeInterval())) /// .returning(pushMsgEvent); /// diff --git a/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.h b/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.h index 4a44542a38..79e4122ba1 100644 --- a/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.h +++ b/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.h @@ -39,20 +39,21 @@ /// Basic Usage Example ///------------------- // +// bslma::Allocator* allocator = bmqtst::TestHelperUtil::allocator(); +// // SimpleEvaluator evaluator; // bsl::string expression = "foo < 3 | bar > 4"; // -// CompilationContext compilationContext(s_allocator_p); +// CompilationContext compilationContext(allocator); // // if (int rc = evaluator.compile(expression, compilationContext)) { // bsl::cerr << compilationContext.lastErrorMessage() << "\n"; // // don't use evaluator // } // -// MockPropertiesReader reader(s_allocator_p); -// EvaluationContext evaluationContext(&reader, -// bmqtst::TestHelperUtil::allocator()); bool result = -// evaluator.evaluate(evaluationContext); +// MockPropertiesReader reader(allocator); +// EvaluationContext evaluationContext(&reader, allocator); +// bool result = evaluator.evaluate(evaluationContext); //.. // BDE diff --git a/src/groups/bmq/bmqu/bmqu_operationchain.h b/src/groups/bmq/bmqu/bmqu_operationchain.h index b6381266d3..01465b8246 100644 --- a/src/groups/bmq/bmqu/bmqu_operationchain.h +++ b/src/groups/bmq/bmqu/bmqu_operationchain.h @@ -130,7 +130,7 @@ // 'bmqu::OperationChain'. //.. // // create a chain -// bmqu::OperationChain chain(s_allocator_p); +// bmqu::OperationChain chain(bmqtst::TestHelperUtil::allocator()); // // static const int k_MY_PAYLOAD = 42; // static const int k_MY_CLIENT_ID = 42; diff --git a/src/groups/mqb/mqbblp/mqbblp_clusterqueuehelper.h b/src/groups/mqb/mqbblp/mqbblp_clusterqueuehelper.h index 5d448dca21..f698d0e2b2 100644 --- a/src/groups/mqb/mqbblp/mqbblp_clusterqueuehelper.h +++ b/src/groups/mqb/mqbblp/mqbblp_clusterqueuehelper.h @@ -93,9 +93,10 @@ namespace mqbblp { // ======================== /// Mechanism to manage queues on a cluster. -class ClusterQueueHelper : public mqbc::ClusterStateObserver, - public mqbc::ClusterMembershipObserver, - public mqbc::ElectorInfoObserver { +class ClusterQueueHelper BSLS_KEYWORD_FINAL +: public mqbc::ClusterStateObserver, + public mqbc::ClusterMembershipObserver, + public mqbc::ElectorInfoObserver { private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBBLP.CLUSTERQUEUEHELPER"); @@ -954,7 +955,7 @@ class ClusterQueueHelper : public mqbc::ClusterStateObserver, /// Callback invoked when self node's status changes to the specified /// `value`. - virtual void onSelfNodeStatus(bmqp_ctrlmsg::NodeStatus::Value value) + void onSelfNodeStatus(bmqp_ctrlmsg::NodeStatus::Value value) BSLS_KEYWORD_OVERRIDE; // PRIVATE MANIPULATORS @@ -965,8 +966,8 @@ class ClusterQueueHelper : public mqbc::ClusterStateObserver, /// for the `node`, and it implies that the cluster has transitioned to /// a state of no leader, and in this case, `status` will be /// `UNDEFINED`. - virtual void onClusterLeader(mqbnet::ClusterNode* node, - mqbc::ElectorInfoLeaderStatus::Enum status) + void onClusterLeader(mqbnet::ClusterNode* node, + mqbc::ElectorInfoLeaderStatus::Enum status) BSLS_KEYWORD_OVERRIDE; // PRIVATE MANIPULATORS @@ -977,7 +978,7 @@ class ClusterQueueHelper : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onQueueAssigned(const mqbc::ClusterStateQueueInfo& info) + void onQueueAssigned(const mqbc::ClusterStateQueueInfo& info) BSLS_KEYWORD_OVERRIDE; /// Callback invoked when a queue with the specified `info` gets @@ -985,7 +986,7 @@ class ClusterQueueHelper : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onQueueUnassigned(const mqbc::ClusterStateQueueInfo& info) + void onQueueUnassigned(const mqbc::ClusterStateQueueInfo& info) BSLS_KEYWORD_OVERRIDE; /// Callback invoked when a queue with the specified `uri` belonging to @@ -995,10 +996,10 @@ class ClusterQueueHelper : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onQueueUpdated(const bmqt::Uri& uri, - const bsl::string& domain, - const AppInfos& addedAppIds, - const AppInfos& removedAppIds = AppInfos()) + void onQueueUpdated(const bmqt::Uri& uri, + const bsl::string& domain, + const AppInfos& addedAppIds, + const AppInfos& removedAppIds = AppInfos()) BSLS_KEYWORD_OVERRIDE; private: diff --git a/src/groups/mqb/mqbblp/mqbblp_clusterstatemanager.h b/src/groups/mqb/mqbblp/mqbblp_clusterstatemanager.h index 25acc06fce..8a1fbc85b4 100644 --- a/src/groups/mqb/mqbblp/mqbblp_clusterstatemanager.h +++ b/src/groups/mqb/mqbblp/mqbblp_clusterstatemanager.h @@ -82,8 +82,9 @@ namespace mqbblp { // class ClusterStateManager // ========================= -class ClusterStateManager : public mqbc::ClusterStateObserver, - public mqbi::ClusterStateManager { +class ClusterStateManager BSLS_KEYWORD_FINAL +: public mqbc::ClusterStateObserver, + public mqbi::ClusterStateManager { private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBBLP.CLUSTERSTATEMANAGER"); @@ -239,7 +240,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onPartitionPrimaryAssignment( + void onPartitionPrimaryAssignment( int partitionId, mqbnet::ClusterNode* primary, unsigned int leaseId, @@ -288,30 +289,29 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; + int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Stop this instance. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void stop() BSLS_KEYWORD_OVERRIDE; + void stop() BSLS_KEYWORD_OVERRIDE; /// Set the storage manager to the specified `value`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - setStorageManager(mqbi::StorageManager* value) BSLS_KEYWORD_OVERRIDE; + void setStorageManager(mqbi::StorageManager* value) BSLS_KEYWORD_OVERRIDE; /// Set the queue assigning callback to the specified `value`. - virtual void + void setQueueAssigningCb(const QueueAssigningCb& value) BSLS_KEYWORD_OVERRIDE; - virtual void setQueueUnassigningCb(const QueueUnassigningCb& value) + void setQueueUnassigningCb(const QueueUnassigningCb& value) BSLS_KEYWORD_OVERRIDE; // Set the queue unassigning callback to the specified 'value'. - virtual void setAfterPartitionPrimaryAssignmentCb( + void setAfterPartitionPrimaryAssignmentCb( const AfterPartitionPrimaryAssignmentCb& value) BSLS_KEYWORD_OVERRIDE; // Set the after partition primary assignment callback to the specified // 'value'. @@ -321,18 +321,17 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - setPrimary(int partitionId, - unsigned int leaseId, - mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; + void setPrimary(int partitionId, + unsigned int leaseId, + mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; /// Set the primary status of the specified `partitionId` to the /// specified `status`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void setPrimaryStatus(int partitionId, - bmqp_ctrlmsg::PrimaryStatus::Value status) + void setPrimaryStatus(int partitionId, + bmqp_ctrlmsg::PrimaryStatus::Value status) BSLS_KEYWORD_OVERRIDE; /// Mark the specified `partitions` as orphaned partitions, due to the @@ -340,9 +339,8 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - markOrphan(const bsl::vector& partitions, - mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; + void markOrphan(const bsl::vector& partitions, + mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; /// Assign an available node to each partition which is currently /// orphan or is assigned to a node which is not available, and load the @@ -351,9 +349,8 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void assignPartitions( - bsl::vector* partitions) - BSLS_KEYWORD_OVERRIDE; + void assignPartitions(bsl::vector* + partitions) BSLS_KEYWORD_OVERRIDE; /// Perform the actual assignment of the queue represented by the /// specified `uri` for a cluster member queue, that is assign it a @@ -366,7 +363,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual QueueAssignmentResult::Enum + QueueAssignmentResult::Enum assignQueue(const bmqt::Uri& uri, bmqp_ctrlmsg::Status* status = 0) BSLS_KEYWORD_OVERRIDE; @@ -377,19 +374,18 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void registerQueueInfo(const bmqt::Uri& uri, - int partitionId, - const mqbu::StorageKey& queueKey, - const AppInfos& appIdInfos, - bool forceUpdate) BSLS_KEYWORD_OVERRIDE; + void registerQueueInfo(const bmqt::Uri& uri, + int partitionId, + const mqbu::StorageKey& queueKey, + const AppInfos& appIdInfos, + bool forceUpdate) BSLS_KEYWORD_OVERRIDE; /// Unassign the queue in the specified `advisory` by applying the /// advisory to the cluster state ledger owned by this object. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - unassignQueue(const bmqp_ctrlmsg::QueueUnassignedAdvisory& advisory) + void unassignQueue(const bmqp_ctrlmsg::QueueUnassignedAdvisory& advisory) BSLS_KEYWORD_OVERRIDE; /// Send the current cluster state to follower nodes. If the specified @@ -404,7 +400,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void sendClusterState( + void sendClusterState( bool sendPartitionPrimaryInfo, bool sendQueuesInfo, mqbnet::ClusterNode* node = 0, @@ -417,32 +413,30 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - registerAppId(const bsl::string& appId, - const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; + void registerAppId(const bsl::string& appId, + const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; /// Unregister the specified `appId` for all queues in the specified /// `domain`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - unregisterAppId(const bsl::string& appId, - const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; + void unregisterAppId(const bsl::string& appId, + const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; /// Invoked when a newly elected (i.e. passive) leader node initiates a /// sync with followers before transitioning to active leader. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void initiateLeaderSync(bool wait) BSLS_KEYWORD_OVERRIDE; + void initiateLeaderSync(bool wait) BSLS_KEYWORD_OVERRIDE; /// Process the specified leader-sync-state-query `message` from the /// specified `source`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processLeaderSyncStateQuery( + void processLeaderSyncStateQuery( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -451,7 +445,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processLeaderSyncDataQuery( + void processLeaderSyncDataQuery( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -460,16 +454,16 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processFollowerLSNRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processFollowerLSNRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; /// Process the specified follower-cluster-state-request `message` from /// the specified `source`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processFollowerClusterStateRequest( + void processFollowerClusterStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -478,7 +472,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processRegistrationRequest( + void processRegistrationRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -486,20 +480,20 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processClusterStateEvent( + void processClusterStateEvent( const mqbi::DispatcherClusterStateEvent& event) BSLS_KEYWORD_OVERRIDE; /// Process any queue assignment and unassignment advisory messages /// which were received while self node was starting. Behavior is /// undefined unless self node has transitioned to AVAILABLE. - virtual void processBufferedQueueAdvisories() BSLS_KEYWORD_OVERRIDE; + void processBufferedQueueAdvisories() BSLS_KEYWORD_OVERRIDE; /// Process the queue assignment in the specified `request`, received /// from the specified `requester`. Return the queue assignment result. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processQueueAssignmentRequest( + void processQueueAssignmentRequest( const bmqp_ctrlmsg::ControlMessage& request, mqbnet::ClusterNode* requester) BSLS_KEYWORD_OVERRIDE; @@ -513,7 +507,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// TODO_CSL: This is the current workflow which we should be able to /// remove after the new workflow via /// ClusterQueueHelper::onQueueAssigned() is stable. - virtual void + void processQueueAssignmentAdvisory(const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source, bool delayed = false) BSLS_KEYWORD_OVERRIDE; @@ -527,7 +521,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// TODO_CSL: This is the current workflow which we should be able to /// remove after the new workflow via /// ClusterQueueHelper::onQueueUnassigned() is stable. - virtual void processQueueUnassignedAdvisory( + void processQueueUnassignedAdvisory( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -541,7 +535,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// TODO_CSL: This is the current workflow which we should be able to /// remove after the new workflow via /// ClusterQueueHelper::onQueueUnassigned() is stable. - virtual void processQueueUnAssignmentAdvisory( + void processQueueUnAssignmentAdvisory( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source, bool delayed = false) BSLS_KEYWORD_OVERRIDE; @@ -551,7 +545,7 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processPartitionPrimaryAdvisory( + void processPartitionPrimaryAdvisory( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -560,41 +554,39 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void + void processLeaderAdvisory(const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Process the shutdown event. /// /// THREAD: Executed by any thread. - virtual void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; + void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; /// Invoked when the specified `node` becomes unavailable. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - onNodeUnavailable(mqbnet::ClusterNode* node) BSLS_KEYWORD_OVERRIDE; + void onNodeUnavailable(mqbnet::ClusterNode* node) BSLS_KEYWORD_OVERRIDE; /// Invoked when this node is stopping. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onNodeStopping() BSLS_KEYWORD_OVERRIDE; + void onNodeStopping() BSLS_KEYWORD_OVERRIDE; /// Invoked when this node is stopped. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onNodeStopped() BSLS_KEYWORD_OVERRIDE; + void onNodeStopped() BSLS_KEYWORD_OVERRIDE; // ACCESSORS // (virtual: mqbi::ClusterStateManager) - virtual bool isFirstLeaderAdvisory() const BSLS_KEYWORD_OVERRIDE; + bool isFirstLeaderAdvisory() const BSLS_KEYWORD_OVERRIDE; /// Return the cluster state managed by this instacne. - virtual const mqbc::ClusterState* - clusterState() const BSLS_KEYWORD_OVERRIDE; + const mqbc::ClusterState* clusterState() const BSLS_KEYWORD_OVERRIDE; /// Invoked to perform validation of CSL's contents (on disk) against /// the "real" cluster state. Logs a descriptive error message if @@ -604,14 +596,14 @@ class ClusterStateManager : public mqbc::ClusterStateObserver, /// dispatcher thread. /// /// TBD: This is mostly temporary, used in phase I of integrating CSL. - virtual void validateClusterStateLedger() const BSLS_KEYWORD_OVERRIDE; + void validateClusterStateLedger() const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `out` the latest ledger LSN associated with /// this cluster node. Return 0 on success, and a non-zero error code /// on failure. Note that this involves iteration over the entire /// ledger which can be an expensive operation. This is necessary to /// give the latest LSN from the ledger. - virtual int latestLedgerLSN(bmqp_ctrlmsg::LeaderMessageSequence* out) const + int latestLedgerLSN(bmqp_ctrlmsg::LeaderMessageSequence* out) const BSLS_KEYWORD_OVERRIDE; }; diff --git a/src/groups/mqb/mqbblp/mqbblp_domain.h b/src/groups/mqb/mqbblp/mqbblp_domain.h index af3af7172b..dc1b760044 100644 --- a/src/groups/mqb/mqbblp/mqbblp_domain.h +++ b/src/groups/mqb/mqbblp/mqbblp_domain.h @@ -89,7 +89,8 @@ namespace mqbblp { // ============ /// Domain implementation -class Domain : public mqbi::Domain, public mqbc::ClusterStateObserver { +class Domain BSLS_KEYWORD_FINAL : public mqbi::Domain, + public mqbc::ClusterStateObserver { private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBBLP.DOMAIN"); @@ -210,7 +211,7 @@ class Domain : public mqbi::Domain, public mqbc::ClusterStateObserver { /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onQueueAssigned(const mqbc::ClusterStateQueueInfo& info) + void onQueueAssigned(const mqbc::ClusterStateQueueInfo& info) BSLS_KEYWORD_OVERRIDE; /// Callback invoked when a queue with the specified `uri` belonging to @@ -220,10 +221,10 @@ class Domain : public mqbi::Domain, public mqbc::ClusterStateObserver { /// /// Note: The `uri` could belong to a different domain than this one, in /// which case this queue update is ignored. - virtual void onQueueUpdated(const bmqt::Uri& uri, - const bsl::string& domain, - const AppInfos& addedAppIds, - const AppInfos& removedAppIds = AppInfos()) + void onQueueUpdated(const bmqt::Uri& uri, + const bsl::string& domain, + const AppInfos& addedAppIds, + const AppInfos& removedAppIds = AppInfos()) BSLS_KEYWORD_OVERRIDE; private: diff --git a/src/groups/mqb/mqbblp/mqbblp_queueenginetester.h b/src/groups/mqb/mqbblp/mqbblp_queueenginetester.h index bdd19a6a8d..ea207a234c 100644 --- a/src/groups/mqb/mqbblp/mqbblp_queueenginetester.h +++ b/src/groups/mqb/mqbblp/mqbblp_queueenginetester.h @@ -52,7 +52,7 @@ // // First, we create a 'QueueEngineTester' object and the Priority Queue Engine. //.. -// mqbblp::QueueEngineTester tester(s_allocator_p); +// mqbblp::QueueEngineTester tester(bmqtst::TestHelperUtil::allocator()); // tester.createQueueEngine(); //.. // Then, we get handles for three consumers, each with one reader. diff --git a/src/groups/mqb/mqbblp/mqbblp_relayqueueengine.h b/src/groups/mqb/mqbblp/mqbblp_relayqueueengine.h index 5a32aaede5..ac4cd31ae0 100644 --- a/src/groups/mqb/mqbblp/mqbblp_relayqueueengine.h +++ b/src/groups/mqb/mqbblp/mqbblp_relayqueueengine.h @@ -140,7 +140,7 @@ struct RelayQueueEngine_AppState : QueueEngineUtil_AppState { // ====================== /// QueueEngine implementation for a BlazingMQ relay node (replica/proxy). -class RelayQueueEngine : public mqbi::QueueEngine { +class RelayQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBBLP.RELAYQUEUEENGINE"); @@ -376,7 +376,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { bslma::Allocator* allocator); /// Destructor - virtual ~RelayQueueEngine() BSLS_KEYWORD_OVERRIDE; + ~RelayQueueEngine() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS // (virtual mqbi::QueueEngine) @@ -384,13 +384,13 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// Configure this instance. The specified `isReconfigure` flag indicate /// if queue is being reconfigured. Return zero on success, non-zero value /// otherwise and populate the specified `errorDescription`. - virtual int configure(bsl::ostream& errorDescription, - bool isReconfigure) BSLS_KEYWORD_OVERRIDE; + int configure(bsl::ostream& errorDescription, + bool isReconfigure) BSLS_KEYWORD_OVERRIDE; /// Reset the internal state of this engine. If the optionally specified /// 'keepConfirming' is 'true', keep the data structures for CONFIRMs /// processing. - virtual void resetState(bool isShuttingDown = false) BSLS_KEYWORD_OVERRIDE; + void resetState(bool isShuttingDown = false) BSLS_KEYWORD_OVERRIDE; /// Rebuild the internal state of this engine. This method is invoked /// when the queue this engine is associated with is created from an @@ -401,7 +401,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// `rebuildInternalState` must be called on an empty-state object /// (i.e., which has just been constructed, or following a call to /// `resetState`) after it has been configured. - virtual int + int rebuildInternalState(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Obtain and return a handle to this queue for the client identified @@ -410,7 +410,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// finished. In case of error, return a null pointer. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual mqbi::QueueHandle* + mqbi::QueueHandle* getHandle(const bsl::shared_ptr& clientContext, const bmqp_ctrlmsg::QueueHandleParameters& handleParameters, @@ -423,7 +423,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// finished. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void configureHandle( + void configureHandle( mqbi::QueueHandle* handle, const bmqp_ctrlmsg::StreamParameters& streamParameters, const mqbi::QueueHandle::HandleConfiguredCallback& configuredCb) @@ -434,7 +434,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// `releasedCb` when done. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void + void releaseHandle(mqbi::QueueHandle* handle, const bmqp_ctrlmsg::QueueHandleParameters& handleParameters, bool isFinal, @@ -448,7 +448,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// messages to the `handle`. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void + void onHandleUsable(mqbi::QueueHandle* handle, unsigned int upstreamSubscriptionId) BSLS_KEYWORD_OVERRIDE; @@ -456,9 +456,8 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// `msgGUID` is available on the queue and ready to be sent to eventual /// interested clients. If available, the specified `source` points to /// the originator of the message. - virtual void - afterNewMessage(const bmqt::MessageGUID& msgGUID, - mqbi::QueueHandle* source) BSLS_KEYWORD_OVERRIDE; + void afterNewMessage(const bmqt::MessageGUID& msgGUID, + mqbi::QueueHandle* source) BSLS_KEYWORD_OVERRIDE; /// Called by the `mqbi::Queue` when the message identified by the /// specified `msgGUID` is confirmed for the specified @@ -469,7 +468,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// associated storage, or 1 if there are still references. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual int + int onConfirmMessage(mqbi::QueueHandle* handle, const bmqt::MessageGUID& msgGUID, unsigned int upstreamSubQueueId) BSLS_KEYWORD_OVERRIDE; @@ -488,7 +487,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// `msgGUID` is removed from the queue (either it's TTL expired, it was /// confirmed by all recipients, etc). The QueueEngine may use this to /// update the positions of the QueueHandles it manages. - virtual void beforeMessageRemoved(const bmqt::MessageGUID& msgGUID) + void beforeMessageRemoved(const bmqt::MessageGUID& msgGUID) BSLS_KEYWORD_OVERRIDE; /// Called by the mqbi::Queue *after* *all* messages are removed from @@ -500,7 +499,7 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// `appId` must be empty if and only if `appKey` is null. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void + void afterQueuePurged(const bsl::string& appId, const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; @@ -509,26 +508,23 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// ensuring messages on the queue are flowing and not accumulating. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - onTimer(bsls::Types::Int64 currentTimer) BSLS_KEYWORD_OVERRIDE; + void onTimer(bsls::Types::Int64 currentTimer) BSLS_KEYWORD_OVERRIDE; /// Called after creation of a new storage for the specified /// `appIdKeyPair`. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - registerStorage(const bsl::string& appId, - const mqbu::StorageKey& appKey, - unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; + void registerStorage(const bsl::string& appId, + const mqbu::StorageKey& appKey, + unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; /// Called after removal of the storage for the specified /// `appIdKeyPair`. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - unregisterStorage(const bsl::string& appId, - const mqbu::StorageKey& appKey, - unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; + void unregisterStorage(const bsl::string& appId, + const mqbu::StorageKey& appKey, + unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; /// Not valid for 'RelayQueueEngine' mqbi::StorageResult::Enum evaluateAutoSubscriptions( @@ -556,12 +552,11 @@ class RelayQueueEngine : public mqbi::QueueEngine { /// posted to the queue managed by this engine. Note that returned /// value may or may not be equal to `numOpenReaderHandles()` depending /// upon the specific type of this engine. - virtual unsigned int messageReferenceCount() const BSLS_KEYWORD_OVERRIDE; + unsigned int messageReferenceCount() const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `out` object the internal information about /// this queue engine and associated queue handles. - virtual void - loadInternals(mqbcmd::QueueEngine* out) const BSLS_KEYWORD_OVERRIDE; + void loadInternals(mqbcmd::QueueEngine* out) const BSLS_KEYWORD_OVERRIDE; /// Load upstream subQueue id into the specified `subQueueId` given the /// specified upstream `subscriptionId`. diff --git a/src/groups/mqb/mqbblp/mqbblp_rootqueueengine.h b/src/groups/mqb/mqbblp/mqbblp_rootqueueengine.h index edc41cdbb9..a9567fd9f3 100644 --- a/src/groups/mqb/mqbblp/mqbblp_rootqueueengine.h +++ b/src/groups/mqb/mqbblp/mqbblp_rootqueueengine.h @@ -247,13 +247,13 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// Configure this instance. The specified `isReconfigure` flag indicates /// if queue is being reconfigured. Return zero on success, non-zero value /// otherwise and populate the specified `errorDescription`. - virtual int configure(bsl::ostream& errorDescription, - bool isReconfigure) BSLS_KEYWORD_OVERRIDE; + int configure(bsl::ostream& errorDescription, + bool isReconfigure) BSLS_KEYWORD_OVERRIDE; /// Reset the internal state of this engine. If the optionally specified /// 'keepConfirming' is 'true', keep the data structures for CONFIRMs /// processing. - virtual void resetState(bool isShuttingDown = false) BSLS_KEYWORD_OVERRIDE; + void resetState(bool isShuttingDown = false) BSLS_KEYWORD_OVERRIDE; /// Rebuild the internal state of this engine. This method is invoked /// when the queue this engine is associated with is created from an @@ -264,7 +264,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// `rebuildInternalState` must be called on an empty-state object /// (i.e., which has just been constructed, or following a call to /// `resetState`) after it has been configured. - virtual int + int rebuildInternalState(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Obtain and return a handle to this queue for the client identified @@ -273,7 +273,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// finished. In case of error, return a null pointer. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual mqbi::QueueHandle* + mqbi::QueueHandle* getHandle(const bsl::shared_ptr& clientContext, const bmqp_ctrlmsg::QueueHandleParameters& handleParameters, @@ -286,7 +286,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// finished. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void configureHandle( + void configureHandle( mqbi::QueueHandle* handle, const bmqp_ctrlmsg::StreamParameters& streamParameters, const mqbi::QueueHandle::HandleConfiguredCallback& configuredCb) @@ -297,7 +297,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// `releasedCb` when done. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void + void releaseHandle(mqbi::QueueHandle* handle, const bmqp_ctrlmsg::QueueHandleParameters& handleParameters, bool isFinal, @@ -311,7 +311,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// messages to the `handle`. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void + void onHandleUsable(mqbi::QueueHandle* handle, unsigned int upstreamSubscriptionId) BSLS_KEYWORD_OVERRIDE; @@ -321,9 +321,8 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// the originator of the message. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - afterNewMessage(const bmqt::MessageGUID& msgGUID, - mqbi::QueueHandle* source) BSLS_KEYWORD_OVERRIDE; + void afterNewMessage(const bmqt::MessageGUID& msgGUID, + mqbi::QueueHandle* source) BSLS_KEYWORD_OVERRIDE; /// Called by the `mqbi::Queue` when the message identified by the /// specified `msgGUID` is confirmed for the specified `subQueueId` @@ -334,10 +333,9 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// or 1 if there are still references. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual int - onConfirmMessage(mqbi::QueueHandle* handle, - const bmqt::MessageGUID& msgGUID, - unsigned int subQueueId) BSLS_KEYWORD_OVERRIDE; + int onConfirmMessage(mqbi::QueueHandle* handle, + const bmqt::MessageGUID& msgGUID, + unsigned int subQueueId) BSLS_KEYWORD_OVERRIDE; /// Called by the `mqbi::Queue` when the message identified by the /// specified `msgGUID` is rejected for the specified @@ -345,7 +343,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// identified by the specified `handle`. Return resulting RDA counter. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual int + int onRejectMessage(mqbi::QueueHandle* handle, const bmqt::MessageGUID& msgGUID, unsigned int downstreamSubQueueId) BSLS_KEYWORD_OVERRIDE; @@ -356,7 +354,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// update the positions of the QueueHandles it manages. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void beforeMessageRemoved(const bmqt::MessageGUID& msgGUID) + void beforeMessageRemoved(const bmqt::MessageGUID& msgGUID) BSLS_KEYWORD_OVERRIDE; /// Called by the mqbi::Queue *after* *all* messages are removed from @@ -368,7 +366,7 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// `appId` must be empty if and only if `appKey` is null. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void + void afterQueuePurged(const bsl::string& appId, const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; @@ -376,40 +374,37 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// `currentTimer`; can be used for regular status check, such as for /// ensuring messages on the queue are flowing and not accumulating. /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - onTimer(bsls::Types::Int64 currentTimer) BSLS_KEYWORD_OVERRIDE; + void onTimer(bsls::Types::Int64 currentTimer) BSLS_KEYWORD_OVERRIDE; /// Called after the specified `addedAppIds` have been dynamically /// registered. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void afterAppIdRegistered( - const mqbi::Storage::AppInfos& addedAppIds) BSLS_KEYWORD_OVERRIDE; + void afterAppIdRegistered(const mqbi::Storage::AppInfos& addedAppIds) + BSLS_KEYWORD_OVERRIDE; /// Called after the specified `removedAppIds` have been dynamically /// unregistered. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void afterAppIdUnregistered( - const mqbi::Storage::AppInfos& removedAppIds) BSLS_KEYWORD_OVERRIDE; + void afterAppIdUnregistered(const mqbi::Storage::AppInfos& removedAppIds) + BSLS_KEYWORD_OVERRIDE; /// Called after creation of a new storage for the specified /// `appIdKeyPair`. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - registerStorage(const bsl::string& appId, - const mqbu::StorageKey& appKey, - unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; + void registerStorage(const bsl::string& appId, + const mqbu::StorageKey& appKey, + unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; /// Called after removal of the storage for the specified /// `appIdKeyPair`. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - unregisterStorage(const bsl::string& appId, - const mqbu::StorageKey& appKey, - unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; + void unregisterStorage(const bsl::string& appId, + const mqbu::StorageKey& appKey, + unsigned int appOrdinal) BSLS_KEYWORD_OVERRIDE; /// Given the specified 'putHeader', 'appData', 'mpi', and 'timestamp', /// evaluate all Auto (Application) subscriptions and exclude applications @@ -434,23 +429,22 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine { /// posted to the queue managed by this engine. Note that returned /// value may or may not be equal to `numOpenReaderHandles()` depending /// upon the specific type of this engine. - virtual unsigned int messageReferenceCount() const BSLS_KEYWORD_OVERRIDE; + unsigned int messageReferenceCount() const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `out` object the internal information about /// this queue engine and associated queue handles. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - loadInternals(mqbcmd::QueueEngine* out) const BSLS_KEYWORD_OVERRIDE; + void loadInternals(mqbcmd::QueueEngine* out) const BSLS_KEYWORD_OVERRIDE; /// Log application subscription info for the specified `appId` into the /// specified `stream`. /// /// THREAD: This method is called from the Queue's /// dispatcher thread. - virtual bsl::ostream& logAppSubscriptionInfo( - bsl::ostream& stream, - const bsl::string& appId) const BSLS_KEYWORD_OVERRIDE; + bsl::ostream& logAppSubscriptionInfo(bsl::ostream& stream, + const bsl::string& appId) const + BSLS_KEYWORD_OVERRIDE; private: /// Log application subscription info for the specified `appState` into diff --git a/src/groups/mqb/mqbblp/mqbblp_storagemanager.h b/src/groups/mqb/mqbblp/mqbblp_storagemanager.h index 12e877f176..d1c2b7b595 100644 --- a/src/groups/mqb/mqbblp/mqbblp_storagemanager.h +++ b/src/groups/mqb/mqbblp/mqbblp_storagemanager.h @@ -121,7 +121,7 @@ class StorageManagerIterator; // ==================== /// Storage Manager, in charge of all the partitions. -class StorageManager : public mqbi::StorageManager { +class StorageManager BSLS_KEYWORD_FINAL : public mqbi::StorageManager { private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBBLP.STORAGEMANAGER"); @@ -455,7 +455,7 @@ class StorageManager : public mqbi::StorageManager { bslma::Allocator* allocator); /// Destructor - virtual ~StorageManager() BSLS_KEYWORD_OVERRIDE; + ~StorageManager() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS @@ -464,16 +464,16 @@ class StorageManager : public mqbi::StorageManager { /// description of the error. /// /// THREAD: Executed by the cluster's dispatcher thread. - virtual int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; + int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Stop this storage manager. - virtual void stop() BSLS_KEYWORD_OVERRIDE; + void stop() BSLS_KEYWORD_OVERRIDE; /// Initialize the queue key info map based on information in the specified /// `clusterState`. Note that this method should only be called once; /// subsequent calls will be ignored. - virtual void initializeQueueKeyInfoMap( - const mqbc::ClusterState& clusterState) BSLS_KEYWORD_OVERRIDE; + void initializeQueueKeyInfoMap(const mqbc::ClusterState& clusterState) + BSLS_KEYWORD_OVERRIDE; /// Register a queue with the specified `uri`, `queueKey` and /// `partitionId`, having the specified `appIdKeyPairs`, and belonging @@ -481,19 +481,19 @@ class StorageManager : public mqbi::StorageManager { /// associated queue storage created. /// /// THREAD: Executed by the Client's dispatcher thread. - virtual void registerQueue(const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const AppInfos& appIdKeyPairs, - mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; + void registerQueue(const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const AppInfos& appIdKeyPairs, + mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; /// Synchronously unregister the queue with the specified `uri` from the /// specified `partitionId`. Behavior is undefined unless this routine /// is invoked from the cluster dispatcher thread. /// /// THREAD: Executed by the Client's dispatcher thread. - virtual void unregisterQueue(const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void unregisterQueue(const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Configure the fanout queue having specified `uri` and `queueKey`, /// assigned to the specified `partitionId` to have the specified @@ -504,56 +504,55 @@ class StorageManager : public mqbi::StorageManager { /// queue is configured in fanout mode. /// /// THREAD: Executed by the Queue's dispatcher thread. - virtual int updateQueuePrimary(const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const AppInfos& addedIdKeyPairs, - const AppInfos& removedIdKeyPairs) + int updateQueuePrimary(const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const AppInfos& addedIdKeyPairs, + const AppInfos& removedIdKeyPairs) BSLS_KEYWORD_OVERRIDE; - virtual void + void registerQueueReplica(int partitionId, const bmqt::Uri& uri, const mqbu::StorageKey& queueKey, mqbi::Domain* domain = 0, bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; - virtual void unregisterQueueReplica(int partitionId, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - const mqbu::StorageKey& appKey) + void unregisterQueueReplica(int partitionId, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; - virtual void - updateQueueReplica(int partitionId, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - const AppInfos& appIdKeyPairs, - mqbi::Domain* domain = 0, - bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; + void updateQueueReplica(int partitionId, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + const AppInfos& appIdKeyPairs, + mqbi::Domain* domain = 0, + bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; /// Set the queue instance associated with the file-backed storage for /// the specified `uri` mapped to the specified `partitionId` to the /// specified `queue` value. Note that this method *does* *not* /// synchronize on the queue-dispatcher thread. - virtual void setQueue(mqbi::Queue* queue, - const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void setQueue(mqbi::Queue* queue, + const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Set the queue instance associated with the file-backed storage for /// the specified `uri` mapped to the specified `partitionId` to the /// specified `queue` value. Behavior is undefined unless `queue` is /// non-null or unless this routine is invoked from the dispatcher /// thread associated with the `partitionId`. - virtual void setQueueRaw(mqbi::Queue* queue, - const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void setQueueRaw(mqbi::Queue* queue, + const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Behavior is undefined unless the specified 'partitionId' is in range /// and the specified 'primaryNode' is not null. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void + void setPrimaryForPartition(int partitionId, mqbnet::ClusterNode* primaryNode, unsigned int primaryLeaseId) BSLS_KEYWORD_OVERRIDE; @@ -562,101 +561,101 @@ class StorageManager : public mqbi::StorageManager { /// and the specified 'primaryNode' is not null. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void clearPrimaryForPartition(int partitionId, - mqbnet::ClusterNode* primary) + void clearPrimaryForPartition(int partitionId, + mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; /// Set the primary status of the specified 'partitionId' to the specified /// 'value'. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void setPrimaryStatusForPartition( - int partitionId, - bmqp_ctrlmsg::PrimaryStatus::Value value) BSLS_KEYWORD_OVERRIDE; + void setPrimaryStatusForPartition(int partitionId, + bmqp_ctrlmsg::PrimaryStatus::Value value) + BSLS_KEYWORD_OVERRIDE; /// Process primary state request received from the specified `source` /// with the specified `message`. - virtual void processPrimaryStateRequest( + void processPrimaryStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; - virtual void processReplicaStateRequest( + void processReplicaStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Process replica data request received from the specified `source` /// with the specified `message`. - virtual void processReplicaDataRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processReplicaDataRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; - virtual int makeStorage(bsl::ostream& errorDescription, - bslma::ManagedPtr* out, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const bsls::Types::Int64 messageTtl, - const int maxDeliveryAttempts, - const mqbconfm::StorageDefinition& storageDef) + int makeStorage(bsl::ostream& errorDescription, + bslma::ManagedPtr* out, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const bsls::Types::Int64 messageTtl, + const int maxDeliveryAttempts, + const mqbconfm::StorageDefinition& storageDef) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processStorageEvent(const mqbi::DispatcherStorageEvent& event) + void processStorageEvent(const mqbi::DispatcherStorageEvent& event) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processStorageSyncRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processStorageSyncRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncStateRequest( + void processPartitionSyncStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncDataRequest( + void processPartitionSyncDataRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncDataRequestStatus( + void processPartitionSyncDataRequestStatus( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processRecoveryEvent( - const mqbi::DispatcherRecoveryEvent& event) BSLS_KEYWORD_OVERRIDE; + void processRecoveryEvent(const mqbi::DispatcherRecoveryEvent& event) + BSLS_KEYWORD_OVERRIDE; /// Executed in IO thread. - virtual void + void processReceiptEvent(const bmqp::Event& event, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void bufferPrimaryStatusAdvisory( + void bufferPrimaryStatusAdvisory( const bmqp_ctrlmsg::PrimaryStatusAdvisory& advisory, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPrimaryStatusAdvisory( + void processPrimaryStatusAdvisory( const bmqp_ctrlmsg::PrimaryStatusAdvisory& advisory, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processReplicaStatusAdvisory( - int partitionId, - mqbnet::ClusterNode* source, - bmqp_ctrlmsg::NodeStatus::Value status) BSLS_KEYWORD_OVERRIDE; + void processReplicaStatusAdvisory(int partitionId, + mqbnet::ClusterNode* source, + bmqp_ctrlmsg::NodeStatus::Value status) + BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; + void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; /// Invoke the specified `functor` with each queue associated to the /// partition identified by the specified `partitionId` if that /// partition has been successfully opened. The behavior is undefined /// unless invoked from the queue thread corresponding to `partitionId`. - virtual void + void applyForEachQueue(int partitionId, const QueueFunctor& functor) const BSLS_KEYWORD_OVERRIDE; @@ -665,35 +664,35 @@ class StorageManager : public mqbi::StorageManager { /// processed, or a non-zero value otherwise. This function can be /// invoked from any thread, and will block until the potentially /// asynchronous operation is complete. - virtual int processCommand(mqbcmd::StorageResult* result, - const mqbcmd::StorageCommand& command) + int processCommand(mqbcmd::StorageResult* result, + const mqbcmd::StorageCommand& command) BSLS_KEYWORD_OVERRIDE; /// GC the queues from unrecognized domains, if any. - virtual void gcUnrecognizedDomainQueues() BSLS_KEYWORD_OVERRIDE; + void gcUnrecognizedDomainQueues() BSLS_KEYWORD_OVERRIDE; // ACCESSORS /// Return the processor handle in charge of the specified /// `partitionId`. The behavior is undefined if `partitionId` does not /// represent a valid partition id. - virtual mqbi::Dispatcher::ProcessorHandle + mqbi::Dispatcher::ProcessorHandle processorForPartition(int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return true if the queue having specified `uri` and assigned to the /// specified `partitionId` has no messages, false in any other case. /// Behavior is undefined unless this routine is invoked from cluster /// dispatcher thread. - virtual bool isStorageEmpty(const bmqt::Uri& uri, - int partitionId) const BSLS_KEYWORD_OVERRIDE; + bool isStorageEmpty(const bmqt::Uri& uri, + int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return partition corresponding to the specified `partitionId`. The /// behavior is undefined if `partitionId` does not represent a valid /// partition id. - virtual const mqbs::FileStore& + const mqbs::FileStore& fileStore(int partitionId) const BSLS_KEYWORD_OVERRIDE; - virtual bslma::ManagedPtr + bslma::ManagedPtr getIterator(int partitionId) const BSLS_KEYWORD_OVERRIDE; }; @@ -708,7 +707,8 @@ class StorageManager : public mqbi::StorageManager { /// provided by locking the manager during the iterator's construction and /// unlocking it at the iterator's destruction. This guarantees that during /// the life time of an iterator, the manager can't be modified. -class StorageManagerIterator : public mqbi::StorageManagerIterator { +class StorageManagerIterator BSLS_KEYWORD_FINAL +: public mqbi::StorageManagerIterator { private: // PRIVATE TYPES typedef StorageManager::StorageSpMap StorageSpMap; @@ -750,24 +750,23 @@ class StorageManagerIterator : public mqbi::StorageManagerIterator { /// then this iterator becomes *invalid*. The behavior is undefined /// unless this iterator is valid. Note that the order of the iteration /// is not specified. - virtual void operator++() BSLS_KEYWORD_OVERRIDE; + void operator++() BSLS_KEYWORD_OVERRIDE; // ACCESSORS /// Return non-zero if the iterator is *valid*, and 0 otherwise. - virtual operator const void*() const BSLS_KEYWORD_OVERRIDE; + operator const void*() const BSLS_KEYWORD_OVERRIDE; /// Return a reference offering non-modifiable access to the queue URI /// being pointed by this iterator. The behavior is undefined unless /// the iterator is *valid*. - virtual const bmqt::Uri& uri() const BSLS_KEYWORD_OVERRIDE; + const bmqt::Uri& uri() const BSLS_KEYWORD_OVERRIDE; /// Return a reference offering non-modifiable access to the storage /// being pointed by this iterator. The behavior is undefined unless /// the iterator is *valid*. Note that since iterator is not a first /// class object, its okay to pass a raw pointer. - virtual const mqbs::ReplicatedStorage* - storage() const BSLS_KEYWORD_OVERRIDE; + const mqbs::ReplicatedStorage* storage() const BSLS_KEYWORD_OVERRIDE; }; // -------------------- diff --git a/src/groups/mqb/mqbc/mqbc_clusterstatemanager.h b/src/groups/mqb/mqbc/mqbc_clusterstatemanager.h index 79af0a1c1c..70be8517be 100644 --- a/src/groups/mqb/mqbc/mqbc_clusterstatemanager.h +++ b/src/groups/mqb/mqbc/mqbc_clusterstatemanager.h @@ -78,7 +78,7 @@ namespace mqbc { // ========================= /// This class provides a mechanism to manage the state of a cluster. -class ClusterStateManager +class ClusterStateManager BSLS_KEYWORD_FINAL : public mqbi::ClusterStateManager, public ClusterStateTableActions, public mqbc::ElectorInfoObserver, @@ -179,97 +179,88 @@ class ClusterStateManager private: // PRIVATE MANIPULATORS // (virtual: mqbc::ClusterStateTableActions) - virtual void do_abort(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_abort(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_startWatchDog(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_startWatchDog(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_stopWatchDog(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_stopWatchDog(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_triggerWatchDog(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_applyCSLSelf(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_applyCSLSelf(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_initializeQueueKeyInfoMap(const ClusterFSMArgsSp& args) + void do_initializeQueueKeyInfoMap(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_sendFollowerLSNRequests(const ClusterFSMArgsSp& args) + void do_sendFollowerLSNRequests(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_sendFollowerLSNResponse(const ClusterFSMArgsSp& args) + void do_sendFollowerLSNResponse(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_sendFailureFollowerLSNResponse( - const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_sendFailureFollowerLSNResponse(const ClusterFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void - do_findHighestLSN(const ClusterFSMArgsSp& x) BSLS_KEYWORD_OVERRIDE; + void do_findHighestLSN(const ClusterFSMArgsSp& x) BSLS_KEYWORD_OVERRIDE; - virtual void do_sendFollowerClusterStateRequest( - const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_sendFollowerClusterStateRequest(const ClusterFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_sendFollowerClusterStateResponse( - const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_sendFollowerClusterStateResponse(const ClusterFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_sendFailureFollowerClusterStateResponse( + void do_sendFailureFollowerClusterStateResponse( const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_storeSelfLSN(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_storeSelfLSN(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_storeFollowerLSNs(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_removeFollowerLSN(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_checkLSNQuorum(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_checkLSNQuorum(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_sendRegistrationRequest(const ClusterFSMArgsSp& args) + void do_sendRegistrationRequest(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_sendRegistrationResponse(const ClusterFSMArgsSp& args) + void do_sendRegistrationResponse(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_sendFailureRegistrationResponse( - const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_sendFailureRegistrationResponse(const ClusterFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_logStaleFollowerLSNResponse(const ClusterFSMArgsSp& args) + void do_logStaleFollowerLSNResponse(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_logStaleFollowerClusterStateResponse( - const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_logStaleFollowerClusterStateResponse(const ClusterFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_logErrorLeaderNotHealed(const ClusterFSMArgsSp& args) + void do_logErrorLeaderNotHealed(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_logFailFollowerLSNResponses(const ClusterFSMArgsSp& args) + void do_logFailFollowerLSNResponses(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_logFailFollowerClusterStateResponse( - const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_logFailFollowerClusterStateResponse(const ClusterFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_logFailRegistrationResponse(const ClusterFSMArgsSp& args) + void do_logFailRegistrationResponse(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_reapplyEvent(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_reapplyEvent(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_reapplySelectLeader(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_reapplySelectFollower(const ClusterFSMArgsSp& args) + void do_reapplySelectFollower(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_cleanupLSNs(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_cleanupLSNs(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_cancelRequests(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_cancelRequests(const ClusterFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; // PRIVATE MANIPULATORS // (virtual: mqbc::ClusterStateObserver) @@ -284,7 +275,7 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onPartitionPrimaryAssignment( + void onPartitionPrimaryAssignment( int partitionId, mqbnet::ClusterNode* primary, unsigned int leaseId, @@ -391,32 +382,31 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; + int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Stop this instance. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void stop() BSLS_KEYWORD_OVERRIDE; + void stop() BSLS_KEYWORD_OVERRIDE; /// Set the storage manager to the specified `value`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - setStorageManager(mqbi::StorageManager* value) BSLS_KEYWORD_OVERRIDE; + void setStorageManager(mqbi::StorageManager* value) BSLS_KEYWORD_OVERRIDE; /// Set the queue assigning callback to the specified `value`. - virtual void + void setQueueAssigningCb(const QueueAssigningCb& value) BSLS_KEYWORD_OVERRIDE; - virtual void setQueueUnassigningCb(const QueueUnassigningCb& value) + void setQueueUnassigningCb(const QueueUnassigningCb& value) BSLS_KEYWORD_OVERRIDE; // Set the queue unassigning callback to the specified 'value'. /// Set the after partition primary assignment callback to the specified /// `value`. - virtual void setAfterPartitionPrimaryAssignmentCb( + void setAfterPartitionPrimaryAssignmentCb( const AfterPartitionPrimaryAssignmentCb& value) BSLS_KEYWORD_OVERRIDE; /// Set the primary for the specified `partitionId` to be the specified @@ -424,18 +414,17 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - setPrimary(int partitionId, - unsigned int leaseId, - mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; + void setPrimary(int partitionId, + unsigned int leaseId, + mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; /// Set the primary status of the specified `partitionId` to the /// specified `status`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void setPrimaryStatus(int partitionId, - bmqp_ctrlmsg::PrimaryStatus::Value status) + void setPrimaryStatus(int partitionId, + bmqp_ctrlmsg::PrimaryStatus::Value status) BSLS_KEYWORD_OVERRIDE; /// Mark the specified `partitions` as orphaned partitions, due to the @@ -443,9 +432,8 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - markOrphan(const bsl::vector& partitions, - mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; + void markOrphan(const bsl::vector& partitions, + mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; /// Assign an available node to each partition which is currently /// orphan or is assigned to a node which is not available, and load the @@ -454,9 +442,8 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void assignPartitions( - bsl::vector* partitions) - BSLS_KEYWORD_OVERRIDE; + void assignPartitions(bsl::vector* + partitions) BSLS_KEYWORD_OVERRIDE; /// Perform the actual assignment of the queue represented by the /// specified `uri` for a cluster member queue, that is assign it a @@ -467,7 +454,7 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual QueueAssignmentResult::Enum + QueueAssignmentResult::Enum assignQueue(const bmqt::Uri& uri, bmqp_ctrlmsg::Status* status = 0) BSLS_KEYWORD_OVERRIDE; @@ -480,19 +467,18 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void registerQueueInfo(const bmqt::Uri& uri, - int partitionId, - const mqbu::StorageKey& queueKey, - const AppInfos& appIdInfos, - bool forceUpdate) BSLS_KEYWORD_OVERRIDE; + void registerQueueInfo(const bmqt::Uri& uri, + int partitionId, + const mqbu::StorageKey& queueKey, + const AppInfos& appIdInfos, + bool forceUpdate) BSLS_KEYWORD_OVERRIDE; /// Unassign the queue in the specified `advisory` by applying the /// advisory to the cluster state ledger owned by this object. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - unassignQueue(const bmqp_ctrlmsg::QueueUnassignedAdvisory& advisory) + void unassignQueue(const bmqp_ctrlmsg::QueueUnassignedAdvisory& advisory) BSLS_KEYWORD_OVERRIDE; /// Send the current cluster state to follower nodes. If the specified @@ -507,7 +493,7 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void sendClusterState( + void sendClusterState( bool sendPartitionPartitionInfo, bool sendQueuesInfo, mqbnet::ClusterNode* node = 0, @@ -520,32 +506,30 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - registerAppId(const bsl::string& appId, - const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; + void registerAppId(const bsl::string& appId, + const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; /// Unregister the specified `appId` for all queues in the specified /// `domain`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - unregisterAppId(const bsl::string& appId, - const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; + void unregisterAppId(const bsl::string& appId, + const mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; /// Invoked when a newly elected (i.e. passive) leader node initiates a /// sync with followers before transitioning to active leader. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void initiateLeaderSync(bool wait) BSLS_KEYWORD_OVERRIDE; + void initiateLeaderSync(bool wait) BSLS_KEYWORD_OVERRIDE; /// Process the specified leader-sync-state-query `message` from the /// specified `source`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processLeaderSyncStateQuery( + void processLeaderSyncStateQuery( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -554,7 +538,7 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processLeaderSyncDataQuery( + void processLeaderSyncDataQuery( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -563,16 +547,16 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processFollowerLSNRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processFollowerLSNRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; /// Process the specified follower-cluster-state-request `message` from /// the specified `source`. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processFollowerClusterStateRequest( + void processFollowerClusterStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -581,7 +565,7 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processRegistrationRequest( + void processRegistrationRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -589,20 +573,20 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processClusterStateEvent( + void processClusterStateEvent( const mqbi::DispatcherClusterStateEvent& event) BSLS_KEYWORD_OVERRIDE; /// Process any queue assignment and unassignment advisory messages /// which were received while self node was starting. Behavior is /// undefined unless self node has transitioned to AVAILABLE. - virtual void processBufferedQueueAdvisories() BSLS_KEYWORD_OVERRIDE; + void processBufferedQueueAdvisories() BSLS_KEYWORD_OVERRIDE; /// Process the queue assignment in the specified `request`, received /// from the specified `requester`. Return the queue assignment result. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processQueueAssignmentRequest( + void processQueueAssignmentRequest( const bmqp_ctrlmsg::ControlMessage& request, mqbnet::ClusterNode* requester) BSLS_KEYWORD_OVERRIDE; @@ -616,7 +600,7 @@ class ClusterStateManager /// TODO_CSL: This is the current workflow which we should be able to /// remove after the new workflow via /// ClusterQueueHelper::onQueueAssigned() is stable. - virtual void + void processQueueAssignmentAdvisory(const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source, bool delayed = false) BSLS_KEYWORD_OVERRIDE; @@ -630,7 +614,7 @@ class ClusterStateManager /// TODO_CSL: This is the current workflow which we should be able to /// remove after the new workflow via /// ClusterQueueHelper::onQueueUnassigned() is stable. - virtual void processQueueUnassignedAdvisory( + void processQueueUnassignedAdvisory( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -644,7 +628,7 @@ class ClusterStateManager /// TODO_CSL: This is the current workflow which we should be able to /// remove after the new workflow via /// ClusterQueueHelper::onQueueUnassigned() is stable. - virtual void processQueueUnAssignmentAdvisory( + void processQueueUnAssignmentAdvisory( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source, bool delayed = false) BSLS_KEYWORD_OVERRIDE; @@ -654,7 +638,7 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void processPartitionPrimaryAdvisory( + void processPartitionPrimaryAdvisory( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; @@ -663,33 +647,32 @@ class ClusterStateManager /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void + void processLeaderAdvisory(const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Process the shutdown event. /// /// THREAD: Executed by any thread. - virtual void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; + void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; /// Invoked when the specified `node` becomes unavailable. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void - onNodeUnavailable(mqbnet::ClusterNode* node) BSLS_KEYWORD_OVERRIDE; + void onNodeUnavailable(mqbnet::ClusterNode* node) BSLS_KEYWORD_OVERRIDE; /// Invoked when this node is stopping. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onNodeStopping() BSLS_KEYWORD_OVERRIDE; + void onNodeStopping() BSLS_KEYWORD_OVERRIDE; /// Invoked when this node is stopped. /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual void onNodeStopped() BSLS_KEYWORD_OVERRIDE; + void onNodeStopped() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS // (virtual: mqbc::ElectorInfoObserver) @@ -708,11 +691,10 @@ class ClusterStateManager // ACCESSORS // (virtual: mqbi::ClusterStateManager) - virtual bool isFirstLeaderAdvisory() const BSLS_KEYWORD_OVERRIDE; + bool isFirstLeaderAdvisory() const BSLS_KEYWORD_OVERRIDE; /// Return the cluster state managed by this instacne. - virtual const mqbc::ClusterState* - clusterState() const BSLS_KEYWORD_OVERRIDE; + const mqbc::ClusterState* clusterState() const BSLS_KEYWORD_OVERRIDE; /// Invoked to perform validation of CSL's contents (on disk) against /// the "real" cluster state. Logs a descriptive error message if @@ -722,14 +704,14 @@ class ClusterStateManager /// dispatcher thread. /// /// TBD: This is mostly temporary, used in phase I of integrating CSL. - virtual void validateClusterStateLedger() const BSLS_KEYWORD_OVERRIDE; + void validateClusterStateLedger() const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `out` the latest ledger LSN associated with /// this cluster node. Return 0 on success, and a non-zero error code /// on failure. Note that this involves iteration over the entire /// ledger which can be an expensive operation. This is necessary to /// give the latest LSN from the ledger. - virtual int latestLedgerLSN(bmqp_ctrlmsg::LeaderMessageSequence* out) const + int latestLedgerLSN(bmqp_ctrlmsg::LeaderMessageSequence* out) const BSLS_KEYWORD_OVERRIDE; // ACCESSORS diff --git a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledgeriterator.h b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledgeriterator.h index b0578034aa..6de5300abc 100644 --- a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledgeriterator.h +++ b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledgeriterator.h @@ -121,21 +121,20 @@ class IncoreClusterStateLedgerIterator BSLS_KEYWORD_FINAL /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual int next() BSLS_KEYWORD_OVERRIDE; + int next() BSLS_KEYWORD_OVERRIDE; /// Assign self to be a copy of the specified `other`. This uses the /// assignment operator under the hood, but circumvents object slicing. /// Behavior is undefined unless `other` and this object have the same /// type. - virtual void - copy(const ClusterStateLedgerIterator& other) BSLS_KEYWORD_OVERRIDE; + void copy(const ClusterStateLedgerIterator& other) BSLS_KEYWORD_OVERRIDE; // ACCESSORS // (virtual mqbc::ClusterStateLedgerIterator) /// Return a new `ClusterStateLedgerIterator`, which is a clone of self, /// using the specified `allocator`. - virtual bslma::ManagedPtr + bslma::ManagedPtr clone(bslma::Allocator* allocator) const BSLS_KEYWORD_OVERRIDE; /// Return true if this iterator is initialized and valid, and the @@ -143,7 +142,7 @@ class IncoreClusterStateLedgerIterator BSLS_KEYWORD_FINAL /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual bool isValid() const BSLS_KEYWORD_OVERRIDE; + bool isValid() const BSLS_KEYWORD_OVERRIDE; /// Return a const reference to the `ClusterStateRecordHeader` at the /// iterator position. Behavior is undefined unless `isValid()` returns @@ -151,8 +150,7 @@ class IncoreClusterStateLedgerIterator BSLS_KEYWORD_FINAL /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual const ClusterStateRecordHeader& - header() const BSLS_KEYWORD_OVERRIDE; + const ClusterStateRecordHeader& header() const BSLS_KEYWORD_OVERRIDE; /// Load the cluster message recorded at the iterator position to the /// specified `message`. Return 0 on success or a non-zero error value @@ -160,7 +158,7 @@ class IncoreClusterStateLedgerIterator BSLS_KEYWORD_FINAL /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual int loadClusterMessage(bmqp_ctrlmsg::ClusterMessage* message) const + int loadClusterMessage(bmqp_ctrlmsg::ClusterMessage* message) const BSLS_KEYWORD_OVERRIDE; /// Format this object to the specified output `stream` at the (absolute @@ -176,10 +174,9 @@ class IncoreClusterStateLedgerIterator BSLS_KEYWORD_FINAL /// /// THREAD: This method is invoked in the associated cluster's /// dispatcher thread. - virtual bsl::ostream& - print(bsl::ostream& stream, - int level = 0, - int spacesPerLevel = 4) const BSLS_KEYWORD_OVERRIDE; + bsl::ostream& print(bsl::ostream& stream, + int level = 0, + int spacesPerLevel = 4) const BSLS_KEYWORD_OVERRIDE; // ACCESSORS diff --git a/src/groups/mqb/mqbc/mqbc_storagemanager.h b/src/groups/mqb/mqbc/mqbc_storagemanager.h index 7a23cfc69f..ba59088926 100644 --- a/src/groups/mqb/mqbc/mqbc_storagemanager.h +++ b/src/groups/mqb/mqbc/mqbc_storagemanager.h @@ -104,7 +104,7 @@ class StorageManagerIterator; // ==================== /// Storage Manager, in charge of all the partitions. -class StorageManager +class StorageManager BSLS_KEYWORD_FINAL : public mqbi::StorageManager, public PartitionStateTableActions, public PartitionFSMObserver { @@ -599,145 +599,139 @@ class StorageManager void forceFlushFileStores(); // (virtual: mqbc::PartitionStateTableActions) - virtual void + void do_startWatchDog(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_stopWatchDog(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_stopWatchDog(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_openRecoveryFileSet(const PartitionFSMArgsSp& args) + void do_openRecoveryFileSet(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_closeRecoveryFileSet(const PartitionFSMArgsSp& args) + void do_closeRecoveryFileSet(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_storeSelfSeq(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_storeSelfSeq(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_storePrimarySeq(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_storeReplicaSeq(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_storePartitionInfo(const PartitionFSMArgsSp& args) + void do_storePartitionInfo(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_clearPartitionInfo(const PartitionFSMArgsSp& args) + void do_clearPartitionInfo(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_replicaStateRequest(const PartitionFSMArgsSp& args) + void do_replicaStateRequest(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_replicaStateResponse(const PartitionFSMArgsSp& args) + void do_replicaStateResponse(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_failureReplicaStateResponse(const PartitionFSMArgsSp& args) + void do_failureReplicaStateResponse(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_logFailureReplicaStateResponse( - const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_logFailureReplicaStateResponse(const PartitionFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_logFailurePrimaryStateResponse( - const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_logFailurePrimaryStateResponse(const PartitionFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_primaryStateRequest(const PartitionFSMArgsSp& args) + void do_primaryStateRequest(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_primaryStateResponse(const PartitionFSMArgsSp& args) + void do_primaryStateResponse(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_failurePrimaryStateResponse(const PartitionFSMArgsSp& args) + void do_failurePrimaryStateResponse(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_replicaDataRequestPush(const PartitionFSMArgsSp& args) + void do_replicaDataRequestPush(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_replicaDataResponsePush(const PartitionFSMArgsSp& args) + void do_replicaDataResponsePush(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_replicaDataRequestDrop(const PartitionFSMArgsSp& args) + void do_replicaDataRequestDrop(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_replicaDataRequestPull(const PartitionFSMArgsSp& args) + void do_replicaDataRequestPull(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_replicaDataResponsePull(const PartitionFSMArgsSp& args) + void do_replicaDataResponsePull(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_failureReplicaDataResponsePull( - const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_failureReplicaDataResponsePull(const PartitionFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void do_failureReplicaDataResponsePush( - const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_failureReplicaDataResponsePush(const PartitionFSMArgsSp& args) + BSLS_KEYWORD_OVERRIDE; - virtual void + void do_bufferLiveData(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_processBufferedLiveData(const PartitionFSMArgsSp& args) + void do_processBufferedLiveData(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_processBufferedPrimaryStatusAdvisories( + void do_processBufferedPrimaryStatusAdvisories( const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_processLiveData(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_processPut(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_processPut(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_nackPut(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_nackPut(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_cleanupSeqnums(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_startSendDataChunks(const PartitionFSMArgsSp& args) + void do_startSendDataChunks(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_setExpectedDataChunkRange(const PartitionFSMArgsSp& args) + void do_setExpectedDataChunkRange(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_resetReceiveDataCtx(const PartitionFSMArgsSp& args) + void do_resetReceiveDataCtx(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_openStorage(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_openStorage(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_updateStorage(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_removeStorage(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_incrementNumRplcaDataRspn(const PartitionFSMArgsSp& args) + void do_incrementNumRplcaDataRspn(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_checkQuorumRplcaDataRspn(const PartitionFSMArgsSp& args) + void do_checkQuorumRplcaDataRspn(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_clearRplcaDataRspnCnt(const PartitionFSMArgsSp& args) + void do_clearRplcaDataRspnCnt(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void - do_reapplyEvent(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; + void do_reapplyEvent(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_checkQuorumSeq(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void + void do_findHighestSeq(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_flagFailedReplicaSeq(const PartitionFSMArgsSp& args) + void do_flagFailedReplicaSeq(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_transitionToActivePrimary(const PartitionFSMArgsSp& args) + void do_transitionToActivePrimary(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_reapplyDetectSelfPrimary(const PartitionFSMArgsSp& args) + void do_reapplyDetectSelfPrimary(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; - virtual void do_reapplyDetectSelfReplica(const PartitionFSMArgsSp& args) + void do_reapplyDetectSelfReplica(const PartitionFSMArgsSp& args) BSLS_KEYWORD_OVERRIDE; // PRIVATE ACCESSORS @@ -798,18 +792,18 @@ class StorageManager /// description of the error. /// /// THREAD: Executed by the cluster's dispatcher thread. - virtual int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; + int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Stop this storage manager. /// /// THREAD: Executed by the cluster's dispatcher thread. - virtual void stop() BSLS_KEYWORD_OVERRIDE; + void stop() BSLS_KEYWORD_OVERRIDE; /// Initialize the queue key info map based on information in the specified /// `clusterState`. Note that this method should only be called once; /// subsequent calls will be ignored. - virtual void initializeQueueKeyInfoMap( - const mqbc::ClusterState& clusterState) BSLS_KEYWORD_OVERRIDE; + void initializeQueueKeyInfoMap(const mqbc::ClusterState& clusterState) + BSLS_KEYWORD_OVERRIDE; /// Register a queue with the specified `uri`, `queueKey` and /// `partitionId`, having the spcified `appIdKeyPairs`, and belonging to @@ -817,19 +811,18 @@ class StorageManager /// associated queue storage created. /// /// THREAD: Executed by the Client's dispatcher thread. - virtual void - registerQueue(const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const bsl::unordered_set& appIdKeyPairs, - mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; + void registerQueue(const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const bsl::unordered_set& appIdKeyPairs, + mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; /// Synchronously unregister the queue with the specified `uri` from the /// specified `partitionId`. /// /// THREAD: Executed by the Client's dispatcher thread. - virtual void unregisterQueue(const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void unregisterQueue(const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Configure the fanout queue having specified `uri` and `queueKey`, /// assigned to the specified `partitionId` to have the specified @@ -840,56 +833,55 @@ class StorageManager /// queue is configured in fanout mode. /// /// THREAD: Executed by the Queue's dispatcher thread. - virtual int updateQueuePrimary(const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const AppInfos& addedIdKeyPairs, - const AppInfos& removedIdKeyPairs) + int updateQueuePrimary(const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const AppInfos& addedIdKeyPairs, + const AppInfos& removedIdKeyPairs) BSLS_KEYWORD_OVERRIDE; - virtual void + void registerQueueReplica(int partitionId, const bmqt::Uri& uri, const mqbu::StorageKey& queueKey, mqbi::Domain* domain = 0, bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; - virtual void unregisterQueueReplica(int partitionId, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - const mqbu::StorageKey& appKey) + void unregisterQueueReplica(int partitionId, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; - virtual void - updateQueueReplica(int partitionId, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - const AppInfos& appIdKeyPairs, - mqbi::Domain* domain = 0, - bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; + void updateQueueReplica(int partitionId, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + const AppInfos& appIdKeyPairs, + mqbi::Domain* domain = 0, + bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; /// Set the queue instance associated with the file-backed storage for /// the specified `uri` mapped to the specified `partitionId` to the /// specified `queue` value. Note that this method *does* *not* /// synchronize on the queue-dispatcher thread. - virtual void setQueue(mqbi::Queue* queue, - const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void setQueue(mqbi::Queue* queue, + const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Set the queue instance associated with the file-backed storage for /// the specified `uri` mapped to the specified `partitionId` to the /// specified `queue` value. Behavior is undefined unless `queue` is /// non-null or unless this routine is invoked from the dispatcher /// thread associated with the `partitionId`. - virtual void setQueueRaw(mqbi::Queue* queue, - const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void setQueueRaw(mqbi::Queue* queue, + const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Behavior is undefined unless the specified 'partitionId' is in range /// and the specified 'primaryNode' is not null. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void + void setPrimaryForPartition(int partitionId, mqbnet::ClusterNode* primaryNode, unsigned int primaryLeaseId) BSLS_KEYWORD_OVERRIDE; @@ -898,103 +890,103 @@ class StorageManager /// and the specified 'primaryNode' is not null. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void clearPrimaryForPartition(int partitionId, - mqbnet::ClusterNode* primary) + void clearPrimaryForPartition(int partitionId, + mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; /// Set the primary status of the specified 'partitionId' to the specified /// 'value'. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void setPrimaryStatusForPartition( - int partitionId, - bmqp_ctrlmsg::PrimaryStatus::Value value) BSLS_KEYWORD_OVERRIDE; + void setPrimaryStatusForPartition(int partitionId, + bmqp_ctrlmsg::PrimaryStatus::Value value) + BSLS_KEYWORD_OVERRIDE; /// Process primary state request received from the specified `source` /// with the specified `message`. - virtual void processPrimaryStateRequest( + void processPrimaryStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Process replica state request received from the specified `source` /// with the specified `message`. - virtual void processReplicaStateRequest( + void processReplicaStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Process replica data request received from the specified `source` /// with the specified `message`. - virtual void processReplicaDataRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processReplicaDataRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; - virtual int makeStorage(bsl::ostream& errorDescription, - bslma::ManagedPtr* out, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const bsls::Types::Int64 messageTtl, - const int maxDeliveryAttempts, - const mqbconfm::StorageDefinition& storageDef) + int makeStorage(bsl::ostream& errorDescription, + bslma::ManagedPtr* out, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const bsls::Types::Int64 messageTtl, + const int maxDeliveryAttempts, + const mqbconfm::StorageDefinition& storageDef) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processStorageEvent(const mqbi::DispatcherStorageEvent& event) + void processStorageEvent(const mqbi::DispatcherStorageEvent& event) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processStorageSyncRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processStorageSyncRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncStateRequest( + void processPartitionSyncStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncDataRequest( + void processPartitionSyncDataRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncDataRequestStatus( + void processPartitionSyncDataRequestStatus( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processRecoveryEvent( - const mqbi::DispatcherRecoveryEvent& event) BSLS_KEYWORD_OVERRIDE; + void processRecoveryEvent(const mqbi::DispatcherRecoveryEvent& event) + BSLS_KEYWORD_OVERRIDE; /// Executed in IO thread. - virtual void + void processReceiptEvent(const bmqp::Event& event, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void bufferPrimaryStatusAdvisory( + void bufferPrimaryStatusAdvisory( const bmqp_ctrlmsg::PrimaryStatusAdvisory& advisory, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processPrimaryStatusAdvisory( + void processPrimaryStatusAdvisory( const bmqp_ctrlmsg::PrimaryStatusAdvisory& advisory, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processReplicaStatusAdvisory( - int partitionId, - mqbnet::ClusterNode* source, - bmqp_ctrlmsg::NodeStatus::Value status) BSLS_KEYWORD_OVERRIDE; + void processReplicaStatusAdvisory(int partitionId, + mqbnet::ClusterNode* source, + bmqp_ctrlmsg::NodeStatus::Value status) + BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; + void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; /// Invoke the specified `functor` with each queue associated to the /// partition identified by the specified `partitionId` if that /// partition has been successfully opened. The behavior is undefined /// unless invoked from the queue thread corresponding to `partitionId`. - virtual void + void applyForEachQueue(int partitionId, const QueueFunctor& functor) const BSLS_KEYWORD_OVERRIDE; @@ -1003,12 +995,12 @@ class StorageManager /// processed, or a non-zero value otherwise. This function can be /// invoked from any thread, and will block until the potentially /// asynchronous operation is complete. - virtual int processCommand(mqbcmd::StorageResult* result, - const mqbcmd::StorageCommand& command) + int processCommand(mqbcmd::StorageResult* result, + const mqbcmd::StorageCommand& command) BSLS_KEYWORD_OVERRIDE; /// GC the queues from unrecognized domains, if any. - virtual void gcUnrecognizedDomainQueues() BSLS_KEYWORD_OVERRIDE; + void gcUnrecognizedDomainQueues() BSLS_KEYWORD_OVERRIDE; /// Return partition corresponding to the specified `partitionId`. The /// behavior is undefined if `partitionId` does not represent a valid @@ -1024,24 +1016,24 @@ class StorageManager // // THREAD: executed by any thread. It is safe because process handle is set // at ctor and never modified afterwards. - virtual mqbi::Dispatcher::ProcessorHandle + mqbi::Dispatcher::ProcessorHandle processorForPartition(int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return true if the queue having specified `uri` and assigned to the /// specified `partitionId` has no messages, false in any other case. /// Behavior is undefined unless this routine is invoked from cluster /// dispatcher thread. - virtual bool isStorageEmpty(const bmqt::Uri& uri, - int partitionId) const BSLS_KEYWORD_OVERRIDE; + bool isStorageEmpty(const bmqt::Uri& uri, + int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return partition corresponding to the specified `partitionId`. The /// behavior is undefined if `partitionId` does not represent a valid /// partition id. - virtual const mqbs::FileStore& + const mqbs::FileStore& fileStore(int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return a StorageManagerIterator for the specified `partitionId`. - virtual bslma::ManagedPtr + bslma::ManagedPtr getIterator(int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return the health state of the specified `partitionId`. diff --git a/src/groups/mqb/mqbmock/mqbmock_logidgenerator.h b/src/groups/mqb/mqbmock/mqbmock_logidgenerator.h index f8eb33f9bf..2539099f66 100644 --- a/src/groups/mqb/mqbmock/mqbmock_logidgenerator.h +++ b/src/groups/mqb/mqbmock/mqbmock_logidgenerator.h @@ -46,7 +46,7 @@ namespace mqbmock { // ==================== /// Mock implementation of the `mqbsi::LogIdGenerator` interface. -class LogIdGenerator : public mqbsi::LogIdGenerator { +class LogIdGenerator BSLS_KEYWORD_FINAL : public mqbsi::LogIdGenerator { private: // DATA bsl::string d_logPrefix; @@ -65,20 +65,19 @@ class LogIdGenerator : public mqbsi::LogIdGenerator { LogIdGenerator(const char* prefix, bslma::Allocator* allocator); /// Destructor - virtual ~LogIdGenerator() BSLS_KEYWORD_OVERRIDE; + ~LogIdGenerator() BSLS_KEYWORD_OVERRIDE; /// Register the specified `logId` among those generated by this object /// and return `true` if successful, `false` otherwise (e.g., `logId` is /// already registered). The effect of this is that `logId` will not be /// returned by a future call to `generateLogId(...)`. - virtual bool - registerLogId(const mqbu::StorageKey& logId) BSLS_KEYWORD_OVERRIDE; + bool registerLogId(const mqbu::StorageKey& logId) BSLS_KEYWORD_OVERRIDE; /// Create a new log name and a new unique log ID that has not before /// been generated or registered by this object and load them into the /// specified `logName` and `logId`. - virtual void generateLogId(bsl::string* logName, - mqbu::StorageKey* logId) BSLS_KEYWORD_OVERRIDE; + void generateLogId(bsl::string* logName, + mqbu::StorageKey* logId) BSLS_KEYWORD_OVERRIDE; }; } // close package namespace diff --git a/src/groups/mqb/mqbmock/mqbmock_queueengine.h b/src/groups/mqb/mqbmock/mqbmock_queueengine.h index 1de541c350..7c7461e22b 100644 --- a/src/groups/mqb/mqbmock/mqbmock_queueengine.h +++ b/src/groups/mqb/mqbmock/mqbmock_queueengine.h @@ -78,7 +78,7 @@ class QueueEngine : public mqbi::QueueEngine { explicit QueueEngine(bslma::Allocator* allocator); /// Destructor - virtual ~QueueEngine() BSLS_KEYWORD_OVERRIDE; + ~QueueEngine() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS // (virtual mqbi::QueueEngine) @@ -86,13 +86,13 @@ class QueueEngine : public mqbi::QueueEngine { /// Configure this instance. The specified `isReconfigure` flag indicate /// if queue is being reconfigured. Return zero on success, non-zero value /// otherwise and populate the specified `errorDescription`. - virtual int configure(bsl::ostream& errorDescription, - bool isReconfigure) BSLS_KEYWORD_OVERRIDE; + int configure(bsl::ostream& errorDescription, + bool isReconfigure) BSLS_KEYWORD_OVERRIDE; /// Reset the internal state of this engine. If the optionally specified /// 'keepConfirming' is 'true', keep the data structures for CONFIRMs /// processing. - virtual void resetState(bool keepConfirming = false) BSLS_KEYWORD_OVERRIDE; + void resetState(bool keepConfirming = false) BSLS_KEYWORD_OVERRIDE; /// Rebuild the internal state of this engine. This method is invoked /// when the queue this engine is associated with is created from an @@ -103,14 +103,14 @@ class QueueEngine : public mqbi::QueueEngine { /// `rebuildInternalState` must be called on an empty-state object /// (i.e., which has just been constructed, or following a call to /// `resetState`) after it has been configured. - virtual int + int rebuildInternalState(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Obtain and return a handle to this queue for the client identified /// with the specified `clientContext`, using the specified /// `handleParameters`, and invoke the specified `callback` when /// finished. - virtual mqbi::QueueHandle* + mqbi::QueueHandle* getHandle(const bsl::shared_ptr& clientContext, const bmqp_ctrlmsg::QueueHandleParameters& handleParameters, @@ -121,7 +121,7 @@ class QueueEngine : public mqbi::QueueEngine { /// Configure the specified `handle` with the specified /// `streamParameters` and invoke the specified `configuredCb` when /// finished. - virtual void configureHandle( + void configureHandle( mqbi::QueueHandle* handle, const bmqp_ctrlmsg::StreamParameters& streamParameters, const mqbi::QueueHandle::HandleConfiguredCallback& configuredCb) @@ -130,7 +130,7 @@ class QueueEngine : public mqbi::QueueEngine { /// Reconfigure the specified `handle` by releasing the specified /// `parameters` from its current settings and invoke the specified /// `releasedCb` once done. - virtual void + void releaseHandle(mqbi::QueueHandle* handle, const bmqp_ctrlmsg::QueueHandleParameters& handleParameters, bool isFinal, @@ -144,16 +144,14 @@ class QueueEngine : public mqbi::QueueEngine { /// messages to the `handle`. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - onHandleUsable(mqbi::QueueHandle* handle, - unsigned int upstreamSubQueueId) BSLS_KEYWORD_OVERRIDE; + void onHandleUsable(mqbi::QueueHandle* handle, + unsigned int upstreamSubQueueId) BSLS_KEYWORD_OVERRIDE; /// Called by the mqbi::Queue when a new message with the specified /// `msgGUID` is available on the queue and ready to be sent to eventual /// interested clients. - virtual void - afterNewMessage(const bmqt::MessageGUID& msgGUID, - mqbi::QueueHandle* source) BSLS_KEYWORD_OVERRIDE; + void afterNewMessage(const bmqt::MessageGUID& msgGUID, + mqbi::QueueHandle* source) BSLS_KEYWORD_OVERRIDE; /// Called by the `mqbi::Queue` when the message identified by the /// specified `msgGUID` is confirmed for the specified `subQueueId` @@ -164,10 +162,9 @@ class QueueEngine : public mqbi::QueueEngine { /// or 1 if there are still references. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual int - onConfirmMessage(mqbi::QueueHandle* handle, - const bmqt::MessageGUID& msgGUID, - unsigned int subQueueId) BSLS_KEYWORD_OVERRIDE; + int onConfirmMessage(mqbi::QueueHandle* handle, + const bmqt::MessageGUID& msgGUID, + unsigned int subQueueId) BSLS_KEYWORD_OVERRIDE; /// Called by the `mqbi::Queue` when the message identified by the /// specified `msgGUID` is rejected for the specified @@ -182,7 +179,7 @@ class QueueEngine : public mqbi::QueueEngine { /// Called by the mqbi::Queue before a message with the specified /// `msgGUID` is removed from the queue. - virtual void beforeMessageRemoved(const bmqt::MessageGUID& msgGUID) + void beforeMessageRemoved(const bmqt::MessageGUID& msgGUID) BSLS_KEYWORD_OVERRIDE; /// Called by the mqbi::Queue *after* *all* messages are removed from @@ -192,7 +189,7 @@ class QueueEngine : public mqbi::QueueEngine { /// it manages. Note that `appKey` may be null, in which case the /// `purge` action is applicable to the entire queue. Also note that /// `appId` must be empty if and only if `appKey` is null. - virtual void + void afterQueuePurged(const bsl::string& appId, const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; @@ -200,8 +197,7 @@ class QueueEngine : public mqbi::QueueEngine { /// `currentTimer`; can be used for regular status check, such as for /// ensuring messages on the queue are flowing and not accumulating. /// THREAD: This method is called from the Queue's dispatcher thread. - virtual void - onTimer(bsls::Types::Int64 currentTimer) BSLS_KEYWORD_OVERRIDE; + void onTimer(bsls::Types::Int64 currentTimer) BSLS_KEYWORD_OVERRIDE; /// Given the specified 'putHeader', 'appData', 'mpi', and 'timestamp', /// evaluate all Auto (Application) subscriptions and exclude applications @@ -209,7 +205,7 @@ class QueueEngine : public mqbi::QueueEngine { /// Return 0 on success or an non-zero error code on failure. /// /// THREAD: This method is called from the Queue's dispatcher thread. - virtual mqbi::StorageResult::Enum evaluateAutoSubscriptions( + mqbi::StorageResult::Enum evaluateAutoSubscriptions( const bmqp::PutHeader& putHeader, const bsl::shared_ptr& appData, const bmqp::MessagePropertiesInfo& mpi, @@ -220,12 +216,11 @@ class QueueEngine : public mqbi::QueueEngine { /// Return the reference count that should be applied to a message /// posted to the queue managed by this engine. - virtual unsigned int messageReferenceCount() const BSLS_KEYWORD_OVERRIDE; + unsigned int messageReferenceCount() const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `out` object the internal information about /// this queue engine and associated queue handles. - virtual void - loadInternals(mqbcmd::QueueEngine* out) const BSLS_KEYWORD_OVERRIDE; + void loadInternals(mqbcmd::QueueEngine* out) const BSLS_KEYWORD_OVERRIDE; }; } // close package namespace diff --git a/src/groups/mqb/mqbmock/mqbmock_storagemanager.h b/src/groups/mqb/mqbmock/mqbmock_storagemanager.h index bde6f19240..a1e5c08a8c 100644 --- a/src/groups/mqb/mqbmock/mqbmock_storagemanager.h +++ b/src/groups/mqb/mqbmock/mqbmock_storagemanager.h @@ -43,7 +43,7 @@ namespace mqbmock { // ==================== /// Mock implementation of `mqbi::StorageManager` interface. -class StorageManager : public mqbi::StorageManager { +class StorageManager BSLS_KEYWORD_FINAL : public mqbi::StorageManager { public: // CREATORS @@ -60,16 +60,16 @@ class StorageManager : public mqbi::StorageManager { /// description of the error. /// /// THREAD: Executed by the cluster's dispatcher thread. - virtual int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; + int start(bsl::ostream& errorDescription) BSLS_KEYWORD_OVERRIDE; /// Stop this storage manager. - virtual void stop() BSLS_KEYWORD_OVERRIDE; + void stop() BSLS_KEYWORD_OVERRIDE; /// Initialize the queue key info map based on information in the specified /// `clusterState`. Note that this method should only be called once; /// subsequent calls will be ignored. - virtual void initializeQueueKeyInfoMap( - const mqbc::ClusterState& clusterState) BSLS_KEYWORD_OVERRIDE; + void initializeQueueKeyInfoMap(const mqbc::ClusterState& clusterState) + BSLS_KEYWORD_OVERRIDE; /// Register a queue with the specified `uri`, `queueKey` and /// `partitionId`, having the specified `appIdKeyPairs`, and belonging @@ -77,19 +77,19 @@ class StorageManager : public mqbi::StorageManager { /// associated queue storage created. /// /// THREAD: Executed by the Client's dispatcher thread. - virtual void registerQueue(const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const AppInfos& appIdKeyPairs, - mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; + void registerQueue(const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const AppInfos& appIdKeyPairs, + mqbi::Domain* domain) BSLS_KEYWORD_OVERRIDE; /// Synchronously unregister the queue with the specified `uri` from the /// specified `partitionId`. Behavior is undefined unless this routine /// is invoked from the cluster dispatcher thread. /// /// THREAD: Executed by the Client's dispatcher thread. - virtual void unregisterQueue(const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void unregisterQueue(const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Configure the fanout queue having specified `uri` and `queueKey`, /// assigned to the specified `partitionId` to have the specified @@ -100,56 +100,55 @@ class StorageManager : public mqbi::StorageManager { /// queue is configured in fanout mode. /// /// THREAD: Executed by the Queue's dispatcher thread. - virtual int updateQueuePrimary(const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const AppInfos& addedIdKeyPairs, - const AppInfos& removedIdKeyPairs) + int updateQueuePrimary(const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const AppInfos& addedIdKeyPairs, + const AppInfos& removedIdKeyPairs) BSLS_KEYWORD_OVERRIDE; - virtual void + void registerQueueReplica(int partitionId, const bmqt::Uri& uri, const mqbu::StorageKey& queueKey, mqbi::Domain* domain = 0, bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; - virtual void unregisterQueueReplica(int partitionId, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - const mqbu::StorageKey& appKey) + void unregisterQueueReplica(int partitionId, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; - virtual void - updateQueueReplica(int partitionId, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - const AppInfos& appIdKeyPairs, - mqbi::Domain* domain = 0, - bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; + void updateQueueReplica(int partitionId, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + const AppInfos& appIdKeyPairs, + mqbi::Domain* domain = 0, + bool allowDuplicate = false) BSLS_KEYWORD_OVERRIDE; /// Set the queue instance associated with the file-backed storage for /// the specified `uri` mapped to the specified `partitionId` to the /// specified `queue` value. Note that this method *does* *not* /// synchronize on the queue-dispatcher thread. - virtual void setQueue(mqbi::Queue* queue, - const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void setQueue(mqbi::Queue* queue, + const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Set the queue instance associated with the file-backed storage for /// the specified `uri` mapped to the specified `partitionId` to the /// specified `queue` value. Behavior is undefined unless `queue` is /// non-null or unless this routine is invoked from the dispatcher /// thread associated with the `partitionId`. - virtual void setQueueRaw(mqbi::Queue* queue, - const bmqt::Uri& uri, - int partitionId) BSLS_KEYWORD_OVERRIDE; + void setQueueRaw(mqbi::Queue* queue, + const bmqt::Uri& uri, + int partitionId) BSLS_KEYWORD_OVERRIDE; /// Behavior is undefined unless the specified 'partitionId' is in range /// and the specified 'primaryNode' is not null. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void + void setPrimaryForPartition(int partitionId, mqbnet::ClusterNode* primaryNode, unsigned int primaryLeaseId) BSLS_KEYWORD_OVERRIDE; @@ -158,103 +157,103 @@ class StorageManager : public mqbi::StorageManager { /// and the specified 'primaryNode' is not null. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void clearPrimaryForPartition(int partitionId, - mqbnet::ClusterNode* primary) + void clearPrimaryForPartition(int partitionId, + mqbnet::ClusterNode* primary) BSLS_KEYWORD_OVERRIDE; /// Set the primary status of the specified 'partitionId' to the specified /// 'value'. /// /// THREAD: Executed in cluster dispatcher thread. - virtual void setPrimaryStatusForPartition( - int partitionId, - bmqp_ctrlmsg::PrimaryStatus::Value value) BSLS_KEYWORD_OVERRIDE; + void setPrimaryStatusForPartition(int partitionId, + bmqp_ctrlmsg::PrimaryStatus::Value value) + BSLS_KEYWORD_OVERRIDE; /// Process primary state request received from the specified `source` /// with the specified `message`. - virtual void processPrimaryStateRequest( + void processPrimaryStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Process replica state request received from the specified `source` /// with the specified `message`. - virtual void processReplicaStateRequest( + void processReplicaStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Process replica data request received from the specified `source` /// with the specified `message`. - virtual void processReplicaDataRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processReplicaDataRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; - virtual int makeStorage(bsl::ostream& errorDescription, - bslma::ManagedPtr* out, - const bmqt::Uri& uri, - const mqbu::StorageKey& queueKey, - int partitionId, - const bsls::Types::Int64 messageTtl, - const int maxDeliveryAttempts, - const mqbconfm::StorageDefinition& storageDef) + int makeStorage(bsl::ostream& errorDescription, + bslma::ManagedPtr* out, + const bmqt::Uri& uri, + const mqbu::StorageKey& queueKey, + int partitionId, + const bsls::Types::Int64 messageTtl, + const int maxDeliveryAttempts, + const mqbconfm::StorageDefinition& storageDef) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processStorageEvent(const mqbi::DispatcherStorageEvent& event) + void processStorageEvent(const mqbi::DispatcherStorageEvent& event) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processStorageSyncRequest( - const bmqp_ctrlmsg::ControlMessage& message, - mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; + void processStorageSyncRequest(const bmqp_ctrlmsg::ControlMessage& message, + mqbnet::ClusterNode* source) + BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncStateRequest( + void processPartitionSyncStateRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncDataRequest( + void processPartitionSyncDataRequest( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPartitionSyncDataRequestStatus( + void processPartitionSyncDataRequestStatus( const bmqp_ctrlmsg::ControlMessage& message, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed in cluster dispatcher thread. - virtual void processRecoveryEvent( - const mqbi::DispatcherRecoveryEvent& event) BSLS_KEYWORD_OVERRIDE; + void processRecoveryEvent(const mqbi::DispatcherRecoveryEvent& event) + BSLS_KEYWORD_OVERRIDE; /// Executed in IO thread. - virtual void + void processReceiptEvent(const bmqp::Event& event, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void bufferPrimaryStatusAdvisory( + void bufferPrimaryStatusAdvisory( const bmqp_ctrlmsg::PrimaryStatusAdvisory& advisory, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processPrimaryStatusAdvisory( + void processPrimaryStatusAdvisory( const bmqp_ctrlmsg::PrimaryStatusAdvisory& advisory, mqbnet::ClusterNode* source) BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processReplicaStatusAdvisory( - int partitionId, - mqbnet::ClusterNode* source, - bmqp_ctrlmsg::NodeStatus::Value status) BSLS_KEYWORD_OVERRIDE; + void processReplicaStatusAdvisory(int partitionId, + mqbnet::ClusterNode* source, + bmqp_ctrlmsg::NodeStatus::Value status) + BSLS_KEYWORD_OVERRIDE; /// Executed by any thread. - virtual void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; + void processShutdownEvent() BSLS_KEYWORD_OVERRIDE; /// Invoke the specified `functor` with each queue associated to the /// partition identified by the specified `partitionId` if that /// partition has been successfully opened. The behavior is undefined /// unless invoked from the queue thread corresponding to `partitionId`. - virtual void + void applyForEachQueue(int partitionId, const QueueFunctor& functor) const BSLS_KEYWORD_OVERRIDE; @@ -263,36 +262,36 @@ class StorageManager : public mqbi::StorageManager { /// processed, or a non-zero value otherwise. This function can be /// invoked from any thread, and will block until the potentially /// asynchronous operation is complete. - virtual int processCommand(mqbcmd::StorageResult* result, - const mqbcmd::StorageCommand& command) + int processCommand(mqbcmd::StorageResult* result, + const mqbcmd::StorageCommand& command) BSLS_KEYWORD_OVERRIDE; /// GC the queues from unrecognized domains, if any. - virtual void gcUnrecognizedDomainQueues() BSLS_KEYWORD_OVERRIDE; + void gcUnrecognizedDomainQueues() BSLS_KEYWORD_OVERRIDE; // ACCESSORS /// Return the processor handle in charge of the specified /// `partitionId`. The behavior is undefined if `partitionId` does not /// represent a valid partition id. - virtual mqbi::Dispatcher::ProcessorHandle + mqbi::Dispatcher::ProcessorHandle processorForPartition(int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return true if the queue having specified `uri` and assigned to the /// specified `partitionId` has no messages, false in any other case. /// Behavior is undefined unless this routine is invoked from cluster /// dispatcher thread. - virtual bool isStorageEmpty(const bmqt::Uri& uri, - int partitionId) const BSLS_KEYWORD_OVERRIDE; + bool isStorageEmpty(const bmqt::Uri& uri, + int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return partition corresponding to the specified `partitionId`. The /// behavior is undefined if `partitionId` does not represent a valid /// partition id. - virtual const mqbs::FileStore& + const mqbs::FileStore& fileStore(int partitionId) const BSLS_KEYWORD_OVERRIDE; /// Return a StorageManagerIterator for the specified `partitionId`. - virtual bslma::ManagedPtr + bslma::ManagedPtr getIterator(int partitionId) const BSLS_KEYWORD_OVERRIDE; }; diff --git a/src/groups/mqb/mqbs/mqbs_filebackedstorage.h b/src/groups/mqb/mqbs/mqbs_filebackedstorage.h index d3c59a5852..827d8b7e3c 100644 --- a/src/groups/mqb/mqbs/mqbs_filebackedstorage.h +++ b/src/groups/mqb/mqbs/mqbs_filebackedstorage.h @@ -249,34 +249,34 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { bslma::Allocator* allocator, bmqma::CountingAllocatorStore* allocatorStore = 0); - virtual ~FileBackedStorage() BSLS_KEYWORD_OVERRIDE; + ~FileBackedStorage() BSLS_KEYWORD_OVERRIDE; // ACCESSORS /// Return the current configuration used by this storage. The behavior /// is undefined unless `configure` was successfully called. - virtual const mqbconfm::Storage& config() const BSLS_KEYWORD_OVERRIDE; + const mqbconfm::Storage& config() const BSLS_KEYWORD_OVERRIDE; /// Return true if storage is backed by a persistent data store, /// otherwise return false. - virtual bool isPersistent() const BSLS_KEYWORD_OVERRIDE; + bool isPersistent() const BSLS_KEYWORD_OVERRIDE; /// Return the queue this storage is associated with. /// Storage exists without a queue before `setQueue`. - virtual mqbi::Queue* queue() const BSLS_KEYWORD_OVERRIDE; + mqbi::Queue* queue() const BSLS_KEYWORD_OVERRIDE; /// Return the URI of the queue this storage is associated with. - virtual const bmqt::Uri& queueUri() const BSLS_KEYWORD_OVERRIDE; + const bmqt::Uri& queueUri() const BSLS_KEYWORD_OVERRIDE; /// Return the queueKey associated with this storage instance. - virtual const mqbu::StorageKey& queueKey() const BSLS_KEYWORD_OVERRIDE; + const mqbu::StorageKey& queueKey() const BSLS_KEYWORD_OVERRIDE; /// Return the number of messages in the virtual storage associated with /// the specified `appKey`. If `appKey` is null, number of messages in /// the `physical` storage is returned. Behavior is undefined if /// `appKey` is non-null but no virtual storage identified with it /// exists. - virtual bsls::Types::Int64 + bsls::Types::Int64 numMessages(const mqbu::StorageKey& appKey) const BSLS_KEYWORD_OVERRIDE; /// Return the number of bytes in the virtual storage associated with @@ -284,23 +284,23 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// `physical` storage is returned. Behavior is undefined if /// `appKey` is non-null but no virtual storage identified with it /// exists. - virtual bsls::Types::Int64 + bsls::Types::Int64 numBytes(const mqbu::StorageKey& appKey) const BSLS_KEYWORD_OVERRIDE; /// Return true if storage is empty. This method can be invoked from /// any thread. - virtual bool isEmpty() const BSLS_KEYWORD_OVERRIDE; + bool isEmpty() const BSLS_KEYWORD_OVERRIDE; /// Return true if this storage has message with the specified /// `msgGUID`, false otherwise. - virtual bool + bool hasMessage(const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; /// Retrieve the message and its metadata having the specified `msgGUID` /// in the specified `appData`, `options` and `attributes` from this /// storage. Return zero on success or a non-zero error code on /// failure. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum get(bsl::shared_ptr* appData, bsl::shared_ptr* options, mqbi::StorageMessageAttributes* attributes, @@ -309,45 +309,44 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// Populate the specified `attributes` buffer with attributes of the /// message having the specified `msgGUID`. Return zero on success or a /// non-zero error code on failure. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum get(mqbi::StorageMessageAttributes* attributes, const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; /// Return the number of virtual storages registered with this instance. - virtual int numVirtualStorages() const BSLS_KEYWORD_OVERRIDE; + int numVirtualStorages() const BSLS_KEYWORD_OVERRIDE; /// Return true if virtual storage identified by the specified 'appKey' /// exists, otherwise return false. Load into the optionally specified /// 'appId' the appId associated with 'appKey' if the virtual storage /// exists, otherwise set it to 0. - virtual bool - hasVirtualStorage(const mqbu::StorageKey& appKey, - bsl::string* appId = 0) const BSLS_KEYWORD_OVERRIDE; + bool hasVirtualStorage(const mqbu::StorageKey& appKey, + bsl::string* appId = 0) const BSLS_KEYWORD_OVERRIDE; /// Return `true` if there was Replication Receipt for the specified /// `msgGUID`. - virtual bool + bool hasReceipt(const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; /// Return true if virtual storage identified by the specified 'appId' /// exists, otherwise return false. Load into the optionally specified /// 'appKey' and 'ordinal' the appKey and ordinal associated with 'appId' /// if the virtual storage exists, otherwise set it to 0. - virtual bool + bool hasVirtualStorage(const bsl::string& appId, mqbu::StorageKey* appKey = 0, unsigned int* ordinal = 0) const BSLS_KEYWORD_OVERRIDE; /// Load into the specified 'buffer' the list of pairs of appId and appKey // for all the virtual storages registered with this instance. - virtual void + void loadVirtualStorageDetails(AppInfos* buffer) const BSLS_KEYWORD_OVERRIDE; /// Store in the specified 'msgSize' the size, in bytes, of the message /// having the specified 'msgGUID' if found and return success, or return /// a non-zero return code and leave 'msgSize' untouched if no message for /// the 'msgGUID' was found. - virtual mqbi::StorageResult::Enum getMessageSize( + mqbi::StorageResult::Enum getMessageSize( int* msgSize, const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; @@ -359,11 +358,11 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// otherwise. Note that calling `configure` on an already configured /// storage should atomically reconfigure that storage with the new /// configuration (or fail and leave the storage untouched). - virtual int configure(bsl::ostream& errorDescription, - const mqbconfm::Storage& config, - const mqbconfm::Limits& limits, - const bsls::Types::Int64 messageTtl, - int maxDeliveryAttempts) BSLS_KEYWORD_OVERRIDE; + int configure(bsl::ostream& errorDescription, + const mqbconfm::Storage& config, + const mqbconfm::Limits& limits, + const bsls::Types::Int64 messageTtl, + int maxDeliveryAttempts) BSLS_KEYWORD_OVERRIDE; /// Set the consistency level associated to this storage to the specified /// `value`. @@ -371,19 +370,19 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { setConsistency(const mqbconfm::Consistency& value) BSLS_KEYWORD_OVERRIDE; /// Return the resource capacity meter associated to this storage. - virtual mqbu::CapacityMeter* capacityMeter() BSLS_KEYWORD_OVERRIDE; + mqbu::CapacityMeter* capacityMeter() BSLS_KEYWORD_OVERRIDE; - virtual void setQueue(mqbi::Queue* queue) BSLS_KEYWORD_OVERRIDE; + void setQueue(mqbi::Queue* queue) BSLS_KEYWORD_OVERRIDE; /// Close this storage. - virtual void close() BSLS_KEYWORD_OVERRIDE; + void close() BSLS_KEYWORD_OVERRIDE; /// Save the message contained in the specified 'appData', 'options' and /// the associated 'attributes' and 'msgGUID' into this storage and the /// associated virtual storage. The 'attributes' is an in/out parameter /// and storage layer can populate certain fields of that struct. /// Return 0 on success or an non-zero error code on failure. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum put(mqbi::StorageMessageAttributes* attributes, const bmqt::MessageGUID& msgGUID, const bsl::shared_ptr& appData, @@ -394,7 +393,7 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// If the 'appKey' is null, the returned iterator can iterate states of /// all Apps; otherwise, the iterator can iterate states of the App /// corresponding to the 'appKey'. - virtual bslma::ManagedPtr + bslma::ManagedPtr getIterator(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; /// Load into the specified 'out' an iterator for data stored in the @@ -405,7 +404,7 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// corresponding to the 'appKey'. /// Return zero on success, and a non-zero code if 'msgGUID' was not /// found in the storage. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum getIterator(bslma::ManagedPtr* out, const mqbu::StorageKey& appKey, const bmqt::MessageGUID& msgGUID) BSLS_KEYWORD_OVERRIDE; @@ -457,9 +456,8 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// On CONFIRM, the caller of 'confirm' is responsible to follow with /// 'remove' call. 'releaseRef' is an alternative way to remove message in /// one call. - virtual mqbi::StorageResult::Enum - remove(const bmqt::MessageGUID& msgGUID, - int* msgSize = 0) BSLS_KEYWORD_OVERRIDE; + mqbi::StorageResult::Enum remove(const bmqt::MessageGUID& msgGUID, + int* msgSize = 0) BSLS_KEYWORD_OVERRIDE; /// Remove all messages from this storage for the App identified by the /// specified 'appKey' if 'appKey' is not null. Otherwise, remove messages @@ -468,7 +466,7 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// * e_SUCCESS : success /// * e_WRITE_FAILURE : failed to record this event in storage /// * e_APPKEY_NOT_FOUND : Invalid 'appKey' specified - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum removeAll(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; /// Flush any buffered replication messages to the peers. Behaviour is @@ -481,22 +479,22 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// from epoch, of the latest message encountered in the iteration, and /// the specified `configuredTtlValue` with the TTL value (in seconds) /// with which this storage instance is configured. - virtual int gcExpiredMessages(bsls::Types::Uint64* latestMsgTimestampEpoch, - bsls::Types::Int64* configuredTtlValue, - bsls::Types::Uint64 secondsFromEpoch) + int gcExpiredMessages(bsls::Types::Uint64* latestMsgTimestampEpoch, + bsls::Types::Int64* configuredTtlValue, + bsls::Types::Uint64 secondsFromEpoch) BSLS_KEYWORD_OVERRIDE; /// Garbage-collect those messages from the deduplication history which /// have expired the deduplication window. Return `true`, if there are /// expired items unprocessed because of the batch limit. - virtual bool gcHistory() BSLS_KEYWORD_OVERRIDE; + bool gcHistory() BSLS_KEYWORD_OVERRIDE; /// Create, if it doesn't exist already, a virtual storage instance with /// the specified `appId` and `appKey`. Return zero upon success and a /// non-zero value otherwise, and populate the specified /// `errorDescription` with a brief reason in case of failure. Behavior /// is undefined unless `appId` is non-empty and `appKey` is non-null. - virtual int + int addVirtualStorage(bsl::ostream& errorDescription, const bsl::string& appId, const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; @@ -507,33 +505,33 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// Behavior is undefined unless `appKey` is non-null. Note that this /// method will delete the virtual storage, and any reference to it will /// become invalid after this method returns. - virtual bool + bool removeVirtualStorage(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; // MANIPULATORS (for mqbs::ReplicatedStorage) - virtual void processMessageRecord(const bmqt::MessageGUID& guid, - unsigned int msgLen, - unsigned int refCount, - const DataStoreRecordHandle& handle) + void processMessageRecord(const bmqt::MessageGUID& guid, + unsigned int msgLen, + unsigned int refCount, + const DataStoreRecordHandle& handle) BSLS_KEYWORD_OVERRIDE; - virtual void processConfirmRecord(const bmqt::MessageGUID& guid, - const mqbu::StorageKey& appKey, - ConfirmReason::Enum reason, - const DataStoreRecordHandle& handle) + void processConfirmRecord(const bmqt::MessageGUID& guid, + const mqbu::StorageKey& appKey, + ConfirmReason::Enum reason, + const DataStoreRecordHandle& handle) BSLS_KEYWORD_OVERRIDE; - virtual void + void processDeletionRecord(const bmqt::MessageGUID& guid) BSLS_KEYWORD_OVERRIDE; - virtual void addQueueOpRecordHandle(const DataStoreRecordHandle& handle) + void addQueueOpRecordHandle(const DataStoreRecordHandle& handle) BSLS_KEYWORD_OVERRIDE; - virtual void purge(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; + void purge(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; - virtual void selectForAutoConfirming(const bmqt::MessageGUID& msgGUID) + void selectForAutoConfirming(const bmqt::MessageGUID& msgGUID) BSLS_KEYWORD_OVERRIDE; - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum autoConfirm(const mqbu::StorageKey& appKey, bsls::Types::Uint64 timestamp) BSLS_KEYWORD_OVERRIDE; /// The sequence of calls is 'startAutoConfirming', then zero or more @@ -544,15 +542,14 @@ class FileBackedStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// Auto-confirmed Apps do not PUSH the message. // ACCESSORS (for mqbs::ReplicatedStorage) - virtual int partitionId() const BSLS_KEYWORD_OVERRIDE; + int partitionId() const BSLS_KEYWORD_OVERRIDE; - virtual const RecordHandles& - queueOpRecordHandles() const BSLS_KEYWORD_OVERRIDE; + const RecordHandles& queueOpRecordHandles() const BSLS_KEYWORD_OVERRIDE; - virtual bool isStrongConsistency() const BSLS_KEYWORD_OVERRIDE; + bool isStrongConsistency() const BSLS_KEYWORD_OVERRIDE; /// Return the number of auto confirmed Apps for the current message. - virtual unsigned int numAutoConfirms() const BSLS_KEYWORD_OVERRIDE; + unsigned int numAutoConfirms() const BSLS_KEYWORD_OVERRIDE; }; // ============================================================================ diff --git a/src/groups/mqb/mqbs/mqbs_filestore.h b/src/groups/mqb/mqbs/mqbs_filestore.h index 9db6a44def..4abdb64c35 100644 --- a/src/groups/mqb/mqbs/mqbs_filestore.h +++ b/src/groups/mqb/mqbs/mqbs_filestore.h @@ -130,7 +130,7 @@ struct FileStore_AliasedBufferDeleter { /// Mechanism to store BlazingMQ messages in file. This component is /// *const-thread* safe. -class FileStore : public DataStore { +class FileStore BSLS_KEYWORD_FINAL : public DataStore { private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBS.FILESTORE"); diff --git a/src/groups/mqb/mqbs/mqbs_inmemorystorage.h b/src/groups/mqb/mqbs/mqbs_inmemorystorage.h index 0666e8921a..8d0cec0760 100644 --- a/src/groups/mqb/mqbs/mqbs_inmemorystorage.h +++ b/src/groups/mqb/mqbs/mqbs_inmemorystorage.h @@ -254,7 +254,7 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { bmqma::CountingAllocatorStore* allocatorStore = 0); /// Destructor - virtual ~InMemoryStorage() BSLS_KEYWORD_OVERRIDE; + ~InMemoryStorage() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS // (virtual mqbi::Storage) @@ -264,28 +264,28 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// description of the error in the specified `errorDescription` /// otherwise. Note that calling `configure` on an already configured /// storage should fail and leave the storage untouched. - virtual int configure(bsl::ostream& errorDescription, - const mqbconfm::Storage& config, - const mqbconfm::Limits& limits, - const bsls::Types::Int64 messageTtl, - const int maxDeliveryAttempts) BSLS_KEYWORD_OVERRIDE; + int configure(bsl::ostream& errorDescription, + const mqbconfm::Storage& config, + const mqbconfm::Limits& limits, + const bsls::Types::Int64 messageTtl, + const int maxDeliveryAttempts) BSLS_KEYWORD_OVERRIDE; /// Set the consistency level associated to this storage to the specified /// `value`. void setConsistency(const mqbconfm::Consistency& value) BSLS_KEYWORD_OVERRIDE; - virtual void setQueue(mqbi::Queue* queue) BSLS_KEYWORD_OVERRIDE; + void setQueue(mqbi::Queue* queue) BSLS_KEYWORD_OVERRIDE; /// Close this storage. - virtual void close() BSLS_KEYWORD_OVERRIDE; + void close() BSLS_KEYWORD_OVERRIDE; /// Get an iterator for data stored in the virtual storage identified by /// the specified 'appKey'. /// If the 'appKey' is null, the returned iterator can iterate states of /// all Apps; otherwise, the iterator can iterate states of the App /// corresponding to the 'appKey'. - virtual bslma::ManagedPtr + bslma::ManagedPtr getIterator(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; /// Load into the specified 'out' an iterator for data stored in the @@ -296,7 +296,7 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// corresponding to the 'appKey'. /// Return zero on success, and a non-zero code if 'msgGUID' was not /// found in the storage. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum getIterator(bslma::ManagedPtr* out, const mqbu::StorageKey& appKey, const bmqt::MessageGUID& msgGUID) BSLS_KEYWORD_OVERRIDE; @@ -306,7 +306,7 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// associated virtual storage. The 'attributes' is an in/out parameter /// and storage layer can populate certain fields of that struct. /// Return 0 on success or an non-zero error code on failure. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum put(mqbi::StorageMessageAttributes* attributes, const bmqt::MessageGUID& msgGUID, const bsl::shared_ptr& appData, @@ -359,9 +359,8 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// On CONFIRM, the caller of 'confirm' is responsible to follow with /// 'remove' call. 'releaseRef' is an alternative way to remove message in /// one call. - virtual mqbi::StorageResult::Enum - remove(const bmqt::MessageGUID& msgGUID, - int* msgSize = 0) BSLS_KEYWORD_OVERRIDE; + mqbi::StorageResult::Enum remove(const bmqt::MessageGUID& msgGUID, + int* msgSize = 0) BSLS_KEYWORD_OVERRIDE; /// Remove all messages from this storage for the App identified by the /// specified 'appKey' if 'appKey' is not null. Otherwise, remove messages @@ -370,7 +369,7 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// * e_SUCCESS : success /// * e_WRITE_FAILURE : failed to record this event in storage /// * e_APPKEY_NOT_FOUND : Invalid 'appKey' specified - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum removeAll(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; /// Flush any buffered replication messages to the peers. Behaviour is @@ -378,7 +377,7 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { void flushStorage() BSLS_KEYWORD_OVERRIDE; /// Return the resource capacity meter associated to this storage. - virtual mqbu::CapacityMeter* capacityMeter() BSLS_KEYWORD_OVERRIDE; + mqbu::CapacityMeter* capacityMeter() BSLS_KEYWORD_OVERRIDE; /// Attempt to garbage-collect messages for which TTL has expired, and /// return the number of messages garbage-collected. Populate the @@ -386,17 +385,17 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// from epoch, of the latest message garbage-collected due to TTL /// expiration, and the specified `configuredTtlValue` with the TTL /// value (in seconds) with which this storage instance is configured. - virtual int gcExpiredMessages(bsls::Types::Uint64* latestMsgTimestampEpoch, - bsls::Types::Int64* configuredTtlValue, - bsls::Types::Uint64 secondsFromEpoch) + int gcExpiredMessages(bsls::Types::Uint64* latestMsgTimestampEpoch, + bsls::Types::Int64* configuredTtlValue, + bsls::Types::Uint64 secondsFromEpoch) BSLS_KEYWORD_OVERRIDE; /// Garbage-collect those messages from the deduplication history which /// have expired the deduplication window. Return `true`, if there are /// expired items unprocessed because of the batch limit. - virtual bool gcHistory() BSLS_KEYWORD_OVERRIDE; + bool gcHistory() BSLS_KEYWORD_OVERRIDE; - virtual int + int addVirtualStorage(bsl::ostream& errorDescription, const bsl::string& appId, const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; @@ -412,12 +411,12 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// Behavior is undefined unless `appKey` is non-null. Note that this /// method will delete the virtual storage, and any reference to it will /// become invalid after this method returns. - virtual bool + bool removeVirtualStorage(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; - virtual void selectForAutoConfirming(const bmqt::MessageGUID& msgGUID) + void selectForAutoConfirming(const bmqt::MessageGUID& msgGUID) BSLS_KEYWORD_OVERRIDE; - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum autoConfirm(const mqbu::StorageKey& appKey, bsls::Types::Uint64 timestamp) BSLS_KEYWORD_OVERRIDE; /// The sequence of calls is 'startAutoConfirming', then zero or more @@ -430,28 +429,28 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// Return the queue this storage is associated with. /// Storage exists without a queue before `setQueue`. - virtual mqbi::Queue* queue() const BSLS_KEYWORD_OVERRIDE; + mqbi::Queue* queue() const BSLS_KEYWORD_OVERRIDE; /// Return the URI of the queue this storage is associated with. - virtual const bmqt::Uri& queueUri() const BSLS_KEYWORD_OVERRIDE; + const bmqt::Uri& queueUri() const BSLS_KEYWORD_OVERRIDE; /// Return the storage key associated with this instance. - virtual const mqbu::StorageKey& queueKey() const BSLS_KEYWORD_OVERRIDE; + const mqbu::StorageKey& queueKey() const BSLS_KEYWORD_OVERRIDE; /// Return the current configuration used by this storage. The behavior /// is undefined unless `configure` was successfully called. - virtual const mqbconfm::Storage& config() const BSLS_KEYWORD_OVERRIDE; + const mqbconfm::Storage& config() const BSLS_KEYWORD_OVERRIDE; /// Return true if storage is backed by a persistent data store, /// otherwise return false. - virtual bool isPersistent() const BSLS_KEYWORD_OVERRIDE; + bool isPersistent() const BSLS_KEYWORD_OVERRIDE; /// Return the number of messages in the virtual storage associated with /// the specified `appKey`. If `appKey` is null, number of messages in /// the `physical` storage is returned. Behavior is undefined if /// `appKey` is non-null but no virtual storage identified with it /// exists. - virtual bsls::Types::Int64 + bsls::Types::Int64 numMessages(const mqbu::StorageKey& appKey) const BSLS_KEYWORD_OVERRIDE; /// Return the number of bytes in the virtual storage associated with @@ -459,23 +458,23 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// `physical` storage is returned. Behavior is undefined if /// `appKey` is non-null but no virtual storage identified with it /// exists. - virtual bsls::Types::Int64 + bsls::Types::Int64 numBytes(const mqbu::StorageKey& appKey) const BSLS_KEYWORD_OVERRIDE; /// Return true if storage is empty. This method can be invoked from /// any thread. - virtual bool isEmpty() const BSLS_KEYWORD_OVERRIDE; + bool isEmpty() const BSLS_KEYWORD_OVERRIDE; /// Return true if this storage has message with the specified /// `msgGUID`, false otherwise. - virtual bool + bool hasMessage(const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; /// Retrieve the message and its metadata having the specified `msgGUID` /// in the specified `appData`, `options` and `attributes` from this /// storage. Return zero on success or a non-zero error code on /// failure. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum get(bsl::shared_ptr* appData, bsl::shared_ptr* options, mqbi::StorageMessageAttributes* attributes, @@ -484,7 +483,7 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// Populate the specified `attributes` buffer with attributes of the /// message having the specified `msgGUID`. Return zero on success or a /// non-zero error code on failure. - virtual mqbi::StorageResult::Enum + mqbi::StorageResult::Enum get(mqbi::StorageMessageAttributes* attributes, const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; @@ -492,72 +491,70 @@ class InMemoryStorage BSLS_KEYWORD_FINAL : public ReplicatedStorage { /// having the specified 'msgGUID' if found and return success, or return a /// non-zero return code and leave 'msgSize' untouched if no message for /// the 'msgGUID' was found. - virtual mqbi::StorageResult::Enum getMessageSize( + mqbi::StorageResult::Enum getMessageSize( int* msgSize, const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; /// Return the number of virtual storages registered with this instance. - virtual int numVirtualStorages() const BSLS_KEYWORD_OVERRIDE; + int numVirtualStorages() const BSLS_KEYWORD_OVERRIDE; /// Return true if virtual storage identified by the specified 'appKey' /// exists, otherwise return false. Load into the optionally specified /// 'appId' the appId associated with 'appKey' if the virtual storage /// exists, otherwise set it to 0. - virtual bool - hasVirtualStorage(const mqbu::StorageKey& appKey, - bsl::string* appId = 0) const BSLS_KEYWORD_OVERRIDE; + bool hasVirtualStorage(const mqbu::StorageKey& appKey, + bsl::string* appId = 0) const BSLS_KEYWORD_OVERRIDE; /// Return true if virtual storage identified by the specified 'appId' /// exists, otherwise return false. Load into the optionally specified /// 'appKey' and 'ordinal' the appKey and ordinal associated with 'appId' /// if the virtual storage exists, otherwise set it to 0. - virtual bool + bool hasVirtualStorage(const bsl::string& appId, mqbu::StorageKey* appKey = 0, unsigned int* ordinal = 0) const BSLS_KEYWORD_OVERRIDE; /// Return 'true' if there was Replication Receipt for the specified /// 'msgGUID'. - virtual bool + bool hasReceipt(const bmqt::MessageGUID& msgGUID) const BSLS_KEYWORD_OVERRIDE; /// Load into the specified 'buffer' the list of pairs of appId and /// appKey for all the virtual storages registered with this instance. - virtual void + void loadVirtualStorageDetails(AppInfos* buffer) const BSLS_KEYWORD_OVERRIDE; - virtual unsigned int numAutoConfirms() const BSLS_KEYWORD_OVERRIDE; + unsigned int numAutoConfirms() const BSLS_KEYWORD_OVERRIDE; // MANIPULATORS // (virtual mqbs::ReplicatedStorage) - virtual void processMessageRecord(const bmqt::MessageGUID& guid, - unsigned int msgLen, - unsigned int refCount, - const DataStoreRecordHandle& handle) + void processMessageRecord(const bmqt::MessageGUID& guid, + unsigned int msgLen, + unsigned int refCount, + const DataStoreRecordHandle& handle) BSLS_KEYWORD_OVERRIDE; - virtual void processConfirmRecord(const bmqt::MessageGUID& guid, - const mqbu::StorageKey& appKey, - ConfirmReason::Enum reason, - const DataStoreRecordHandle& handle) + void processConfirmRecord(const bmqt::MessageGUID& guid, + const mqbu::StorageKey& appKey, + ConfirmReason::Enum reason, + const DataStoreRecordHandle& handle) BSLS_KEYWORD_OVERRIDE; - virtual void + void processDeletionRecord(const bmqt::MessageGUID& guid) BSLS_KEYWORD_OVERRIDE; - virtual void addQueueOpRecordHandle(const DataStoreRecordHandle& handle) + void addQueueOpRecordHandle(const DataStoreRecordHandle& handle) BSLS_KEYWORD_OVERRIDE; - virtual void purge(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; + void purge(const mqbu::StorageKey& appKey) BSLS_KEYWORD_OVERRIDE; // ACCESSORS // (virtual mqbs::ReplicatedStorage) - virtual int partitionId() const BSLS_KEYWORD_OVERRIDE; + int partitionId() const BSLS_KEYWORD_OVERRIDE; - virtual const RecordHandles& - queueOpRecordHandles() const BSLS_KEYWORD_OVERRIDE; + const RecordHandles& queueOpRecordHandles() const BSLS_KEYWORD_OVERRIDE; - virtual bool isStrongConsistency() const BSLS_KEYWORD_OVERRIDE; + bool isStrongConsistency() const BSLS_KEYWORD_OVERRIDE; // ACCESSORS bool isProxy() const; diff --git a/src/groups/mqb/mqbsl/mqbsl_inmemorylog.h b/src/groups/mqb/mqbsl/mqbsl_inmemorylog.h index be7fd84c57..808fa65403 100644 --- a/src/groups/mqb/mqbsl/mqbsl_inmemorylog.h +++ b/src/groups/mqb/mqbsl/mqbsl_inmemorylog.h @@ -85,12 +85,12 @@ class InMemoryLogFactory BSLS_KEYWORD_FINAL : public mqbsi::LogFactory { bdlbb::BlobBufferFactory* bufferFactory); /// Destructor. - virtual ~InMemoryLogFactory() BSLS_KEYWORD_OVERRIDE; + ~InMemoryLogFactory() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS /// Create a new log using the specified `config`. - virtual bslma::ManagedPtr + bslma::ManagedPtr create(const mqbsi::LogConfig& config) BSLS_KEYWORD_OVERRIDE; }; @@ -204,11 +204,11 @@ class InMemoryLog BSLS_KEYWORD_FINAL : public mqbsi::Log { /// guarantee, upon successful completion of `open()`, `currentOffset()` /// must point to the end of the log, while `totalNumBytes()` and /// `outstandingNumBytes()` must be equal to the size of the log. - virtual int open(int flags) BSLS_KEYWORD_OVERRIDE; + int open(int flags) BSLS_KEYWORD_OVERRIDE; /// Close the log, and return 0 on success, or a negative value /// LogOpResult on error. - virtual int close() BSLS_KEYWORD_OVERRIDE; + int close() BSLS_KEYWORD_OVERRIDE; /// Move the log's internal write position to the specified `offset`, /// and return 0 on success, or a negative value LogOpResult on error. @@ -218,19 +218,19 @@ class InMemoryLog BSLS_KEYWORD_FINAL : public mqbsi::Log { /// Also note that it is the onus of the user of this component to /// update the number of outstanding bytes before seeking and /// overwriting existing bytes. - virtual int seek(Offset offset) BSLS_KEYWORD_OVERRIDE; + int seek(Offset offset) BSLS_KEYWORD_OVERRIDE; /// Increment the number of outstanding bytes in the log by the /// specified `value` (can be negative). - virtual void + void updateOutstandingNumBytes(bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; /// Update the number of outstanding bytes in the log to the specified /// `value`. - virtual void + void setOutstandingNumBytes(bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; - virtual Offset + Offset write(const void* entry, int offset, int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `length` bytes starting at the specified @@ -242,9 +242,9 @@ class InMemoryLog BSLS_KEYWORD_FINAL : public mqbsi::Log { /// overwritten. Therefore, it is the onus of the user to invoke /// `updateOutstandingNumBytes` properly before overwriting an existing /// record. - virtual Offset write(const bdlbb::Blob& entry, - const bmqu::BlobPosition& offset, - int length) BSLS_KEYWORD_OVERRIDE; + Offset write(const bdlbb::Blob& entry, + const bmqu::BlobPosition& offset, + int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `section` of the specified `entry` into the /// log's internal write position. Return the offset at which the @@ -254,57 +254,55 @@ class InMemoryLog BSLS_KEYWORD_FINAL : public mqbsi::Log { /// regardless of whether an existing record is overwritten. Therefore, /// it is the onus of the user to invoke `updateOutstandingNumBytes` /// properly before overwriting an existing record. - virtual Offset - write(const bdlbb::Blob& entry, - const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; + Offset write(const bdlbb::Blob& entry, + const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; /// Flush any cached data up to the optionally specified `offset` to the /// underlying storing mechanism, and return 0 on success, or a negative /// value `mqbsi::LogOpResult` on error. If `offset` is not specified, /// all data is flushed. - virtual int flush(Offset offset = 0) BSLS_KEYWORD_OVERRIDE; + int flush(Offset offset = 0) BSLS_KEYWORD_OVERRIDE; // ACCESSORS - virtual int + int read(void* entry, int length, Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Copy the specified `length` bytes starting at the specified `offset` /// of the log into the specified `entry`, and return 0 on success, or a /// negative value LogOpResult on error. Behavior is undefined unless /// `entry` has space for at least `length` bytes. - virtual int read(bdlbb::Blob* entry, - int length, - Offset offset) const BSLS_KEYWORD_OVERRIDE; + int read(bdlbb::Blob* entry, + int length, + Offset offset) const BSLS_KEYWORD_OVERRIDE; - virtual int + int alias(void** entry, int length, Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `entry a reference to the specified `length' /// bytes starting at the specified `offset` of the log, and return 0 on /// success, or a negative value LogOpResult on error. Behavior is /// undefined unless aliasing is supported. - virtual int alias(bdlbb::Blob* entry, - int length, - Offset offset) const BSLS_KEYWORD_OVERRIDE; + int alias(bdlbb::Blob* entry, + int length, + Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Return true if this log is opened, false otherwise. - virtual bool isOpened() const BSLS_KEYWORD_OVERRIDE; + bool isOpened() const BSLS_KEYWORD_OVERRIDE; /// Return the total number of bytes in the log. - virtual bsls::Types::Int64 totalNumBytes() const BSLS_KEYWORD_OVERRIDE; + bsls::Types::Int64 totalNumBytes() const BSLS_KEYWORD_OVERRIDE; /// Return the number of outstanding bytes in the log. - virtual bsls::Types::Int64 - outstandingNumBytes() const BSLS_KEYWORD_OVERRIDE; + bsls::Types::Int64 outstandingNumBytes() const BSLS_KEYWORD_OVERRIDE; /// Return the current offset of the log's internal write position. - virtual Offset currentOffset() const BSLS_KEYWORD_OVERRIDE; + Offset currentOffset() const BSLS_KEYWORD_OVERRIDE; /// Return the config of the log. - virtual const LogConfig& logConfig() const BSLS_KEYWORD_OVERRIDE; + const LogConfig& logConfig() const BSLS_KEYWORD_OVERRIDE; /// Return true if the log supports aliasing, false otherwise. - virtual bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; + bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; }; // ============================================================================ diff --git a/src/groups/mqb/mqbsl/mqbsl_ledger.h b/src/groups/mqb/mqbsl/mqbsl_ledger.h index 15c8401f75..863981d697 100644 --- a/src/groups/mqb/mqbsl/mqbsl_ledger.h +++ b/src/groups/mqb/mqbsl/mqbsl_ledger.h @@ -209,7 +209,7 @@ class Ledger BSLS_KEYWORD_FINAL : public mqbsi::Ledger { Ledger(const mqbsi::LedgerConfig& config, bslma::Allocator* allocator); /// Destructor - virtual ~Ledger() BSLS_KEYWORD_OVERRIDE; + ~Ledger() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS // (virtual 'mqbsi::Ledger') @@ -223,30 +223,29 @@ class Ledger BSLS_KEYWORD_FINAL : public mqbsi::Ledger { /// true, create the ledger if it does not exist. Else, return error if /// it does not exist. Note that if e_READ_ONLY is true, /// `writeRecord()` will return failure. - virtual int open(int flags) BSLS_KEYWORD_OVERRIDE; + int open(int flags) BSLS_KEYWORD_OVERRIDE; /// Close the ledger, and return 0 on success or a non-zero value /// otherwise. - virtual int close() BSLS_KEYWORD_OVERRIDE; + int close() BSLS_KEYWORD_OVERRIDE; /// Increment the number of outstanding bytes in the log having the /// specified `logId` by the specified `value` (can be negative). /// Return 0 on success or a non-zero value otherwise. - virtual int + int updateOutstandingNumBytes(const mqbu::StorageKey& logId, bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; /// Set the number of outstanding bytes in the log having the specified /// `logId` to the specified `value`. Return 0 on success or a non-zero /// value otherwise. - virtual int - setOutstandingNumBytes(const mqbu::StorageKey& logId, - bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; + int setOutstandingNumBytes(const mqbu::StorageKey& logId, + bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; - virtual int writeRecord(LedgerRecordId* recordId, - const void* record, - int offset, - int length) BSLS_KEYWORD_OVERRIDE; + int writeRecord(LedgerRecordId* recordId, + const void* record, + int offset, + int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `record` starting at the specified `offset` and /// of the specified `length` into this ledger and load into `recordId` @@ -254,72 +253,67 @@ class Ledger BSLS_KEYWORD_FINAL : public mqbsi::Ledger { /// Return 0 on success and a non zero value otherwise. The /// implementation must also adjust outstanding num bytes of the /// corresponding log. - virtual int writeRecord(LedgerRecordId* recordId, - const bdlbb::Blob& record, - const bmqu::BlobPosition& offset, - int length) BSLS_KEYWORD_OVERRIDE; + int writeRecord(LedgerRecordId* recordId, + const bdlbb::Blob& record, + const bmqu::BlobPosition& offset, + int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `section` of the specified `record` into this /// ledger and load into the specified `recordId` an identifier which /// can be used to retrieve the record later. Return 0 on success and a /// non zero value otherwise. The implementation must also adjust /// outstanding num bytes of the corresponding log. - virtual int - writeRecord(LedgerRecordId* recordId, - const bdlbb::Blob& record, - const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; + int writeRecord(LedgerRecordId* recordId, + const bdlbb::Blob& record, + const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; /// Flush any cached data in this ledger to the underlying storing /// mechanism, and return 0 on success, or a non-zero value on error. - virtual int flush() BSLS_KEYWORD_OVERRIDE; + int flush() BSLS_KEYWORD_OVERRIDE; // ACCESSORS // (virtual 'mqbsi::Ledger') - virtual int - readRecord(void* entry, - int length, - const LedgerRecordId& recordId) const BSLS_KEYWORD_OVERRIDE; + int readRecord(void* entry, + int length, + const LedgerRecordId& recordId) const BSLS_KEYWORD_OVERRIDE; /// Copy the specified `length` bytes from the specified `recordId` in /// this ledger into the specified `entry`, and return 0 on success, or /// a non-zero value on error. Behavior is undefined unless `entry` has /// space for at least `length` bytes. - virtual int - readRecord(bdlbb::Blob* entry, - int length, - const LedgerRecordId& recordId) const BSLS_KEYWORD_OVERRIDE; + int readRecord(bdlbb::Blob* entry, + int length, + const LedgerRecordId& recordId) const BSLS_KEYWORD_OVERRIDE; - virtual int - aliasRecord(void** entry, - int length, - const LedgerRecordId& recordId) const BSLS_KEYWORD_OVERRIDE; + int aliasRecord(void** entry, int length, const LedgerRecordId& recordId) + const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `entry` a reference to the specified /// `length` bytes from the specified `recordId` in this ledger, and /// return 0 on success, or a non-zero value on error. Behavior is /// undefined unless aliasing is supported. - virtual int + int aliasRecord(bdlbb::Blob* entry, int length, const LedgerRecordId& recordId) const BSLS_KEYWORD_OVERRIDE; /// Return true if this ledger is opened, false otherwise. - virtual bool isOpened() const BSLS_KEYWORD_OVERRIDE; + bool isOpened() const BSLS_KEYWORD_OVERRIDE; /// Return true if this ledger supports aliasing, false otherwise. - virtual bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; + bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; /// Return the number of logs in this ledger. - virtual size_t numLogs() const BSLS_KEYWORD_OVERRIDE; + size_t numLogs() const BSLS_KEYWORD_OVERRIDE; /// Return the list of logs inside the ledger. Note that the last log /// instance in the returned list is the "current" one (i.e., the one /// to which next record will be written). - virtual const Logs& logs() const BSLS_KEYWORD_OVERRIDE; + const Logs& logs() const BSLS_KEYWORD_OVERRIDE; /// Return a reference not offering modifiable access to the current log /// being written to in this ledger. - virtual const LogSp& currentLog() const BSLS_KEYWORD_OVERRIDE; + const LogSp& currentLog() const BSLS_KEYWORD_OVERRIDE; /// If the optionally specified `logId` is null (`isNull()` returns /// true), return the number of outstanding bytes across all log @@ -327,11 +321,11 @@ class Ledger BSLS_KEYWORD_FINAL : public mqbsi::Ledger { /// bytes in the log instance identified by `logId`. The behavior is /// undefined unless there is a log instance identified by `logId` in /// this ledger. - virtual bsls::Types::Int64 + bsls::Types::Int64 outstandingNumBytes(const mqbu::StorageKey& logId = mqbu::StorageKey()) const BSLS_KEYWORD_OVERRIDE; - virtual bsls::Types::Int64 + bsls::Types::Int64 totalNumBytes(const mqbu::StorageKey& logId = mqbu::StorageKey()) const BSLS_KEYWORD_OVERRIDE; // If the optionally specified 'logId' is null ('isNull()' returns diff --git a/src/groups/mqb/mqbsl/mqbsl_memorymappedondisklog.h b/src/groups/mqb/mqbsl/mqbsl_memorymappedondisklog.h index 217ca8c4fa..6c1166f3e4 100644 --- a/src/groups/mqb/mqbsl/mqbsl_memorymappedondisklog.h +++ b/src/groups/mqb/mqbsl/mqbsl_memorymappedondisklog.h @@ -79,12 +79,12 @@ class MemoryMappedOnDiskLogFactory BSLS_KEYWORD_FINAL MemoryMappedOnDiskLogFactory(bslma::Allocator* allocator); /// Destructor. - virtual ~MemoryMappedOnDiskLogFactory() BSLS_KEYWORD_OVERRIDE; + ~MemoryMappedOnDiskLogFactory() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS /// Create a new log using the specified `config`. - virtual bslma::ManagedPtr + bslma::ManagedPtr create(const mqbsi::LogConfig& config) BSLS_KEYWORD_OVERRIDE; }; @@ -174,11 +174,11 @@ class MemoryMappedOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// guarantee, upon successful completion of `open()`, `currentOffset()` /// must point to the end of the log, while `totalNumBytes()` and /// `outstandingNumBytes()` must be equal to the size of the log. - virtual int open(int flags) BSLS_KEYWORD_OVERRIDE; + int open(int flags) BSLS_KEYWORD_OVERRIDE; /// Close the log, and return 0 on success, or a negative value /// LogOpResult on error. - virtual int close() BSLS_KEYWORD_OVERRIDE; + int close() BSLS_KEYWORD_OVERRIDE; /// Move the log's internal write position to the specified `offset`, /// and return 0 on success, or a negative value LogOpResult on error. @@ -188,19 +188,19 @@ class MemoryMappedOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// Also note that it is the onus of the user of this component to /// update the number of outstanding bytes before seeking and /// overwriting existing bytes. - virtual int seek(Offset offset) BSLS_KEYWORD_OVERRIDE; + int seek(Offset offset) BSLS_KEYWORD_OVERRIDE; /// Increment the number of outstanding bytes in the log by the /// specified `value` (can be negative). - virtual void + void updateOutstandingNumBytes(bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; /// Update the number of outstanding bytes in the log to the specified /// `value`. - virtual void + void setOutstandingNumBytes(bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; - virtual Offset + Offset write(const void* entry, int offset, int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `length` bytes starting at the specified @@ -212,9 +212,9 @@ class MemoryMappedOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// overwritten. Therefore, it is the onus of the user to invoke /// `updateOutstandingNumBytes` properly before overwriting an existing /// record. - virtual Offset write(const bdlbb::Blob& entry, - const bmqu::BlobPosition& offset, - int length) BSLS_KEYWORD_OVERRIDE; + Offset write(const bdlbb::Blob& entry, + const bmqu::BlobPosition& offset, + int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `section` of the specified `entry` into the /// log's internal write position. Return the offset at which the @@ -224,60 +224,58 @@ class MemoryMappedOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// regardless of whether an existing record is overwritten. Therefore, /// it is the onus of the user to invoke `updateOutstandingNumBytes` /// properly before overwriting an existing record. - virtual Offset - write(const bdlbb::Blob& entry, - const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; + Offset write(const bdlbb::Blob& entry, + const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; /// Flush any cached data up to the optionally specified `offset` to the /// underlying storing mechanism, and return 0 on success, or a negative /// value `mqbsi::LogOpResult` on error. If `offset` is not specified, /// all data is flushed. - virtual int flush(Offset offset = 0) BSLS_KEYWORD_OVERRIDE; + int flush(Offset offset = 0) BSLS_KEYWORD_OVERRIDE; // ACCESSORS - virtual int + int read(void* entry, int length, Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Copy the specified `length` bytes starting at the specified `offset` /// of the log into the specified `entry`, and return 0 on success, or a /// negative value LogOpResult on error. Behavior is undefined unless /// `entry` has space for at least `length` bytes. - virtual int read(bdlbb::Blob* entry, - int length, - Offset offset) const BSLS_KEYWORD_OVERRIDE; + int read(bdlbb::Blob* entry, + int length, + Offset offset) const BSLS_KEYWORD_OVERRIDE; - virtual int + int alias(void** entry, int length, Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `entry a reference to the specified `length' /// bytes starting at the specified `offset` of the log, and return 0 on /// success, or a negative value LogOpResult on error. Behavior is /// undefined unless aliasing is supported. - virtual int alias(bdlbb::Blob* entry, - int length, - Offset offset) const BSLS_KEYWORD_OVERRIDE; + int alias(bdlbb::Blob* entry, + int length, + Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Return true if this log is opened, false otherwise. - virtual bool isOpened() const BSLS_KEYWORD_OVERRIDE; + bool isOpened() const BSLS_KEYWORD_OVERRIDE; /// Return the total number of bytes in the log. - virtual bsls::Types::Int64 totalNumBytes() const BSLS_KEYWORD_OVERRIDE; + bsls::Types::Int64 totalNumBytes() const BSLS_KEYWORD_OVERRIDE; /// Return the number of outstanding bytes in the log. - virtual bsls::Types::Int64 - outstandingNumBytes() const BSLS_KEYWORD_OVERRIDE; + bsls::Types::Int64 outstandingNumBytes() const BSLS_KEYWORD_OVERRIDE; /// Return the current offset of the log's internal write position. - virtual Offset currentOffset() const BSLS_KEYWORD_OVERRIDE; + Offset currentOffset() const BSLS_KEYWORD_OVERRIDE; /// Return the config of the log. - virtual const LogConfig& logConfig() const BSLS_KEYWORD_OVERRIDE; + const LogConfig& logConfig() const BSLS_KEYWORD_OVERRIDE; /// Return true if the log supports aliasing, false otherwise. - virtual bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; + bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; /// Return the config of this on-disk log - virtual const mqbsi::LogConfig& config() const BSLS_KEYWORD_OVERRIDE; + const mqbsi::LogConfig& config() const BSLS_KEYWORD_OVERRIDE; }; // ============================================================================ diff --git a/src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.h b/src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.h index 9a313ff5c2..1b8d68cca1 100644 --- a/src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.h +++ b/src/groups/mqb/mqbsl/mqbsl_readwriteondisklog.h @@ -83,12 +83,12 @@ class ReadWriteOnDiskLogFactory BSLS_KEYWORD_FINAL : public mqbsi::LogFactory { explicit ReadWriteOnDiskLogFactory(bslma::Allocator* allocator); /// Destructor. - virtual ~ReadWriteOnDiskLogFactory() BSLS_KEYWORD_OVERRIDE; + ~ReadWriteOnDiskLogFactory() BSLS_KEYWORD_OVERRIDE; // MANIPULATORS /// Create a new log using the specified `config`. - virtual bslma::ManagedPtr + bslma::ManagedPtr create(const mqbsi::LogConfig& config) BSLS_KEYWORD_OVERRIDE; }; @@ -201,11 +201,11 @@ class ReadWriteOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// guarantee, upon successful completion of `open()`, `currentOffset()` /// must point to the end of the log, while `totalNumBytes()` and /// `outstandingNumBytes()` must be equal to the size of the log. - virtual int open(int flags) BSLS_KEYWORD_OVERRIDE; + int open(int flags) BSLS_KEYWORD_OVERRIDE; /// Close the log, and return 0 on success, or a negative value /// LogOpResult on error. - virtual int close() BSLS_KEYWORD_OVERRIDE; + int close() BSLS_KEYWORD_OVERRIDE; /// Move the log's internal write position to the specified `offset`, /// and return 0 on success, or a negative value LogOpResult on error. @@ -215,19 +215,19 @@ class ReadWriteOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// Also note that it is the onus of the user of this component to /// update the number of outstanding bytes before seeking and /// overwriting existing bytes. - virtual int seek(Offset offset) BSLS_KEYWORD_OVERRIDE; + int seek(Offset offset) BSLS_KEYWORD_OVERRIDE; /// Increment the number of outstanding bytes in the log by the /// specified `value` (can be negative). - virtual void + void updateOutstandingNumBytes(bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; /// Update the number of outstanding bytes in the log to the specified /// `value`. - virtual void + void setOutstandingNumBytes(bsls::Types::Int64 value) BSLS_KEYWORD_OVERRIDE; - virtual Offset + Offset write(const void* entry, int offset, int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `length` bytes starting at the specified @@ -239,9 +239,9 @@ class ReadWriteOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// overwritten. Therefore, it is the onus of the user to invoke /// `updateOutstandingNumBytes` properly before overwriting an existing /// record. - virtual Offset write(const bdlbb::Blob& entry, - const bmqu::BlobPosition& offset, - int length) BSLS_KEYWORD_OVERRIDE; + Offset write(const bdlbb::Blob& entry, + const bmqu::BlobPosition& offset, + int length) BSLS_KEYWORD_OVERRIDE; /// Write the specified `section` of the specified `entry` into the /// log's internal write position. Return the offset at which the @@ -251,60 +251,58 @@ class ReadWriteOnDiskLog BSLS_KEYWORD_FINAL : public OnDiskLog { /// regardless of whether an existing record is overwritten. Therefore, /// it is the onus of the user to invoke `updateOutstandingNumBytes` /// properly before overwriting an existing record. - virtual Offset - write(const bdlbb::Blob& entry, - const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; + Offset write(const bdlbb::Blob& entry, + const bmqu::BlobSection& section) BSLS_KEYWORD_OVERRIDE; /// Flush any cached data up to the optionally specified `offset` to the /// underlying storing mechanism, and return 0 on success, or a negative /// value `mqbsi::LogOpResult` on error. If `offset` is not specified, /// all data is flushed. - virtual int flush(Offset offset = 0) BSLS_KEYWORD_OVERRIDE; + int flush(Offset offset = 0) BSLS_KEYWORD_OVERRIDE; // ACCESSORS - virtual int + int read(void* entry, int length, Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Copy the specified `length` bytes starting at the specified `offset` /// of the log into the specified `entry`, and return 0 on success, or a /// negative value LogOpResult on error. Behavior is undefined unless /// `entry` has space for at least `length` bytes. - virtual int read(bdlbb::Blob* entry, - int length, - Offset offset) const BSLS_KEYWORD_OVERRIDE; + int read(bdlbb::Blob* entry, + int length, + Offset offset) const BSLS_KEYWORD_OVERRIDE; - virtual int + int alias(void** entry, int length, Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Load into the specified `entry a reference to the specified `length' /// bytes starting at the specified `offset` of the log, and return 0 on /// success, or a negative value LogOpResult on error. Behavior is /// undefined unless aliasing is supported. - virtual int alias(bdlbb::Blob* entry, - int length, - Offset offset) const BSLS_KEYWORD_OVERRIDE; + int alias(bdlbb::Blob* entry, + int length, + Offset offset) const BSLS_KEYWORD_OVERRIDE; /// Return true if this log is opened, false otherwise. - virtual bool isOpened() const BSLS_KEYWORD_OVERRIDE; + bool isOpened() const BSLS_KEYWORD_OVERRIDE; /// Return the total number of bytes in the log. - virtual bsls::Types::Int64 totalNumBytes() const BSLS_KEYWORD_OVERRIDE; + bsls::Types::Int64 totalNumBytes() const BSLS_KEYWORD_OVERRIDE; /// Return the number of outstanding bytes in the log. - virtual bsls::Types::Int64 - outstandingNumBytes() const BSLS_KEYWORD_OVERRIDE; + bsls::Types::Int64 outstandingNumBytes() const BSLS_KEYWORD_OVERRIDE; /// Return the current offset of the log's internal write position. - virtual Offset currentOffset() const BSLS_KEYWORD_OVERRIDE; + Offset currentOffset() const BSLS_KEYWORD_OVERRIDE; /// Return the config of the log. - virtual const LogConfig& logConfig() const BSLS_KEYWORD_OVERRIDE; + const LogConfig& logConfig() const BSLS_KEYWORD_OVERRIDE; /// Return true if the log supports aliasing, false otherwise. - virtual bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; + bool supportsAliasing() const BSLS_KEYWORD_OVERRIDE; /// Return the config of this on-disk log. - virtual const mqbsi::LogConfig& config() const BSLS_KEYWORD_OVERRIDE; + const mqbsi::LogConfig& config() const BSLS_KEYWORD_OVERRIDE; }; // ============================================================================ From 09ba4f2536f8e2e89b3bc8d90e68612b06864114 Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Fri, 6 Dec 2024 20:28:56 +0200 Subject: [PATCH 02/17] Performance[MQB,BMQ]: return constructed blobs as pointers (#471) Signed-off-by: Evgeny Malygin --- .../bmq/bmqa/bmqa_confirmeventbuilder.cpp | 2 +- src/groups/bmq/bmqa/bmqa_message.t.cpp | 42 ++- src/groups/bmq/bmqa/bmqa_messageevent.t.cpp | 18 +- src/groups/bmq/bmqa/bmqa_mocksession.cpp | 26 +- src/groups/bmq/bmqa/bmqa_mocksession.h | 22 +- src/groups/bmq/bmqa/bmqa_session.cpp | 6 +- src/groups/bmq/bmqimp/bmqimp_application.cpp | 6 +- src/groups/bmq/bmqimp/bmqimp_application.h | 22 +- .../bmq/bmqimp/bmqimp_brokersession.cpp | 27 +- src/groups/bmq/bmqimp/bmqimp_brokersession.h | 14 +- .../bmq/bmqimp/bmqimp_brokersession.t.cpp | 135 +++++++-- src/groups/bmq/bmqimp/bmqimp_event.cpp | 9 +- src/groups/bmq/bmqimp/bmqimp_event.h | 5 +- src/groups/bmq/bmqimp/bmqimp_event.t.cpp | 24 +- src/groups/bmq/bmqimp/bmqimp_eventqueue.t.cpp | 16 +- .../bmq/bmqimp/bmqimp_messagedumper.t.cpp | 20 +- .../bmqimp_negotiatedchannelfactory.cpp | 17 +- .../bmqimp/bmqimp_negotiatedchannelfactory.h | 13 +- .../bmq/bmqimp/bmqimp_queuemanager.t.cpp | 20 +- src/groups/bmq/bmqp/bmqp_ackeventbuilder.cpp | 48 ++-- src/groups/bmq/bmqp/bmqp_ackeventbuilder.h | 54 ++-- .../bmq/bmqp/bmqp_ackeventbuilder.t.cpp | 45 ++- src/groups/bmq/bmqp/bmqp_blobpoolutil.cpp | 62 ++++ src/groups/bmq/bmqp/bmqp_blobpoolutil.h | 60 ++++ .../bmq/bmqp/bmqp_confirmeventbuilder.cpp | 48 ++-- .../bmq/bmqp/bmqp_confirmeventbuilder.h | 54 ++-- .../bmq/bmqp/bmqp_confirmeventbuilder.t.cpp | 47 +++- src/groups/bmq/bmqp/bmqp_event.t.cpp | 33 ++- src/groups/bmq/bmqp/bmqp_eventutil.cpp | 17 +- src/groups/bmq/bmqp/bmqp_eventutil.h | 10 +- src/groups/bmq/bmqp/bmqp_eventutil.t.cpp | 27 +- src/groups/bmq/bmqp/bmqp_protocolutil.cpp | 15 +- src/groups/bmq/bmqp/bmqp_protocolutil.h | 14 +- src/groups/bmq/bmqp/bmqp_protocolutil.t.cpp | 16 +- src/groups/bmq/bmqp/bmqp_pusheventbuilder.cpp | 56 ++-- src/groups/bmq/bmqp/bmqp_pusheventbuilder.h | 61 ++-- .../bmq/bmqp/bmqp_pusheventbuilder.t.cpp | 113 +++++--- src/groups/bmq/bmqp/bmqp_puteventbuilder.cpp | 123 ++++---- src/groups/bmq/bmqp/bmqp_puteventbuilder.h | 54 ++-- .../bmq/bmqp/bmqp_puteventbuilder.t.cpp | 122 +++++--- .../bmq/bmqp/bmqp_recoveryeventbuilder.cpp | 46 +-- .../bmq/bmqp/bmqp_recoveryeventbuilder.h | 51 ++-- .../bmq/bmqp/bmqp_recoveryeventbuilder.t.cpp | 47 ++-- .../bmq/bmqp/bmqp_rejecteventbuilder.cpp | 47 ++-- src/groups/bmq/bmqp/bmqp_rejecteventbuilder.h | 54 ++-- .../bmq/bmqp/bmqp_rejecteventbuilder.t.cpp | 47 +++- src/groups/bmq/bmqp/bmqp_requestmanager.h | 103 +++---- src/groups/bmq/bmqp/bmqp_requestmanager.t.cpp | 25 +- src/groups/bmq/bmqp/bmqp_schemaeventbuilder.h | 103 ++++--- .../bmq/bmqp/bmqp_schemaeventbuilder.t.cpp | 39 ++- .../bmq/bmqp/bmqp_storageeventbuilder.cpp | 60 ++-- .../bmq/bmqp/bmqp_storageeventbuilder.h | 54 ++-- .../bmq/bmqp/bmqp_storageeventbuilder.t.cpp | 53 +++- src/groups/bmq/bmqp/package/bmqp.mem | 1 + src/groups/mqb/mqba/mqba_adminsession.cpp | 16 +- src/groups/mqb/mqba/mqba_adminsession.h | 34 +-- src/groups/mqb/mqba/mqba_adminsession.t.cpp | 9 +- src/groups/mqb/mqba/mqba_clientsession.cpp | 25 +- src/groups/mqb/mqba/mqba_clientsession.h | 12 +- src/groups/mqb/mqba/mqba_clientsession.t.cpp | 38 ++- .../mqb/mqba/mqba_sessionnegotiator.cpp | 9 +- src/groups/mqb/mqba/mqba_sessionnegotiator.h | 5 +- .../mqb/mqbblp/mqbblp_clustercatalog.cpp | 2 +- .../mqb/mqbblp/mqbblp_clusterorchestrator.cpp | 6 +- .../mqb/mqbblp/mqbblp_recoverymanager.cpp | 13 +- src/groups/mqb/mqbc/mqbc_clusterdata.cpp | 4 +- .../mqbc/mqbc_controlmessagetransmitter.cpp | 20 +- .../mqb/mqbc/mqbc_controlmessagetransmitter.h | 12 +- .../mqbc/mqbc_incoreclusterstateledger.cpp | 59 ++-- .../mqb/mqbc/mqbc_incoreclusterstateledger.h | 13 +- .../mqbc/mqbc_incoreclusterstateledger.t.cpp | 2 +- src/groups/mqb/mqbc/mqbc_recoverymanager.cpp | 7 +- src/groups/mqb/mqbc/mqbc_recoverymanager.h | 24 +- src/groups/mqb/mqbc/mqbc_storagemanager.cpp | 14 +- src/groups/mqb/mqbc/mqbc_storagemanager.h | 3 - src/groups/mqb/mqbmock/mqbmock_cluster.h | 16 +- src/groups/mqb/mqbnet/mqbnet_channel.cpp | 37 +-- src/groups/mqb/mqbnet/mqbnet_channel.h | 96 +++---- src/groups/mqb/mqbnet/mqbnet_channel.t.cpp | 266 ++++++++---------- src/groups/mqb/mqbnet/mqbnet_cluster.h | 11 +- src/groups/mqb/mqbnet/mqbnet_cluster.t.cpp | 18 +- src/groups/mqb/mqbnet/mqbnet_clusterimp.cpp | 12 +- src/groups/mqb/mqbnet/mqbnet_clusterimp.h | 9 +- src/groups/mqb/mqbnet/mqbnet_elector.cpp | 12 +- src/groups/mqb/mqbnet/mqbnet_elector.h | 9 +- src/groups/mqb/mqbnet/mqbnet_mockcluster.cpp | 10 +- src/groups/mqb/mqbnet/mqbnet_mockcluster.h | 9 +- .../mqb/mqbnet/mqbnet_multirequestmanager.h | 11 +- .../mqbnet/mqbnet_multirequestmanager.t.cpp | 8 +- src/groups/mqb/mqbs/mqbs_filestore.cpp | 25 +- src/groups/mqb/mqbs/mqbs_filestore.h | 28 +- src/groups/mqb/mqbs/mqbs_filestore.t.cpp | 18 +- 92 files changed, 1945 insertions(+), 1230 deletions(-) create mode 100644 src/groups/bmq/bmqp/bmqp_blobpoolutil.cpp create mode 100644 src/groups/bmq/bmqp/bmqp_blobpoolutil.h diff --git a/src/groups/bmq/bmqa/bmqa_confirmeventbuilder.cpp b/src/groups/bmq/bmqa/bmqa_confirmeventbuilder.cpp index 5726045063..32dee1c887 100644 --- a/src/groups/bmq/bmqa/bmqa_confirmeventbuilder.cpp +++ b/src/groups/bmq/bmqa/bmqa_confirmeventbuilder.cpp @@ -100,7 +100,7 @@ const bdlbb::Blob& ConfirmEventBuilder::blob() const // PRECONDITIONS BSLS_ASSERT(d_impl.d_builder_p); - return d_impl.d_builder_p->blob(); + return *d_impl.d_builder_p->blob(); } } // close package namespace diff --git a/src/groups/bmq/bmqa/bmqa_message.t.cpp b/src/groups/bmq/bmqa/bmqa_message.t.cpp index d12225587d..af2ecfb14a 100644 --- a/src/groups/bmq/bmqa/bmqa_message.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_message.t.cpp @@ -166,6 +166,10 @@ static void test2_validPushMessagePrint() bdlbb::PooledBlobBufferFactory bufferFactory( 4 * 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqa::Event event; EventImplSp& implPtr = reinterpret_cast(event); @@ -188,11 +192,11 @@ static void test2_validPushMessagePrint() bsl::strlen(buffer)); // Create PushEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); ASSERT_EQ(0, peb.messageCount()); // Add SubQueueInfo option @@ -203,7 +207,7 @@ static void test2_validPushMessagePrint() ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); // 'eventSize()' excludes unpacked messages ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // But the option is written to the underlying blob rc = peb.packMessage(payload, queueId, @@ -215,7 +219,7 @@ static void test2_validPushMessagePrint() ASSERT_LT(payload.length(), peb.eventSize()); ASSERT_EQ(1, peb.messageCount()); - bmqp::Event bmqpEvent(&peb.blob(), + bmqp::Event bmqpEvent(peb.blob().get(), bmqtst::TestHelperUtil::allocator(), true); implPtr->configureAsMessageEvent(bmqpEvent); @@ -250,6 +254,10 @@ static void test3_messageProperties() bdlbb::PooledBlobBufferFactory bufferFactory( 4 * 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); const int queueId = 4321; const bmqt::MessageGUID guid; @@ -280,7 +288,7 @@ static void test3_messageProperties() bdlbb::BlobUtil::append(&payload, buffer, bsl::strlen(buffer)); // Create PushEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); // Add SubQueueInfo option @@ -314,7 +322,7 @@ static void test3_messageProperties() queue->setId(queueId); implPtr->insertQueue(subQueueId, queue); - bmqp::Event bmqpEvent(&peb.blob(), + bmqp::Event bmqpEvent(peb.blob().get(), bmqtst::TestHelperUtil::allocator(), true); @@ -422,6 +430,10 @@ static void test4_subscriptionHandle() bdlbb::PooledBlobBufferFactory bufferFactory( 4 * 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bdlbb::Blob payload(&bufferFactory, bmqtst::TestHelperUtil::allocator()); queueSp->setId(queueId); @@ -445,7 +457,7 @@ static void test4_subscriptionHandle() bmqtst::TestHelperUtil::allocator()); // Create PushEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(0, peb.messageCount()); @@ -459,7 +471,7 @@ static void test4_subscriptionHandle() static_cast(peb.eventSize())); // 'eventSize()' excludes unpacked messages ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // But the option is written to the underlying blob // Add message @@ -473,7 +485,7 @@ static void test4_subscriptionHandle() ASSERT_LT(payload.length(), peb.eventSize()); ASSERT_EQ(1, peb.messageCount()); - bmqp::Event bmqpEvent(&peb.blob(), + bmqp::Event bmqpEvent(peb.blob().get(), bmqtst::TestHelperUtil::allocator(), true); implPtr->configureAsMessageEvent(bmqpEvent); @@ -510,7 +522,7 @@ static void test4_subscriptionHandle() bmqtst::TestHelperUtil::allocator()); // Create PushEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(0, peb.messageCount()); @@ -526,7 +538,7 @@ static void test4_subscriptionHandle() ASSERT_LT(payload.length(), peb.eventSize()); ASSERT_EQ(1, peb.messageCount()); - bmqp::Event bmqpEvent(&peb.blob(), + bmqp::Event bmqpEvent(peb.blob().get(), bmqtst::TestHelperUtil::allocator(), true); implPtr->configureAsMessageEvent(bmqpEvent); @@ -558,7 +570,7 @@ static void test4_subscriptionHandle() bmqtst::TestHelperUtil::allocator()); // Create PutEventBuilder - bmqp::PutEventBuilder builder(&bufferFactory, + bmqp::PutEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(0, builder.messageCount()); @@ -572,7 +584,7 @@ static void test4_subscriptionHandle() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); ASSERT_EQ(1, builder.messageCount()); - bmqp::Event bmqpEvent(&builder.blob(), + bmqp::Event bmqpEvent(builder.blob().get(), bmqtst::TestHelperUtil::allocator()); implPtr->configureAsMessageEvent(bmqpEvent); @@ -599,7 +611,7 @@ static void test4_subscriptionHandle() bmqtst::TestHelperUtil::allocator()); // Create AckEventBuilder - bmqp::AckEventBuilder builder(&bufferFactory, + bmqp::AckEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(0, builder.messageCount()); @@ -609,7 +621,7 @@ static void test4_subscriptionHandle() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); ASSERT_EQ(1, builder.messageCount()); - bmqp::Event bmqpEvent(&builder.blob(), + bmqp::Event bmqpEvent(builder.blob().get(), bmqtst::TestHelperUtil::allocator()); implPtr->configureAsMessageEvent(bmqpEvent); diff --git a/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp b/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp index 46e06bbc19..54d29d2a16 100644 --- a/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp @@ -167,14 +167,19 @@ static void test2_ackMesageIteratorTest() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::AckEventBuilder builder(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::AckEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); PVV("Appending messages"); appendMessages(&builder, &messages, k_NUM_MSGS); - bmqp::Event rawEvent(&builder.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(builder.blob().get(), + bmqtst::TestHelperUtil::allocator()); bsl::shared_ptr eventImpl; eventImpl.createInplace(bmqtst::TestHelperUtil::allocator(), @@ -229,7 +234,11 @@ static void test3_putMessageIteratorTest() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder builder(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -244,7 +253,8 @@ static void test3_putMessageIteratorTest() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); } - bmqp::Event rawEvent(&builder.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(builder.blob().get(), + bmqtst::TestHelperUtil::allocator()); bsl::shared_ptr eventImpl; eventImpl.createInplace(bmqtst::TestHelperUtil::allocator(), diff --git a/src/groups/bmq/bmqa/bmqa_mocksession.cpp b/src/groups/bmq/bmqa/bmqa_mocksession.cpp index 6ca08d409a..753c5e46cc 100644 --- a/src/groups/bmq/bmqa/bmqa_mocksession.cpp +++ b/src/groups/bmq/bmqa/bmqa_mocksession.cpp @@ -298,7 +298,12 @@ Event MockSessionUtil::createAckEvent(const bsl::vector& acks, implPtr = EventImplSp(new (*alloc) bmqimp::Event(g_bufferFactory_p, alloc), alloc); - bmqp::AckEventBuilder ackBuilder(bufferFactory, alloc); + // TODO: deprecate `createAckEvent` with bufferFactory arg and introduce + // another function with BlobSpPool arg. + BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(bufferFactory, allocator)); + + bmqp::AckEventBuilder ackBuilder(&blobSpPool, alloc); for (size_t i = 0; i != acks.size(); ++i) { const AckParams& params = acks[i]; const QueueImplSp& impQueue = reinterpret_cast( @@ -313,7 +318,7 @@ Event MockSessionUtil::createAckEvent(const bsl::vector& acks, } implPtr->configureAsMessageEvent( - bmqp::Event(&ackBuilder.blob(), alloc, true)); + bmqp::Event(ackBuilder.blob().get(), alloc, true)); for (size_t i = 0; i != acks.size(); ++i) { implPtr->addCorrelationId(acks[i].d_correlationId); } @@ -336,7 +341,12 @@ Event MockSessionUtil::createPushEvent( implPtr = EventImplSp(new (*alloc) bmqimp::Event(g_bufferFactory_p, alloc), alloc); - bmqp::PushEventBuilder pushBuilder(bufferFactory, alloc); + // TODO: deprecate `createPushEvent` with bufferFactory arg and introduce + // another function with BlobSpPool arg. + BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(bufferFactory, allocator)); + + bmqp::PushEventBuilder pushBuilder(&blobSpPool, alloc); for (size_t i = 0; i != pushEventParams.size(); ++i) { const QueueImplSp& queueImplPtr = reinterpret_cast( @@ -369,7 +379,7 @@ Event MockSessionUtil::createPushEvent( implPtr->addCorrelationId(bmqt::CorrelationId()); } - bmqp::Event bmqpEvent(&pushBuilder.blob(), alloc, true); + bmqp::Event bmqpEvent(pushBuilder.blob().get(), alloc, true); implPtr->configureAsMessageEvent(bmqpEvent); return event; @@ -946,6 +956,8 @@ int MockSession::start(const bsls::TimeInterval& timeout) MockSession::MockSession(const bmqt::SessionOptions& options, bslma::Allocator* allocator) : d_blobBufferFactory(1024, allocator) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(&d_blobBufferFactory, allocator)) , d_eventHandler_mp(0) , d_calls(allocator) , d_eventsAndJobs(allocator) @@ -990,6 +1002,8 @@ MockSession::MockSession(bslma::ManagedPtr eventHandler, const bmqt::SessionOptions& options, bslma::Allocator* allocator) : d_blobBufferFactory(1024, allocator) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(&d_blobBufferFactory, allocator)) , d_eventHandler_mp(eventHandler) , d_calls(bslma::Default::allocator(allocator)) , d_eventsAndJobs(bslma::Default::allocator(allocator)) @@ -1514,7 +1528,7 @@ void MockSession::loadMessageEventBuilder(MessageEventBuilder* builder) g_bufferFactory_p, d_allocator_p); - eventImplSpRef->configureAsMessageEvent(&d_blobBufferFactory); + eventImplSpRef->configureAsMessageEvent(&d_blobSpPool); eventImplSpRef->setMessageCorrelationIdContainer( d_corrIdContainer_sp.get()); } @@ -1538,7 +1552,7 @@ void MockSession::loadConfirmEventBuilder(ConfirmEventBuilder* builder) } new (builderImplRef.d_buffer.buffer()) - bmqp::ConfirmEventBuilder(&d_blobBufferFactory, d_allocator_p); + bmqp::ConfirmEventBuilder(&d_blobSpPool, d_allocator_p); builderImplRef.d_builder_p = reinterpret_cast( builderImplRef.d_buffer.buffer()); diff --git a/src/groups/bmq/bmqa/bmqa_mocksession.h b/src/groups/bmq/bmqa/bmqa_mocksession.h index 453f3b4d86..04914df336 100644 --- a/src/groups/bmq/bmqa/bmqa_mocksession.h +++ b/src/groups/bmq/bmqa/bmqa_mocksession.h @@ -560,6 +560,7 @@ #include #include #include +#include #include #include #include @@ -611,6 +612,13 @@ struct MockSessionUtil { private: // PRIVATE TYPES + /// Pool of shared pointers to Blobs + typedef bdlcc::SharedObjectPool< + bdlbb::Blob, + bdlcc::ObjectPoolFunctors::DefaultCreator, + bdlcc::ObjectPoolFunctors::RemoveAll > + BlobSpPool; + /// Event impl shared pointer to access /// the pimpl of `bmqa::Event`. typedef bsl::shared_ptr EventImplSp; @@ -753,6 +761,8 @@ struct MockSessionUtil { /// Mechanism to mock a `bmqa::Session` class MockSession : public AbstractSession { public: + // TYPES + // CLASS METHODS /// Perform a one time initialization needed by components used in @@ -802,6 +812,13 @@ class MockSession : public AbstractSession { // PRIVATE TYPES + /// Pool of shared pointers to Blobs + typedef bdlcc::SharedObjectPool< + bdlbb::Blob, + bdlcc::ObjectPoolFunctors::DefaultCreator, + bdlcc::ObjectPoolFunctors::RemoveAll > + BlobSpPool; + /// Aligned buffer holding the two key hash map typedef bsls::AlignedBuffer TwoKeyHashMapBuffer; @@ -1011,9 +1028,12 @@ class MockSession : public AbstractSession { // DATA - /// Buffer factory + /// Buffer factory used to build Blobs with `d_blobSpPool` bdlbb::PooledBlobBufferFactory d_blobBufferFactory; + /// Pool of shared pointers to blobs + BlobSpPool d_blobSpPool; + /// Event handler (set only in asynchronous mode) bslma::ManagedPtr d_eventHandler_mp; diff --git a/src/groups/bmq/bmqa/bmqa_session.cpp b/src/groups/bmq/bmqa/bmqa_session.cpp index 46b95f64c5..719af4f13f 100644 --- a/src/groups/bmq/bmqa/bmqa_session.cpp +++ b/src/groups/bmq/bmqa/bmqa_session.cpp @@ -787,7 +787,7 @@ MessageEventBuilder Session::createMessageEventBuilder() eventImplSpRef = d_impl.d_application_mp->brokerSession().createEvent(); eventImplSpRef->configureAsMessageEvent( - d_impl.d_application_mp->bufferFactory()); + d_impl.d_application_mp->blobSpPool()); return builder; } @@ -814,7 +814,7 @@ void Session::loadMessageEventBuilder(MessageEventBuilder* builder) eventImplSpRef = d_impl.d_application_mp->brokerSession().createEvent(); eventImplSpRef->configureAsMessageEvent( - d_impl.d_application_mp->bufferFactory()); + d_impl.d_application_mp->blobSpPool()); } void Session::loadConfirmEventBuilder(ConfirmEventBuilder* builder) @@ -837,7 +837,7 @@ void Session::loadConfirmEventBuilder(ConfirmEventBuilder* builder) } new (builderImplRef.d_buffer.buffer()) - bmqp::ConfirmEventBuilder(d_impl.d_application_mp->bufferFactory(), + bmqp::ConfirmEventBuilder(d_impl.d_application_mp->blobSpPool(), d_impl.d_allocator_p); builderImplRef.d_builder_p = reinterpret_cast( diff --git a/src/groups/bmq/bmqimp/bmqimp_application.cpp b/src/groups/bmq/bmqimp/bmqimp_application.cpp index 05db364106..4d6dd304d2 100644 --- a/src/groups/bmq/bmqimp/bmqimp_application.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_application.cpp @@ -553,6 +553,9 @@ Application::Application( , d_channelsTip(&d_allocator) , d_blobBufferFactory(sessionOptions.blobBufferSize(), d_allocators.get("BlobBufferFactory")) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(&d_blobBufferFactory, + d_allocators.get("BlobSpPool"))) , d_scheduler(bsls::SystemClockType::e_MONOTONIC, &d_allocator) , d_channelFactory(ntcCreateInterfaceConfig(sessionOptions, allocator), &d_blobBufferFactory, @@ -581,12 +584,13 @@ Application::Application( NegotiatedChannelFactoryConfig(&d_statChannelFactory, negotiationMessage, sessionOptions.connectTimeout(), - &d_blobBufferFactory, + &d_blobSpPool, allocator), allocator) , d_connectHandle_mp() , d_brokerSession(&d_scheduler, &d_blobBufferFactory, + &d_blobSpPool, d_sessionOptions, eventHandlerCB, bdlf::MemFnUtil::memFn(&Application::stateCb, this), diff --git a/src/groups/bmq/bmqimp/bmqimp_application.h b/src/groups/bmq/bmqimp/bmqimp_application.h index e997029192..d5d3b00daa 100644 --- a/src/groups/bmq/bmqimp/bmqimp_application.h +++ b/src/groups/bmq/bmqimp/bmqimp_application.h @@ -78,16 +78,18 @@ namespace bmqimp { /// Top level object to manipulate a session with bmqbrkr class Application { + public: + // PUBLIC TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // PRIVATE TYPES typedef bslma::ManagedPtr ChannelFactoryOpHandleMp; - private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("BMQIMP.APPLICATION"); - private: // DATA bmqst::StatContext d_allocatorStatContext; // Stat context for counting allocators @@ -116,6 +118,9 @@ class Application { bdlbb::PooledBlobBufferFactory d_blobBufferFactory; // Factory for blob buffers + /// Pool of shared pointers to blobs. + BlobSpPool d_blobSpPool; + bdlmt::EventScheduler d_scheduler; // Scheduler @@ -254,12 +259,9 @@ class Application { // MANIPULATORS - /// Return a pointer to the blob buffer factory used by this instance. - /// Note that lifetime of the pointed-to buffer factory is bound by this - /// instance. - bdlbb::BlobBufferFactory* bufferFactory(); - - // MANIPULATORS + /// Return a pointer to the blob shared pointer pool used by this instance. + /// Note that lifetime of the pointed-to pool is bound by this instance. + BlobSpPool* blobSpPool(); /// Start the session and the session pool. Return 0 on success or a /// non-zero negative code otherwise. Calling start on an already @@ -320,9 +322,9 @@ inline bool Application::isStarted() const state == bmqimp::BrokerSession::State::e_RECONNECTING); } -inline bdlbb::BlobBufferFactory* Application::bufferFactory() +inline Application::BlobSpPool* Application::blobSpPool() { - return &d_blobBufferFactory; + return &d_blobSpPool; } } // close package namespace diff --git a/src/groups/bmq/bmqimp/bmqimp_brokersession.cpp b/src/groups/bmq/bmqimp/bmqimp_brokersession.cpp index 70cf73c1b0..4ea0dd7ae7 100644 --- a/src/groups/bmq/bmqimp/bmqimp_brokersession.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_brokersession.cpp @@ -3629,6 +3629,7 @@ void BrokerSession::processPushEvent(const bmqp::Event& event) rc = bmqp::EventUtil::flattenPushEvent(&eventInfos, event, d_bufferFactory_p, + d_blobSpPool_p, d_allocator_p); if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(rc != 0)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; @@ -4250,7 +4251,7 @@ void BrokerSession::doHandlePendingPutExpirationTimeout( // PRECONDITIONS BSLS_ASSERT_SAFE(d_fsmThreadChecker.inSameThread()); - bmqp::AckEventBuilder ackBuilder(d_bufferFactory_p, d_allocator_p); + bmqp::AckEventBuilder ackBuilder(d_blobSpPool_p, d_allocator_p); bsl::vector expiredKeys(d_allocator_p); bsl::shared_ptr ackEvent = createEvent(); bsl::shared_ptr queueSp; @@ -4529,7 +4530,7 @@ void BrokerSession::transferAckEvent(bmqp::AckEventBuilder* ackBuilder, // Our event is full at this point so send this ack event to the user and // reset the builder to append the ack that was rejected. - bmqp::Event event(&ackBuilder->blob(), d_allocator_p, true); + bmqp::Event event(ackBuilder->blob().get(), d_allocator_p, true); // clone = true if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY( d_messageDumper.isEventDumpEnabled())) { @@ -4728,7 +4729,7 @@ void BrokerSession::cancelPendingMessages( // PRECONDITIONS BSLS_ASSERT_SAFE(d_fsmThreadChecker.inSameThread()); - bmqp::AckEventBuilder ackBuilder(d_bufferFactory_p, d_allocator_p); + bmqp::AckEventBuilder ackBuilder(d_blobSpPool_p, d_allocator_p); bsl::shared_ptr ackEvent = createEvent(); MessageCorrelationIdContainer::KeyIdsCb callback = bdlf::BindUtil::bind( @@ -4819,7 +4820,7 @@ bool BrokerSession::appendOrSend( if (result == bmqt::EventBuilderResult::e_PAYLOAD_TOO_BIG) { // Send the current event, reset the builder. bmqt::GenericResult::Enum res = writeOrBuffer( - builder.blob(), + *builder.blob(), d_sessionOptions.channelHighWatermark()); if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY( @@ -4915,7 +4916,7 @@ void BrokerSession::retransmitPendingMessages() // Cancel pending PUTs expiration timer d_scheduler_p->cancelEvent(&d_messageExpirationTimeoutHandle); - bmqp::PutEventBuilder putBuilder(d_bufferFactory_p, d_allocator_p); + bmqp::PutEventBuilder putBuilder(d_blobSpPool_p, d_allocator_p); MessageCorrelationIdContainer::KeyIdsCb callback = bdlf::BindUtil::bind( &BrokerSession::handlePendingMessage, @@ -4942,7 +4943,7 @@ void BrokerSession::retransmitPendingMessages() // Send the final PUT event if there are any messages in the builder if (putBuilder.messageCount()) { bmqt::GenericResult::Enum res = writeOrBuffer( - putBuilder.blob(), + *putBuilder.blob(), d_sessionOptions.channelHighWatermark()); if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY( @@ -5609,7 +5610,7 @@ void BrokerSession::actionResumeHealthSensitiveQueues() bmqt::GenericResult::Enum BrokerSession::requestWriterCb(const RequestManagerType::RequestSp& context, const bmqp::QueueId& queueId, - const bdlbb::Blob& blob, + const bsl::shared_ptr& blob_sp, bsls::Types::Int64 watermark) { // executed by the FSM thread @@ -5621,7 +5622,7 @@ BrokerSession::requestWriterCb(const RequestManagerType::RequestSp& context, if (isBuffered) { const bmqt::MessageGUID guid = - d_messageCorrelationIdContainer.add(context, queueId, blob); + d_messageCorrelationIdContainer.add(context, queueId, *blob_sp); char guidHex[bmqt::MessageGUID::e_SIZE_HEX]; guid.toHex(guidHex); context->adoptUserData( @@ -5640,7 +5641,7 @@ BrokerSession::requestWriterCb(const RequestManagerType::RequestSp& context, return bmqt::GenericResult::e_SUCCESS; // RETURN } - bmqt::GenericResult::Enum res = writeOrBuffer(blob, watermark); + bmqt::GenericResult::Enum res = writeOrBuffer(*blob_sp, watermark); if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY( res != bmqt::GenericResult::e_SUCCESS && isBuffered)) { @@ -5702,6 +5703,7 @@ BrokerSession::writeOrBuffer(const bdlbb::Blob& eventBlob, BrokerSession::BrokerSession( bdlmt::EventScheduler* scheduler, bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, const bmqt::SessionOptions& sessionOptions, const EventQueue::EventHandlerCallback& eventHandlerCb, const StateFunctor& stateCb, @@ -5716,6 +5718,7 @@ BrokerSession::BrokerSession( , d_sessionOptions(sessionOptions) , d_scheduler_p(scheduler) , d_bufferFactory_p(bufferFactory) +, d_blobSpPool_p(blobSpPool_p) , d_channel_sp() , d_extensionBlobBuffer(allocator) , d_acceptRequests(false) @@ -5747,7 +5750,7 @@ BrokerSession::BrokerSession( (eventHandlerCb ? sessionOptions.numProcessingThreads() : 0), d_allocators.get("EventQueue")) , d_requestManager(bmqp::EventType::e_CONTROL, - bufferFactory, + blobSpPool_p, scheduler, true, // lateResponseMode BrokerSession_Executor(this), @@ -7313,7 +7316,7 @@ int BrokerSession::confirmMessage(const bsl::shared_ptr& queue, } // Build event - bmqp::ConfirmEventBuilder builder(d_bufferFactory_p, d_allocator_p); + bmqp::ConfirmEventBuilder builder(d_blobSpPool_p, d_allocator_p); bmqt::EventBuilderResult::Enum rc = builder.appendMessage(queue->id(), queue->subQueueId(), messageId); @@ -7327,7 +7330,7 @@ int BrokerSession::confirmMessage(const bsl::shared_ptr& queue, << rc; return rc; // RETURN } - bool isAccepted = acceptUserEvent(builder.blob(), timeout); + bool isAccepted = acceptUserEvent(*builder.blob(), timeout); if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(!isAccepted)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; diff --git a/src/groups/bmq/bmqimp/bmqimp_brokersession.h b/src/groups/bmq/bmqimp/bmqimp_brokersession.h index 3b78c79bbb..ccf0734175 100644 --- a/src/groups/bmq/bmqimp/bmqimp_brokersession.h +++ b/src/groups/bmq/bmqimp/bmqimp_brokersession.h @@ -31,7 +31,6 @@ // Thread safe. // BMQ - #include #include #include @@ -134,6 +133,7 @@ class BrokerSession_Executor { class BrokerSession BSLS_CPP11_FINAL { public: // PUBLIC TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; /// Invoked as a result of a response from the broker to a session event /// submitted by the user, `EventCallback` is an alias for a callback @@ -721,6 +721,9 @@ class BrokerSession BSLS_CPP11_FINAL { // Raw pointer (held, not owned) to // the blob buffer factory to use. + /// Pool of shared pointers to blobs. Held, not owned. + BlobSpPool* d_blobSpPool_p; + bsl::shared_ptr d_channel_sp; // Channel to use for communication, // held not owned @@ -1440,13 +1443,13 @@ class BrokerSession BSLS_CPP11_FINAL { /// channel `highWaterMark` value. If a special extention buffer is not /// empty append the `blob` into the buffer and return success. If the /// write operation fails with e_LIMIT error which indicates HWM - /// condition put the specified `blob` into the buffer and return + /// condition put the specified `blob_sp` into the buffer and return /// success. In all other cases return the result of the write /// operation. bmqt::GenericResult::Enum requestWriterCb(const RequestManagerType::RequestSp& context, const bmqp::QueueId& queueId, - const bdlbb::Blob& blob, + const bsl::shared_ptr& blob_sp, bsls::Types::Int64 highWatermark); /// Write the specified `blob` into the channel providing the specified @@ -1490,14 +1493,15 @@ class BrokerSession BSLS_CPP11_FINAL { // CREATORS - /// Create a new object using the specified `scheduler` and - /// `bufferFactory`. Use the configuration from the specified + /// Create a new object using the specified `scheduler`, `bufferFactory` + /// and `blobSpPool_p`. Use the configuration from the specified /// `sessionOptions`. If the specified `eventHandlerCb` is defined, /// invoke it for any events. Invoke the specified `stateCb` when /// the session makes state transition. All memory allocations will be /// done using the specified `allocator`. BrokerSession(bdlmt::EventScheduler* scheduler, bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, const bmqt::SessionOptions& sessionOptions, const EventQueue::EventHandlerCallback& eventHandlerCb, const StateFunctor& stateCb, diff --git a/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp b/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp index 406a5d9528..b73e0adbde 100644 --- a/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_brokersession.t.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -396,6 +397,9 @@ struct TestSession BSLS_CPP11_FINAL { // Buffer factory provided to the // various builders + /// Blob pool used to provide blobs to event builders. + bmqp::BlobPoolUtil::BlobSpPool d_blobSpPool; + bdlmt::EventScheduler& d_scheduler; // event scheduler used in the // broker session @@ -450,8 +454,8 @@ struct TestSession BSLS_CPP11_FINAL { // ACCESSORS bmqimp::BrokerSession& session(); bmqio::TestChannel& channel(); - bslma::Allocator* allocator(); - bdlbb::BlobBufferFactory& blobBufferFactory(); + bslma::Allocator* allocator(); + bmqp::BlobPoolUtil::BlobSpPool& blobSpPool(); // MANIPULATORS @@ -838,11 +842,15 @@ TestSession::TestSession(const bmqt::SessionOptions& sessionOptions, bslma::Allocator* allocator) : d_allocator_p(allocator) , d_blobBufferFactory(1024, d_allocator_p) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(&d_blobBufferFactory, + bmqtst::TestHelperUtil::allocator())) , d_scheduler(scheduler) , d_testChannel(d_allocator_p) , d_eventQueue(bsls::SystemClockType::e_MONOTONIC, d_allocator_p) , d_brokerSession(&d_scheduler, &d_blobBufferFactory, + &d_blobSpPool, sessionOptions, useEventHandler ? bdlf::BindUtil::bind(&sessionEventHandler, @@ -870,11 +878,15 @@ TestSession::TestSession(const bmqt::SessionOptions& sessionOptions, bslma::Allocator* allocator) : d_allocator_p(allocator) , d_blobBufferFactory(1024, d_allocator_p) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(&d_blobBufferFactory, + bmqtst::TestHelperUtil::allocator())) , d_scheduler(testClock.d_scheduler) , d_testChannel(d_allocator_p) , d_eventQueue(bsls::SystemClockType::e_MONOTONIC, d_allocator_p) , d_brokerSession(&d_scheduler, &d_blobBufferFactory, + &d_blobSpPool, sessionOptions, useEventHandler ? bdlf::BindUtil::bind(&sessionEventHandler, @@ -926,9 +938,9 @@ bslma::Allocator* TestSession::allocator() return d_allocator_p; } -bdlbb::BlobBufferFactory& TestSession::blobBufferFactory() +bmqp::BlobPoolUtil::BlobSpPool& TestSession::blobSpPool() { - return d_blobBufferFactory; + return d_blobSpPool; } // MANIPULATORS @@ -2426,11 +2438,13 @@ void TestSession::getOutboundControlMessage( void TestSession::sendControlMessage( const bmqp_ctrlmsg::ControlMessage& message) { - bmqp::SchemaEventBuilder builder(&d_blobBufferFactory, d_allocator_p); + bmqp::SchemaEventBuilder builder(&d_blobSpPool, + bmqp::EncodingType::e_BER, + d_allocator_p); int rc = builder.setMessage(message, bmqp::EventType::e_CONTROL); ASSERT_EQ(0, rc); - const bdlbb::Blob& packet = builder.blob(); + const bdlbb::Blob& packet = *builder.blob(); PVVV_SAFE("Send control message"); d_brokerSession.processPacket(packet); @@ -2820,6 +2834,10 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; sessionOptions.setNumProcessingThreads(1); @@ -2830,6 +2848,7 @@ static void test1_breathingTest() bmqimp::BrokerSession session( &scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, emptyEventHandler, // emptyEventHandler, bdlf::BindUtil::bind(&stateCb, @@ -2884,6 +2903,10 @@ static void test2_basicAccessorsTest() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; bdlmt::EventScheduler scheduler(bsls::SystemClockType::e_MONOTONIC, @@ -2894,6 +2917,7 @@ static void test2_basicAccessorsTest() bmqimp::BrokerSession obj(&scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, emptyEventHandler, emptyStateCb, @@ -2930,6 +2954,10 @@ static void test3_nullChannelTest() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; bsls::AtomicInt eventCounter(0); bsls::AtomicInt startCounter(0); @@ -2942,6 +2970,7 @@ static void test3_nullChannelTest() bmqimp::BrokerSession obj( &scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, bdlf::BindUtil::bind(&channelEventHandler, bdlf::PlaceHolders::_1, @@ -3024,6 +3053,10 @@ static void test4_createEventTest() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; bmqimp::EventQueue::EventHandlerCallback emptyEventHandler; @@ -3031,6 +3064,7 @@ static void test4_createEventTest() bmqimp::BrokerSession obj(&scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, emptyEventHandler, emptyStateCb, @@ -3048,6 +3082,10 @@ static void queueErrorsTest(bsls::Types::Uint64 queueFlags) bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; bmqt::QueueOptions queueOptions; bsl::shared_ptr eventSp; @@ -3077,6 +3115,7 @@ static void queueErrorsTest(bsls::Types::Uint64 queueFlags) bmqimp::BrokerSession session( &scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, eventCallback, bdlf::BindUtil::bind(&stateCb, @@ -3279,6 +3318,10 @@ static void test6_setChannelTest() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; bsls::AtomicInt eventCounter(0); bsls::AtomicInt startCounter(0); @@ -3292,6 +3335,7 @@ static void test6_setChannelTest() bmqimp::BrokerSession obj( &scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, bdlf::BindUtil::bind(&channelSetEventHandler, bdlf::PlaceHolders::_1, @@ -3945,6 +3989,10 @@ static void test11_disconnect() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bdlcc::Deque > eventQueue( bsls::SystemClockType::e_MONOTONIC, bmqtst::TestHelperUtil::allocator()); @@ -3967,6 +4015,7 @@ static void test11_disconnect() bmqimp::BrokerSession obj( &scheduler, &blobBufferFactory, + &blobSpPool, options, bdlf::BindUtil::bind(&sessionEventHandler, &eventQueue, @@ -4032,13 +4081,14 @@ static void test11_disconnect() disconnectMessage.rId().value()); disconnectResponseMessage.choice().makeDisconnectResponse(); - bmqp::SchemaEventBuilder builder(&blobBufferFactory, + bmqp::SchemaEventBuilder builder(&blobSpPool, + bmqp::EncodingType::e_BER, bmqtst::TestHelperUtil::allocator()); rc = builder.setMessage(disconnectResponseMessage, bmqp::EventType::e_CONTROL); ASSERT_EQ(rc, 0); - obj.processPacket(builder.blob()); + obj.processPacket(*builder.blob()); // Reset the channel obj.setChannel(bsl::shared_ptr()); @@ -4072,6 +4122,7 @@ static void test11_disconnect() bmqimp::BrokerSession obj( &scheduler, &blobBufferFactory, + &blobSpPool, options, bmqimp::EventQueue::EventHandlerCallback(), bdlf::BindUtil::bind(&stateCb, @@ -4132,13 +4183,14 @@ static void test11_disconnect() disconnectMessage.rId().value()); disconnectResponseMessage.choice().makeDisconnectResponse(); - bmqp::SchemaEventBuilder builder(&blobBufferFactory, + bmqp::SchemaEventBuilder builder(&blobSpPool, + bmqp::EncodingType::e_BER, bmqtst::TestHelperUtil::allocator()); rc = builder.setMessage(disconnectResponseMessage, bmqp::EventType::e_CONTROL); ASSERT_EQ(rc, 0); - obj.processPacket(builder.blob()); + obj.processPacket(*builder.blob()); // Reset the channel obj.setChannel(bsl::shared_ptr()); @@ -4692,7 +4744,7 @@ static void test21_post_Limit() PVV_SAFE("Step 4. Create and post PUT message"); bmqp::Crc32c::initialize(); - bmqp::PutEventBuilder builder(&obj.blobBufferFactory(), obj.allocator()); + bmqp::PutEventBuilder builder(&obj.blobSpPool(), obj.allocator()); const char* k_PAYLOAD = "abcdefghijklmnopqrstuvwxyz"; const int k_PAYLOAD_LEN = bsl::strlen(k_PAYLOAD); @@ -4703,7 +4755,7 @@ static void test21_post_Limit() ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, builder.packMessage(pQueue->id())); - int rc = obj.session().post(builder.blob(), postTimeout); + int rc = obj.session().post(*builder.blob(), postTimeout); PVV_SAFE("Step 5. Ensure the PUT message is accepted"); ASSERT_EQ(rc, bmqt::PostResult::e_SUCCESS); @@ -4718,7 +4770,7 @@ static void test21_post_Limit() ASSERT(rawEvent.isPutEvent()); PVV_SAFE("Step 6. Ensure e_BW_LIMIT is returned for the second post"); - rc = obj.session().post(builder.blob(), postTimeout); + rc = obj.session().post(*builder.blob(), postTimeout); ASSERT_EQ(rc, bmqt::PostResult::e_BW_LIMIT); ASSERT_EQ(obj.channel().writeCalls().size(), 0u); @@ -4732,7 +4784,7 @@ static void test21_post_Limit() // Call post with a bigger timeout so that LWM event arrives before it // expires. - rc = obj.session().post(builder.blob(), timeout); + rc = obj.session().post(*builder.blob(), timeout); PVV_SAFE("Step 8. Ensure e_SUCCESS is returned"); ASSERT_EQ(rc, bmqt::PostResult::e_SUCCESS); @@ -4752,7 +4804,7 @@ static void test21_post_Limit() PVV_SAFE("Step 9. Set the channel to return e_GENERIC_ERROR on write"); obj.channel().setWriteStatus(bmqio::StatusCategory::e_GENERIC_ERROR); - rc = obj.session().post(builder.blob(), postTimeout); + rc = obj.session().post(*builder.blob(), postTimeout); PVV_SAFE("Step 10. Ensure e_SUCCESS is returned"); ASSERT_EQ(rc, bmqt::PostResult::e_SUCCESS); @@ -4829,15 +4881,14 @@ static void test22_confirm_Limit() obj.channel().setWriteStatus(bmqio::StatusCategory::e_LIMIT); PVV_SAFE("Step 4. Create the blob and confirm messages"); - bmqp::ConfirmEventBuilder builder(&obj.blobBufferFactory(), - obj.allocator()); + bmqp::ConfirmEventBuilder builder(&obj.blobSpPool(), obj.allocator()); int rc = builder.appendMessage(pQueue->id(), pQueue->subQueueId(), bmqt::MessageGUID()); ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); - rc = obj.session().confirmMessages(builder.blob(), confirmTimeout); + rc = obj.session().confirmMessages(*builder.blob(), confirmTimeout); PVV_SAFE("Step 5. Ensure e_SUCCESS is returned"); ASSERT_EQ(rc, bmqt::GenericResult::e_SUCCESS); @@ -4861,7 +4912,7 @@ static void test22_confirm_Limit() // Call confirm with a bigger timeout so that LWM event arrives before it // expires. - rc = obj.session().confirmMessages(builder.blob(), timeout); + rc = obj.session().confirmMessages(*builder.blob(), timeout); PVV_SAFE("Step 7. Ensure e_SUCCESS is returned"); ASSERT_EQ(rc, bmqt::GenericResult::e_SUCCESS); @@ -4879,7 +4930,7 @@ static void test22_confirm_Limit() PVV_SAFE("Step 8. Set the channel to return e_GENERIC_ERROR on write"); obj.channel().setWriteStatus(bmqio::StatusCategory::e_GENERIC_ERROR); - rc = obj.session().confirmMessages(builder.blob(), confirmTimeout); + rc = obj.session().confirmMessages(*builder.blob(), confirmTimeout); PVV_SAFE("Step 9. Ensure e_SUCCESS"); @@ -5713,6 +5764,10 @@ static void test25_sessionFsmTable() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; sessionOptions.setNumProcessingThreads(1).setHostHealthMonitor(monitor_sp); @@ -5727,6 +5782,7 @@ static void test25_sessionFsmTable() bmqimp::BrokerSession obj( &scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, emptyEventHandler, // emptyEventHandler, bdlf::BindUtil::bind(&transitionCb, @@ -6641,7 +6697,11 @@ static void test33_queueNackTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder eventBuilder(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder eventBuilder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); const bmqt::CorrelationId corrId(243); bmqt::MessageGUID guid = bmqp::MessageGUIDGenerator::testGUID(); @@ -6690,7 +6750,7 @@ static void test33_queueNackTest() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); // Post the event using just event blob - int res = obj.session().post(eventBuilder.blob(), timeout); + int res = obj.session().post(*eventBuilder.blob(), timeout); ASSERT_EQ(res, bmqt::PostResult::e_SUCCESS); @@ -7731,6 +7791,10 @@ static void test40_syncCalledFromEventHandler() bdlbb::PooledBlobBufferFactory blobBufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqt::SessionOptions sessionOptions; bmqt::QueueOptions queueOptions; bsl::shared_ptr eventSp; @@ -7754,6 +7818,7 @@ static void test40_syncCalledFromEventHandler() bmqimp::BrokerSession session( &scheduler, &blobBufferFactory, + &blobSpPool, sessionOptions, bdlf::BindUtil::bind(&eventHandlerSyncCall, &eventSp, @@ -9028,11 +9093,15 @@ static void test50_putRetransmittingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder putEventBuilder(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder putEventBuilder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqp::PutMessageIterator putIter(&bufferFactory, bmqtst::TestHelperUtil::allocator()); - bmqp::AckEventBuilder ackEventBuilder(&bufferFactory, + bmqp::AckEventBuilder ackEventBuilder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqp::Event rawEvent(bmqtst::TestHelperUtil::allocator()); const bmqt::CorrelationId corrIdFirst(243); @@ -9101,7 +9170,7 @@ static void test50_putRetransmittingTest() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); // Post the event using event blob - int res = obj.session().post(putEventBuilder.blob(), timeout); + int res = obj.session().post(*putEventBuilder.blob(), timeout); ASSERT_EQ(res, bmqt::PostResult::e_SUCCESS); @@ -9116,7 +9185,7 @@ static void test50_putRetransmittingTest() guidFirst, pQueue->id()); - obj.session().processPacket(ackEventBuilder.blob()); + obj.session().processPacket(*ackEventBuilder.blob()); bsl::shared_ptr ackEvent = obj.waitAckEvent(); @@ -9147,7 +9216,7 @@ static void test50_putRetransmittingTest() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); // Post the event using event blob - res = obj.session().post(putEventBuilder.blob(), timeout); + res = obj.session().post(*putEventBuilder.blob(), timeout); ASSERT_EQ(res, bmqt::PostResult::e_SUCCESS); @@ -9220,7 +9289,7 @@ static void test50_putRetransmittingTest() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); // Post the event using event blob - res = obj.session().post(putEventBuilder.blob(), timeout); + res = obj.session().post(*putEventBuilder.blob(), timeout); ASSERT_EQ(res, bmqt::PostResult::e_SUCCESS); @@ -9317,7 +9386,11 @@ static void test51_putRetransmittingNoAckTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder putEventBuilder(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder putEventBuilder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqp::PutMessageIterator putIter(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -9380,7 +9453,7 @@ static void test51_putRetransmittingNoAckTest() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); // Post the event using event blob - int res = obj.session().post(putEventBuilder.blob(), timeout); + int res = obj.session().post(*putEventBuilder.blob(), timeout); ASSERT_EQ(res, bmqt::PostResult::e_SUCCESS); @@ -9405,7 +9478,7 @@ static void test51_putRetransmittingNoAckTest() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); // Post the event using event blob - res = obj.session().post(putEventBuilder.blob(), timeout); + res = obj.session().post(*putEventBuilder.blob(), timeout); ASSERT_EQ(res, bmqt::PostResult::e_SUCCESS); diff --git a/src/groups/bmq/bmqimp/bmqimp_event.cpp b/src/groups/bmq/bmqimp/bmqimp_event.cpp index 32b80dee94..fdb469f367 100644 --- a/src/groups/bmq/bmqimp/bmqimp_event.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_event.cpp @@ -293,16 +293,17 @@ Event& Event::configureAsMessageEvent(const bmqp::Event& rawEvent) return *this; } -Event& Event::configureAsMessageEvent(bdlbb::BlobBufferFactory* bufferFactory) +Event& +Event::configureAsMessageEvent(bmqp::BlobPoolUtil::BlobSpPool* blobSpPool_p) { // PRECONDITIONS BSLS_ASSERT_SAFE(type() == EventType::e_UNINITIALIZED); - BSLS_ASSERT_SAFE(bufferFactory); + BSLS_ASSERT_SAFE(blobSpPool_p); d_type = EventType::e_MESSAGE; d_msgEventMode = MessageEventMode::e_WRITE; new (d_putEventBuilderBuffer.buffer()) - bmqp::PutEventBuilder(bufferFactory, d_allocator_p); + bmqp::PutEventBuilder(blobSpPool_p, d_allocator_p); d_isPutEventBuilderConstructed = true; return *this; @@ -319,7 +320,7 @@ Event& Event::downgradeMessageEventModeToRead() d_msgEventMode = MessageEventMode::e_READ; - d_rawEvent.reset(&(d_putEventBuilderBuffer.object().blob())); + d_rawEvent.reset(d_putEventBuilderBuffer.object().blob().get()); BSLS_ASSERT(d_rawEvent.isPutEvent()); // Only PUT events can be built via SDK diff --git a/src/groups/bmq/bmqimp/bmqimp_event.h b/src/groups/bmq/bmqimp/bmqimp_event.h index fffa4ed8b1..20d214b87a 100644 --- a/src/groups/bmq/bmqimp/bmqimp_event.h +++ b/src/groups/bmq/bmqimp/bmqimp_event.h @@ -332,11 +332,12 @@ class Event { Event& configureAsMessageEvent(const bmqp::Event& rawEvent); /// Configure this instance as a message event in write mode with the - /// specified `bufferFactory` to allocate blob buffers when needed. + /// specified `blobSpPool_p` to allocate shared pointers to blobs. /// Behavior is undefined unless `bufferFactory` points to a valid blob /// buffer factory. Also change the type of this Event to be /// `MESSAGEEVENT`, and type of message event mode to `WRITE`. - Event& configureAsMessageEvent(bdlbb::BlobBufferFactory* bufferFactory); + Event& + configureAsMessageEvent(bmqp::BlobPoolUtil::BlobSpPool* blobSpPool_p); /// Change the message event mode with which this instance is currently /// configured to MessageEventMode::READ *without* *any* modification to diff --git a/src/groups/bmq/bmqimp/bmqimp_event.t.cpp b/src/groups/bmq/bmqimp/bmqimp_event.t.cpp index 46ee37ad52..6768842b10 100644 --- a/src/groups/bmq/bmqimp/bmqimp_event.t.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_event.t.cpp @@ -767,6 +767,10 @@ static void test6_comparisonOperatorTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqimp::Event obj1(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bmqimp::Event obj2(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bmqt::SessionEventType::Enum sessionType = @@ -807,8 +811,8 @@ static void test6_comparisonOperatorTest() PV("Configure as MesageEvent"); bmqimp::Event obj3(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bmqimp::Event obj4(&bufferFactory, bmqtst::TestHelperUtil::allocator()); - obj3.configureAsMessageEvent(&bufferFactory); - obj4.configureAsMessageEvent(&bufferFactory); + obj3.configureAsMessageEvent(&blobSpPool); + obj4.configureAsMessageEvent(&blobSpPool); // NOTE: Message event can not be equal. Is it expected? ASSERT(obj3 != obj4); @@ -1101,6 +1105,10 @@ static void test8_putEventBuilder() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); #ifdef BMQ_ENABLE_MSG_GROUPID const bmqp::Protocol::MsgGroupId k_MSG_GROUP_ID( "gid:0", @@ -1129,7 +1137,7 @@ static void test8_putEventBuilder() // Create PutEventBuilder bmqimp::Event obj(&bufferFactory, bmqtst::TestHelperUtil::allocator()); - obj.configureAsMessageEvent(&bufferFactory); + obj.configureAsMessageEvent(&blobSpPool); bmqp::PutEventBuilder& builder = *(obj.putEventBuilder()); builder.startMessage(); @@ -1201,8 +1209,8 @@ static void test8_putEventBuilder() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = builder.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(builder.blob().get(), + bmqtst::TestHelperUtil::allocator()); ASSERT(rawEvent.isValid()); ASSERT(rawEvent.isPutEvent()); @@ -1551,12 +1559,16 @@ static void test12_upgradeDowngradeMessageEvent() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); // 1. Create session event bmqimp::Event obj(&bufferFactory, bmqtst::TestHelperUtil::allocator()); // 2. Configure event as message event in WRITE mode. - obj.configureAsMessageEvent(&bufferFactory); + obj.configureAsMessageEvent(&blobSpPool); ASSERT_EQ(bmqimp::Event::MessageEventMode::e_WRITE, obj.messageEventMode()); diff --git a/src/groups/bmq/bmqimp/bmqimp_eventqueue.t.cpp b/src/groups/bmq/bmqimp/bmqimp_eventqueue.t.cpp index 513ad8f312..9362dbd62f 100644 --- a/src/groups/bmq/bmqimp/bmqimp_eventqueue.t.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_eventqueue.t.cpp @@ -260,7 +260,11 @@ static void test2_capacityTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder builder(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqimp::EventQueue::EventPool eventPool( bdlf::BindUtil::bind(&poolCreateEvent, @@ -281,7 +285,7 @@ static void test2_capacityTest() bmqtst::TestHelperUtil::allocator()); builder.startMessage(); - const bdlbb::Blob& eventBlob = builder.blob(); + const bdlbb::Blob& eventBlob = *builder.blob(); bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); bsl::shared_ptr event; @@ -563,7 +567,11 @@ static void test6_workingStatsTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder builder(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqimp::EventQueue::EventPool eventPool( bdlf::BindUtil::bind(&poolCreateEvent, @@ -622,7 +630,7 @@ static void test6_workingStatsTest() obj.initializeStats(&rootStatContext, start, end); builder.startMessage(); - const bdlbb::Blob& eventBlob = builder.blob(); + const bdlbb::Blob& eventBlob = *builder.blob(); bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); bsl::shared_ptr event; diff --git a/src/groups/bmq/bmqimp/bmqimp_messagedumper.t.cpp b/src/groups/bmq/bmqimp/bmqimp_messagedumper.t.cpp index 4a99bff973..2eda77a872 100644 --- a/src/groups/bmq/bmqimp/bmqimp_messagedumper.t.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_messagedumper.t.cpp @@ -140,6 +140,9 @@ struct Tester BSLS_CPP11_FINAL { // Buffer factory provided to the // various builders + /// Blob shared pointer pool used in event builders. + bmqp::BlobPoolUtil::BlobSpPool d_blobSpPool; + bmqp::PushEventBuilder d_pushEventBuilder; // PUSH event builder @@ -333,10 +336,11 @@ Tester::Tester(bslma::Allocator* allocator) , d_nextCorrelationId(0) , d_time(0, 0) , d_bufferFactory(1024, allocator) -, d_pushEventBuilder(&d_bufferFactory, allocator) -, d_ackEventBuilder(&d_bufferFactory, allocator) -, d_putEventBuilder(&d_bufferFactory, allocator) -, d_confirmEventBuilder(&d_bufferFactory, allocator) +, d_blobSpPool(bmqp::BlobPoolUtil::createBlobPool(&d_bufferFactory, allocator)) +, d_pushEventBuilder(&d_blobSpPool, allocator) +, d_ackEventBuilder(&d_blobSpPool, allocator) +, d_putEventBuilder(&d_blobSpPool, allocator) +, d_confirmEventBuilder(&d_blobSpPool, allocator) , d_allocator_p(allocator) { bmqsys::Time::initialize( @@ -653,7 +657,7 @@ bmqp::Event& Tester::pushEvent(bmqp::Event* event) const // PRECONDITIONS BSLS_ASSERT_OPT(event && "'event' must be provided"); - event->reset(&d_pushEventBuilder.blob(), true); + event->reset(d_pushEventBuilder.blob().get(), true); return *event; } @@ -663,7 +667,7 @@ bmqp::Event& Tester::ackEvent(bmqp::Event* event) const // PRECONDITIONS BSLS_ASSERT_OPT(event && "'event' must be provided"); - event->reset(&d_ackEventBuilder.blob(), true); + event->reset(d_ackEventBuilder.blob().get(), true); return *event; } @@ -673,7 +677,7 @@ bmqp::Event& Tester::putEvent(bmqp::Event* event) const // PRECONDITIONS BSLS_ASSERT_OPT(event && "'event' must be provided"); - event->reset(&d_putEventBuilder.blob(), true); + event->reset(d_putEventBuilder.blob().get(), true); return *event; } @@ -683,7 +687,7 @@ bmqp::Event& Tester::confirmEvent(bmqp::Event* event) const // PRECONDITIONS BSLS_ASSERT_OPT(event && "'event' must be provided"); - event->reset(&d_confirmEventBuilder.blob(), true); + event->reset(d_confirmEventBuilder.blob().get(), true); return *event; } diff --git a/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.cpp b/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.cpp index 2c31f4d412..af83af5567 100644 --- a/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.cpp @@ -66,17 +66,16 @@ NegotiatedChannelFactoryConfig::NegotiatedChannelFactoryConfig( bmqio::ChannelFactory* base, const bmqp_ctrlmsg::NegotiationMessage& negotiationMessage, const bsls::TimeInterval& negotiationTimeout, - bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* basicAllocator) : d_baseFactory_p(base) , d_negotiationMessage(negotiationMessage, basicAllocator) , d_negotiationTimeout(negotiationTimeout) -, d_bufferFactory_p(bufferFactory) +, d_blobSpPool_p(blobSpPool_p) , d_allocator_p(bslma::Default::allocator(basicAllocator)) { // PRECONDITIONS BSLS_ASSERT(base); - BSLS_ASSERT(bufferFactory); } NegotiatedChannelFactoryConfig::NegotiatedChannelFactoryConfig( @@ -85,7 +84,7 @@ NegotiatedChannelFactoryConfig::NegotiatedChannelFactoryConfig( : d_baseFactory_p(original.d_baseFactory_p) , d_negotiationMessage(original.d_negotiationMessage, basicAllocator) , d_negotiationTimeout(original.d_negotiationTimeout) -, d_bufferFactory_p(original.d_bufferFactory_p) +, d_blobSpPool_p(original.d_blobSpPool_p) , d_allocator_p(bslma::Default::allocator(basicAllocator)) { // NOTHING @@ -124,9 +123,9 @@ void NegotiatedChannelFactory::negotiate( { static const bmqp::EncodingType::Enum k_DEFAULT_ENCODING = bmqp::EncodingType::e_BER; - bmqp::SchemaEventBuilder builder(d_config.d_bufferFactory_p, - d_config.d_allocator_p, - k_DEFAULT_ENCODING); + bmqp::SchemaEventBuilder builder(d_config.d_blobSpPool_p, + k_DEFAULT_ENCODING, + d_config.d_allocator_p); const int rc = builder.setMessage(d_config.d_negotiationMessage, bmqp::EventType::e_CONTROL); if (rc != 0) { @@ -143,8 +142,8 @@ void NegotiatedChannelFactory::negotiate( << "': " << d_config.d_negotiationMessage; bmqio::Status status; BALL_LOG_TRACE << "Sending blob:\n" - << bmqu::BlobStartHexDumper(&builder.blob()); - channel->write(&status, builder.blob()); + << bmqu::BlobStartHexDumper(builder.blob().get()); + channel->write(&status, *builder.blob()); if (!status) { BALL_LOG_ERROR << "Negotiation failed [reason: 'failed sending packet'" << ", status: " << status << "]"; diff --git a/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.h b/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.h index 84b648f7a6..05cbf2ad50 100644 --- a/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.h +++ b/src/groups/bmq/bmqimp/bmqimp_negotiatedchannelfactory.h @@ -30,14 +30,13 @@ // peer on top of a channel created using a base 'bmqio::ChannelFactory'. // BMQ - -#include - #include #include #include #include #include +#include +#include #include // BDE @@ -59,12 +58,16 @@ namespace bmqimp { /// Configuration for a `NegotiatedChannelFactory`. class NegotiatedChannelFactoryConfig { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // PRIVATE DATA bmqio::ChannelFactory* d_baseFactory_p; bmqp_ctrlmsg::NegotiationMessage d_negotiationMessage; bsls::TimeInterval d_negotiationTimeout; - bdlbb::BlobBufferFactory* d_bufferFactory_p; + BlobSpPool* d_blobSpPool_p; bslma::Allocator* d_allocator_p; // FRIENDS @@ -80,7 +83,7 @@ class NegotiatedChannelFactoryConfig { bmqio::ChannelFactory* base, const bmqp_ctrlmsg::NegotiationMessage& negotiationMessage, const bsls::TimeInterval& negotiationTimeout, - bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* basicAllocator = 0); NegotiatedChannelFactoryConfig( diff --git a/src/groups/bmq/bmqimp/bmqimp_queuemanager.t.cpp b/src/groups/bmq/bmqimp/bmqimp_queuemanager.t.cpp index 39cb5afc75..f5ff026e63 100644 --- a/src/groups/bmq/bmqimp/bmqimp_queuemanager.t.cpp +++ b/src/groups/bmq/bmqimp/bmqimp_queuemanager.t.cpp @@ -590,7 +590,11 @@ static void test9_pushStatsTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bdlbb::Blob payload(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bmqt::Uri uri(k_URI, bmqtst::TestHelperUtil::allocator()); @@ -625,8 +629,8 @@ static void test9_pushStatsTest() BSLS_ASSERT_SAFE(rc == bmqt::EventBuilderResult::e_SUCCESS); - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -704,7 +708,11 @@ static void test10_putStatsTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder peb(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqt::Uri uri(k_URI, bmqtst::TestHelperUtil::allocator()); bmqimp::QueueManager::QueueSp queueSp; @@ -730,8 +738,8 @@ static void test10_putStatsTest() BSLS_ASSERT_SAFE(rc == bmqt::EventBuilderResult::e_SUCCESS); - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPutEvent()); diff --git a/src/groups/bmq/bmqp/bmqp_ackeventbuilder.cpp b/src/groups/bmq/bmqp/bmqp_ackeventbuilder.cpp index ddf1161137..9293ffc798 100644 --- a/src/groups/bmq/bmqp/bmqp_ackeventbuilder.cpp +++ b/src/groups/bmq/bmqp/bmqp_ackeventbuilder.cpp @@ -34,17 +34,32 @@ namespace bmqp { // class AckEventBuilder // --------------------- -AckEventBuilder::AckEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator) -: d_blob(bufferFactory, allocator) +AckEventBuilder::AckEventBuilder(BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator) +: d_blobSpPool_p(blobSpPool_p) +, d_blob_sp(0, allocator) // initialized in `reset()` +, d_emptyBlob_sp(0, allocator) // initialized later in constructor , d_msgCount(0) { + // PRECONDITIONS + BSLS_ASSERT_SAFE(blobSpPool_p); + + d_emptyBlob_sp = blobSpPool_p->getObject(); + + // Assume that items built with the given `blobSpPool_p` either all have or + // all don't have buffer factory, and check it once for `d_emptyBlob_sp`. + // We require this since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != d_emptyBlob_sp->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); + reset(); } void AckEventBuilder::reset() { - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); + d_msgCount = 0; // NOTE: Since AckEventBuilder owns the blob and we just reset it, we have @@ -56,16 +71,16 @@ void AckEventBuilder::reset() // Use placement new to create the object directly in the blob buffer, // while still calling it's constructor (to memset memory and initialize // some fields). - d_blob.setLength(sizeof(EventHeader) + sizeof(AckHeader)); - BSLS_ASSERT_SAFE(d_blob.numDataBuffers() == 1 && + d_blob_sp->setLength(sizeof(EventHeader) + sizeof(AckHeader)); + BSLS_ASSERT_SAFE(d_blob_sp->numDataBuffers() == 1 && "The buffers allocated by the supplied bufferFactory " "are too small"); // EventHeader - new (d_blob.buffer(0).data()) EventHeader(EventType::e_ACK); + new (d_blob_sp->buffer(0).data()) EventHeader(EventType::e_ACK); // AckHeader - new (d_blob.buffer(0).data() + sizeof(EventHeader)) AckHeader(); + new (d_blob_sp->buffer(0).data() + sizeof(EventHeader)) AckHeader(); } bmqt::EventBuilderResult::Enum @@ -82,9 +97,9 @@ AckEventBuilder::appendMessage(int status, // Resize the blob to have space for an 'AckMessage' at the end ... bmqu::BlobPosition offset; - bmqu::BlobUtil::reserve(&offset, &d_blob, sizeof(AckMessage)); + bmqu::BlobUtil::reserve(&offset, d_blob_sp.get(), sizeof(AckMessage)); - bmqu::BlobObjectProxy ackMessage(&d_blob, + bmqu::BlobObjectProxy ackMessage(d_blob_sp.get(), offset, false, // no read true); // write mode @@ -104,23 +119,24 @@ AckEventBuilder::appendMessage(int status, return bmqt::EventBuilderResult::e_SUCCESS; } -const bdlbb::Blob& AckEventBuilder::blob() const +const bsl::shared_ptr& AckEventBuilder::blob() const { // PRECONDITIONS - BSLS_ASSERT_SAFE(d_blob.length() <= EventHeader::k_MAX_SIZE_SOFT); + BSLS_ASSERT_SAFE(d_blob_sp->length() <= EventHeader::k_MAX_SIZE_SOFT); // Empty event if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(messageCount() == 0)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; - return ProtocolUtil::emptyBlob(); // RETURN + return d_emptyBlob_sp; // RETURN } // Fix packet's length in header now that we know it. Following is valid // (see comment in reset). - EventHeader& eh = *reinterpret_cast(d_blob.buffer(0).data()); - eh.setLength(d_blob.length()); + EventHeader& eh = *reinterpret_cast( + d_blob_sp->buffer(0).data()); + eh.setLength(d_blob_sp->length()); - return d_blob; + return d_blob_sp; } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_ackeventbuilder.h b/src/groups/bmq/bmqp/bmqp_ackeventbuilder.h index 348128bff7..c2f573e783 100644 --- a/src/groups/bmq/bmqp/bmqp_ackeventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_ackeventbuilder.h @@ -41,23 +41,27 @@ /// Usage ///----- //.. -// bdlbb::BlobPooledBlobBufferFactory bufferFactory(1024, d_allocator_p); -// bmqp::AckEventBuilder builder(&bufferFactory, d_allocator_p); +// bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p); +// bmqp::BlobPoolUtil::BlobSpPool blobSpPool( +// bmqp::BlobPoolUtil::createBlobPool(&bufferFactory, s_allocator_p)); +// bmqp::AckEventBuilder builder(&blobSpPool, d_allocator_p); // // // Append multiple messages // builder.appendMessage(0, 1, bmqt::MessageGUID(), 1); // builder.appendMessage(-1, 2, bmqt::MessageGUID(), 1); // -// const bdlbb::Blob& eventBlob = builder.blob(); +// const bsl::shared_ptr& eventBlob = builder.blob(); // // Send the blob ... // // // We can reset the builder to reuse it; note that this invalidates the -// // 'eventBlob' retrieved above +// // 'eventBlob' shared pointer reference retrieved above. To keep the +// // bdlbb::Blob valid the shared pointer should be copied, and the copy +// // should be passed and kept in IO components. // builder.reset(); //.. // BMQ - +#include #include #include #include @@ -80,12 +84,22 @@ namespace bmqp { /// Mechanism to build a BlazingMQ ACK event class AckEventBuilder BSLS_CPP11_FINAL { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // DATA - mutable bdlbb::Blob d_blob; // blob being built by this object. - // This has been done mutable to be able to - // skip writing the length until the blob - // is retrieved. + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; + + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; + + /// Empty blob to be returned when no messages were added to this builder. + bsl::shared_ptr d_emptyBlob_sp; + int d_msgCount; // number of messages currently in the // event @@ -103,10 +117,11 @@ class AckEventBuilder BSLS_CPP11_FINAL { public: // CREATORS - /// Create a new `AckEventBuilder` using the specified `bufferFactory` - /// and `allocator` for the blob. - AckEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator); + /// Create a new `AckEventBuilder` using the specified `blobSpPool_p` and + /// `allocator` for the blob. We require BlobSpPool to build Blobs with + /// set BlobBufferFactory since we might want to expand the built Blob + /// dynamically. + AckEventBuilder(BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); // MANIPULATORS @@ -137,10 +152,13 @@ class AckEventBuilder BSLS_CPP11_FINAL { /// were added, this will return 0. int eventSize() const; - /// Return a reference not offering modifiable access to the blob built - /// by this event. If no messages were added, this will return an empty - /// blob, i.e., a blob with length == 0. - const bdlbb::Blob& blob() const; + /// Return a reference to the shared pointer to the built Blob. If no + /// messages were added, the Blob object under this reference will be + /// empty. + /// Note that this accessor exposes an internal shared pointer object, and + /// it is the user's responsibility to make a copy of it if it needs to be + /// passed and kept in another thread while this builder object is used. + const bsl::shared_ptr& blob() const; }; // ============================================================================ @@ -171,7 +189,7 @@ inline int AckEventBuilder::eventSize() const return 0; // RETURN } - return d_blob.length(); + return d_blob_sp->length(); } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_ackeventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_ackeventbuilder.t.cpp index 499b000196..be44a94022 100644 --- a/src/groups/bmq/bmqp/bmqp_ackeventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_ackeventbuilder.t.cpp @@ -97,10 +97,11 @@ static void verifyContent(const bmqp::AckEventBuilder& builder, (data.size() * sizeof(bmqp::AckMessage)); ASSERT_EQ(static_cast(builder.messageCount()), data.size()); ASSERT_EQ(static_cast(builder.eventSize()), expectedSize); - ASSERT_EQ(static_cast(builder.blob().length()), expectedSize); + ASSERT_EQ(static_cast(builder.blob()->length()), expectedSize); PVV("Iterating over messages"); - bmqp::Event event(&builder.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event event(builder.blob().get(), + bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(event.isValid(), true); ASSERT_EQ(event.isAckEvent(), true); @@ -140,7 +141,11 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::AckEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::AckEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -148,7 +153,7 @@ static void test1_breathingTest() ASSERT_EQ(obj.messageCount(), 0); ASSERT_NE(obj.maxMessageCount(), 0); ASSERT_EQ(obj.eventSize(), 0); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); PVV("Appending one message"); appendMessages(&obj, &messages, 1); @@ -167,7 +172,11 @@ static void test2_multiMessage() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::AckEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::AckEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -186,7 +195,11 @@ static void test3_reset() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::AckEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::AckEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -199,7 +212,7 @@ static void test3_reset() PV("Verifying accessors"); ASSERT_EQ(obj.messageCount(), 0); ASSERT_EQ(obj.eventSize(), 0); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); PV("Appending another message"); messages.clear(); @@ -218,7 +231,11 @@ static void test4_capacity() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::AckEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::AckEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); PVV("Computing max message"); @@ -272,7 +289,11 @@ static void testN1_decodeFromFile() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::AckEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::AckEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); bdlbb::Blob outBlob(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -303,7 +324,7 @@ static void testN1_decodeFromFile() BSLS_ASSERT(ofile.good() == true); - bdlbb::BlobUtil::copy(buf, obj.blob(), 0, obj.blob().length()); + bdlbb::BlobUtil::copy(buf, *obj.blob(), 0, obj.blob()->length()); ofile.write(buf, k_SIZE); ofile.close(); bsl::memset(buf, 0, k_SIZE); @@ -322,9 +343,9 @@ static void testN1_decodeFromFile() bdlbb::BlobBuffer dataBlobBuffer(dataBufferSp, k_SIZE); outBlob.appendDataBuffer(dataBlobBuffer); - outBlob.setLength(obj.blob().length()); + outBlob.setLength(obj.blob()->length()); - ASSERT_EQ(bdlbb::BlobUtil::compare(obj.blob(), outBlob), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*obj.blob(), outBlob), 0); // Decode event bmqp::Event event(&outBlob, bmqtst::TestHelperUtil::allocator()); diff --git a/src/groups/bmq/bmqp/bmqp_blobpoolutil.cpp b/src/groups/bmq/bmqp/bmqp_blobpoolutil.cpp new file mode 100644 index 0000000000..281bb5d9d9 --- /dev/null +++ b/src/groups/bmq/bmqp/bmqp_blobpoolutil.cpp @@ -0,0 +1,62 @@ +// Copyright 2024 Bloomberg Finance L.P. +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// bmqp_blobpoolutil.cpp -*-C++-*- +#include + +#include + +// BDE +#include + +namespace BloombergLP { +namespace bmqp { + +namespace { +const int k_BLOB_POOL_GROWTH_STRATEGY = 1024; + +/// Create a new blob at the specified `arena` address, using the specified +/// `bufferFactory` and `allocator`. +void createBlob(bdlbb::BlobBufferFactory* bufferFactory, + void* arena, + bslma::Allocator* allocator) +{ + new (arena) bdlbb::Blob(bufferFactory, allocator); +} + +} // close unnamed namespace + +// ------------------ +// class BlobPoolUtil +// ------------------ + +BlobPoolUtil::BlobSpPool +BlobPoolUtil::createBlobPool(bdlbb::BlobBufferFactory* blobBufferFactory_p, + bslma::Allocator* allocator) +{ + // PRECONDITIONS + BSLS_ASSERT(blobBufferFactory_p); + + return BlobSpPool( + bdlf::BindUtil::bind(&createBlob, + blobBufferFactory_p, + bdlf::PlaceHolders::_1, // arena + bdlf::PlaceHolders::_2), // allocator + k_BLOB_POOL_GROWTH_STRATEGY, + bslma::Default::allocator(allocator)); +} + +} // close package namespace +} // close enterprise namespace diff --git a/src/groups/bmq/bmqp/bmqp_blobpoolutil.h b/src/groups/bmq/bmqp/bmqp_blobpoolutil.h new file mode 100644 index 0000000000..aa41b2e070 --- /dev/null +++ b/src/groups/bmq/bmqp/bmqp_blobpoolutil.h @@ -0,0 +1,60 @@ +// Copyright 2024 Bloomberg Finance L.P. +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// bmqp_blobpoolutil.h -*-C++-*- +#ifndef INCLUDED_BMQP_BLOBPOOLUTIL +#define INCLUDED_BMQP_BLOBPOOLUTIL + +//@PURPOSE: Provide a mechanism to build Blob shared pointer pools compatible +// with event builders used in BlazingMQ. +// +//@CLASSES: +// bmqp::BlobPoolUtil: mechanism to build bdlbb::Blob shared pointer pool. +// +//@DESCRIPTION: +// + +// BDE +#include +#include +#include + +namespace BloombergLP { +namespace bmqp { + +struct BlobPoolUtil { + // TYPES + + /// Pool of shared pointers to Blobs + typedef bdlcc::SharedObjectPool< + bdlbb::Blob, + bdlcc::ObjectPoolFunctors::DefaultCreator, + bdlcc::ObjectPoolFunctors::RemoveAll > + BlobSpPool; + + // CLASS METHODS + + /// Create a blob shared pointer pool, using the specified + /// `blobBufferFactory_p`. Use the optionally specified `allocator` + /// for memory allocations. + static BlobSpPool + createBlobPool(bdlbb::BlobBufferFactory* blobBufferFactory_p, + bslma::Allocator* allocator = 0); +}; + +} // close package namespace +} // close enterprise namespace + +#endif diff --git a/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.cpp b/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.cpp index ceadeec7de..4e120f7025 100644 --- a/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.cpp +++ b/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.cpp @@ -34,18 +34,31 @@ namespace bmqp { // class ConfirmEventBuilder // ------------------------- -ConfirmEventBuilder::ConfirmEventBuilder( - bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator) -: d_blob(bufferFactory, allocator) +ConfirmEventBuilder::ConfirmEventBuilder(BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator) +: d_blobSpPool_p(blobSpPool_p) +, d_blob_sp(0, allocator) // initialized in `reset()` +, d_emptyBlob_sp(0, allocator) // initialized later in constructor , d_msgCount(0) { + // PRECONDITIONS + BSLS_ASSERT_SAFE(blobSpPool_p); + + d_emptyBlob_sp = blobSpPool_p->getObject(); + + // Assume that items built with the given `blobSpPool_p` either all have or + // all don't have buffer factory, and check it once for `d_emptyBlob_sp`. + // We require this since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != d_emptyBlob_sp->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); + reset(); } void ConfirmEventBuilder::reset() { - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); d_msgCount = 0; @@ -58,16 +71,16 @@ void ConfirmEventBuilder::reset() // ConfirmHeader Use placement new to create the object directly in the // blob buffer, while still calling it's constructor (to memset memory and // initialize some fields). - d_blob.setLength(sizeof(EventHeader) + sizeof(ConfirmHeader)); - BSLS_ASSERT_SAFE(d_blob.numDataBuffers() == 1 && + d_blob_sp->setLength(sizeof(EventHeader) + sizeof(ConfirmHeader)); + BSLS_ASSERT_SAFE(d_blob_sp->numDataBuffers() == 1 && "The buffers allocated by the supplied bufferFactory " "are too small"); // EventHeader - new (d_blob.buffer(0).data()) EventHeader(EventType::e_CONFIRM); + new (d_blob_sp->buffer(0).data()) EventHeader(EventType::e_CONFIRM); // ConfirmHeader - new (d_blob.buffer(0).data() + sizeof(EventHeader)) ConfirmHeader(); + new (d_blob_sp->buffer(0).data() + sizeof(EventHeader)) ConfirmHeader(); } bmqt::EventBuilderResult::Enum @@ -87,9 +100,9 @@ ConfirmEventBuilder::appendMessage(int queueId, // Resize the blob to have space for an 'ConfirmMessage' at the end ... bmqu::BlobPosition offset; - bmqu::BlobUtil::reserve(&offset, &d_blob, sizeof(ConfirmMessage)); + bmqu::BlobUtil::reserve(&offset, d_blob_sp.get(), sizeof(ConfirmMessage)); - bmqu::BlobObjectProxy confirmMessage(&d_blob, + bmqu::BlobObjectProxy confirmMessage(d_blob_sp.get(), offset, false, // no read true); // write mode @@ -108,23 +121,24 @@ ConfirmEventBuilder::appendMessage(int queueId, return bmqt::EventBuilderResult::e_SUCCESS; } -const bdlbb::Blob& ConfirmEventBuilder::blob() const +const bsl::shared_ptr& ConfirmEventBuilder::blob() const { // PRECONDITIONS - BSLS_ASSERT_SAFE(d_blob.length() <= EventHeader::k_MAX_SIZE_SOFT); + BSLS_ASSERT_SAFE(d_blob_sp->length() <= EventHeader::k_MAX_SIZE_SOFT); // Empty event if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(messageCount() == 0)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; - return ProtocolUtil::emptyBlob(); // RETURN + return d_emptyBlob_sp; // RETURN } // Fix packet's length in header now that we know it. Following is valid // (see comment in reset). - EventHeader& eh = *reinterpret_cast(d_blob.buffer(0).data()); - eh.setLength(d_blob.length()); + EventHeader& eh = *reinterpret_cast( + d_blob_sp->buffer(0).data()); + eh.setLength(d_blob_sp->length()); - return d_blob; + return d_blob_sp; } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.h b/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.h index e050938ba2..8d24bae8c2 100644 --- a/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.h @@ -41,24 +41,28 @@ /// Usage ///----- //.. -// bdlbb::BlobPooledBlobBufferFactory bufferFactory(1024, d_allocator_p); -// bmqp::ConfirmEventBuilder builder(&bufferFactory, d_allocator_p); +// bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p); +// bmqp::BlobPoolUtil::BlobSpPool blobSpPool( +// bmqp::BlobPoolUtil::createBlobPool(&bufferFactory, s_allocator_p)); +// bmqp::ConfirmEventBuilder builder(&blobSpPool, d_allocator_p); // // // Append multiple messages, from same or different queue // builder.appendMessage(k_QUEUEID1, k_SUBQUEUEID1, bmqt::MessageGUID()); // builder.appendMessage(k_QUEUEID2, k_SUBQUEUEID2, bmqt::MessageGUID()); // -// const bdlbb::Blob& eventBlob = builder.blob(); +// const bsl::shared_ptr& eventBlob = builder.blob(); // // Send the blob ... // // // We can reset the builder to reuse it; note that this invalidates the -// // 'eventBlob' retrieved above +// // 'eventBlob' shared pointer reference retrieved above. To keep the +// // bdlbb::Blob valid the shared pointer should be copied, and the copy +// // should be passed and kept in IO components. // builder.reset(); // //.. // BMQ - +#include #include #include #include @@ -79,12 +83,22 @@ namespace bmqp { /// Mechanism to build a BlazingMQ CONFIRM event class ConfirmEventBuilder { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // DATA - mutable bdlbb::Blob d_blob; // blob being built by this object - // This has been done mutable to be able to - // skip writing the length until the blob - // is retrieved. + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; + + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; + + /// Empty blob to be returned when no messages were added to this builder. + bsl::shared_ptr d_emptyBlob_sp; + int d_msgCount; // number of messages currently in the // event @@ -104,10 +118,11 @@ class ConfirmEventBuilder { public: // CREATORS - /// Create a new `ConfirmEventBuilder` using the specified - /// `bufferFactory` and `allocator` for the blob. - ConfirmEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator); + /// Create a new `ConfirmEventBuilder` using the specified `blobSpPool_p` + /// and `allocator` for the blob. We require BlobSpPool to build Blobs + /// with set BlobBufferFactory since we might want to expand the built Blob + /// dynamically. + ConfirmEventBuilder(BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); // MANIPULATORS @@ -136,10 +151,13 @@ class ConfirmEventBuilder { /// were added, this will return 0. int eventSize() const; - /// Return a reference not offering modifiable access to the blob built - /// by this event. If no messages were added, this will return an empty - /// blob, i.e., a blob with length == 0. - const bdlbb::Blob& blob() const; + /// Return a reference to the shared pointer to the built Blob. If no + /// messages were added, the Blob object under this reference will be + /// empty. + /// Note that this accessor exposes an internal shared pointer object, and + /// it is the user's responsibility to make a copy of it if it needs to be + /// passed and kept in another thread while this builder object is used. + const bsl::shared_ptr& blob() const; }; // ============================================================================ @@ -170,7 +188,7 @@ inline int ConfirmEventBuilder::eventSize() const return 0; // RETURN } - return d_blob.length(); + return d_blob_sp->length(); } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.t.cpp index 5392df3c3f..6f39e621e6 100644 --- a/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_confirmeventbuilder.t.cpp @@ -95,10 +95,11 @@ static void verifyContent(const bmqp::ConfirmEventBuilder& builder, (data.size() * sizeof(bmqp::ConfirmMessage)); ASSERT_EQ(static_cast(builder.messageCount()), data.size()); ASSERT_EQ(static_cast(builder.eventSize()), expectedSize); - ASSERT_EQ(static_cast(builder.blob().length()), expectedSize); + ASSERT_EQ(static_cast(builder.blob()->length()), expectedSize); PVV("Iterating over messages"); - bmqp::Event event(&builder.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event event(builder.blob().get(), + bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(event.isValid(), true); ASSERT_EQ(event.isConfirmEvent(), true); @@ -137,7 +138,11 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::ConfirmEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::ConfirmEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -145,7 +150,7 @@ static void test1_breathingTest() ASSERT_EQ(obj.messageCount(), 0); ASSERT_NE(obj.maxMessageCount(), 0); ASSERT_EQ(obj.eventSize(), 0); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); PVV("Appending one message"); appendMessages(&obj, &messages, 1); @@ -164,7 +169,11 @@ static void test2_multiMessage() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::ConfirmEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::ConfirmEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -183,7 +192,11 @@ static void test3_reset() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::ConfirmEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::ConfirmEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -196,7 +209,7 @@ static void test3_reset() PV("Verifying accessors"); ASSERT_EQ(obj.messageCount(), 0); ASSERT_EQ(obj.eventSize(), 0); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); PV("Appending another message"); messages.clear(); @@ -215,7 +228,11 @@ static void test4_capacity() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::ConfirmEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::ConfirmEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); PVV("Computing max message"); @@ -271,7 +288,11 @@ static void testN1_decodeFromFile() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::ConfirmEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::ConfirmEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); bdlbb::Blob outBlob(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -282,11 +303,11 @@ static void testN1_decodeFromFile() PVV("Appending messages"); appendMessages(&obj, &messages, k_NUM_MSGS); - ASSERT_NE(obj.blob().length(), 0); + ASSERT_NE(obj.blob()->length(), 0); os << "msg_confirm_" << guid << ".bin" << bsl::ends; - const int blobLen = obj.blob().length(); + const int blobLen = obj.blob()->length(); char* buf = new char[blobLen]; /// Functor invoked to delete the file at the specified `filePath` @@ -306,7 +327,7 @@ static void testN1_decodeFromFile() BSLS_ASSERT(ofile.good() == true); - bdlbb::BlobUtil::copy(buf, obj.blob(), 0, blobLen); + bdlbb::BlobUtil::copy(buf, *obj.blob(), 0, blobLen); ofile.write(buf, blobLen); ofile.close(); bsl::memset(buf, 0, blobLen); @@ -327,7 +348,7 @@ static void testN1_decodeFromFile() outBlob.appendDataBuffer(dataBlobBuffer); outBlob.setLength(blobLen); - ASSERT_EQ(bdlbb::BlobUtil::compare(obj.blob(), outBlob), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*obj.blob(), outBlob), 0); // Decode event bmqp::Event event(&outBlob, bmqtst::TestHelperUtil::allocator()); diff --git a/src/groups/bmq/bmqp/bmqp_event.t.cpp b/src/groups/bmq/bmqp/bmqp_event.t.cpp index 6a5502a151..51bca8c045 100644 --- a/src/groups/bmq/bmqp/bmqp_event.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_event.t.cpp @@ -524,6 +524,10 @@ static void test4_eventLoading() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); struct Test { int d_line; @@ -540,11 +544,11 @@ static void test4_eventLoading() const Test& test = k_DATA[idx]; PVV(test.d_line << ": Testing " << test.d_encodingType << "encoding"); - bmqp::SchemaEventBuilder obj(&bufferFactory, - bmqtst::TestHelperUtil::allocator(), - test.d_encodingType); + bmqp::SchemaEventBuilder obj(&blobSpPool, + test.d_encodingType, + bmqtst::TestHelperUtil::allocator()); - BSLS_ASSERT_OPT(obj.blob().length() == 0); + BSLS_ASSERT_OPT(obj.blob()->length() == 0); { PVV(test.d_line << ": Create a control message"); @@ -557,12 +561,12 @@ static void test4_eventLoading() // Encode the message rc = obj.setMessage(ctrlMessage, bmqp::EventType::e_CONTROL); BSLS_ASSERT_OPT(rc == 0); - BSLS_ASSERT_OPT(obj.blob().length() > 0); - BSLS_ASSERT_OPT(obj.blob().length() % 4 == 0); + BSLS_ASSERT_OPT(obj.blob()->length() > 0); + BSLS_ASSERT_OPT(obj.blob()->length() % 4 == 0); PVV(test.d_line << ": Decode and compare message"); - bmqp::Event ctrlEvent(&obj.blob(), + bmqp::Event ctrlEvent(obj.blob().get(), bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(ctrlEvent.isValid(), true); @@ -582,13 +586,14 @@ static void test4_eventLoading() PVV(test.d_line << ": Reset"); obj.reset(); - BSLS_ASSERT_OPT(obj.blob().length() == 0); + BSLS_ASSERT_OPT(obj.blob()->length() == 0); } { - bmqp::SchemaEventBuilder obj(&bufferFactory, + bmqp::SchemaEventBuilder obj(&blobSpPool, + bmqp::EncodingType::e_BER, bmqtst::TestHelperUtil::allocator()); - BSLS_ASSERT_OPT(obj.blob().length() == 0); + BSLS_ASSERT_OPT(obj.blob()->length() == 0); PVV(L_ << ": Create an elector message"); @@ -599,12 +604,12 @@ static void test4_eventLoading() rc = obj.setMessage(electorMsg, bmqp::EventType::e_ELECTOR); BSLS_ASSERT_OPT(rc == 0); - BSLS_ASSERT_OPT(obj.blob().length() > 0); - BSLS_ASSERT_OPT(obj.blob().length() % 4 == 0); + BSLS_ASSERT_OPT(obj.blob()->length() > 0); + BSLS_ASSERT_OPT(obj.blob()->length() % 4 == 0); PVV(L_ << ": Decode and compare message"); - bmqp::Event electorEvent(&obj.blob(), + bmqp::Event electorEvent(obj.blob().get(), bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(electorEvent.isValid()); @@ -619,7 +624,7 @@ static void test4_eventLoading() PVV(L_ << ": Reset"); obj.reset(); - BSLS_ASSERT_OPT(obj.blob().length() == 0); + BSLS_ASSERT_OPT(obj.blob()->length() == 0); } bmqp::ProtocolUtil::shutdown(); diff --git a/src/groups/bmq/bmqp/bmqp_eventutil.cpp b/src/groups/bmq/bmqp/bmqp_eventutil.cpp index 6ffcb0bf38..415b32203e 100644 --- a/src/groups/bmq/bmqp/bmqp_eventutil.cpp +++ b/src/groups/bmq/bmqp/bmqp_eventutil.cpp @@ -60,6 +60,8 @@ BSLMF_ASSERT(Protocol::SubQueueIdsArrayOld::static_size >= 1); class Flattener { private: // PRIVATE TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + enum RcEnum { // Value for the various RC error categories rc_SUCCESS = 0 // No error @@ -180,10 +182,11 @@ class Flattener { // CREATORS /// Create a `Flattener` using the specified `eventInfos`, `event`, - /// `bufferFactory` and `allocator` + /// `blobSpPool_p`, `bufferFactory` and `allocator` Flattener(bsl::vector* eventInfos, const Event& event, bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); // MANIPULATORS @@ -391,7 +394,7 @@ void Flattener::advanceEvent() BSLS_ASSERT_SAFE(d_builder.messageCount() > 0); BSLS_ASSERT_SAFE(!d_currEventInfo.d_ids.empty()); - d_eventInfos_p->emplace_back(d_builder.blob(), d_currEventInfo.d_ids); + d_eventInfos_p->emplace_back(*d_builder.blob(), d_currEventInfo.d_ids); d_currEventInfo.d_ids.clear(); d_builder.reset(); @@ -400,10 +403,11 @@ void Flattener::advanceEvent() Flattener::Flattener(bsl::vector* eventInfos, const Event& event, bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator) : d_eventInfos_p(eventInfos) , d_allocator_p(allocator) -, d_builder(bufferFactory, allocator) +, d_builder(blobSpPool_p, allocator) , d_msgIterator(bufferFactory, allocator) , d_currEventInfo(allocator) , d_appData(bufferFactory, allocator) @@ -486,6 +490,7 @@ int Flattener::flattenPushEvent() int EventUtil::flattenPushEvent(bsl::vector* eventInfos, const Event& event, bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator) { // PRECONDITIONS @@ -495,7 +500,11 @@ int EventUtil::flattenPushEvent(bsl::vector* eventInfos, BSLS_ASSERT_SAFE(bufferFactory); BSLS_ASSERT_SAFE(allocator); - Flattener flattener(eventInfos, event, bufferFactory, allocator); + Flattener flattener(eventInfos, + event, + bufferFactory, + blobSpPool_p, + allocator); return flattener.flattenPushEvent(); } diff --git a/src/groups/bmq/bmqp/bmqp_eventutil.h b/src/groups/bmq/bmqp/bmqp_eventutil.h index 5e016d4ec3..c705466049 100644 --- a/src/groups/bmq/bmqp/bmqp_eventutil.h +++ b/src/groups/bmq/bmqp/bmqp_eventutil.h @@ -30,12 +30,13 @@ // Thread safe. // BMQ - +#include #include #include // BDE #include +#include #include #include #include @@ -113,6 +114,9 @@ struct EventUtilEventInfo { /// Utilities for BlazingMQ protocol events. struct EventUtil { + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + // CLASS METHODS /// PushEvent Utilities @@ -125,10 +129,12 @@ struct EventUtil { /// case of failure. The behavior is undefined unless the `event` is a /// valid push event. Note that this function is exclusively used by /// the SDK and thus we can assume that the messages will only contain - /// old flavor of SubQueueIdsArray (i.e. SubQueueIdsArrayOld). + /// old flavor of SubQueueIdsArray (i.e. SubQueueIdsArrayOld). Use the + /// specified `blobSpPool_p` to allocate shared pointer to blobs. static int flattenPushEvent(bsl::vector* eventInfos, const Event& event, bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); }; diff --git a/src/groups/bmq/bmqp/bmqp_eventutil.t.cpp b/src/groups/bmq/bmqp/bmqp_eventutil.t.cpp index 66e1ea4f3f..8763d91598 100644 --- a/src/groups/bmq/bmqp/bmqp_eventutil.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_eventutil.t.cpp @@ -251,8 +251,12 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::PushEventBuilder pushEventBuilder( - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); int payloadLength = 0; @@ -307,7 +311,7 @@ static void test1_breathingTest() // Create event appendMessages(&pushEventBuilder, data); - bmqp::Event event(&(pushEventBuilder.blob()), + bmqp::Event event(pushEventBuilder.blob().get(), bmqtst::TestHelperUtil::allocator()); // 2) Flatten the event @@ -317,6 +321,7 @@ static void test1_breathingTest() &eventInfos, event, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(rc, 0); ASSERT_EQ(eventInfos.size(), 1u); @@ -449,8 +454,12 @@ static void test2_flattenExplodesEvent() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::PushEventBuilder pushEventBuilder( - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); int payloadLength = 0; @@ -478,7 +487,7 @@ static void test2_flattenExplodesEvent() // Create event appendMessages(&pushEventBuilder, data); - bmqp::Event event(&(pushEventBuilder.blob()), + bmqp::Event event(pushEventBuilder.blob().get(), bmqtst::TestHelperUtil::allocator()); // 2) Flatten the event @@ -488,6 +497,7 @@ static void test2_flattenExplodesEvent() &eventInfos, event, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(rc, 0); ASSERT_EQ(eventInfos.size(), 2u); @@ -672,10 +682,14 @@ static void test3_flattenWithMessageProperties() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::MessageProperties msgProperties(bmqtst::TestHelperUtil::allocator()); bdlbb::Blob appData(bmqtst::TestHelperUtil::allocator()); bmqp::PushEventBuilder pushEventBuilder( - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqt::EventBuilderResult::Enum result; int payloadLength = 0; @@ -746,7 +760,7 @@ static void test3_flattenWithMessageProperties() logic); BSLS_ASSERT_OPT(result == bmqt::EventBuilderResult::e_SUCCESS); - bmqp::Event event(&(pushEventBuilder.blob()), + bmqp::Event event(pushEventBuilder.blob().get(), bmqtst::TestHelperUtil::allocator()); // 2) Flatten the event. @@ -756,6 +770,7 @@ static void test3_flattenWithMessageProperties() &eventInfos, event, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(rc, 0); ASSERT_EQ(eventInfos.size(), 1U); diff --git a/src/groups/bmq/bmqp/bmqp_protocolutil.cpp b/src/groups/bmq/bmqp/bmqp_protocolutil.cpp index b429b5f962..79e5676958 100644 --- a/src/groups/bmq/bmqp/bmqp_protocolutil.cpp +++ b/src/groups/bmq/bmqp/bmqp_protocolutil.cpp @@ -59,13 +59,11 @@ const char k_PADDING_DATA[9][8] = { /// Array of all potential padding buffers used for word and dword padding. bsls::ObjectBuffer g_paddingBlobBuffer[9]; +/// Static prefilled blobs respectively containing a heartbeat request and +/// a heartbeat response. bsls::ObjectBuffer g_heartbeatReqBlob; bsls::ObjectBuffer g_heartbeatRspBlob; -/// Static prefilled blobs respectively containing a heartbeat request, -/// heartbeat response and an empty blob. -bsls::ObjectBuffer g_emptyBlob; - /// Integer to keep track of the number of calls to `initialize` for the /// `ProtocolUtil`. If the value is non-zero, then it has already been /// initialized, otherwise it can be initialized. Each call to `initialize` @@ -160,9 +158,6 @@ void ProtocolUtil::initialize(bslma::Allocator* allocator) new (g_heartbeatRspBlob.buffer()) bdlbb::Blob(alloc); g_heartbeatRspBlob.object().appendDataBuffer(buffer); } - - // Create empty blob - new (g_emptyBlob.buffer()) bdlbb::Blob(alloc); } void ProtocolUtil::shutdown() @@ -178,7 +173,6 @@ void ProtocolUtil::shutdown() g_heartbeatRspBlob.object().bdlbb::Blob::~Blob(); g_heartbeatReqBlob.object().bdlbb::Blob::~Blob(); - g_emptyBlob.object().bdlbb::Blob::~Blob(); for (int i = 0; i < 9; ++i) { g_paddingBlobBuffer[i].object().reset(); @@ -292,11 +286,6 @@ const bdlbb::Blob& ProtocolUtil::heartbeatRspBlob() return g_heartbeatRspBlob.object(); } -const bdlbb::Blob& ProtocolUtil::emptyBlob() -{ - return g_emptyBlob.object(); -} - void ProtocolUtil::hexToBinary(char* buffer, int length, const char* hex) { for (int i = 0; i < length; ++i) { diff --git a/src/groups/bmq/bmqp/bmqp_protocolutil.h b/src/groups/bmq/bmqp/bmqp_protocolutil.h index 0532c6e358..f8dcff0393 100644 --- a/src/groups/bmq/bmqp/bmqp_protocolutil.h +++ b/src/groups/bmq/bmqp/bmqp_protocolutil.h @@ -284,13 +284,6 @@ struct ProtocolUtil { /// event. static const bdlbb::Blob& heartbeatRspBlob(); - /// Return const reference to the pre-allocated empty blob. If you need - /// an empty blob and not going to modify it use this method instead of - /// creating another blob. Heap allocate it to prevent 'exit-time- - /// destructor needed' compiler warning. Causes valgrind-reported - /// memory leak. - static const bdlbb::Blob& emptyBlob(); - /// Hex/Binary conversion ///--------------------- @@ -413,8 +406,8 @@ struct ProtocolUtil { buildEvent(ACTION_FUNCTOR_TYPE& actionCb, OVERFLOW_FUNCTOR_TYPE& overflowCb); - /// Encode Receipt into the specified `blob` for the specified - /// `partitionId`, `primaryLeaseId`, and `sequenceNumber`. + /// Encode Receipt into the specified `blob` (expected to be empty) for + /// the specified `partitionId`, `primaryLeaseId`, and `sequenceNumber`. static void buildReceipt(bdlbb::Blob* blob, int partitionId, unsigned int primaryLeaseId, @@ -739,7 +732,8 @@ inline void ProtocolUtil::buildReceipt(bdlbb::Blob* blob, unsigned int primaryLeaseId, bsls::Types::Uint64 sequenceNumber) { - blob->removeAll(); + // PRECONDITIONS + BSLS_ASSERT_SAFE(0 == blob->length()); blob->setLength(sizeof(EventHeader) + sizeof(ReplicationReceipt)); diff --git a/src/groups/bmq/bmqp/bmqp_protocolutil.t.cpp b/src/groups/bmq/bmqp/bmqp_protocolutil.t.cpp index 1aace00a00..d73f7fe9c8 100644 --- a/src/groups/bmq/bmqp/bmqp_protocolutil.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_protocolutil.t.cpp @@ -526,13 +526,6 @@ static void test6_heartbeatAndEmptyBlobs() sizeof(bmqp::EventHeader))); } - PV("Verifying emtpy blob") - { - const bdlbb::Blob& blob = bmqp::ProtocolUtil::emptyBlob(); - ASSERT_EQ(0, blob.length()); - ASSERT_EQ(0, blob.numDataBuffers()); - } - bmqp::ProtocolUtil::shutdown(); } @@ -861,10 +854,14 @@ static void test11_parseMessageProperties() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::MessageProperties in(bmqtst::TestHelperUtil::allocator()); encode(&in); const int queueId = 4; - bmqp::PutEventBuilder peb(&bufferFactory, + bmqp::PutEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bdlbb::Blob payload(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -883,7 +880,8 @@ static void test11_parseMessageProperties() bmqp::PutMessageIterator putIt(&bufferFactory, bmqtst::TestHelperUtil::allocator(), true); - bmqp::Event rawEvent(&peb.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(rawEvent.isPutEvent()); rawEvent.loadPutMessageIterator(&putIt); diff --git a/src/groups/bmq/bmqp/bmqp_pusheventbuilder.cpp b/src/groups/bmq/bmqp/bmqp_pusheventbuilder.cpp index ff27f63426..bc2c740bfe 100644 --- a/src/groups/bmq/bmqp/bmqp_pusheventbuilder.cpp +++ b/src/groups/bmq/bmqp/bmqp_pusheventbuilder.cpp @@ -114,10 +114,10 @@ bmqt::EventBuilderResult::Enum PushEventBuilder::packMessageImp( d_currPushHeader.reset(); // i.e., flush writing to blob.. // Add the payload - bdlbb::BlobUtil::append(&d_blob, payload); + bdlbb::BlobUtil::append(d_blob_sp.get(), payload); // Add padding - ProtocolUtil::appendPadding(&d_blob, payloadLen); + ProtocolUtil::appendPadding(d_blob_sp.get(), payloadLen); d_options.reset(); ++d_msgCount; @@ -134,9 +134,9 @@ void PushEventBuilder::ensurePushHeader() // Add the PushHeader bmqu::BlobPosition phOffset; - bmqu::BlobUtil::reserve(&phOffset, &d_blob, sizeof(PushHeader)); + bmqu::BlobUtil::reserve(&phOffset, d_blob_sp.get(), sizeof(PushHeader)); - d_currPushHeader.reset(&d_blob, + d_currPushHeader.reset(d_blob_sp.get(), phOffset, false, // no read true); // write mode @@ -146,13 +146,25 @@ void PushEventBuilder::ensurePushHeader() } // CREATORS -PushEventBuilder::PushEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator) -: d_allocator_p(allocator) -, d_blob(bufferFactory, allocator) +PushEventBuilder::PushEventBuilder(BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator) +: d_allocator_p(bslma::Default::allocator(allocator)) +, d_blobSpPool_p(blobSpPool_p) +, d_blob_sp(0, allocator) // initialized in `reset()` , d_msgCount(0) , d_options() +, d_currPushHeader() { + // PRECONDITIONS + BSLS_ASSERT_SAFE(blobSpPool_p); + + // Assume that items built with the given `blobSpPool_p` either all have or + // all don't have buffer factory, and check it once for a sample blob. + // We require this since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != d_blobSpPool_p->getObject()->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); + reset(); } @@ -163,7 +175,7 @@ int PushEventBuilder::reset() // Flush any buffered changes if necessary, and make this object not // refer to any valid blob object. - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); d_msgCount = 0; d_options.reset(); @@ -177,8 +189,8 @@ int PushEventBuilder::reset() // Use placement new to create the object directly in the blob buffer, // while still calling it's constructor (to memset memory and initialize // some fields) - d_blob.setLength(sizeof(EventHeader)); - new (d_blob.buffer(0).data()) EventHeader(EventType::e_PUSH); + d_blob_sp->setLength(sizeof(EventHeader)); + new (d_blob_sp->buffer(0).data()) EventHeader(EventType::e_PUSH); return 0; } @@ -230,7 +242,7 @@ bmqt::EventBuilderResult::Enum PushEventBuilder::addSubQueueIdsOption( bdlb::BigEndianUint32::make); // TODO_POISON_PILL Make sure that adding *packed* option also works - d_options.add(&d_blob, + d_options.add(d_blob_sp.get(), reinterpret_cast(tempVec.data()), option); @@ -298,7 +310,7 @@ bmqt::EventBuilderResult::Enum PushEventBuilder::addSubQueueInfosOption( if (packRdaCounter && isDefaultSubQueueInfo(subQueueInfos)) { // The header is packed and there is no payload, so simply add the // option header. - d_options.add(&d_blob, 0, option); + d_options.add(d_blob_sp.get(), 0, option); return bmqt::EventBuilderResult::e_SUCCESS; // RETURN } @@ -311,7 +323,7 @@ bmqt::EventBuilderResult::Enum PushEventBuilder::addSubQueueInfosOption( bsl::copy(subQueueInfos.begin(), subQueueInfos.end(), bsl::back_inserter(tempVec)); - d_options.add(&d_blob, + d_options.add(d_blob_sp.get(), reinterpret_cast(tempVec.data()), option); return bmqt::EventBuilderResult::e_SUCCESS; // RETURN @@ -332,7 +344,7 @@ bmqt::EventBuilderResult::Enum PushEventBuilder::addSubQueueInfosOption( tempVec.push_back(bdlb::BigEndianUint32::make(citer->id())); } - d_options.add(&d_blob, + d_options.add(d_blob_sp.get(), reinterpret_cast(tempVec.data()), option); @@ -383,7 +395,7 @@ PushEventBuilder::addMsgGroupIdOption(const Protocol::MsgGroupId& msgGroupId) // Make sure PushHeader is written for current message ensurePushHeader(); - d_options.add(&d_blob, + d_options.add(d_blob_sp.get(), reinterpret_cast(msgGroupId.data()), option); @@ -391,14 +403,18 @@ PushEventBuilder::addMsgGroupIdOption(const Protocol::MsgGroupId& msgGroupId) } // ACCESSORS -const bdlbb::Blob& PushEventBuilder::blob() const +const bsl::shared_ptr& PushEventBuilder::blob() const { + // PRECONDITIONS + BSLS_ASSERT_SAFE(d_blob_sp->length() <= EventHeader::k_MAX_SIZE_SOFT); + // Fix packet's length in header now that we know it .. Following is valid // (see comment in reset) - EventHeader& eh = *reinterpret_cast(d_blob.buffer(0).data()); - eh.setLength(d_blob.length()); + EventHeader& eh = *reinterpret_cast( + d_blob_sp->buffer(0).data()); + eh.setLength(d_blob_sp->length()); - return d_blob; + return d_blob_sp; } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_pusheventbuilder.h b/src/groups/bmq/bmqp/bmqp_pusheventbuilder.h index 47d71e2f72..2775384834 100644 --- a/src/groups/bmq/bmqp/bmqp_pusheventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_pusheventbuilder.h @@ -40,23 +40,27 @@ /// Usage ///----- //.. -// bdlbb::PooledBlobBufferFactory bufferFactory(1024, d_allocator_p); -// bmqp::PushEventBuilder builder(&bufferFactory, d_allocator_p); +// bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p); +// bmqp::BlobPoolUtil::BlobSpPool blobSpPool( +// bmqp::BlobPoolUtil::createBlobPool(&bufferFactory, s_allocator_p)); +// bmqp::PushEventBuilder builder(&blobSpPool, d_allocator_p); // // // Append multiple messages // builder.packMessage("hello", 5, 0, bmqt::MessageGUID()); // builder.packMessage(myBlob, 0, bmqt::MessageGUID()); // -// const bdlbb::Blob& eventBlob = builder.blob(); +// const bsl::shared_ptr& eventBlob = builder.blob(); // // Send the blob ... // // // We can reset the builder to reuse it; note that this invalidates the -// // 'eventBlob' retrieved above +// // 'eventBlob' shared pointer reference retrieved above. To keep the +// // bdlbb::Blob valid the shared pointer should be copied, and the copy +// // should be passed and kept in IO components. // builder.reset(); //.. // BMQ - +#include #include #include #include @@ -83,17 +87,21 @@ namespace bmqp { /// Mechanism to build a BlazingMQ PUSH event class PushEventBuilder { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // DATA + /// Allocator to use. bslma::Allocator* d_allocator_p; - // Allocator to use. - mutable bdlbb::Blob d_blob; - // blob being built by this - // PushEventBuilder. - // This has been done mutable to be - // able to skip writing the length - // until the blob is retrieved. + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; + + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; int d_msgCount; // number of messages currently in @@ -151,10 +159,11 @@ class PushEventBuilder { // CREATORS - /// Create a new `PushEventBuilder` using the specified `bufferFactory` - /// and `allocator` for the blob. - PushEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator); + /// Create a new `PushEventBuilder` using the specified `blobSpPool_p` and + /// `allocator` for the blob. We require BlobSpPool to build Blobs with + /// set BlobBufferFactory since we might want to expand the built Blob + /// dynamically. + PushEventBuilder(BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); // MANIPULATORS @@ -240,10 +249,13 @@ class PushEventBuilder { /// Return the number of messages currently in the event being built. int messageCount() const; - /// Return a reference not offering modifiable access to the blob built - /// by this event. If no messages were added, this will return a blob - /// composed only of an `EventHeader`. - const bdlbb::Blob& blob() const; + /// Return a reference to the shared pointer to the built Blob. If no + /// messages were added, the Blob object under this reference will be + /// empty. + /// Note that this accessor exposes an internal shared pointer object, and + /// it is the user's responsibility to make a copy of it if it needs to be + /// passed and kept in another thread while this builder object is used. + const bsl::shared_ptr& blob() const; }; // ============================================================================ @@ -263,7 +275,7 @@ inline int PushEventBuilder::eraseCurrentMessage() #ifdef BSLS_ASSERT_SAFE_IS_ACTIVE bool hasNoOptions = optionsSize == 0 && !d_currPushHeader.isSet(); bool hasOptions = optionsSize > 0 && d_currPushHeader.isSet(); - bool isValidBlobSize = d_blob.length() > + bool isValidBlobSize = d_blob_sp->length() > (static_cast(sizeof(PushHeader)) + optionsSize); @@ -276,7 +288,8 @@ inline int PushEventBuilder::eraseCurrentMessage() // Flush any buffered changes if necessary, and make this object // not refer to any valid blob object. - d_blob.setLength(d_blob.length() - sizeof(PushHeader) - optionsSize); + d_blob_sp->setLength(d_blob_sp->length() - sizeof(PushHeader) - + optionsSize); d_options.reset(); } @@ -339,10 +352,10 @@ inline int PushEventBuilder::eventSize() const (optionsCount == 0 && !d_currPushHeader.isSet())); if (optionsCount > 0) { - return d_blob.length() - sizeof(PushHeader) - d_options.size(); + return d_blob_sp->length() - sizeof(PushHeader) - d_options.size(); // RETURN } - return d_blob.length(); + return d_blob_sp->length(); } inline int PushEventBuilder::messageCount() const diff --git a/src/groups/bmq/bmqp/bmqp_pusheventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_pusheventbuilder.t.cpp index 89279dedf9..62fa1acf18 100644 --- a/src/groups/bmq/bmqp/bmqp_pusheventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_pusheventbuilder.t.cpp @@ -273,6 +273,10 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::Protocol::SubQueueInfosArray subQueueInfos( bmqtst::TestHelperUtil::allocator()); @@ -292,11 +296,11 @@ static void test1_breathingTest() bsl::strlen(buffer)); // Create PushEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); ASSERT_EQ(0, peb.messageCount()); // Add SubQueueInfo option @@ -308,7 +312,7 @@ static void test1_breathingTest() ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); // 'eventSize()' excludes unpacked messages ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // But the option is written to the underlying blob rc = peb.packMessage(payload, queueId, @@ -323,8 +327,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -393,6 +397,10 @@ static void test2_buildEventBackwardsCompatibility() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::Protocol::SubQueueInfosArray subQueueInfos( bmqtst::TestHelperUtil::allocator()); @@ -412,11 +420,11 @@ static void test2_buildEventBackwardsCompatibility() bsl::strlen(buffer)); // Create PushEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); ASSERT_EQ(0, peb.messageCount()); // Add SubQueueInfo option @@ -428,7 +436,7 @@ static void test2_buildEventBackwardsCompatibility() ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); // 'eventSize()' excludes unpacked messages ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // But the option is written to the underlying blob rc = peb.packMessage(payload, queueId, @@ -443,8 +451,8 @@ static void test2_buildEventBackwardsCompatibility() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -514,6 +522,10 @@ static void test3_buildEventWithPackedOption() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::Protocol::SubQueueInfosArray subQueueInfos( bmqtst::TestHelperUtil::allocator()); @@ -529,11 +541,11 @@ static void test3_buildEventWithPackedOption() bsl::strlen(buffer)); // Create PushEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); ASSERT_EQ(0, peb.messageCount()); // Add SubQueueInfo option @@ -548,7 +560,7 @@ static void test3_buildEventWithPackedOption() ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); // 'eventSize()' excludes unpacked messages ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // But the option is written to the underlying blob rc = peb.packMessage(payload, queueId, @@ -563,8 +575,8 @@ static void test3_buildEventWithPackedOption() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -622,7 +634,11 @@ static void test4_buildEventWithMultipleMessages() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); @@ -641,8 +657,8 @@ static void test4_buildEventWithMultipleMessages() } // Iterate and check - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -732,6 +748,10 @@ static void test5_buildEventWithPayloadTooBig() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); const bmqt::MessageGUID guid; bdlbb::Blob bigMsgPayload(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -752,11 +772,11 @@ static void test5_buildEventWithPayloadTooBig() bigMsgPayload.length()); // Create PutEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); ASSERT_EQ(0, peb.messageCount()); // Add a valid size option @@ -766,7 +786,7 @@ static void test5_buildEventWithPayloadTooBig() ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // We expect 'addSubQueueInfosOption' to write directly to the underlying // blob ASSERT_EQ(0, peb.messageCount()); @@ -781,7 +801,7 @@ static void test5_buildEventWithPayloadTooBig() ASSERT_EQ(rc, bmqt::EventBuilderResult::e_PAYLOAD_TOO_BIG); ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // Already-written options have to be removed if packing a message // fails ASSERT_EQ(0, peb.messageCount()); @@ -809,8 +829,8 @@ static void test5_buildEventWithPayloadTooBig() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -849,12 +869,16 @@ static void test6_buildEventWithImplicitPayload() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); const bmqt::MessageGUID guid; const int queueId = 4321; const int flags = bmqp::PushHeaderFlags::e_IMPLICIT_PAYLOAD; // Create PutEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bmqt::EventBuilderResult::Enum rc = peb.packMessage( queueId, @@ -872,8 +896,9 @@ static void test6_buildEventWithImplicitPayload() // Get blob and use bmqp iterator to test. Note that bmqp event and bmqp // iterators are lower than bmqp builders, and thus, can be used to test // them. - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); + BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -929,6 +954,10 @@ static void test7_buildEventOptionTooBig() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); int numSubQueueInfos; int optionSize; bmqp::Protocol::SubQueueInfosArray subQueueInfos( @@ -949,7 +978,7 @@ static void test7_buildEventOptionTooBig() generateSubQueueInfos(&subQueueInfos, numSubQueueInfos); // Create PutEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); // Add option larger than maximum allowed @@ -981,7 +1010,7 @@ static void test7_buildEventOptionTooBig() ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); ASSERT_EQ(0, peb.messageCount()); // Add option of valid size @@ -1004,7 +1033,7 @@ static void test7_buildEventOptionTooBig() ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); ASSERT_LE(sizeof(bmqp::EventHeader) + sizeof(bmqp::PushHeader) + optionSize, - static_cast(peb.blob().length())); + static_cast(peb.blob()->length())); // Less than or equal due to possible padding ASSERT_EQ(0, peb.messageCount()); @@ -1033,15 +1062,15 @@ static void test7_buildEventOptionTooBig() regularPayload.length(); ASSERT_LE(evtSizeUnpadded, peb.eventSize()); // Less than or equal due to possible padding - ASSERT_LE(evtSizeUnpadded, peb.blob().length()); + ASSERT_LE(evtSizeUnpadded, peb.blob()->length()); // Less than or equal due to possible padding ASSERT_EQ(1, peb.messageCount()); // Get blob and use bmqp iterator to test. Note that bmqp event and bmqp // iterators are lower than bmqp builders, and thus, can be used to test // them. - const bdlbb::Blob& eventBlob = peb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_SAFE(true == rawEvent.isValid()); BSLS_ASSERT_SAFE(true == rawEvent.isPushEvent()); @@ -1106,6 +1135,10 @@ static void test8_buildEventTooBig() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); const bmqt::MessageGUID guid; bdlbb::Blob validPayload1(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -1122,7 +1155,7 @@ static void test8_buildEventTooBig() bdlbb::BlobUtil::append(&validPayload1, s.c_str(), validLen); // Create PutEventBuilder - bmqp::PushEventBuilder peb(&bufferFactory, + bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); // Add message with valid payload size @@ -1194,6 +1227,10 @@ static void testN1_decodeFromFile() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bdlbb::Blob outBlob(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bdlbb::Blob payloadBlob(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -1207,7 +1244,7 @@ static void testN1_decodeFromFile() bdlbb::BlobUtil::append(&payloadBlob, k_PAYLOAD, k_PAYLOAD_LEN); // Create PutEventBuilder - bmqp::PushEventBuilder obj(&bufferFactory, + bmqp::PushEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); // Pack one msg @@ -1236,7 +1273,7 @@ static void testN1_decodeFromFile() BSLS_ASSERT(ofile.good() == true); - bdlbb::BlobUtil::copy(buf, obj.blob(), 0, obj.blob().length()); + bdlbb::BlobUtil::copy(buf, *obj.blob(), 0, obj.blob()->length()); ofile.write(buf, k_SIZE); ofile.close(); bsl::memset(buf, 0, k_SIZE); @@ -1255,9 +1292,9 @@ static void testN1_decodeFromFile() bdlbb::BlobBuffer dataBlobBuffer(dataBufferSp, k_SIZE); outBlob.appendDataBuffer(dataBlobBuffer); - outBlob.setLength(obj.blob().length()); + outBlob.setLength(obj.blob()->length()); - ASSERT_EQ(bdlbb::BlobUtil::compare(obj.blob(), outBlob), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*obj.blob(), outBlob), 0); // Decode event bmqp::Event rawEvent(&outBlob, bmqtst::TestHelperUtil::allocator()); diff --git a/src/groups/bmq/bmqp/bmqp_puteventbuilder.cpp b/src/groups/bmq/bmqp/bmqp_puteventbuilder.cpp index f05701c1f4..9da9d8d1a7 100644 --- a/src/groups/bmq/bmqp/bmqp_puteventbuilder.cpp +++ b/src/groups/bmq/bmqp/bmqp_puteventbuilder.cpp @@ -105,8 +105,8 @@ PutEventBuilder::packMessageInternal(const bdlbb::Blob& appData, int queueId) // Add the PutHeader bmqu::BlobPosition offset; - bmqu::BlobUtil::reserve(&offset, &d_blob, sizeof(PutHeader)); - bmqu::BlobObjectProxy putHeader(&d_blob, + bmqu::BlobUtil::reserve(&offset, d_blob_sp.get(), sizeof(PutHeader)); + bmqu::BlobObjectProxy putHeader(d_blob_sp.get(), offset, false, // no read true); // write mode @@ -132,7 +132,7 @@ PutEventBuilder::packMessageInternal(const bdlbb::Blob& appData, int queueId) return res; // RETURN } optionBox.add( - &d_blob, + d_blob_sp.get(), reinterpret_cast(d_msgGroupId.value().data()), msgGroupId); } @@ -159,22 +159,23 @@ PutEventBuilder::packMessageInternal(const bdlbb::Blob& appData, int queueId) putHeader.reset(); // i.e., flush writing to blob.. // Just a sanity test. Should still be word aligned. - BSLS_ASSERT_SAFE(isWordAligned(d_blob)); + BSLS_ASSERT_SAFE(isWordAligned(*d_blob_sp)); - bdlbb::BlobUtil::append(&d_blob, appData); + bdlbb::BlobUtil::append(d_blob_sp.get(), appData); // Add padding - ProtocolUtil::appendPaddingRaw(&d_blob, numPaddingBytes); + ProtocolUtil::appendPaddingRaw(d_blob_sp.get(), numPaddingBytes); ++d_msgCount; return Result::e_SUCCESS; } -PutEventBuilder::PutEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator) -: d_bufferFactory_p(bufferFactory) -, d_blob(bufferFactory, allocator) +PutEventBuilder::PutEventBuilder(BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator) +: d_allocator_p(bslma::Default::allocator(allocator)) +, d_blobSpPool_p(blobSpPool_p) +, d_blob_sp(0, allocator) // initialized in `reset()` , d_msgStarted(false) , d_blobPayload_p(0) , d_rawPayload_p(0) @@ -188,14 +189,22 @@ PutEventBuilder::PutEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, , d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE) , d_lastPackedMessageCompressionRatio(-1) , d_messagePropertiesInfo() -, d_allocator_p(allocator) { + // PRECONDITIONS + BSLS_ASSERT_SAFE(blobSpPool_p); + reset(); } int PutEventBuilder::reset() { - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); + + // The following prerequisite is necessary since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != d_blob_sp->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); + d_msgStarted = false; d_blobPayload_p = 0; d_rawPayload_p = 0; @@ -218,8 +227,8 @@ int PutEventBuilder::reset() // Use placement new to create the object directly in the blob buffer, // while still calling it's constructor (to memset memory and initialize // some fields) - d_blob.setLength(sizeof(EventHeader)); - new (d_blob.buffer(0).data()) EventHeader(EventType::e_PUT); + d_blob_sp->setLength(sizeof(EventHeader)); + new (d_blob_sp->buffer(0).data()) EventHeader(EventType::e_PUT); return 0; } @@ -238,7 +247,8 @@ PutEventBuilder::packMessageInOldStyle(int queueId) // Calculate length of entire application data (includes payload, message // properties and padding, if any). - bdlbb::Blob applicationData(d_bufferFactory_p, d_allocator_p); + bsl::shared_ptr applicationData_sp = + d_blobSpPool_p->getObject(); const bdlbb::Blob* propertiesBlob = 0; if (d_properties_p && 0 != d_properties_p->numProperties()) { @@ -250,10 +260,10 @@ PutEventBuilder::packMessageInOldStyle(int queueId) d_messagePropertiesInfo = MessagePropertiesInfo::makeNoSchema(); // propertiesBlob include 6 byte mph along with properties - propertiesBlob = &(d_properties_p->streamOut(d_bufferFactory_p, + propertiesBlob = &(d_properties_p->streamOut(d_blob_sp->factory(), d_messagePropertiesInfo)); - bdlbb::BlobUtil::append(&applicationData, *propertiesBlob); + bdlbb::BlobUtil::append(applicationData_sp.get(), *propertiesBlob); } else { BSLS_ASSERT_SAFE(!d_messagePropertiesInfo.isPresent()); @@ -261,39 +271,41 @@ PutEventBuilder::packMessageInOldStyle(int queueId) // Add the payload if (d_rawPayload_p) { - bdlbb::BlobUtil::append(&applicationData, + bdlbb::BlobUtil::append(applicationData_sp.get(), d_rawPayload_p, d_rawPayloadLength); } else { - bdlbb::BlobUtil::append(&applicationData, *d_blobPayload_p); + bdlbb::BlobUtil::append(applicationData_sp.get(), *d_blobPayload_p); } // Compress - if (applicationData.length() >= Protocol::k_COMPRESSION_MIN_APPDATA_SIZE && + if (applicationData_sp->length() >= + Protocol::k_COMPRESSION_MIN_APPDATA_SIZE && d_compressionAlgorithmType != bmqt::CompressionAlgorithmType::e_NONE) { - bdlbb::Blob compressedApplicationData(d_bufferFactory_p, - d_allocator_p); + bsl::shared_ptr compressedApplicationData_sp = + d_blobSpPool_p->getObject(); bmqu::MemOutStream error(d_allocator_p); - int rc = Compression::compress(&compressedApplicationData, - d_bufferFactory_p, + int rc = Compression::compress(compressedApplicationData_sp.get(), + d_blob_sp->factory(), d_compressionAlgorithmType, - applicationData, + *applicationData_sp, &error, d_allocator_p); if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY( - rc == Result::e_SUCCESS && compressedApplicationData.length() < - applicationData.length())) { + rc == Result::e_SUCCESS && + compressedApplicationData_sp->length() < + applicationData_sp->length())) { // Compression is successful and is worth using! - d_crc32c = Crc32c::calculate(compressedApplicationData); + d_crc32c = Crc32c::calculate(*compressedApplicationData_sp); // Keep track of the compression ratio. d_lastPackedMessageCompressionRatio = - static_cast(applicationData.length()) / - compressedApplicationData.length(); + static_cast(applicationData_sp->length()) / + compressedApplicationData_sp->length(); - return packMessageInternal(compressedApplicationData, + return packMessageInternal(*compressedApplicationData_sp, queueId); // RETURN } } @@ -304,10 +316,10 @@ PutEventBuilder::packMessageInOldStyle(int queueId) // worth using. In either way, we fall back to using the original blob. // Explicitly set the 'd_compressionAlgorithmType' to 'NONE'. d_compressionAlgorithmType = bmqt::CompressionAlgorithmType::e_NONE; - d_crc32c = Crc32c::calculate(applicationData); + d_crc32c = Crc32c::calculate(*applicationData_sp); d_lastPackedMessageCompressionRatio = 1; - return packMessageInternal(applicationData, queueId); + return packMessageInternal(*applicationData_sp, queueId); } bmqt::EventBuilderResult::Enum PutEventBuilder::packMessage(int queueId) @@ -323,8 +335,8 @@ bmqt::EventBuilderResult::Enum PutEventBuilder::packMessage(int queueId) // Calculate length of entire application data (includes payload, message // properties and padding, if any). - bdlbb::Blob bufferBlob(d_bufferFactory_p, d_allocator_p); - bdlbb::Blob resultBlob(d_bufferFactory_p, d_allocator_p); + bsl::shared_ptr bufferBlob_sp = d_blobSpPool_p->getObject(); + bsl::shared_ptr resultBlob_sp = d_blobSpPool_p->getObject(); const bdlbb::Blob* payloadBlob = d_blobPayload_p; if (d_properties_p && 0 != d_properties_p->numProperties()) { @@ -340,10 +352,10 @@ bmqt::EventBuilderResult::Enum PutEventBuilder::packMessage(int queueId) // propertiesBlob include 6 byte mph along with properties const bdlbb::Blob& propertiesBlob = d_properties_p->streamOut( - d_bufferFactory_p, + d_blob_sp->factory(), d_messagePropertiesInfo); - bdlbb::BlobUtil::append(&resultBlob, propertiesBlob); + bdlbb::BlobUtil::append(resultBlob_sp.get(), propertiesBlob); } else { BSLS_ASSERT_SAFE(!d_messagePropertiesInfo.isPresent()); @@ -351,10 +363,10 @@ bmqt::EventBuilderResult::Enum PutEventBuilder::packMessage(int queueId) // Add the payload if (d_rawPayload_p) { - bdlbb::BlobUtil::append(&bufferBlob, + bdlbb::BlobUtil::append(bufferBlob_sp.get(), d_rawPayload_p, d_rawPayloadLength); - payloadBlob = &bufferBlob; + payloadBlob = bufferBlob_sp.get(); } else { payloadBlob = d_blobPayload_p; @@ -363,28 +375,30 @@ bmqt::EventBuilderResult::Enum PutEventBuilder::packMessage(int queueId) // Compress if (payloadBlob->length() >= Protocol::k_COMPRESSION_MIN_APPDATA_SIZE && d_compressionAlgorithmType != bmqt::CompressionAlgorithmType::e_NONE) { - bdlbb::Blob compressedPayloadBlob(d_bufferFactory_p, d_allocator_p); + bsl::shared_ptr compressedPayloadBlob_sp = + d_blobSpPool_p->getObject(); bmqu::MemOutStream error(d_allocator_p); - int rc = Compression::compress(&compressedPayloadBlob, - d_bufferFactory_p, + int rc = Compression::compress(compressedPayloadBlob_sp.get(), + d_blob_sp->factory(), d_compressionAlgorithmType, *payloadBlob, &error, d_allocator_p); if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY( rc == Result::e_SUCCESS && - compressedPayloadBlob.length() < payloadBlob->length())) { + compressedPayloadBlob_sp->length() < payloadBlob->length())) { // Compression is successful and is worth using! // Keep track of the compression ratio. d_lastPackedMessageCompressionRatio = static_cast(payloadBlob->length()) / - compressedPayloadBlob.length(); - bdlbb::BlobUtil::append(&resultBlob, compressedPayloadBlob); - d_crc32c = Crc32c::calculate(resultBlob); + compressedPayloadBlob_sp->length(); + bdlbb::BlobUtil::append(resultBlob_sp.get(), + *compressedPayloadBlob_sp); + d_crc32c = Crc32c::calculate(*resultBlob_sp); - return packMessageInternal(resultBlob, queueId); // RETURN + return packMessageInternal(*resultBlob_sp, queueId); // RETURN } } @@ -392,13 +406,13 @@ bmqt::EventBuilderResult::Enum PutEventBuilder::packMessage(int queueId) // was bigger and not worth using. In either way, we fall back to using the // original blob. Explicitly set the 'd_compressionAlgorithmType' to // 'NONE'. - bdlbb::BlobUtil::append(&resultBlob, *payloadBlob); + bdlbb::BlobUtil::append(resultBlob_sp.get(), *payloadBlob); d_compressionAlgorithmType = bmqt::CompressionAlgorithmType::e_NONE; - d_crc32c = Crc32c::calculate(resultBlob); + d_crc32c = Crc32c::calculate(*resultBlob_sp); d_lastPackedMessageCompressionRatio = 1; - return packMessageInternal(resultBlob, queueId); + return packMessageInternal(*resultBlob_sp, queueId); } bmqt::EventBuilderResult::Enum PutEventBuilder::packMessageRaw(int queueId) @@ -414,14 +428,15 @@ bmqt::EventBuilderResult::Enum PutEventBuilder::packMessageRaw(int queueId) return packMessageInternal(*d_blobPayload_p, queueId); } -const bdlbb::Blob& PutEventBuilder::blob() const +const bsl::shared_ptr& PutEventBuilder::blob() const { // Fix packet's length in header now that we know it .. Following is valid // (see comment in reset) - EventHeader& eh = *reinterpret_cast(d_blob.buffer(0).data()); - eh.setLength(d_blob.length()); + EventHeader& eh = *reinterpret_cast( + d_blob_sp->buffer(0).data()); + eh.setLength(d_blob_sp->length()); - return d_blob; + return d_blob_sp; } const bmqp::MessageProperties* PutEventBuilder::messageProperties() const diff --git a/src/groups/bmq/bmqp/bmqp_puteventbuilder.h b/src/groups/bmq/bmqp/bmqp_puteventbuilder.h index 50675cf74a..ef8a7d4e22 100644 --- a/src/groups/bmq/bmqp/bmqp_puteventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_puteventbuilder.h @@ -40,8 +40,10 @@ /// Usage ///----- //.. -// bdlbb::PooledBlobBufferFactory bufferFactory(1024, d_allocator_p); -// bmqp::PutEventBuilder builder(&bufferFactory, d_allocator_p); +// bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p); +// bmqp::BlobPoolUtil::BlobSpPool blobSpPool( +// bmqp::BlobPoolUtil::createBlobPool(&bufferFactory, s_allocator_p)); +// bmqp::PutEventBuilder builder(&blobSpPool, d_allocator_p); // // // Append multiple messages // // (Error handling omitted below for brevity) @@ -51,16 +53,19 @@ // // // Repeat above steps if adding more messages to this event is desired. // -// const bdlbb::Blob& eventBlob = builder.blob(); +// const bsl::shared_ptr& eventBlob = builder.blob(); // // Send the blob ... // // // We can reset the builder to reuse it; note that this invalidates the -// // 'eventBlob' retrieved above +// // 'eventBlob' shared pointer reference retrieved above. To keep the +// // bdlbb::Blob valid the shared pointer should be copied, and the copy +// // should be passed and kept in IO components. // builder.reset(); //.. // // BMQ +#include #include #include #include @@ -90,6 +95,8 @@ class PutEventBuilder { // TYPES typedef bdlb::NullableValue NullableMsgGroupId; + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // TYPES /// Mechanism to automatically reset PutEventBuilder on a built message @@ -104,14 +111,15 @@ class PutEventBuilder { }; // DATA - bdlbb::BlobBufferFactory* d_bufferFactory_p; + /// Allocator to use. + bslma::Allocator* d_allocator_p; + + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; - mutable bdlbb::Blob d_blob; - // blob being built by this - // PutEventBuilder. - // This has been done mutable to be able to - // skip writing the length until the blob - // is retrieved. + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; bool d_msgStarted; // has startMessage been called @@ -170,8 +178,6 @@ class PutEventBuilder { MessagePropertiesInfo d_messagePropertiesInfo; - bslma::Allocator* d_allocator_p; - private: // NOT IMPLEMENTED PutEventBuilder(const PutEventBuilder&) BSLS_CPP11_DELETED; @@ -194,10 +200,11 @@ class PutEventBuilder { public: // CREATORS - /// Create a new `PutEventBuilder` using the specified `bufferFactory` - /// and `allocator` for the blob. - PutEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator); + /// Create a new `PutEventBuilder` using the specified `blobSpPool_p` and + /// `allocator` for the blob. We require BlobSpPool to build Blobs with + /// set BlobBufferFactory since we might want to expand the built Blob + /// dynamically. + PutEventBuilder(BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); // MANIPULATORS @@ -336,10 +343,13 @@ class PutEventBuilder { /// message was not compressed, a value of 1 is returned. double lastPackedMesageCompressionRatio() const; - /// Return a reference not offering modifiable access to the blob built - /// by this event. If no messages were added, this will return a blob - /// composed only of an `EventHeader`. - const bdlbb::Blob& blob() const; + /// Return a reference to the shared pointer to the built Blob. If no + /// messages were added, the Blob object under this reference will be + /// empty. + /// Note that this accessor exposes an internal shared pointer object, and + /// it is the user's responsibility to make a copy of it if it needs to be + /// passed and kept in another thread while this builder object is used. + const bsl::shared_ptr& blob() const; const bmqp::MessageProperties* messageProperties() const; }; @@ -500,7 +510,7 @@ inline const bmqt::MessageGUID& PutEventBuilder::messageGUID() const inline int PutEventBuilder::eventSize() const { - return d_blob.length(); + return d_blob_sp->length(); } inline int PutEventBuilder::unpackedMessageSize() const diff --git a/src/groups/bmq/bmqp/bmqp_puteventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_puteventbuilder.t.cpp index 5360f805ce..72034c9793 100644 --- a/src/groups/bmq/bmqp/bmqp_puteventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_puteventbuilder.t.cpp @@ -217,6 +217,10 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); #ifdef BMQ_ENABLE_MSG_GROUPID const bmqp::Protocol::MsgGroupId k_MSG_GROUP_ID( "gid:0", @@ -257,7 +261,7 @@ static void test1_breathingTest() BSLS_ASSERT_OPT(k_NUM_PROPERTIES == msgProps.numProperties()); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.crc32c(), 0U); @@ -339,8 +343,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(rawEvent.isValid()); BSLS_ASSERT_OPT(rawEvent.isPutEvent()); @@ -441,7 +445,7 @@ static void test1_breathingTest() ASSERT_GT(obj.eventSize(), k_PAYLOAD_BIGGER_LEN); ASSERT_EQ(obj.messageCount(), 1); - rawEvent.reset(&obj.blob()); + rawEvent.reset(obj.blob().get()); rawEvent.loadPutMessageIterator(&putIter, true); ASSERT_EQ(1, putIter.next()); @@ -484,7 +488,7 @@ static void test1_breathingTest() BSLS_ASSERT_OPT(k_NUM_PROPERTIES == msgProps.numProperties()); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.crc32c(), 0U); @@ -566,8 +570,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(rawEvent.isValid()); BSLS_ASSERT_OPT(rawEvent.isPutEvent()); @@ -674,7 +678,7 @@ static void test1_breathingTest() ASSERT_LT(obj.eventSize(), k_PAYLOAD_BIGGER_LEN); ASSERT_EQ(obj.messageCount(), 1); - rawEvent.reset(&obj.blob()); + rawEvent.reset(obj.blob().get()); rawEvent.loadPutMessageIterator(&putIter, true); ASSERT_EQ(1, putIter.next()); @@ -717,7 +721,7 @@ static void test1_breathingTest() BSLS_ASSERT_OPT(k_NUM_PROPERTIES == msgProps.numProperties()); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.crc32c(), 0U); @@ -807,8 +811,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(rawEvent.isValid()); BSLS_ASSERT_OPT(rawEvent.isPutEvent()); @@ -921,7 +925,7 @@ static void test1_breathingTest() ASSERT_LT(obj.eventSize(), k_PAYLOAD_BIGGER_LEN); ASSERT_EQ(obj.messageCount(), 1); - rawEvent.reset(&obj.blob()); + rawEvent.reset(obj.blob().get()); rawEvent.loadPutMessageIterator(&putIter, true); ASSERT_EQ(1, putIter.next()); @@ -965,7 +969,7 @@ static void test1_breathingTest() BSLS_ASSERT_OPT(k_NUM_PROPERTIES == msgProps.numProperties()); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.crc32c(), 0U); @@ -1053,8 +1057,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(rawEvent.isValid()); BSLS_ASSERT_OPT(rawEvent.isPutEvent()); @@ -1157,7 +1161,7 @@ static void test1_breathingTest() ASSERT_GT(obj.eventSize(), k_PAYLOAD_LEN); ASSERT_EQ(obj.messageCount(), 1); - rawEvent.reset(&obj.blob()); + rawEvent.reset(obj.blob().get()); rawEvent.loadPutMessageIterator(&putIter, true); ASSERT_EQ(1, putIter.next()); @@ -1201,7 +1205,7 @@ static void test1_breathingTest() BSLS_ASSERT_OPT(k_NUM_PROPERTIES == msgProps.numProperties()); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.crc32c(), 0U); @@ -1283,8 +1287,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(rawEvent.isValid()); BSLS_ASSERT_OPT(rawEvent.isPutEvent()); @@ -1386,7 +1390,7 @@ static void test1_breathingTest() ASSERT_GT(obj.eventSize(), k_PAYLOAD_BIGGER_LEN); ASSERT_EQ(obj.messageCount(), 1); - rawEvent.reset(&obj.blob()); + rawEvent.reset(obj.blob().get()); rawEvent.loadPutMessageIterator(&putIter, true); ASSERT_EQ(1, putIter.next()); @@ -1419,7 +1423,7 @@ static void test1_breathingTest() PVV("DO NOT USE COMPRESSION FOR RELAYED PUT MESSAGES"); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.crc32c(), 0U); bmqu::MemOutStream error(bmqtst::TestHelperUtil::allocator()); @@ -1491,8 +1495,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(rawEvent.isValid()); BSLS_ASSERT_OPT(rawEvent.isPutEvent()); @@ -1575,7 +1579,7 @@ static void test1_breathingTest() ASSERT_GT(obj.eventSize(), payload.length()); ASSERT_EQ(obj.messageCount(), 1); - rawEvent.reset(&obj.blob()); + rawEvent.reset(obj.blob().get()); rawEvent.loadPutMessageIterator(&putIter, true); ASSERT_EQ(1, putIter.next()); @@ -1673,7 +1677,11 @@ static void test2_manipulators_one() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); // Properties. @@ -1734,8 +1742,8 @@ static void test2_manipulators_one() } // Iterate and check - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT_OPT(true == rawEvent.isValid()); BSLS_ASSERT_OPT(true == rawEvent.isPutEvent()); @@ -1821,6 +1829,10 @@ static void test3_eventTooBig() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bdlbb::Blob bigMsgPayload(&bufferFactory, bmqtst::TestHelperUtil::allocator()); #ifdef BMQ_ENABLE_MSG_GROUPID @@ -1839,7 +1851,7 @@ static void test3_eventTooBig() bigMsgPayload.length()); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); obj.startMessage(); @@ -1870,8 +1882,8 @@ static void test3_eventTooBig() // Get blob and use bmqp iterator to test. Note that bmqp event and bmqp // iterators are lower than bmqp builders, and thus, can be used to test // them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); BSLS_ASSERT(true == rawEvent.isPutEvent()); @@ -1933,7 +1945,11 @@ static void test4_manipulators_two() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); const size_t k_NUM_MSGS = 1000; @@ -1952,8 +1968,8 @@ static void test4_manipulators_two() } // Iterate and check - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); BSLS_ASSERT(true == rawEvent.isPutEvent()); @@ -2014,7 +2030,11 @@ static void test5_putEventWithZeroLengthMessage() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); @@ -2029,8 +2049,8 @@ static void test5_putEventWithZeroLengthMessage() ASSERT_EQ_D(0, rc, bmqt::EventBuilderResult::e_SUCCESS); // Iterate and check - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); BSLS_ASSERT(true == rawEvent.isPutEvent()); @@ -2065,6 +2085,10 @@ static void test6_emptyBuilder() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); #ifdef BMQ_ENABLE_MSG_GROUPID bmqp::Protocol::MsgGroupId k_MSG_GROUP_ID( "gid:0", @@ -2083,7 +2107,7 @@ static void test6_emptyBuilder() const char* k_PAYLOAD = "abcdefghijklmnopqrstuvwxyz"; - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.unpackedMessageSize(), 0); @@ -2155,6 +2179,10 @@ static void test7_multiplePackMessage() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); #ifdef BMQ_ENABLE_MSG_GROUPID const bmqp::Protocol::MsgGroupId k_MSG_GROUP_ID( "gid:0", @@ -2191,7 +2219,7 @@ static void test7_multiplePackMessage() ASSERT_EQ(k_NUM_PROPERTIES, msgProps.numProperties()); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(obj.crc32c(), 0U); @@ -2251,8 +2279,8 @@ static void test7_multiplePackMessage() // Get blob and use bmqp iterator to test. Note that bmqp event and // bmqp iterators are lower than bmqp builders, and thus, can be used // to test them. - const bdlbb::Blob& eventBlob = obj.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); ASSERT(rawEvent.isValid()); ASSERT(rawEvent.isPutEvent()); @@ -2344,7 +2372,7 @@ static void test7_multiplePackMessage() #endif ASSERT_EQ(obj.compressionAlgorithmType(), bmqt::CompressionAlgorithmType::e_NONE); - rawEvent.reset(&obj.blob()); + rawEvent.reset(obj.blob().get()); rawEvent.loadPutMessageIterator(&putIter, true); // we want to test the 3rd message so we call next thrice @@ -2399,6 +2427,10 @@ static void testN1_decodeFromFile() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bdlbb::Blob outBlob(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bdlbb::Blob payloadBlob(bmqtst::TestHelperUtil::allocator()); bmqu::MemOutStream os(bmqtst::TestHelperUtil::allocator()); @@ -2439,7 +2471,7 @@ static void testN1_decodeFromFile() bmqp::PutHeaderFlags::e_MESSAGE_PROPERTIES); // Create PutEventBuilder - bmqp::PutEventBuilder obj(&bufferFactory, + bmqp::PutEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); obj.startMessage(); @@ -2480,7 +2512,7 @@ static void testN1_decodeFromFile() BSLS_ASSERT(ofile.good() == true); - bdlbb::BlobUtil::copy(buf, obj.blob(), 0, obj.blob().length()); + bdlbb::BlobUtil::copy(buf, *obj.blob(), 0, obj.blob()->length()); ofile.write(buf, k_SIZE); ofile.close(); bsl::memset(buf, 0, k_SIZE); @@ -2499,9 +2531,9 @@ static void testN1_decodeFromFile() bdlbb::BlobBuffer dataBlobBuffer(dataBufferSp, k_SIZE); outBlob.appendDataBuffer(dataBlobBuffer); - outBlob.setLength(obj.blob().length()); + outBlob.setLength(obj.blob()->length()); - ASSERT_EQ(bdlbb::BlobUtil::compare(obj.blob(), outBlob), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*obj.blob(), outBlob), 0); // Decode event bmqp::Event rawEvent(&outBlob, bmqtst::TestHelperUtil::allocator()); diff --git a/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.cpp b/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.cpp index 943e79683d..b6a170da59 100644 --- a/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.cpp +++ b/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.cpp @@ -39,15 +39,21 @@ namespace bmqp { // -------------------------- // CREATORS -RecoveryEventBuilder::RecoveryEventBuilder( - bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator) -: d_blob(bufferFactory, allocator) +RecoveryEventBuilder::RecoveryEventBuilder(BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator) +: d_blobSpPool_p(blobSpPool_p) +, d_blob_sp(0, allocator) // initialized in `reset()` , d_msgCount(0) { // PRECONDITIONS - BSLS_ASSERT_SAFE(bufferFactory); - BSLS_ASSERT_SAFE(allocator); + BSLS_ASSERT_SAFE(blobSpPool_p); + + // Assume that items built with the given `blobSpPool_p` either all have or + // all don't have buffer factory, and check it once for a sample blob. + // We require this since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != blobSpPool_p->getObject()->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); reset(); } @@ -55,7 +61,8 @@ RecoveryEventBuilder::RecoveryEventBuilder( // MANIPULATORS void RecoveryEventBuilder::reset() { - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); + d_msgCount = 0; // NOTE: Since RecoveryEventBuilder owns the blob and we just reset it, we @@ -67,8 +74,8 @@ void RecoveryEventBuilder::reset() // Use placement new to create the object directly in the blob buffer, // while still calling it's constructor (to memset memory and initialize // some fields) - d_blob.setLength(sizeof(EventHeader)); - new (d_blob.buffer(0).data()) EventHeader(EventType::e_RECOVERY); + d_blob_sp->setLength(sizeof(EventHeader)); + new (d_blob_sp->buffer(0).data()) EventHeader(EventType::e_RECOVERY); } bmqt::EventBuilderResult::Enum @@ -103,9 +110,9 @@ RecoveryEventBuilder::packMessage(unsigned int partitionId, // Add RecoveryHeader bmqu::BlobPosition offset; - bmqu::BlobUtil::reserve(&offset, &d_blob, sizeof(RecoveryHeader)); + bmqu::BlobUtil::reserve(&offset, d_blob_sp.get(), sizeof(RecoveryHeader)); - bmqu::BlobObjectProxy recoveryHeader(&d_blob, + bmqu::BlobObjectProxy recoveryHeader(d_blob_sp.get(), offset, false, // no read true); // write mode @@ -139,26 +146,25 @@ RecoveryEventBuilder::packMessage(unsigned int partitionId, if (0 != payloadLen) { // Per bdlbb::Blob contract, specifying a buffer of zero length in // 'appendDataBuffer' is undefined. - d_blob.appendDataBuffer(chunkBuffer); + d_blob_sp->appendDataBuffer(chunkBuffer); } ++d_msgCount; return bmqt::EventBuilderResult::e_SUCCESS; } -const bdlbb::Blob& RecoveryEventBuilder::blob() const +const bsl::shared_ptr& RecoveryEventBuilder::blob() const { - if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(messageCount() == 0)) { - BSLS_PERFORMANCEHINT_UNLIKELY_HINT; - return ProtocolUtil::emptyBlob(); // RETURN - } + // PRECONDITIONS + BSLS_ASSERT_SAFE(d_blob_sp->length() <= EventHeader::k_MAX_SIZE_SOFT); // Fix packet's length in header now that we know it .. Following is valid // (see comment in reset) - EventHeader& eh = *reinterpret_cast(d_blob.buffer(0).data()); - eh.setLength(d_blob.length()); + EventHeader& eh = *reinterpret_cast( + d_blob_sp->buffer(0).data()); + eh.setLength(d_blob_sp->length()); - return d_blob; + return d_blob_sp; } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.h b/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.h index c5a28fd4f4..789e12512b 100644 --- a/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.h @@ -42,25 +42,29 @@ /// Usage ///----- //.. -// bdlbb::PooledBlobBufferFactory bufferFactory(1024, d_allocator_p); -// bmqp::RecoveryEventBuilder builder(&bufferFactory, d_allocator_p); +// bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p); +// bmqp::BlobPoolUtil::BlobSpPool blobSpPool( +// bmqp::BlobPoolUtil::createBlobPool(&bufferFactory, s_allocator_p)); +// bmqp::RecoveryEventBuilder builder(&blobSpPool, d_allocator_p); // // // Append multiple messages // builder.appendMessage(0, 1, bmqt::MessageGUID(), 1); // builder.appendMessage(-1, 2, bmqt::MessageGUID(), 1); // -// const bdlbb::Blob& eventBlob = builder.blob(); +// const bsl::shared_ptr& eventBlob = builder.blob(); // // Send the blob ... // // // We can reset the builder to reuse it; note that this invalidates the -// // 'eventBlob' retrieved above +// // 'eventBlob' shared pointer reference retrieved above. To keep the +// // bdlbb::Blob valid the shared pointer should be copied, and the copy +// // should be passed and kept in IO components. // builder.reset(); // //.. // // BMQ - +#include #include #include @@ -81,13 +85,19 @@ namespace bmqp { /// Mechanism to build a BlazingMQ RECOVERY event class RecoveryEventBuilder BSLS_CPP11_FINAL { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // DATA - mutable bdlbb::Blob d_blob; // blob being built by this - // PushEventBuilder - // This has been done mutable to be able to - // skip writing the length until the blob - // is retrieved. + + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; + + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; int d_msgCount; // number of messages currently in the // event @@ -106,10 +116,12 @@ class RecoveryEventBuilder BSLS_CPP11_FINAL { public: // CREATORS - /// Create a new `RecoveryEventBuilder` instance using the specified - /// `bufferFactory` and `allocator` for the blob - RecoveryEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator); + /// Create a new `RecoveryEventBuilder` using the specified `blobSpPool_p` + /// and `allocator` for the blob. We require BlobSpPool to build Blobs + /// with set BlobBufferFactory since we might want to expand the built Blob + /// dynamically. + RecoveryEventBuilder(BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator); // MANIPULATORS @@ -141,10 +153,11 @@ class RecoveryEventBuilder BSLS_CPP11_FINAL { /// Return the number of messages currently in the event being built. int messageCount() const; - /// Return a reference not offering modifiable access to the blob built - /// by this event. If no messages were added, this will return an empty - /// blob, i.e., a blob with length == 0. - const bdlbb::Blob& blob() const; + /// Return a reference to the shared pointer to the built Blob. + /// Note that this accessor exposes an internal shared pointer object, and + /// it is the user's responsibility to make a copy of it if it needs to be + /// passed and kept in another thread while this builder object is used. + const bsl::shared_ptr& blob() const; }; // ============================================================================ @@ -158,7 +171,7 @@ class RecoveryEventBuilder BSLS_CPP11_FINAL { // ACCESSORS inline int RecoveryEventBuilder::eventSize() const { - return d_blob.length(); + return d_blob_sp->length(); } inline int RecoveryEventBuilder::messageCount() const diff --git a/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.t.cpp index 20a6bdb9a5..85678ac0f8 100644 --- a/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_recoveryeventbuilder.t.cpp @@ -115,6 +115,10 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); const char* CHUNK = "abcdefghijklmnopqrstuvwx"; // Note that chunk must be word aligned per RecoveryEventBuilder's @@ -126,7 +130,7 @@ static void test1_breathingTest() // Create RecoveryEventBuilder. - bmqp::RecoveryEventBuilder reb(&bufferFactory, + bmqp::RecoveryEventBuilder reb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(reb.eventSize())); ASSERT_EQ(reb.messageCount(), 0); @@ -149,9 +153,8 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test. Note that bmqp event and bmqp // iterators are lower than bmqp builders, and thus, can be used to test // them. - - const bdlbb::Blob& eventBlob = reb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(reb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); BSLS_ASSERT(true == rawEvent.isRecoveryEvent()); @@ -179,7 +182,7 @@ static void test1_breathingTest() ASSERT_EQ(recoveryIter.loadChunkPosition(&position), 0); int res, compareResult; res = bmqu::BlobUtil::compareSection(&compareResult, - eventBlob, + *reb.blob(), position, CHUNK, CHUNK_LEN); @@ -206,7 +209,11 @@ static void test2_multipleMessagesTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::RecoveryEventBuilder reb(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RecoveryEventBuilder reb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); const size_t NUM_MSGS = 1000; @@ -221,8 +228,8 @@ static void test2_multipleMessagesTest() } // Iterate and check - const bdlbb::Blob& eventBlob = reb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(reb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); BSLS_ASSERT(true == rawEvent.isRecoveryEvent()); @@ -259,7 +266,7 @@ static void test2_multipleMessagesTest() int res, compareResult; res = bmqu::BlobUtil::compareSection(&compareResult, - eventBlob, + *reb.blob(), chunkPosition, D.d_chunk.c_str(), D.d_chunk.size()); @@ -286,7 +293,11 @@ static void test3_eventTooBigTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::RecoveryEventBuilder reb(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RecoveryEventBuilder reb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::string bigChunk(bmqtst::TestHelperUtil::allocator()); bigChunk.resize(bmqp::RecoveryHeader::k_MAX_PAYLOAD_SIZE_SOFT + 4, 'a'); @@ -330,8 +341,8 @@ static void test3_eventTooBigTest() static_cast(reb.eventSize())); ASSERT_EQ(reb.messageCount(), 1); - const bdlbb::Blob& eventBlob = reb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(reb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); BSLS_ASSERT(true == rawEvent.isRecoveryEvent()); @@ -356,7 +367,7 @@ static void test3_eventTooBigTest() ASSERT_EQ(recoveryIter.loadChunkPosition(&position), 0); int res, compareResult; res = bmqu::BlobUtil::compareSection(&compareResult, - eventBlob, + *reb.blob(), position, k_SMALL_CHUNK, k_SMALL_CHUNK_LEN); @@ -378,7 +389,11 @@ static void test4_emptyPayloadTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); - bmqp::RecoveryEventBuilder reb(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RecoveryEventBuilder reb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::shared_ptr chunkBufferSp( @@ -399,8 +414,8 @@ static void test4_emptyPayloadTest() // static_cast(reb.eventSize())); ASSERT_EQ(reb.messageCount(), 1); - const bdlbb::Blob& eventBlob = reb.blob(); - bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(reb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); BSLS_ASSERT(true == rawEvent.isRecoveryEvent()); diff --git a/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.cpp b/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.cpp index 0cbea16b07..e6ae0d4d9e 100644 --- a/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.cpp +++ b/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.cpp @@ -34,17 +34,31 @@ namespace bmqp { // class RejectEventBuilder // ------------------------ -RejectEventBuilder::RejectEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator) -: d_blob(bufferFactory, allocator) +RejectEventBuilder::RejectEventBuilder(BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator) +: d_blobSpPool_p(blobSpPool_p) +, d_blob_sp(0, allocator) // initialized in `reset()` +, d_emptyBlob_sp(0, allocator) // initialized later in constructor , d_msgCount(0) { + // PRECONDITIONS + BSLS_ASSERT_SAFE(blobSpPool_p); + + d_emptyBlob_sp = blobSpPool_p->getObject(); + + // Assume that items built with the given `blobSpPool_p` either all have or + // all don't have buffer factory, and check it once for `d_emptyBlob_sp`. + // We require this since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != blobSpPool_p->getObject()->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); + reset(); } void RejectEventBuilder::reset() { - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); d_msgCount = 0; @@ -57,16 +71,16 @@ void RejectEventBuilder::reset() // RejectHeader Use placement new to create the object directly in the // blob buffer, while still calling it's constructor (to memset memory and // initialize some fields). - d_blob.setLength(sizeof(EventHeader) + sizeof(RejectHeader)); - BSLS_ASSERT_SAFE(d_blob.numDataBuffers() == 1 && + d_blob_sp->setLength(sizeof(EventHeader) + sizeof(RejectHeader)); + BSLS_ASSERT_SAFE(d_blob_sp->numDataBuffers() == 1 && "The buffers allocated by the supplied bufferFactory " "are too small"); // EventHeader - new (d_blob.buffer(0).data()) EventHeader(EventType::e_REJECT); + new (d_blob_sp->buffer(0).data()) EventHeader(EventType::e_REJECT); // RejectHeader - new (d_blob.buffer(0).data() + sizeof(EventHeader)) RejectHeader(); + new (d_blob_sp->buffer(0).data() + sizeof(EventHeader)) RejectHeader(); } bmqt::EventBuilderResult::Enum @@ -86,9 +100,9 @@ RejectEventBuilder::appendMessage(int queueId, // Resize the blob to have space for an 'RejectMessage' at the end ... bmqu::BlobPosition offset; - bmqu::BlobUtil::reserve(&offset, &d_blob, sizeof(RejectMessage)); + bmqu::BlobUtil::reserve(&offset, d_blob_sp.get(), sizeof(RejectMessage)); - bmqu::BlobObjectProxy rejectMessage(&d_blob, + bmqu::BlobObjectProxy rejectMessage(d_blob_sp.get(), offset, false, // no read true); // write mode @@ -108,23 +122,24 @@ RejectEventBuilder::appendMessage(int queueId, return bmqt::EventBuilderResult::e_SUCCESS; } -const bdlbb::Blob& RejectEventBuilder::blob() const +const bsl::shared_ptr& RejectEventBuilder::blob() const { // PRECONDITIONS - BSLS_ASSERT_SAFE(d_blob.length() <= EventHeader::k_MAX_SIZE_SOFT); + BSLS_ASSERT_SAFE(d_blob_sp->length() <= EventHeader::k_MAX_SIZE_SOFT); // Empty event if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(messageCount() == 0)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; - return ProtocolUtil::emptyBlob(); // RETURN + return d_emptyBlob_sp; // RETURN } // Fix packet's length in header now that we know it. Following is valid // (see comment in reset). - EventHeader& eh = *reinterpret_cast(d_blob.buffer(0).data()); - eh.setLength(d_blob.length()); + EventHeader& eh = *reinterpret_cast( + d_blob_sp->buffer(0).data()); + eh.setLength(d_blob_sp->length()); - return d_blob; + return d_blob_sp; } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.h b/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.h index e3cadec7c2..46e814a339 100644 --- a/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.h @@ -41,24 +41,28 @@ /// Usage ///----- //.. -// bdlbb::BlobPooledBlobBufferFactory bufferFactory(1024, d_allocator_p); -// bmqp::RejectEventBuilder builder(&bufferFactory, d_allocator_p); +// bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p); +// bmqp::BlobPoolUtil::BlobSpPool blobSpPool( +// bmqp::BlobPoolUtil::createBlobPool(&bufferFactory, s_allocator_p)); +// bmqp::RejectEventBuilder builder(&blobSpPool, d_allocator_p); // // // Append multiple messages, from same or different queue // builder.appendMessage(k_QUEUEID1, k_SUBQUEUEID1, bmqt::MessageGUID(), 5); // builder.appendMessage(k_QUEUEID2, k_SUBQUEUEID2, bmqt::MessageGUID(), 16); // -// const bdlbb::Blob& eventBlob = builder.blob(); +// const bsl::shared_ptr& eventBlob = builder.blob(); // // Send the blob ... // // // We can reset the builder to reuse it; note that this invalidates the -// // 'eventBlob' retrieved above +// // 'eventBlob' shared pointer reference retrieved above. To keep the +// // bdlbb::Blob valid the shared pointer should be copied, and the copy +// // should be passed and kept in IO components. // builder.reset(); // //.. // BMQ - +#include #include #include #include @@ -79,12 +83,22 @@ namespace bmqp { /// Mechanism to build a BlazingMQ REJECT event class RejectEventBuilder { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // DATA - mutable bdlbb::Blob d_blob; // blob being built by this object - // This has been done mutable to be able to - // skip writing the length until the blob - // is retrieved. + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; + + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; + + /// Empty blob to be returned when no messages were added to this builder. + bsl::shared_ptr d_emptyBlob_sp; + int d_msgCount; // number of messages currently in the // event @@ -104,10 +118,11 @@ class RejectEventBuilder { public: // CREATORS - /// Create a new `RejectEventBuilder` using the specified - /// `bufferFactory` and `allocator` for the blob. - RejectEventBuilder(bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator); + /// Create a new `RejectEventBuilder` using the specified `blobSpPool_p` + /// and `allocator` for the blob. We require BlobSpPool to build Blobs + /// with set BlobBufferFactory since we might want to expand the built Blob + /// dynamically. + RejectEventBuilder(BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); // MANIPULATORS @@ -136,10 +151,13 @@ class RejectEventBuilder { /// were added, this will return 0. int eventSize() const; - /// Return a reference not offering modifiable access to the blob built - /// by this event. If no messages were added, this will return an empty - /// blob, i.e., a blob with length == 0.*/ - const bdlbb::Blob& blob() const; + /// Return a reference to the shared pointer to the built Blob. If no + /// messages were added, the Blob object under this reference will be + /// empty. + /// Note that this accessor exposes an internal shared pointer object, and + /// it is the user's responsibility to make a copy of it if it needs to be + /// passed and kept in another thread while this builder object is used. + const bsl::shared_ptr& blob() const; }; // ============================================================================ @@ -170,7 +188,7 @@ inline int RejectEventBuilder::eventSize() const return 0; // RETURN } - return d_blob.length(); + return d_blob_sp->length(); } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.t.cpp index 1863401fab..4aaf424892 100644 --- a/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_rejecteventbuilder.t.cpp @@ -95,10 +95,11 @@ static void verifyContent(const bmqp::RejectEventBuilder& builder, (data.size() * sizeof(bmqp::RejectMessage)); ASSERT_EQ(static_cast(builder.messageCount()), data.size()); ASSERT_EQ(static_cast(builder.eventSize()), expectedSize); - ASSERT_EQ(static_cast(builder.blob().length()), expectedSize); + ASSERT_EQ(static_cast(builder.blob()->length()), expectedSize); PVV("Iterating over messages"); - bmqp::Event event(&builder.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event event(builder.blob().get(), + bmqtst::TestHelperUtil::allocator()); ASSERT(event.isValid()); ASSERT(event.isRejectEvent()); @@ -137,7 +138,11 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::RejectEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RejectEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -145,7 +150,7 @@ static void test1_breathingTest() ASSERT_EQ(obj.messageCount(), 0); ASSERT_NE(obj.maxMessageCount(), 0); ASSERT_EQ(obj.eventSize(), 0); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); PVV("Appending one message"); appendMessages(&obj, &messages, 1); @@ -164,7 +169,11 @@ static void test2_multiMessage() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::RejectEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RejectEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -183,7 +192,11 @@ static void test3_reset() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::RejectEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RejectEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); @@ -196,7 +209,7 @@ static void test3_reset() PV("Verifying accessors"); ASSERT_EQ(obj.messageCount(), 0); ASSERT_EQ(obj.eventSize(), 0); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); PV("Appending another message"); messages.clear(); @@ -215,7 +228,11 @@ static void test4_capacity() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::RejectEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RejectEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); PVV("Computing max message"); @@ -271,7 +288,11 @@ static void testN1_decodeFromFile() bdlbb::PooledBlobBufferFactory bufferFactory( 256, bmqtst::TestHelperUtil::allocator()); - bmqp::RejectEventBuilder obj(&bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::RejectEventBuilder obj(&blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector messages(bmqtst::TestHelperUtil::allocator()); bdlbb::Blob outBlob(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -282,11 +303,11 @@ static void testN1_decodeFromFile() PVV("Appending messages"); appendMessages(&obj, &messages, k_NUM_MSGS); - ASSERT_NE(obj.blob().length(), 0); + ASSERT_NE(obj.blob()->length(), 0); os << "msg_reject_" << guid << ".bin" << bsl::ends; - const int blobLen = obj.blob().length(); + const int blobLen = obj.blob()->length(); char* buf = new char[blobLen]; /// Functor invoked to delete the file at the specified `filePath` @@ -306,7 +327,7 @@ static void testN1_decodeFromFile() bsl::ofstream ofile(os.str().data(), bsl::ios::binary); BSLS_ASSERT(ofile.good()); - bdlbb::BlobUtil::copy(buf, obj.blob(), 0, blobLen); + bdlbb::BlobUtil::copy(buf, *obj.blob(), 0, blobLen); ofile.write(buf, blobLen); ofile.close(); bsl::memset(buf, 0, blobLen); @@ -326,7 +347,7 @@ static void testN1_decodeFromFile() outBlob.appendDataBuffer(dataBlobBuffer); outBlob.setLength(blobLen); - ASSERT_EQ(bdlbb::BlobUtil::compare(obj.blob(), outBlob), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*obj.blob(), outBlob), 0); // Decode event bmqp::Event event(&outBlob, bmqtst::TestHelperUtil::allocator()); diff --git a/src/groups/bmq/bmqp/bmqp_requestmanager.h b/src/groups/bmq/bmqp/bmqp_requestmanager.h index 6121729e76..3888cc3068 100644 --- a/src/groups/bmq/bmqp/bmqp_requestmanager.h +++ b/src/groups/bmq/bmqp/bmqp_requestmanager.h @@ -596,12 +596,14 @@ template class RequestManager { public: // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; /// Signature of a method to send a request, represented by the /// specified `blob`. Return 0 on success, and a non-zero value /// otherwise, populating the optionally specified `status` with /// information pertaining to the error. - typedef bsl::function + typedef bsl::function& blob)> SendFn; typedef RequestManagerRequest RequestType; @@ -696,12 +698,13 @@ class RequestManager { private: // PRIVATE MANIPULATORS - /// Send the specified `blob` over the specified `channel` using the + /// Send the specified `blob_sp` over the specified `channel` using the /// specified `watermark`. Return a Generic Result code representing /// the status of delivery of this request. - static bmqt::GenericResult::Enum sendHelper(bmqio::Channel* channel, - const bdlbb::Blob& blob, - bsls::Types::Int64 watermark); + static bmqt::GenericResult::Enum + sendHelper(bmqio::Channel* channel, + const bsl::shared_ptr& blob_sp, + bsls::Types::Int64 watermark); /// Callback invoked by the scheduler when the request identified by the /// specified `requestId` has timedout. @@ -730,31 +733,31 @@ class RequestManager { // CREATORS - /// Create a new object using the specified `bufferFactory`, `scheduler` + /// Create a new object using the specified `blobSpPool_p`, `scheduler` /// and `executor` and the provided `allocator` for memory allocation. /// Events sent will be of the specified `eventType`. If `executor` is /// specified, it will be used around the invocation of the callback /// when a request times out. Note that `scheduler` must be /// configured to use the `bsls::SystemClockType::e_MONOTONIC` clock /// type. - RequestManager(bmqp::EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bdlmt::EventScheduler* scheduler, - bool lateResponseMode, - bslma::Allocator* allocator = 0); - RequestManager(bmqp::EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bdlmt::EventScheduler* scheduler, - bool lateResponseMode, - const bmqex::Executor& executor, - bslma::Allocator* allocator = 0); - RequestManager(bmqp::EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bdlmt::EventScheduler* scheduler, - bool lateResponseMode, - const bmqex::Executor& executor, - const DTContextSp& dtContextSp, - bslma::Allocator* allocator = 0); + RequestManager(bmqp::EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bdlmt::EventScheduler* scheduler, + bool lateResponseMode, + bslma::Allocator* allocator = 0); + RequestManager(bmqp::EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bdlmt::EventScheduler* scheduler, + bool lateResponseMode, + const bmqex::Executor& executor, + bslma::Allocator* allocator = 0); + RequestManager(bmqp::EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bdlmt::EventScheduler* scheduler, + bool lateResponseMode, + const bmqex::Executor& executor, + const DTContextSp& dtContextSp, + bslma::Allocator* allocator = 0); /// Destroy this object. ~RequestManager(); @@ -1042,13 +1045,13 @@ const bdld::Datum& RequestManagerRequest::userData() const // -------------------- template -inline bmqt::GenericResult::Enum -RequestManager::sendHelper(bmqio::Channel* channel, - const bdlbb::Blob& blob, - bsls::Types::Int64 watermark) +inline bmqt::GenericResult::Enum RequestManager::sendHelper( + bmqio::Channel* channel, + const bsl::shared_ptr& blob_sp, + bsls::Types::Int64 watermark) { bmqio::Status status; - channel->write(&status, blob, watermark); + channel->write(&status, *blob_sp, watermark); switch (status.category()) { case bmqio::StatusCategory::e_SUCCESS: @@ -1192,17 +1195,17 @@ void RequestManager::applyResponse(const RequestSp& request, template RequestManager::RequestManager( - bmqp::EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bdlmt::EventScheduler* scheduler, - bool lateResponseMode, - bslma::Allocator* allocator) + bmqp::EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bdlmt::EventScheduler* scheduler, + bool lateResponseMode, + bslma::Allocator* allocator) : d_allocator_p(allocator) , d_eventType(eventType) , d_scheduler_p(scheduler) , d_nextRequestId(0) , d_requests(allocator) -, d_schemaEventBuilder(bufferFactory, allocator) +, d_schemaEventBuilder(blobSpPool_p, bmqp::EncodingType::e_BER, allocator) , d_lateResponseMode(lateResponseMode) , d_executor(bmqex::SystemExecutor()) // Use SystemExecutor so that when using // 'possiblyBlocking' it will inline @@ -1218,18 +1221,18 @@ RequestManager::RequestManager( template RequestManager::RequestManager( - bmqp::EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bdlmt::EventScheduler* scheduler, - bool lateResponseMode, - const bmqex::Executor& executor, - bslma::Allocator* allocator) + bmqp::EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bdlmt::EventScheduler* scheduler, + bool lateResponseMode, + const bmqex::Executor& executor, + bslma::Allocator* allocator) : d_allocator_p(allocator) , d_eventType(eventType) , d_scheduler_p(scheduler) , d_nextRequestId(0) , d_requests(allocator) -, d_schemaEventBuilder(bufferFactory, allocator) +, d_schemaEventBuilder(blobSpPool_p, bmqp::EncodingType::e_BER, allocator) , d_lateResponseMode(lateResponseMode) , d_executor(executor) , d_dtContext_sp(NULL) @@ -1242,19 +1245,19 @@ RequestManager::RequestManager( template RequestManager::RequestManager( - bmqp::EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bdlmt::EventScheduler* scheduler, - bool lateResponseMode, - const bmqex::Executor& executor, - const DTContextSp& dtContext, - bslma::Allocator* allocator) + bmqp::EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bdlmt::EventScheduler* scheduler, + bool lateResponseMode, + const bmqex::Executor& executor, + const DTContextSp& dtContext, + bslma::Allocator* allocator) : d_allocator_p(allocator) , d_eventType(eventType) , d_scheduler_p(scheduler) , d_nextRequestId(0) , d_requests(allocator) -, d_schemaEventBuilder(bufferFactory, allocator) +, d_schemaEventBuilder(blobSpPool_p, bmqp::EncodingType::e_BER, allocator) , d_lateResponseMode(lateResponseMode) , d_executor(executor) , d_dtContext_sp(dtContext) diff --git a/src/groups/bmq/bmqp/bmqp_requestmanager.t.cpp b/src/groups/bmq/bmqp/bmqp_requestmanager.t.cpp index 814b041dc2..6d4a6715bf 100644 --- a/src/groups/bmq/bmqp/bmqp_requestmanager.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_requestmanager.t.cpp @@ -111,6 +111,9 @@ struct TestClock { class TestContext { bdlbb::PooledBlobBufferFactory d_blobBufferFactory; + /// Blob pool used to provide blobs to event builders. + bmqp::BlobPoolUtil::BlobSpPool d_blobSpPool; + TestClock d_testClock; // Pointer to struct to initialize system time @@ -201,11 +204,13 @@ class TestContext { TestContext::TestContext(bool lateResponseMode, bslma::Allocator* allocator) : d_blobBufferFactory(1024, allocator) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(&d_blobBufferFactory, allocator)) , d_testClock(allocator) , d_scheduler(d_testClock.d_scheduler) , d_testChannel(allocator) , d_requestManager(bmqp::EventType::e_CONTROL, - &d_blobBufferFactory, + &d_blobSpPool, &d_scheduler, lateResponseMode, allocator) @@ -381,6 +386,10 @@ static void test1_creatorsTest() bdlbb::PooledBlobBufferFactory blobBufferFactory( 4096, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &blobBufferFactory, + bmqtst::TestHelperUtil::allocator())); { // Wrong clock type @@ -388,7 +397,7 @@ static void test1_creatorsTest() bmqtst::TestHelperUtil::allocator()); ASSERT_SAFE_FAIL(ReqManagerType(bmqp::EventType::e_CONTROL, - &blobBufferFactory, + &blobSpPool, &scheduler, false, // late response mode is off bmqtst::TestHelperUtil::allocator())); @@ -400,20 +409,20 @@ static void test1_creatorsTest() bmqtst::TestHelperUtil::allocator()); ASSERT_PASS(ReqManagerType(bmqp::EventType::e_CONTROL, - &blobBufferFactory, + &blobSpPool, &scheduler, false, // late response mode is off bmqtst::TestHelperUtil::allocator())); ASSERT_PASS(ReqManagerType(bmqp::EventType::e_CONTROL, - &blobBufferFactory, + &blobSpPool, &scheduler, false, // late response mode is off bmqex::SystemExecutor(), bmqtst::TestHelperUtil::allocator())); ASSERT_PASS(ReqManagerType(bmqp::EventType::e_CONTROL, - &blobBufferFactory, + &blobSpPool, &scheduler, false, // late response mode is off bmqex::SystemExecutor(), @@ -465,10 +474,12 @@ static void test4_sendRequestTest() /// specified `request`, and set the specified `called` flag to true struct Caller { static bmqt::GenericResult::Enum - sendFn(bool* called, const bdlbb::Blob& blob, const ReqSp& request) + sendFn(bool* called, + const bsl::shared_ptr& blob_sp, + const ReqSp& request) { *called = true; - bmqp::Event ev(&blob, bmqtst::TestHelperUtil::allocator()); + bmqp::Event ev(blob_sp.get(), bmqtst::TestHelperUtil::allocator()); ASSERT(ev.isControlEvent()); Mes controlMessage(bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(0, ev.loadControlEvent(&controlMessage)); diff --git a/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.h b/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.h index e419405aeb..e19932a04a 100644 --- a/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.h @@ -65,10 +65,9 @@ //.. // BMQ - +#include #include #include - #include // BDE @@ -93,20 +92,32 @@ namespace bmqp { /// Mechanism to build a BlazingMQ schema event class SchemaEventBuilder { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("BMQP.SCHEMAEVENTBUILDER"); - private: // DATA + /// Allocator to use. bslma::Allocator* d_allocator_p; - // Allocator to use by this object. - mutable bdlbb::Blob d_blob; - // blob containing the event under construction. - // This has been done mutable to be able to skip - // writing the length until the blob is retrieved. + + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; + + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; + + /// Error stream used to report errors when building a blob. + /// This stream is a field to prevent reallocations of the internal stream + /// buffer on multiple `SchemaEventBuilder::setMessage` calls. + bmqu::MemOutStream d_errorStream; + + /// Encoding type for encoding the message EncodingType::Enum d_encodingType; - // Encoding type for encoding the message private: // NOT IMPLEMENTED @@ -123,14 +134,15 @@ class SchemaEventBuilder { // CREATORS - /// Constructor of a `SchemaEventBuilder` using the specified - /// `bufferFactory` and `allocator` for the internal blob data member, - /// and the optionally specified `encodingType` (default to `ber`) for - /// encoding the message. - SchemaEventBuilder( - bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator, - bmqp::EncodingType::Enum encodingType = bmqp::EncodingType::e_BER); + /// Create a new `SchemaEventBuilder` using the specified `blobSpPool_p` + /// for the blob. Use the optionally specified `encodingType` (default to + /// `ber`) for encoding the message. We require BlobSpPool to build Blobs + /// with set BlobBufferFactory since we might want to expand the built Blob + /// dynamically. Use the optionally specified `allocator`. + explicit SchemaEventBuilder( + BlobSpPool* blobSpPool_p, + bmqp::EncodingType::Enum encodingType = bmqp::EncodingType::e_BER, + bslma::Allocator* allocator = 0); // MANIPULATORS @@ -151,7 +163,7 @@ class SchemaEventBuilder { /// Note that if `setMessage` has not been called on this /// SchemaEventBuilder, or if `reset` has been called since, the blob /// returned will be an empty one. - const bdlbb::Blob& blob() const; + const bsl::shared_ptr& blob() const; }; // ============================= @@ -178,26 +190,36 @@ struct SchemaEventBuilderUtil { // ------------------------ inline SchemaEventBuilder::SchemaEventBuilder( - bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator, - bmqp::EncodingType::Enum encodingType) + BlobSpPool* blobSpPool_p, + bmqp::EncodingType::Enum encodingType, + bslma::Allocator* allocator) : d_allocator_p(allocator) -, d_blob(bufferFactory, allocator) +, d_blobSpPool_p(blobSpPool_p) +, d_blob_sp(0, allocator) // initialized in `reset()` +, d_errorStream(allocator) , d_encodingType(encodingType) { - // NOTHING + // PRECONDITIONS + BSLS_ASSERT_SAFE(blobSpPool_p); + + reset(); } inline void SchemaEventBuilder::reset() { - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); + + // The following prerequisite is necessary since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != d_blob_sp->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); } template int SchemaEventBuilder::setMessage(const TYPE& message, EventType::Enum type) { // PRECONDITIONS - BSLS_ASSERT_SAFE(d_blob.length() == 0); // Ensure the blob is empty + BSLS_ASSERT_SAFE(d_blob_sp->length() == 0); // Ensure the blob is empty BSLS_ASSERT_SAFE(d_encodingType != EncodingType::e_UNKNOWN); BSLS_ASSERT_SAFE(type == EventType::e_CONTROL || (type == EventType::e_ELECTOR && @@ -214,12 +236,13 @@ int SchemaEventBuilder::setMessage(const TYPE& message, EventType::Enum type) // Ensure blob has enough space for an EventHeader. Use placement new to // create the object directly in the blob buffer, while still calling it's // constructor (to memset memory and initialize some fields) - d_blob.setLength(sizeof(EventHeader)); - BSLS_ASSERT_SAFE(d_blob.numDataBuffers() == 1 && + d_blob_sp->setLength(sizeof(EventHeader)); + BSLS_ASSERT_SAFE(d_blob_sp->numDataBuffers() == 1 && "The buffers allocated by the supplied bufferFactory " "are too small"); - EventHeader* eventHeader = new (d_blob.buffer(0).data()) EventHeader(type); + EventHeader* eventHeader = new (d_blob_sp->buffer(0).data()) + EventHeader(type); // Specify the encoding type in the EventHeader for control messages if (type == EventType::e_CONTROL) { @@ -228,15 +251,15 @@ int SchemaEventBuilder::setMessage(const TYPE& message, EventType::Enum type) } // Append appropriate encoding of 'message' to the blob - bmqu::MemOutStream os; - int rc = ProtocolUtil::encodeMessage(os, - &d_blob, + int rc = ProtocolUtil::encodeMessage(d_errorStream, + d_blob_sp.get(), message, d_encodingType, d_allocator_p); - if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(!os.isEmpty())) { + if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(!d_errorStream.isEmpty())) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; - BALL_LOG_DEBUG << os.str(); + BALL_LOG_DEBUG << d_errorStream.str(); + d_errorStream.clear(); } if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(rc != 0)) { @@ -246,13 +269,13 @@ int SchemaEventBuilder::setMessage(const TYPE& message, EventType::Enum type) } // Make sure the event is padded - ProtocolUtil::appendPadding(&d_blob, d_blob.length()); + ProtocolUtil::appendPadding(d_blob_sp.get(), d_blob_sp->length()); // Fix packet's length in header now that we know it .. - eventHeader->setLength(d_blob.length()); + eventHeader->setLength(d_blob_sp->length()); // Guard against too big events - if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(d_blob.length() > + if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(d_blob_sp->length() > EventHeader::k_MAX_SIZE_SOFT)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; reset(); @@ -262,13 +285,13 @@ int SchemaEventBuilder::setMessage(const TYPE& message, EventType::Enum type) return 0; } -inline const bdlbb::Blob& SchemaEventBuilder::blob() const +inline const bsl::shared_ptr& SchemaEventBuilder::blob() const { // PRECONDITIONS - BSLS_ASSERT_SAFE(d_blob.length() <= EventHeader::k_MAX_SIZE_SOFT); - BSLS_ASSERT_SAFE(d_blob.length() % 4 == 0); + BSLS_ASSERT_SAFE(d_blob_sp->length() <= EventHeader::k_MAX_SIZE_SOFT); + BSLS_ASSERT_SAFE(d_blob_sp->length() % 4 == 0); - return d_blob; + return d_blob_sp; } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.t.cpp index 0dfe0f7b45..451df724c6 100644 --- a/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_schemaeventbuilder.t.cpp @@ -58,6 +58,10 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); struct Test { int d_line; @@ -74,12 +78,12 @@ static void test1_breathingTest() const Test& test = k_DATA[idx]; PVV(test.d_line << ": Testing " << test.d_encodingType << "encoding"); - bmqp::SchemaEventBuilder obj(&bufferFactory, - bmqtst::TestHelperUtil::allocator(), - test.d_encodingType); + bmqp::SchemaEventBuilder obj(&blobSpPool, + test.d_encodingType, + bmqtst::TestHelperUtil::allocator()); PVV(test.d_line << ": Verifying accessors"); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); PVV(test.d_line << ": Create a message"); bmqp_ctrlmsg::ControlMessage message( @@ -91,11 +95,12 @@ static void test1_breathingTest() // Encode the message rc = obj.setMessage(message, bmqp::EventType::e_CONTROL); ASSERT_EQ(rc, 0); - ASSERT_NE(obj.blob().length(), 0); - ASSERT_EQ(obj.blob().length() % 4, 0); + ASSERT_NE(obj.blob()->length(), 0); + ASSERT_EQ(obj.blob()->length() % 4, 0); PVV(test.d_line << ": Decode and compare message"); - bmqp::Event event(&obj.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event event(obj.blob().get(), + bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(event.isValid(), true); ASSERT_EQ(event.isControlEvent(), true); @@ -111,7 +116,7 @@ static void test1_breathingTest() PVV("Reset"); obj.reset(); - ASSERT_EQ(obj.blob().length(), 0); + ASSERT_EQ(obj.blob()->length(), 0); } } @@ -133,7 +138,7 @@ void testDecodeFromFileHelper(bmqp::SchemaEventBuilder* obj, // Encode the message rc = obj->setMessage(message, bmqp::EventType::e_CONTROL); ASSERT_EQ(rc, 0); - ASSERT_NE(obj->blob().length(), 0); + ASSERT_NE(obj->blob()->length(), 0); bmqu::MemOutStream os(bmqtst::TestHelperUtil::allocator()); bdlb::Guid guid = bdlb::GuidUtil::generate(); @@ -156,15 +161,15 @@ void testDecodeFromFileHelper(bmqp::SchemaEventBuilder* obj, BSLS_ASSERT(ofile.good() == true); - const int blobLen = obj->blob().length(); + const int blobLen = obj->blob()->length(); char* buf = new char[blobLen]; - bdlbb::BlobUtil::copy(buf, obj->blob(), 0, blobLen); + bdlbb::BlobUtil::copy(buf, *obj->blob(), 0, blobLen); ofile.write(buf, blobLen); ofile.close(); bsl::memset(buf, 0, blobLen); obj->reset(); - ASSERT_EQ(obj->blob().length(), 0); + ASSERT_EQ(obj->blob()->length(), 0); // Read blob from file bsl::ifstream ifile(os.str().data(), bsl::ios::binary); @@ -281,6 +286,10 @@ static void testN1_decodeFromFile() bdlbb::PooledBlobBufferFactory bufferFactory( k_SIZE, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); struct Test { int d_line; @@ -297,9 +306,9 @@ static void testN1_decodeFromFile() const Test& test = k_DATA[idx]; PVV(test.d_line << ": Testing " << test.d_encodingType << " encoding"); - bmqp::SchemaEventBuilder obj(&bufferFactory, - bmqtst::TestHelperUtil::allocator(), - test.d_encodingType); + bmqp::SchemaEventBuilder obj(&blobSpPool, + test.d_encodingType, + bmqtst::TestHelperUtil::allocator()); PVV(test.d_line << ": Status message"); { diff --git a/src/groups/bmq/bmqp/bmqp_storageeventbuilder.cpp b/src/groups/bmq/bmqp/bmqp_storageeventbuilder.cpp index 445649fd5d..13a54e84d4 100644 --- a/src/groups/bmq/bmqp/bmqp_storageeventbuilder.cpp +++ b/src/groups/bmq/bmqp/bmqp_storageeventbuilder.cpp @@ -68,9 +68,9 @@ bmqt::EventBuilderResult::Enum StorageEventBuilder::packMessageImp( // Add the StorageHeader bmqu::BlobPosition offset; - bmqu::BlobUtil::reserve(&offset, &d_blob, sizeof(StorageHeader)); + bmqu::BlobUtil::reserve(&offset, d_blob_sp.get(), sizeof(StorageHeader)); - bmqu::BlobObjectProxy storageHeader(&d_blob, + bmqu::BlobObjectProxy storageHeader(d_blob_sp.get(), offset, false, // no read true); // write mode @@ -91,11 +91,11 @@ bmqt::EventBuilderResult::Enum StorageEventBuilder::packMessageImp( storageHeader.reset(); // i.e., flush writing to blob.. - d_blob.appendDataBuffer(journalRecordBuffer); + d_blob_sp->appendDataBuffer(journalRecordBuffer); if (StorageMessageType::e_DATA == messageType || StorageMessageType::e_QLIST == messageType) { - d_blob.appendDataBuffer(payloadBuffer); + d_blob_sp->appendDataBuffer(payloadBuffer); } ++d_msgCount; @@ -103,26 +103,38 @@ bmqt::EventBuilderResult::Enum StorageEventBuilder::packMessageImp( } // CREATORS -StorageEventBuilder::StorageEventBuilder( - int storageProtocolVersion, - EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator) -: d_storageProtocolVersion(storageProtocolVersion) +StorageEventBuilder::StorageEventBuilder(int storageProtocolVersion, + EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator) +: d_blobSpPool_p(blobSpPool_p) +, d_storageProtocolVersion(storageProtocolVersion) , d_eventType(eventType) -, d_blob(bufferFactory, allocator) +, d_blob_sp(0, allocator) // initialized in `reset()` +, d_emptyBlob_sp(0, allocator) // initialized later in constructor , d_msgCount(0) { // PRECONDITIONS + BSLS_ASSERT_SAFE(blobSpPool_p); BSLS_ASSERT_SAFE(EventType::e_STORAGE == eventType || EventType::e_PARTITION_SYNC == eventType); + + d_emptyBlob_sp = blobSpPool_p->getObject(); + + // Assume that items built with the given `blobSpPool_p` either all have or + // all don't have buffer factory, and check it once for `d_emptyBlob_sp`. + // We require this since we do `Blob::setLength`: + BSLS_ASSERT_SAFE( + NULL != d_emptyBlob_sp->factory() && + "Passed BlobSpPool must build Blobs with set BlobBufferFactory"); + reset(); } // MANIPULATORS void StorageEventBuilder::reset() { - d_blob.removeAll(); + d_blob_sp = d_blobSpPool_p->getObject(); d_msgCount = 0; // NOTE: Since StorageEventBuilder owns the blob and we just reset it, we @@ -134,8 +146,8 @@ void StorageEventBuilder::reset() // Use placement new to create the object directly in the blob buffer, // while still calling it's constructor (to memset memory and initialize // some fields) - d_blob.setLength(sizeof(EventHeader)); - new (d_blob.buffer(0).data()) EventHeader(d_eventType); + d_blob_sp->setLength(sizeof(EventHeader)); + new (d_blob_sp->buffer(0).data()) EventHeader(d_eventType); } bmqt::EventBuilderResult::Enum @@ -168,8 +180,10 @@ StorageEventBuilder::packMessageRaw(const bdlbb::Blob& blob, } if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY( - 0 != - bmqu::BlobUtil::appendToBlob(&d_blob, blob, startPos, length))) { + 0 != bmqu::BlobUtil::appendToBlob(d_blob_sp.get(), + blob, + startPos, + length))) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; return bmqt::EventBuilderResult::e_UNKNOWN; // RETURN } @@ -178,19 +192,23 @@ StorageEventBuilder::packMessageRaw(const bdlbb::Blob& blob, return bmqt::EventBuilderResult::e_SUCCESS; } -const bdlbb::Blob& StorageEventBuilder::blob() const +const bsl::shared_ptr& StorageEventBuilder::blob() const { + // PRECONDITIONS + BSLS_ASSERT_SAFE(d_blob_sp->length() <= EventHeader::k_MAX_SIZE_SOFT); + if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(messageCount() == 0)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; - return ProtocolUtil::emptyBlob(); // RETURN + return d_emptyBlob_sp; // RETURN } // Fix packet's length in header now that we know it .. Following is valid // (see comment in reset) - EventHeader& eh = *reinterpret_cast(d_blob.buffer(0).data()); - eh.setLength(d_blob.length()); + EventHeader& eh = *reinterpret_cast( + d_blob_sp->buffer(0).data()); + eh.setLength(d_blob_sp->length()); - return d_blob; + return d_blob_sp; } } // close package namespace diff --git a/src/groups/bmq/bmqp/bmqp_storageeventbuilder.h b/src/groups/bmq/bmqp/bmqp_storageeventbuilder.h index c9fbd45e0d..84b3015f73 100644 --- a/src/groups/bmq/bmqp/bmqp_storageeventbuilder.h +++ b/src/groups/bmq/bmqp/bmqp_storageeventbuilder.h @@ -42,25 +42,29 @@ /// Usage ///----- //.. -// bdlbb::PooledBlobBufferFactory bufferFactory(1024, d_allocator_p); -// bmqp::StorageEventBuilder builder(&bufferFactory, d_allocator_p); +// bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p); +// bmqp::BlobPoolUtil::BlobSpPool blobSpPool( +// bmqp::BlobPoolUtil::createBlobPool(&bufferFactory, s_allocator_p)); +// bmqp::StorageEventBuilder builder(&blobSpPool, d_allocator_p); // // // Append multiple messages // builder.packMessage(...); -// builder.packMessage(...; +// builder.packMessage(...); // -// const bdlbb::Blob& eventBlob = builder.blob(); +// const bsl::shared_ptr& eventBlob = builder.blob(); // // Send the blob ... // // // We can reset the builder to reuse it; note that this invalidates the -// // 'eventBlob' retrieved above +// // 'eventBlob' shared pointer reference retrieved above. To keep the +// // bdlbb::Blob valid the shared pointer should be copied, and the copy +// // should be passed and kept in IO components. // builder.reset(); // //.. // // BMQ - +#include #include #include #include @@ -69,6 +73,7 @@ // BDE #include +#include #include #include #include @@ -86,18 +91,26 @@ namespace bmqp { /// Mechanism to build a BlazingMQ STORAGE event class StorageEventBuilder BSLS_CPP11_FINAL { + public: + /// Pool of shared pointers to Blobs + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // DATA + BlobSpPool* d_blobSpPool_p; + int d_storageProtocolVersion; // file storage protocol version EventType::Enum d_eventType; // Event type, either 'e_STORAGE' or 'e_PARTITION_SYNC' - mutable bdlbb::Blob d_blob; - // blob being built by this PushEventBuilder. - // This has been done mutable to be able to skip - // writing the length until the blob is retrieved. + /// Blob being built by this object. + /// `mutable` to skip writing the length until the blob is retrieved. + mutable bsl::shared_ptr d_blob_sp; + + /// Empty blob to be returned when no messages were added to this builder. + bsl::shared_ptr d_emptyBlob_sp; int d_msgCount; // number of messages currently in the event @@ -133,10 +146,10 @@ class StorageEventBuilder BSLS_CPP11_FINAL { /// blob, and operating with the specified `storageProtocolVersion`. /// Behavior is undefined unless `eventType` is `e_STORAGE` or /// `e_PARTITION_SYNC`. - StorageEventBuilder(int storageProtocolVersion, - EventType::Enum eventType, - bdlbb::BlobBufferFactory* bufferFactory, - bslma::Allocator* allocator); + StorageEventBuilder(int storageProtocolVersion, + EventType::Enum eventType, + BlobSpPool* blobSpPool_p, + bslma::Allocator* allocator); // MANIPULATORS @@ -193,10 +206,13 @@ class StorageEventBuilder BSLS_CPP11_FINAL { /// Return the number of messages currently in the event being built. int messageCount() const; - /// Return a reference not offering modifiable access to the blob built - /// by this event. If no messages were added, this will return an empty - /// blob, i.e., a blob with length == 0. - const bdlbb::Blob& blob() const; + /// Return a reference to the shared pointer to the built Blob. If no + /// messages were added, the Blob object under this reference will be + /// empty. + /// Note that this accessor exposes an internal shared pointer object, and + /// it is the user's responsibility to make a copy of it if it needs to be + /// passed and kept in another thread while this builder object is used. + const bsl::shared_ptr& blob() const; }; // ============================================================================ @@ -272,7 +288,7 @@ inline EventType::Enum StorageEventBuilder::eventType() const inline int StorageEventBuilder::eventSize() const { - return d_blob.length(); + return d_blob_sp->length(); } inline int StorageEventBuilder::messageCount() const diff --git a/src/groups/bmq/bmqp/bmqp_storageeventbuilder.t.cpp b/src/groups/bmq/bmqp/bmqp_storageeventbuilder.t.cpp index dc2675908e..7c1747b00d 100644 --- a/src/groups/bmq/bmqp/bmqp_storageeventbuilder.t.cpp +++ b/src/groups/bmq/bmqp/bmqp_storageeventbuilder.t.cpp @@ -187,6 +187,10 @@ static void test1_breathingTest() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); const char* PAYLOAD = "abcdefghijklmnopqrstuvwx"; const unsigned int PAYLOAD_LEN = bsl::strlen(PAYLOAD); // 24 const char* JOURNAL_REC = "12345678"; @@ -198,7 +202,7 @@ static void test1_breathingTest() // Create StorageEventBuilder bmqp::StorageEventBuilder seb(1, // storage protocol version bmqp::EventType::e_STORAGE, - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); ASSERT_EQ(seb.eventSize(), static_cast(sizeof(bmqp::EventHeader))); ASSERT_EQ(seb.messageCount(), 0); @@ -230,7 +234,7 @@ static void test1_breathingTest() // Get blob and use bmqp iterator to test // Note that bmqp event and bmqp iterators are lower than bmqp builders, // and thus, can be used to test them. - const bdlbb::Blob& eventBlob = seb.blob(); + const bdlbb::Blob& eventBlob = *seb.blob(); bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); @@ -290,9 +294,14 @@ static void test2_storageEventHavingMultipleMessages() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); + bmqp::StorageEventBuilder seb(k_SPV, bmqp::EventType::e_STORAGE, - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); const size_t NUM_MSGS = 1000; @@ -308,7 +317,7 @@ static void test2_storageEventHavingMultipleMessages() } // Iterate and check - const bdlbb::Blob& eventBlob = seb.blob(); + const bdlbb::Blob& eventBlob = *seb.blob(); bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); @@ -380,6 +389,10 @@ static void test3_packMessage_payloadTooBig() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); const int k_SPV = 1; // Storage proto version const char* PAYLOAD = "abcdefghijklmnopqrstuvwx"; @@ -390,7 +403,7 @@ static void test3_packMessage_payloadTooBig() bmqp::StorageEventBuilder seb(k_SPV, bmqp::EventType::e_STORAGE, - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::string bigPayload(bmqtst::TestHelperUtil::allocator()); bigPayload.resize(bmqp::StorageHeader::k_MAX_PAYLOAD_SIZE_SOFT + 4, 'a'); @@ -446,7 +459,7 @@ static void test3_packMessage_payloadTooBig() static_cast(seb.eventSize())); ASSERT_EQ(seb.messageCount(), 1); - const bdlbb::Blob& eventBlob = seb.blob(); + const bdlbb::Blob& eventBlob = *seb.blob(); bmqp::Event rawEvent(&eventBlob, bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEvent.isValid()); @@ -515,9 +528,13 @@ static void test4_packMessageRaw() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::StorageEventBuilder sebA(k_SPV, bmqp::EventType::e_STORAGE, - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); bsl::vector data(bmqtst::TestHelperUtil::allocator()); const size_t NUM_MSGS = 1000; @@ -532,7 +549,7 @@ static void test4_packMessageRaw() ASSERT_EQ_D(dataIdx, rc, bmqt::EventBuilderResult::e_SUCCESS); } - const bdlbb::Blob& eventA = sebA.blob(); + const bdlbb::Blob& eventA = *sebA.blob(); bmqp::Event rawEventA(&eventA, bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(rawEventA.isValid() == true); BSLS_ASSERT(rawEventA.isStorageEvent() == true); @@ -546,7 +563,7 @@ static void test4_packMessageRaw() // Iterate over event 'A', and create event 'B' using 'packMessageRaw'. bmqp::StorageEventBuilder sebB(k_SPV, bmqp::EventType::e_STORAGE, - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); while (1 == iterA.next() && dataIndex < NUM_MSGS) { @@ -568,7 +585,7 @@ static void test4_packMessageRaw() ASSERT_EQ(iterA.isValid(), false); // Finally, iterate over event 'B' and verify. - const bdlbb::Blob& eventB = sebB.blob(); + const bdlbb::Blob& eventB = *sebB.blob(); bmqp::Event rawEventB(&eventB, bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(true == rawEventB.isValid()); @@ -648,9 +665,13 @@ static void test5_packMessageRaw_emptyMessage() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bmqp::StorageEventBuilder seb(k_SPV, bmqp::EventType::e_STORAGE, - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); bdlbb::Blob emptyBlob(&bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -662,7 +683,7 @@ static void test5_packMessageRaw_emptyMessage() // Above we packMessageRaw with 'length' of 10 because we need an // arbitrary 'length > 0' to not trigger an assert and at the same time // ensure that packing an empty blob succeeds. - ASSERT_EQ(bdlbb::BlobUtil::compare(seb.blob(), emptyBlob), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*seb.blob(), emptyBlob), 0); ASSERT_EQ(seb.messageCount(), 0); ASSERT_EQ(seb.eventSize(), static_cast(sizeof(bmqp::EventHeader))); } @@ -689,11 +710,15 @@ static void test6_packMessageRaw_invalidPosition() bdlbb::PooledBlobBufferFactory bufferFactory( 1024, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); bdlbb::Blob k_EMPTY_BLOB(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bmqp::StorageEventBuilder seb(k_SPV, bmqp::EventType::e_STORAGE, - &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()); // 1. @@ -709,7 +734,7 @@ static void test6_packMessageRaw_invalidPosition() bmqu::BlobPosition invalidPosition(-1, -1); ASSERT_NE(seb.packMessageRaw(message, invalidPosition, message.length()), bmqt::EventBuilderResult::e_SUCCESS); - ASSERT_EQ(bdlbb::BlobUtil::compare(seb.blob(), k_EMPTY_BLOB), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*seb.blob(), k_EMPTY_BLOB), 0); ASSERT_EQ(seb.messageCount(), 0); ASSERT_EQ(seb.eventSize(), static_cast(sizeof(bmqp::EventHeader))); } diff --git a/src/groups/bmq/bmqp/package/bmqp.mem b/src/groups/bmq/bmqp/package/bmqp.mem index 16aaa2608b..5798c8f901 100644 --- a/src/groups/bmq/bmqp/package/bmqp.mem +++ b/src/groups/bmq/bmqp/package/bmqp.mem @@ -1,5 +1,6 @@ bmqp_ackeventbuilder bmqp_ackmessageiterator +bmqp_blobpoolutil bmqp_compression bmqp_confirmeventbuilder bmqp_confirmmessageiterator diff --git a/src/groups/mqb/mqba/mqba_adminsession.cpp b/src/groups/mqb/mqba/mqba_adminsession.cpp index 2bf5caea2d..364f4d1930 100644 --- a/src/groups/mqb/mqba/mqba_adminsession.cpp +++ b/src/groups/mqb/mqba/mqba_adminsession.cpp @@ -106,15 +106,13 @@ bmqp_ctrlmsg::ClientIdentity* extractClientIdentity( // struct AdminSessionState // ------------------------- -AdminSessionState::AdminSessionState(BlobSpPool* blobSpPool, - bdlbb::BlobBufferFactory* bufferFactory, - bmqp::EncodingType::Enum encodingType, - bslma::Allocator* allocator) +AdminSessionState::AdminSessionState(BlobSpPool* blobSpPool, + bmqp::EncodingType::Enum encodingType, + bslma::Allocator* allocator) : d_allocator_p(allocator) , d_dispatcherClientData() -, d_bufferFactory_p(bufferFactory) , d_blobSpPool_p(blobSpPool) -, d_schemaEventBuilder(bufferFactory, allocator, encodingType) +, d_schemaEventBuilder(blobSpPool, encodingType, allocator) { // PRECONDITIONS BSLS_ASSERT_SAFE(encodingType != bmqp::EncodingType::e_UNKNOWN); @@ -135,7 +133,7 @@ void AdminSession::sendPacket() bdlb::ScopeExitAny resetBlobScopeGuard( bdlf::BindUtil::bind(&bmqp::SchemaEventBuilder::reset, &d_state.d_schemaEventBuilder)); - const bdlbb::Blob& blob = d_state.d_schemaEventBuilder.blob(); + const bdlbb::Blob& blob = *d_state.d_schemaEventBuilder.blob(); // This method is the centralized *single* place where we should try to // send data to the client over the channel. @@ -194,7 +192,7 @@ void AdminSession::finalizeAdminCommand( // PRECONDITIONS BSLS_ASSERT_SAFE(dispatcher()->inDispatcherThread(this)); BSLS_ASSERT_SAFE(adminCommandCtrlMsg.choice().isAdminCommandValue()); - BSLS_ASSERT_SAFE(d_state.d_schemaEventBuilder.blob().length() == 0); + BSLS_ASSERT_SAFE(d_state.d_schemaEventBuilder.blob()->length() == 0); // Send success/error response to client bdlma::LocalSequentialAllocator<2048> localAllocator( @@ -274,7 +272,6 @@ AdminSession::AdminSession( const bsl::string& sessionDescription, mqbi::Dispatcher* dispatcher, AdminSessionState::BlobSpPool* blobSpPool, - bdlbb::BlobBufferFactory* bufferFactory, bdlmt::EventScheduler* scheduler, const mqbnet::Session::AdminCommandEnqueueCb& adminCb, bslma::Allocator* allocator) @@ -285,7 +282,6 @@ AdminSession::AdminSession( , d_description(sessionDescription, allocator) , d_channel_sp(channel) , d_state(blobSpPool, - bufferFactory, bmqp::SchemaEventBuilderUtil::bestEncodingSupported( d_clientIdentity_p->features()), allocator) diff --git a/src/groups/mqb/mqba/mqba_adminsession.h b/src/groups/mqb/mqba/mqba_adminsession.h index 135ed3db05..a05a127e56 100644 --- a/src/groups/mqb/mqba/mqba_adminsession.h +++ b/src/groups/mqb/mqba/mqba_adminsession.h @@ -92,9 +92,6 @@ struct AdminSessionState { // Dispatcher client data associated to // this session. - bdlbb::BlobBufferFactory* d_bufferFactory_p; - // Blob buffer factory to use. - BlobSpPool* d_blobSpPool_p; // Pool of shared pointers to blob to // use. @@ -118,14 +115,13 @@ struct AdminSessionState { // CREATORS - /// Constructor of a new session state using the specified `dispatcher`, - /// `blobSpPool` and `bufferFactory`. The specified `encodingType` is - /// the encoding which the schema event builder will use. Memory - /// allocations are performed using the specified `allocator`. - AdminSessionState(BlobSpPool* blobSpPool, - bdlbb::BlobBufferFactory* bufferFactory, - bmqp::EncodingType::Enum encodingType, - bslma::Allocator* allocator); + /// Constructor of a new session state using the specified `dispatcher` and + /// `blobSpPool`. The specified `encodingType` is the encoding which the + /// schema event builder will use. Memory allocations are performed using + /// the specified `allocator`. + AdminSessionState(BlobSpPool* blobSpPool, + bmqp::EncodingType::Enum encodingType, + bslma::Allocator* allocator); }; // ================== @@ -230,20 +226,18 @@ class AdminSession : public mqbnet::Session, public mqbi::DispatcherClient { // CREATORS /// Constructor of a new session associated to the specified `channel` - /// and using the specified `dispatcher`, `blobSpPool`, `bufferFactory` - /// and `scheduler`. The specified `negotiationMessage` represents the - /// identity received from the peer during negotiation, and the - /// specified `sessionDescription` is the short form description of the - /// session. Memory allocations are performed using the specified - /// `allocator`. The specified `adminEnqueueCb` callback is used to - /// enqueue admin commands to entity that is responsible for executing - /// admin commands. + /// and using the specified `dispatcher`, `blobSpPool` and `scheduler`. + /// The specified `negotiationMessage` represents the identity received + /// from the peer during negotiation, and the specified + /// `sessionDescription` is the short form description of the session. + /// Memory allocations are performed using the specified `allocator`. + /// The specified `adminEnqueueCb` callback is used to enqueue admin + /// commands to entity that is responsible for executing admin commands. AdminSession(const bsl::shared_ptr& channel, const bmqp_ctrlmsg::NegotiationMessage& negotiationMessage, const bsl::string& sessionDescription, mqbi::Dispatcher* dispatcher, AdminSessionState::BlobSpPool* blobSpPool, - bdlbb::BlobBufferFactory* bufferFactory, bdlmt::EventScheduler* scheduler, const mqbnet::Session::AdminCommandEnqueueCb& adminEnqueueCb, bslma::Allocator* allocator); diff --git a/src/groups/mqb/mqba/mqba_adminsession.t.cpp b/src/groups/mqb/mqba/mqba_adminsession.t.cpp index ede1669913..3e0ce6eeb1 100644 --- a/src/groups/mqb/mqba/mqba_adminsession.t.cpp +++ b/src/groups/mqb/mqba/mqba_adminsession.t.cpp @@ -171,7 +171,6 @@ class TestBench { "sessionDescription", setInDispatcherThread(&d_mockDispatcher), &d_blobSpPool, - &d_bufferFactory, &d_scheduler, adminEnqueueCb, allocator) @@ -251,14 +250,14 @@ static void test1_watermark() admin.choice().makeAdminCommand(); admin.choice().adminCommand().command() = command; - bmqp::SchemaEventBuilder builder(&tb.d_bufferFactory, - tb.d_allocator_p, - bmqp::EncodingType::e_JSON); + bmqp::SchemaEventBuilder builder(&tb.d_blobSpPool, + bmqp::EncodingType::e_JSON, + tb.d_allocator_p); int rc = builder.setMessage(admin, bmqp::EventType::e_CONTROL); ASSERT_EQ(rc, 0); - bmqp::Event adminEvent(&builder.blob(), + bmqp::Event adminEvent(builder.blob().get(), bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(adminEvent.isValid()); BSLS_ASSERT(adminEvent.isControlEvent()); diff --git a/src/groups/mqb/mqba/mqba_clientsession.cpp b/src/groups/mqb/mqba/mqba_clientsession.cpp index 278e7f8988..636eec3168 100644 --- a/src/groups/mqb/mqba/mqba_clientsession.cpp +++ b/src/groups/mqb/mqba/mqba_clientsession.cpp @@ -356,9 +356,9 @@ ClientSessionState::ClientSessionState( , d_statContext_mp(clientStatContext) , d_bufferFactory_p(bufferFactory) , d_blobSpPool_p(blobSpPool) -, d_schemaEventBuilder(bufferFactory, allocator, encodingType) -, d_pushBuilder(bufferFactory, allocator) -, d_ackBuilder(bufferFactory, allocator) +, d_schemaEventBuilder(blobSpPool, encodingType, allocator) +, d_pushBuilder(blobSpPool, allocator) +, d_ackBuilder(blobSpPool, allocator) , d_throttledFailedAckMessages() , d_throttledFailedPutMessages() { @@ -422,7 +422,8 @@ void ClientSession::sendErrorResponse( sendPacketDispatched(d_state.d_schemaEventBuilder.blob(), true); } -void ClientSession::sendPacket(const bdlbb::Blob& blob, bool flushBuilders) +void ClientSession::sendPacket(const bsl::shared_ptr& blob, + bool flushBuilders) { dispatcher()->execute( bdlf::BindUtil::bind(&ClientSession::sendPacketDispatched, @@ -432,8 +433,9 @@ void ClientSession::sendPacket(const bdlbb::Blob& blob, bool flushBuilders) this); } -void ClientSession::sendPacketDispatched(const bdlbb::Blob& blob, - bool flushBuilders) +void ClientSession::sendPacketDispatched( + const bsl::shared_ptr& blob, + bool flushBuilders) { // executed by the *CLIENT* dispatcher thread @@ -484,7 +486,7 @@ void ClientSession::sendPacketDispatched(const bdlbb::Blob& blob, // the message to the channelBufferQueue, and we'll send it later, once we // get the lowWatermark notification. bmqio::Status status; - d_channel_sp->write(&status, blob); + d_channel_sp->write(&status, *blob); if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY( status.category() != bmqio::StatusCategory::e_SUCCESS)) { BSLS_PERFORMANCEHINT_UNLIKELY_HINT; @@ -496,7 +498,7 @@ void ClientSession::sendPacketDispatched(const bdlbb::Blob& blob, if (status.category() == bmqio::StatusCategory::e_LIMIT) { BALL_LOG_WARN << "#CLIENT_SEND_FAILURE " << description() << ": Failed to send data [size: " - << bmqu::PrintUtil::prettyNumber(blob.length()) + << bmqu::PrintUtil::prettyNumber(blob->length()) << " bytes] to client due to channel watermark limit" << "; enqueuing to the ChannelBufferQueue."; d_state.d_channelBufferQueue.push_back(blob); @@ -504,7 +506,7 @@ void ClientSession::sendPacketDispatched(const bdlbb::Blob& blob, else { BALL_LOG_INFO << "#CLIENT_SEND_FAILURE " << description() << ": Failed to send data [size: " - << bmqu::PrintUtil::prettyNumber(blob.length()) + << bmqu::PrintUtil::prettyNumber(blob->length()) << " bytes] to client with status: " << status; } } @@ -527,10 +529,11 @@ void ClientSession::flushChannelBufferQueue() // Try to send as many data as possible while (!d_state.d_channelBufferQueue.empty()) { - const bdlbb::Blob& blob = d_state.d_channelBufferQueue.front(); + const bsl::shared_ptr& blob_sp = + d_state.d_channelBufferQueue.front(); bmqio::Status status; - d_channel_sp->write(&status, blob); + d_channel_sp->write(&status, *blob_sp); if (status.category() == bmqio::StatusCategory::e_LIMIT) { // We are hitting the limit again, can't continue.. stop sending // and we'll resume with the next lowWatermark notification. diff --git a/src/groups/mqb/mqba/mqba_clientsession.h b/src/groups/mqb/mqba/mqba_clientsession.h index 47c9e7ada3..7e7d9f762d 100644 --- a/src/groups/mqb/mqba/mqba_clientsession.h +++ b/src/groups/mqb/mqba/mqba_clientsession.h @@ -155,7 +155,7 @@ struct ClientSessionState { bslma::Allocator* d_allocator_p; // Allocator to use. - bsl::deque d_channelBufferQueue; + bsl::deque > d_channelBufferQueue; // Queue of data pending being sent to // the client. This should almost // always be empty, and is meant to @@ -183,8 +183,10 @@ struct ClientSessionState { // context for any queue in this // domain. + /// Blob buffer factory to use. + /// TODO: this field should be removed once we retire the code for + /// message properties conversion. bdlbb::BlobBufferFactory* d_bufferFactory_p; - // Blob buffer factory to use. BlobSpPool* d_blobSpPool_p; // Pool of shared pointers to blob to @@ -427,8 +429,10 @@ class ClientSession : public mqbnet::Session, /// ACK) will be flushed and sent before `blob`; this is necessary to /// guarantee strict serialization of events when sending a control /// message. - void sendPacket(const bdlbb::Blob& blob, bool flushBuilders); - void sendPacketDispatched(const bdlbb::Blob& blob, bool flushBuilders); + void sendPacket(const bsl::shared_ptr& blob, + bool flushBuilders); + void sendPacketDispatched(const bsl::shared_ptr& blob, + bool flushBuilders); /// Flush as much as possible of the content of the internal /// `channelBufferQueue`. diff --git a/src/groups/mqb/mqba/mqba_clientsession.t.cpp b/src/groups/mqb/mqba/mqba_clientsession.t.cpp index fd280523a2..d2046f8c48 100644 --- a/src/groups/mqb/mqba/mqba_clientsession.t.cpp +++ b/src/groups/mqb/mqba/mqba_clientsession.t.cpp @@ -762,7 +762,9 @@ class TestBench { /// this testbench's `ClientSession`. void openQueue(const bsl::string& uri, const int queueId) { - bmqp::SchemaEventBuilder obj(&d_bufferFactory, d_allocator_p); + bmqp::SchemaEventBuilder obj(&d_blobSpPool, + bmqp::EncodingType::e_BER, + d_allocator_p); bmqp_ctrlmsg::ControlMessage controlMessage(d_allocator_p); bmqp_ctrlmsg::OpenQueue& openQueue = controlMessage.choice().makeOpenQueue(); @@ -778,7 +780,7 @@ class TestBench { int rc = obj.setMessage(controlMessage, bmqp::EventType::e_CONTROL); ASSERT_EQ(rc, 0); - bmqp::Event event(&obj.blob(), d_allocator_p); + bmqp::Event event(obj.blob().get(), d_allocator_p); d_cs.processEvent(event); } @@ -787,7 +789,9 @@ class TestBench { /// this testbench's `ClientSession`. void closeQueue(const bsl::string& uri, const int queueId) { - bmqp::SchemaEventBuilder obj(&d_bufferFactory, d_allocator_p); + bmqp::SchemaEventBuilder obj(&d_blobSpPool, + bmqp::EncodingType::e_BER, + d_allocator_p); bmqp_ctrlmsg::ControlMessage controlMessage(d_allocator_p); bmqp_ctrlmsg::CloseQueue& closeQueue = controlMessage.choice().makeCloseQueue(); @@ -804,7 +808,7 @@ class TestBench { int rc = obj.setMessage(controlMessage, bmqp::EventType::e_CONTROL); ASSERT_EQ(rc, 0); - bmqp::Event event(&obj.blob(), d_allocator_p); + bmqp::Event event(obj.blob().get(), d_allocator_p); d_cs.processEvent(event); } @@ -1908,7 +1912,7 @@ static void test9_newStylePush() bmqp::MessageProperties in(bmqtst::TestHelperUtil::allocator()); encode(&in); - bmqp::PutEventBuilder peb(&tb.d_bufferFactory, + bmqp::PutEventBuilder peb(&tb.d_blobSpPool, bmqtst::TestHelperUtil::allocator()); bdlbb::Blob payload(&tb.d_bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -1927,7 +1931,8 @@ static void test9_newStylePush() ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); mqbi::DispatcherEvent putEvent(bmqtst::TestHelperUtil::allocator()); - bmqp::Event rawEvent(&peb.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(rawEvent.isValid()); BSLS_ASSERT(rawEvent.isPutEvent()); @@ -1937,17 +1942,11 @@ static void test9_newStylePush() rawEvent.loadPutMessageIterator(&putIt, false); BSLS_ASSERT(putIt.next()); - bsl::shared_ptr blobSp; - blobSp.createInplace(bmqtst::TestHelperUtil::allocator(), - &tb.d_bufferFactory, - bmqtst::TestHelperUtil::allocator()); - *blobSp = peb.blob(); - putEvent.setType(mqbi::DispatcherEventType::e_PUT) .setIsRelay(true) // Relay message .setSource(&tb.d_cs) // DispatcherClient *value .setPutHeader(putIt.header()) - .setBlob(blobSp); // const bsl::shared_ptr& value + .setBlob(peb.blob()); // const bsl::shared_ptr& value tb.dispatch(putEvent); @@ -2023,7 +2022,7 @@ static void test10_newStyleCompressedPush() bmqp::MessageProperties in(bmqtst::TestHelperUtil::allocator()); encode(&in); - bmqp::PutEventBuilder peb(&tb.d_bufferFactory, + bmqp::PutEventBuilder peb(&tb.d_blobSpPool, bmqtst::TestHelperUtil::allocator()); bdlbb::Blob payload(&tb.d_bufferFactory, bmqtst::TestHelperUtil::allocator()); @@ -2043,7 +2042,8 @@ static void test10_newStyleCompressedPush() ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); mqbi::DispatcherEvent putEvent(bmqtst::TestHelperUtil::allocator()); - bmqp::Event rawEvent(&peb.blob(), bmqtst::TestHelperUtil::allocator()); + bmqp::Event rawEvent(peb.blob().get(), + bmqtst::TestHelperUtil::allocator()); BSLS_ASSERT(rawEvent.isValid()); BSLS_ASSERT(rawEvent.isPutEvent()); @@ -2053,17 +2053,11 @@ static void test10_newStyleCompressedPush() rawEvent.loadPutMessageIterator(&putIt, false); BSLS_ASSERT(putIt.next()); - bsl::shared_ptr blobSp; - blobSp.createInplace(bmqtst::TestHelperUtil::allocator(), - &tb.d_bufferFactory, - bmqtst::TestHelperUtil::allocator()); - *blobSp = peb.blob(); - putEvent.setType(mqbi::DispatcherEventType::e_PUT) .setIsRelay(true) // Relay message .setSource(&tb.d_cs) // DispatcherClient *value .setPutHeader(putIt.header()) - .setBlob(blobSp) // const bsl::shared_ptr& value + .setBlob(peb.blob()) // const bsl::shared_ptr& value .setCompressionAlgorithmType(bmqt::CompressionAlgorithmType::e_ZLIB); tb.dispatch(putEvent); diff --git a/src/groups/mqb/mqba/mqba_sessionnegotiator.cpp b/src/groups/mqb/mqba/mqba_sessionnegotiator.cpp index f6a54203ca..d7186ec053 100644 --- a/src/groups/mqb/mqba/mqba_sessionnegotiator.cpp +++ b/src/groups/mqb/mqba/mqba_sessionnegotiator.cpp @@ -686,9 +686,9 @@ int SessionNegotiator::sendNegotiationMessage( // Build connection response event bdlma::LocalSequentialAllocator<2048> localAllocator(d_allocator_p); - bmqp::SchemaEventBuilder builder(d_bufferFactory_p, - &localAllocator, - encodingType); + bmqp::SchemaEventBuilder builder(d_blobSpPool_p, + encodingType, + &localAllocator); int rc = builder.setMessage(message, bmqp::EventType::e_CONTROL); if (rc != 0) { @@ -699,7 +699,7 @@ int SessionNegotiator::sendNegotiationMessage( // Send response event bmqio::Status status; - context->d_channelSp->write(&status, builder.blob()); + context->d_channelSp->write(&status, *builder.blob()); if (!status) { errorDescription << "Failed sending NegotiationMessage " << "[status: " << status << ", message: " << message @@ -736,7 +736,6 @@ void SessionNegotiator::createSession(bsl::ostream& errorDescription, description, d_dispatcher_p, d_blobSpPool_p, - d_bufferFactory_p, d_scheduler_p, d_adminCb, d_allocator_p); diff --git a/src/groups/mqb/mqba/mqba_sessionnegotiator.h b/src/groups/mqb/mqba/mqba_sessionnegotiator.h index b4db32e661..adc966fc63 100644 --- a/src/groups/mqb/mqba/mqba_sessionnegotiator.h +++ b/src/groups/mqb/mqba/mqba_sessionnegotiator.h @@ -150,9 +150,10 @@ class SessionNegotiator : public mqbnet::Negotiator { bslma::Allocator* d_allocator_p; // Allocator to use + /// Buffer factory to use in constructed client sessions + /// TODO: this field should be removed once we retire the code for + /// message properties conversion in `mqba::ClientSession`. bdlbb::BlobBufferFactory* d_bufferFactory_p; - // Buffer factory to inject into new client - // sessions mqbi::Dispatcher* d_dispatcher_p; // Dispatcher to inject into new client diff --git a/src/groups/mqb/mqbblp/mqbblp_clustercatalog.cpp b/src/groups/mqb/mqbblp/mqbblp_clustercatalog.cpp index ac02017f69..89ad25a179 100644 --- a/src/groups/mqb/mqbblp/mqbblp_clustercatalog.cpp +++ b/src/groups/mqb/mqbblp/mqbblp_clustercatalog.cpp @@ -378,7 +378,7 @@ ClusterCatalog::ClusterCatalog(mqbi::Dispatcher* dispatcher, , d_resources(resources) , d_adminCb() , d_requestManager(bmqp::EventType::e_CONTROL, - resources.bufferFactory(), + resources.blobSpPool(), resources.scheduler(), false, // lateResponseMode d_allocator_p) diff --git a/src/groups/mqb/mqbblp/mqbblp_clusterorchestrator.cpp b/src/groups/mqb/mqbblp/mqbblp_clusterorchestrator.cpp index 388544711a..2b465498a0 100644 --- a/src/groups/mqb/mqbblp/mqbblp_clusterorchestrator.cpp +++ b/src/groups/mqb/mqbblp/mqbblp_clusterorchestrator.cpp @@ -592,7 +592,7 @@ ClusterOrchestrator::ClusterOrchestrator( // Strong d_clusterData_p, clusterState, - &d_clusterData_p->bufferFactory())), + &d_clusterData_p->blobSpPool())), k_WATCHDOG_TIMEOUT_DURATION, d_allocators.get("ClusterStateManager"))) : static_cast( @@ -611,7 +611,7 @@ ClusterOrchestrator::ClusterOrchestrator( // Strong d_clusterData_p, clusterState, - &d_clusterData_p->bufferFactory())), + &d_clusterData_p->blobSpPool())), d_allocators.get("ClusterStateManager"))), d_allocator_p) , d_queueHelper(d_clusterData_p, @@ -706,7 +706,7 @@ int ClusterOrchestrator::start(bsl::ostream& errorDescription) _3, // LeaderNodeId _4), // Term electorTerm, - &d_clusterData_p->bufferFactory(), + &d_clusterData_p->blobSpPool(), d_allocator_p), d_allocator_p); diff --git a/src/groups/mqb/mqbblp/mqbblp_recoverymanager.cpp b/src/groups/mqb/mqbblp/mqbblp_recoverymanager.cpp index 9aa99c4c2e..e90ef1b400 100644 --- a/src/groups/mqb/mqbblp/mqbblp_recoverymanager.cpp +++ b/src/groups/mqb/mqbblp/mqbblp_recoverymanager.cpp @@ -1522,7 +1522,7 @@ int RecoveryManager::sendFile(RequestContext* context, unsigned int sequenceNumber = 0; bsls::Types::Uint64 currOffset = beginOffset; - bmqp::RecoveryEventBuilder builder(&d_clusterData_p->bufferFactory(), + bmqp::RecoveryEventBuilder builder(&d_clusterData_p->blobSpPool(), d_allocator_p); while ((currOffset + chunkSize) < endOffset) { @@ -1707,7 +1707,7 @@ int RecoveryManager::replayPartition( bmqp::StorageEventBuilder builder(mqbs::FileStoreProtocol::k_VERSION, bmqp::EventType::e_PARTITION_SYNC, - &d_clusterData_p->bufferFactory(), + &d_clusterData_p->blobSpPool(), d_allocator_p); // Note that partition has to be replayed from the record *after* @@ -3271,7 +3271,7 @@ void RecoveryManager::processStorageEvent( bmqp::StorageEventBuilder seb(mqbs::FileStoreProtocol::k_VERSION, bmqp::EventType::e_STORAGE, - &d_clusterData_p->bufferFactory(), + &d_clusterData_p->blobSpPool(), d_allocator_p); while (1 == iter.next()) { @@ -3297,12 +3297,7 @@ void RecoveryManager::processStorageEvent( // nothing to buffer in this event. if (0 < seb.messageCount()) { - bsl::shared_ptr blobSp; - blobSp.createInplace(d_allocator_p, - &d_clusterData_p->bufferFactory(), - d_allocator_p); - *blobSp = seb.blob(); - recoveryCtx.addStorageEvent(blobSp); + recoveryCtx.addStorageEvent(seb.blob()); } recoveryCtx.setNewSyncPoint(syncPoint); diff --git a/src/groups/mqb/mqbc/mqbc_clusterdata.cpp b/src/groups/mqb/mqbc/mqbc_clusterdata.cpp index 0b8c369560..db972b6ade 100644 --- a/src/groups/mqb/mqbc/mqbc_clusterdata.cpp +++ b/src/groups/mqb/mqbc/mqbc_clusterdata.cpp @@ -117,12 +117,12 @@ ClusterData::ClusterData( cluster->isRemote(), allocator)) , d_cluster_p(cluster) -, d_messageTransmitter(resources.bufferFactory(), +, d_messageTransmitter(resources.blobSpPool(), cluster, transportManager, allocator) , d_requestManager(bmqp::EventType::e_CONTROL, - resources.bufferFactory(), + resources.blobSpPool(), resources.scheduler(), false, // lateResponseMode allocator) diff --git a/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.cpp b/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.cpp index 26c96b5f44..99d2c1221d 100644 --- a/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.cpp +++ b/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.cpp @@ -114,7 +114,7 @@ void ControlMessageTransmitter::broadcastMessageHelper( bmqp::HighAvailabilityFeatures::k_BROADCAST_TO_PROXIES, negoMsg.clientIdentity().features())) { bmqio::Status status; - sessionSp->channel()->write(&status, schemaBuilder->blob()); + sessionSp->channel()->write(&status, *schemaBuilder->blob()); if (status.category() == bmqio::StatusCategory::e_SUCCESS) { BALL_LOG_INFO << "Sent message '" << message << "' to proxy " << sessionSp->description(); @@ -131,19 +131,19 @@ void ControlMessageTransmitter::broadcastMessageHelper( // CREATORS ControlMessageTransmitter::ControlMessageTransmitter( - bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, mqbi::Cluster* cluster, mqbnet::TransportManager* transportManager, bslma::Allocator* allocator) : d_allocator_p(allocator) -, d_bufferFactory_p(bufferFactory) -, d_schemaBuilder(bufferFactory, allocator) +, d_blobSpPool_p(blobSpPool_p) +, d_schemaBuilder(d_blobSpPool_p, bmqp::EncodingType::e_BER, allocator) , d_cluster_p(cluster) , d_transportManager_p(transportManager) { // PRECONDITIONS BSLS_ASSERT_SAFE(d_allocator_p); - BSLS_ASSERT_SAFE(d_bufferFactory_p); + BSLS_ASSERT_SAFE(d_blobSpPool_p); BSLS_ASSERT_SAFE(d_cluster_p); } @@ -189,7 +189,7 @@ void ControlMessageTransmitter::sendMessage( } bmqio::Status status; - channel->write(&status, d_schemaBuilder.blob()); + channel->write(&status, *d_schemaBuilder.blob()); if (status.category() != bmqio::StatusCategory::e_SUCCESS) { BALL_LOG_ERROR << "#CLUSTER_SEND_FAILURE " << "Failed to write schema message: " << message @@ -212,7 +212,9 @@ void ControlMessageTransmitter::sendMessageSafe( // Since this method can be invoked from any thread, schema event builder // is created on the stack, instead of using 'd_schemaBuilder'. - bmqp::SchemaEventBuilder schemaBuilder(d_bufferFactory_p, d_allocator_p); + bmqp::SchemaEventBuilder schemaBuilder(d_blobSpPool_p, + bmqp::EncodingType::e_BER, + d_allocator_p); sendMessageHelper(message, destination, &schemaBuilder); } @@ -238,7 +240,9 @@ void ControlMessageTransmitter::broadcastMessageSafe( // Since this method can be invoked from any thread, schema event builder // is created on the stack, instead of using 'd_schemaBuilder'. - bmqp::SchemaEventBuilder schemaBuilder(d_bufferFactory_p, d_allocator_p); + bmqp::SchemaEventBuilder schemaBuilder(d_blobSpPool_p, + bmqp::EncodingType::e_BER, + d_allocator_p); broadcastMessageHelper(message, &schemaBuilder, false); } diff --git a/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.h b/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.h index 69a15c091c..5e5aba2151 100644 --- a/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.h +++ b/src/groups/mqb/mqbc/mqbc_controlmessagetransmitter.h @@ -69,17 +69,19 @@ namespace mqbc { /// This class provides a mechanism to transmit messages to peer nodes in /// the same cluster. class ControlMessageTransmitter { + public: + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBC.ControlMessageTransmitter"); - private: // DATA bslma::Allocator* d_allocator_p; // Allocator to use. - bdlbb::BlobBufferFactory* d_bufferFactory_p; - // Blob buffer factory to use. + /// Blob pool to use. Held, not owned. + BlobSpPool* d_blobSpPool_p; bmqp::SchemaEventBuilder d_schemaBuilder; // Schema event builder to use. Must be used @@ -127,9 +129,9 @@ class ControlMessageTransmitter { // CREATORS /// Create an instance of `ControlMessageTransmitter` associated with - /// the specified `cluster` and using the specified `bufferFactory`. + /// the specified `cluster` and using the specified `blobSpPool_p`. /// Use the specified `allocator` for memory allocations. - ControlMessageTransmitter(bdlbb::BlobBufferFactory* bufferFactory, + ControlMessageTransmitter(BlobSpPool* blobSpPool_p, mqbi::Cluster* cluster, mqbnet::TransportManager* transportManager, bslma::Allocator* allocator); diff --git a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.cpp b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.cpp index 834982b4f8..16ea3acbd0 100644 --- a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.cpp +++ b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.cpp @@ -268,12 +268,12 @@ int IncoreClusterStateLedger::onLogRolloverCb(const mqbu::StorageKey& oldLogId, ++advisoryIt) { ClusterMessageInfo& info = advisoryIt->second; - bdlbb::Blob record(d_bufferFactory_p, d_allocator_p); + bsl::shared_ptr record = d_blobSpPool_p->getObject(); ClusterStateRecordType::Enum recordType = info.d_clusterMessage.choice().isLeaderAdvisoryValue() ? ClusterStateRecordType::e_SNAPSHOT : ClusterStateRecordType::e_UPDATE; - rc = ClusterStateLedgerUtil::appendRecord(&record, + rc = ClusterStateLedgerUtil::appendRecord(record.get(), info.d_clusterMessage, advisoryIt->first, currentTime(), @@ -283,9 +283,9 @@ int IncoreClusterStateLedger::onLogRolloverCb(const mqbu::StorageKey& oldLogId, } rc = d_ledger_mp->writeRecord(&(info.d_recordId), - record, + *record, bmqu::BlobPosition(), - record.length()); + record->length()); if (rc != 0) { return 10 * rc + rc_WRITE_RECORD_FAILURE; // RETURN } @@ -343,9 +343,9 @@ int IncoreClusterStateLedger::onLogRolloverCb(const mqbu::StorageKey& oldLogId, ClusterMessageInfo info; info.d_clusterMessage.choice().makeLeaderAdvisory(leaderAdvisory); - bdlbb::Blob record(d_bufferFactory_p, d_allocator_p); - rc = ClusterStateLedgerUtil::appendRecord( - &record, + bsl::shared_ptr record = d_blobSpPool_p->getObject(); + rc = ClusterStateLedgerUtil::appendRecord( + record.get(), info.d_clusterMessage, leaderAdvisory.sequenceNumber(), currentTime(), @@ -355,9 +355,9 @@ int IncoreClusterStateLedger::onLogRolloverCb(const mqbu::StorageKey& oldLogId, } rc = d_ledger_mp->writeRecord(&(info.d_recordId), - record, + *record, bmqu::BlobPosition(), - record.length()); + record->length()); if (rc != 0) { return 10 * rc + rc_WRITE_RECORD_FAILURE; // RETURN } @@ -415,8 +415,8 @@ int IncoreClusterStateLedger::applyAdvisoryInternal( } // Do leader logic: apply and broadcast advisory, then apply its ack - bdlbb::Blob advisoryRecord(d_bufferFactory_p, d_allocator_p); - int rc = ClusterStateLedgerUtil::appendRecord(&advisoryRecord, + bsl::shared_ptr advisoryRecord = d_blobSpPool_p->getObject(); + int rc = ClusterStateLedgerUtil::appendRecord(advisoryRecord.get(), clusterMessage, sequenceNumber, currentTime(), @@ -425,7 +425,7 @@ int IncoreClusterStateLedger::applyAdvisoryInternal( return 10 * rc + rc_CREATE_RECORD_FAILURE; // RETURN } - rc = applyRecordInternal(advisoryRecord, + rc = applyRecordInternal(*advisoryRecord, 0, clusterMessage, sequenceNumber, @@ -523,8 +523,10 @@ int IncoreClusterStateLedger::applyRecordInternal( // record offset should be 0. BSLS_ASSERT_SAFE(recordOffset == 0); - bdlbb::Blob advisoryEvent(d_bufferFactory_p, d_allocator_p); - constructEventBlob(&advisoryEvent, record); + bsl::shared_ptr advisoryEvent = + d_blobSpPool_p->getObject(); + + constructEventBlob(advisoryEvent.get(), record); d_clusterData_p->membership().netCluster()->writeAll( advisoryEvent, bmqp::EventType::e_CLUSTER_STATE); @@ -543,9 +545,9 @@ int IncoreClusterStateLedger::applyRecordInternal( ackMessage.choice().makeLeaderAdvisoryAck().sequenceNumberAcked() = sequenceNumber; - bdlbb::Blob ackRecord(d_bufferFactory_p, d_allocator_p); + bsl::shared_ptr ackRecord = d_blobSpPool_p->getObject(); rc = ClusterStateLedgerUtil::appendRecord( - &ackRecord, + ackRecord.get(), ackMessage, sequenceNumber, currentTime(), @@ -556,7 +558,7 @@ int IncoreClusterStateLedger::applyRecordInternal( // If leader, apply Ack to self. Else, reply Ack back to leader if (isSelfLeader()) { - rc = applyRecordInternal(ackRecord, + rc = applyRecordInternal(*ackRecord, 0, ackMessage, sequenceNumber, @@ -566,8 +568,10 @@ int IncoreClusterStateLedger::applyRecordInternal( } } else { - bdlbb::Blob ackEvent(d_bufferFactory_p, d_allocator_p); - constructEventBlob(&ackEvent, ackRecord); + bsl::shared_ptr ackEvent = + d_blobSpPool_p->getObject(); + + constructEventBlob(ackEvent.get(), *ackRecord); mqbnet::ClusterNode* leaderNode = d_clusterData_p->electorInfo().leaderNode(); @@ -631,8 +635,10 @@ int IncoreClusterStateLedger::applyRecordInternal( } if (isSelfLeader()) { - bdlbb::Blob commitEvent(d_bufferFactory_p, d_allocator_p); - constructEventBlob(&commitEvent, record); + bsl::shared_ptr commitEvent = + d_blobSpPool_p->getObject(); + + constructEventBlob(commitEvent.get(), record); d_clusterData_p->membership().netCluster()->writeAll( commitEvent, bmqp::EventType::e_CLUSTER_STATE); @@ -694,9 +700,10 @@ int IncoreClusterStateLedger::applyRecordInternal( << ", creating and applying commit advisory: " << commitMessage << "."; - bdlbb::Blob commitRecord(d_bufferFactory_p, d_allocator_p); + bsl::shared_ptr commitRecord = + d_blobSpPool_p->getObject(); rc = ClusterStateLedgerUtil::appendRecord( - &commitRecord, + commitRecord.get(), commitMessage, commitAdvisory.sequenceNumber(), currentTime(), @@ -705,7 +712,7 @@ int IncoreClusterStateLedger::applyRecordInternal( return 10 * rc + rc_CREATE_COMMIT_FAILURE; // RETURN } - rc = applyRecordInternal(commitRecord, + rc = applyRecordInternal(*commitRecord, 0, commitMessage, commitAdvisory.sequenceNumber(), @@ -1177,12 +1184,12 @@ IncoreClusterStateLedger::IncoreClusterStateLedger( ClusterStateLedgerConsistency::Enum consistencyLevel, ClusterData* clusterData, ClusterState* clusterState, - bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator) : d_allocator_p(allocator) , d_isFirstLeaderAdvisory(true) , d_isOpen(false) -, d_bufferFactory_p(bufferFactory) +, d_blobSpPool_p(blobSpPool_p) , d_description(allocator) , d_commitCb() , d_clusterData_p(clusterData) diff --git a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.h b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.h index 0550a8c249..0e30680e9d 100644 --- a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.h +++ b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.h @@ -127,11 +127,14 @@ struct IncoreClusterStateLedger_ClusterMessageInfo { /// cluster nodes themselves instead of being offloaded to an external meta /// data (e.g., ZooKeeper). class IncoreClusterStateLedger BSLS_KEYWORD_FINAL : public ClusterStateLedger { + public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + private: // CLASS-SCOPE CATEGORY BALL_LOG_SET_CLASS_CATEGORY("MQBC.INCORECLUSTERSTATELEDGER"); - private: // TYPES typedef IncoreClusterStateLedger_ClusterMessageInfo ClusterMessageInfo; typedef ClusterStateLedgerCommitStatus CommitStatus; @@ -163,10 +166,8 @@ class IncoreClusterStateLedger BSLS_KEYWORD_FINAL : public ClusterStateLedger { // Flag to indicate open/close status // of this object - bdlbb::BlobBufferFactory* d_bufferFactory_p; - // Buffer factory for the headers and - // payloads of the messages to be - // written + /// Pool of shared pointers to blobs + BlobSpPool* d_blobSpPool_p; bsl::string d_description; // Brief description for logging @@ -300,7 +301,7 @@ class IncoreClusterStateLedger BSLS_KEYWORD_FINAL : public ClusterStateLedger { ClusterStateLedgerConsistency::Enum consistencyLevel, ClusterData* clusterData, ClusterState* clusterState, - bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); /// Destructor. diff --git a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.t.cpp b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.t.cpp index 1028498724..f524c85a4f 100644 --- a/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.t.cpp +++ b/src/groups/mqb/mqbc/mqbc_incoreclusterstateledger.t.cpp @@ -292,7 +292,7 @@ struct Tester { d_consistencyLevel, d_cluster_mp->_clusterData(), &d_cluster_mp->_state(), - d_cluster_mp->_bufferFactory(), + d_cluster_mp->_blobSpPool(), bmqtst::TestHelperUtil::allocator()), bmqtst::TestHelperUtil::allocator()); d_clusterStateLedger_mp->setCommitCb( diff --git a/src/groups/mqb/mqbc/mqbc_recoverymanager.cpp b/src/groups/mqb/mqbc/mqbc_recoverymanager.cpp index 636f4d0da5..a31c6e5d18 100644 --- a/src/groups/mqb/mqbc/mqbc_recoverymanager.cpp +++ b/src/groups/mqb/mqbc/mqbc_recoverymanager.cpp @@ -117,13 +117,12 @@ void RecoveryManager::ReceiveDataContext::reset() // CREATORS RecoveryManager::RecoveryManager( - bdlbb::BlobBufferFactory* bufferFactory, const mqbcfg::ClusterDefinition& clusterConfig, - const mqbc::ClusterData& clusterData, + mqbc::ClusterData& clusterData, const mqbs::DataStoreConfig& dataStoreConfig, bslma::Allocator* allocator) : d_allocator_p(allocator) -, d_bufferFactory_p(bufferFactory) +, d_blobSpPool_p(&clusterData.blobSpPool()) , d_clusterConfig(clusterConfig) , d_dataStoreConfig(dataStoreConfig) , d_clusterData(clusterData) @@ -422,7 +421,7 @@ int RecoveryManager::processSendDataChunks( bmqp::StorageEventBuilder builder(mqbs::FileStoreProtocol::k_VERSION, bmqp::EventType::e_PARTITION_SYNC, - d_bufferFactory_p, + d_blobSpPool_p, d_allocator_p); // Note that partition has to be replayed from the record *after* diff --git a/src/groups/mqb/mqbc/mqbc_recoverymanager.h b/src/groups/mqb/mqbc/mqbc_recoverymanager.h index 0c9fa62963..b21f53290a 100644 --- a/src/groups/mqb/mqbc/mqbc_recoverymanager.h +++ b/src/groups/mqb/mqbc/mqbc_recoverymanager.h @@ -26,7 +26,6 @@ // storage recovery in a cluster node. // MQB - #include #include #include @@ -64,6 +63,12 @@ namespace mqbc { /// This component provides a mechanism to manage storage recovery in a /// cluster node. class RecoveryManager { + public: + // TYPES + /// Pool of shared pointers to Blobs + typedef mqbs::FileStore::BlobSpPool BlobSpPool; + + private: // ================== // class ChunkDeleter // ================== @@ -259,11 +264,11 @@ class RecoveryManager { private: // DATA - bslma::Allocator* d_allocator_p; /// Allocator to use + bslma::Allocator* d_allocator_p; - /// Blob buffer factory to use - bdlbb::BlobBufferFactory* d_bufferFactory_p; + /// Blob shared pointer pool to use + BlobSpPool* d_blobSpPool_p; /// Cluster configuration to use const mqbcfg::ClusterDefinition& d_clusterConfig; @@ -294,12 +299,11 @@ class RecoveryManager { // CREATORS - /// Create a `RecoveryManager` object with the specified `bufferFactory`, - /// `clusterConfig`, `dataStoreConfig`, and `clusterData`. Use the - /// specified `allocator` for any memory allocation. - RecoveryManager(bdlbb::BlobBufferFactory* bufferFactory, - const mqbcfg::ClusterDefinition& clusterConfig, - const mqbc::ClusterData& clusterData, + /// Create a `RecoveryManager` object with the specified `clusterConfig`, + /// `clusterData` and `dataStoreConfig`. Use the specified `allocator` + /// for any memory allocation. + RecoveryManager(const mqbcfg::ClusterDefinition& clusterConfig, + mqbc::ClusterData& clusterData, const mqbs::DataStoreConfig& dataStoreConfig, bslma::Allocator* allocator); diff --git a/src/groups/mqb/mqbc/mqbc_storagemanager.cpp b/src/groups/mqb/mqbc/mqbc_storagemanager.cpp index 860937cc86..c97387cfc1 100644 --- a/src/groups/mqb/mqbc/mqbc_storagemanager.cpp +++ b/src/groups/mqb/mqbc/mqbc_storagemanager.cpp @@ -3342,7 +3342,6 @@ StorageManager::StorageManager( , d_lowDiskspaceWarning(false) , d_unrecognizedDomainsLock() , d_unrecognizedDomains(allocator) -, d_blobSpPool_p(&clusterData->blobSpPool()) , d_domainFactory_p(domainFactory) , d_dispatcher_p(dispatcher) , d_cluster_p(cluster) @@ -3500,7 +3499,7 @@ int StorageManager::start(bsl::ostream& errorDescription) d_dispatcher_p, partitionCfg, &d_fileStores, - d_blobSpPool_p, + &d_clusterData_p->blobSpPool(), &d_allocators, errorDescription, d_replicationFactor, @@ -3527,12 +3526,11 @@ int StorageManager::start(bsl::ostream& errorDescription) bslma::Allocator* recoveryManagerAllocator = d_allocators.get( "RecoveryManager"); - d_recoveryManager_mp.load(new (*recoveryManagerAllocator) RecoveryManager( - &d_clusterData_p->bufferFactory(), - d_clusterConfig, - *d_clusterData_p, - dsCfg, - recoveryManagerAllocator), + d_recoveryManager_mp.load(new (*recoveryManagerAllocator) + RecoveryManager(d_clusterConfig, + *d_clusterData_p, + dsCfg, + recoveryManagerAllocator), recoveryManagerAllocator); rc = d_recoveryManager_mp->start(errorDescription); diff --git a/src/groups/mqb/mqbc/mqbc_storagemanager.h b/src/groups/mqb/mqbc/mqbc_storagemanager.h index ba59088926..ca991c6205 100644 --- a/src/groups/mqb/mqbc/mqbc_storagemanager.h +++ b/src/groups/mqb/mqbc/mqbc_storagemanager.h @@ -235,9 +235,6 @@ class StorageManager BSLS_KEYWORD_FINAL // // THREAD: Protected by 'd_unrecognizedDomainsLock'. - BlobSpPool* d_blobSpPool_p; - // SharedObjectPool of blobs to use - mqbi::DomainFactory* d_domainFactory_p; // Domain factory to use diff --git a/src/groups/mqb/mqbmock/mqbmock_cluster.h b/src/groups/mqb/mqbmock/mqbmock_cluster.h index ed3885345f..23f03dbe1c 100644 --- a/src/groups/mqb/mqbmock/mqbmock_cluster.h +++ b/src/groups/mqb/mqbmock/mqbmock_cluster.h @@ -129,14 +129,10 @@ class Cluster : public mqbi::Cluster { typedef bsl::shared_ptr StatContextSp; typedef mqbc::ClusterData::StatContextsMap StatContextsMap; - typedef bdlcc::SharedObjectPool< - bdlbb::Blob, - bdlcc::ObjectPoolFunctors::DefaultCreator, - bdlcc::ObjectPoolFunctors::RemoveAll > - BlobSpPool; - public: // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + typedef bsl::vector ClusterNodeDefs; typedef bsl::shared_ptr TestChannelSp; @@ -420,6 +416,9 @@ class Cluster : public mqbi::Cluster { /// Get a modifiable reference to this object's buffer factory. bdlbb::BlobBufferFactory* _bufferFactory(); + /// Get a modifiable reference to this object's blob shared pointer pool. + BlobSpPool* _blobSpPool(); + /// Get a modifiable reference to this object's _scheduler. bdlmt::EventScheduler& _scheduler(); @@ -569,6 +568,11 @@ inline bdlbb::BlobBufferFactory* Cluster::_bufferFactory() return d_bufferFactory_p; } +inline Cluster::BlobSpPool* Cluster::_blobSpPool() +{ + return &d_blobSpPool; +} + inline bdlmt::EventScheduler& Cluster::_scheduler() { return d_scheduler; diff --git a/src/groups/mqb/mqbnet/mqbnet_channel.cpp b/src/groups/mqb/mqbnet/mqbnet_channel.cpp index cf57b065f7..79f1c37487 100644 --- a/src/groups/mqb/mqbnet/mqbnet_channel.cpp +++ b/src/groups/mqb/mqbnet/mqbnet_channel.cpp @@ -41,7 +41,7 @@ size_t Channel::ControlArgs::eventSize() const return 0; // RETURN } - return d_data.length(); + return d_data_sp->length(); } // -------------------- @@ -67,14 +67,17 @@ Channel::Channel(bdlbb::BlobBufferFactory* blobBufferFactory, bslma::Allocator* allocator) : d_allocators(allocator) , d_allocator_p(d_allocators.get("Channel")) -, d_putBuilder(blobBufferFactory, d_allocator_p) -, d_pushBuilder(blobBufferFactory, d_allocator_p) -, d_ackBuilder(blobBufferFactory, d_allocator_p) -, d_confirmBuilder(blobBufferFactory, d_allocator_p) -, d_rejectBuilder(blobBufferFactory, d_allocator_p) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(blobBufferFactory, + d_allocators.get("BlobSpPool"))) +, d_putBuilder(&d_blobSpPool, d_allocator_p) +, d_pushBuilder(&d_blobSpPool, d_allocator_p) +, d_ackBuilder(&d_blobSpPool, d_allocator_p) +, d_confirmBuilder(&d_blobSpPool, d_allocator_p) +, d_rejectBuilder(&d_blobSpPool, d_allocator_p) , d_itemPool(sizeof(Item), bsls::BlockGrowth::BSLS_CONSTANT, - d_allocators.get(bsl::string("ItemPool"))) + d_allocators.get("ItemPool")) , d_buffer(1024, allocator) , d_secondaryBuffer(1024, allocator) , d_doStop(false) @@ -116,14 +119,12 @@ void Channel::deleteItem(void* item, void* cookie) bmqt::GenericResult::Enum Channel::writePut(const bmqp::PutHeader& ph, const bsl::shared_ptr& data, - const bsl::shared_ptr& state, - bool keepWeakPtr) + const bsl::shared_ptr& state) { - bslma::ManagedPtr item( - new (d_itemPool.allocate()) - Item(ph, data, keepWeakPtr, state, d_allocator_p), - this, - deleteItem); + bslma::ManagedPtr item(new (d_itemPool.allocate()) + Item(ph, data, state, d_allocator_p), + this, + deleteItem); return enqueue(item); } @@ -227,7 +228,7 @@ Channel::writeReject(int queueId, } bmqt::GenericResult::Enum -Channel::writeBlob(const bdlbb::Blob& data, +Channel::writeBlob(const bsl::shared_ptr& data, bmqp::EventType::Enum type, const bsl::shared_ptr& state) { @@ -483,7 +484,7 @@ bmqt::EventBuilderResult::Enum Channel::pack(bmqp::PutEventBuilder& builder, // PRECONDITIONS BSLS_ASSERT_SAFE(d_internalThreadChecker.inSameThread()); - if (!args.d_data) { + if (!args.d_data_sp.get()) { return bmqt::EventBuilderResult::e_PAYLOAD_EMPTY; } const bmqp::PutHeader& ph = args.d_putHeader; @@ -491,7 +492,7 @@ bmqt::EventBuilderResult::Enum Channel::pack(bmqp::PutEventBuilder& builder, builder.startMessage(); builder.setMessageGUID(ph.messageGUID()) .setFlags(ph.flags()) - .setMessagePayload(args.d_data.get()) + .setMessagePayload(args.d_data_sp.get()) .setCompressionAlgorithmType(ph.compressionAlgorithmType()) .setCrc32c(ph.crc32c()) .setMessagePropertiesInfo(bmqp::MessagePropertiesInfo(ph)); @@ -512,7 +513,7 @@ bmqt::EventBuilderResult::Enum Channel::pack(bmqp::PushEventBuilder& builder, args.d_subQueueInfos); if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY( rc == bmqt::EventBuilderResult::e_SUCCESS)) { - rc = builder.packMessage(*args.d_data.get(), + rc = builder.packMessage(*args.d_data_sp, args.d_queueId, args.d_msgId, args.d_flags, diff --git a/src/groups/mqb/mqbnet/mqbnet_channel.h b/src/groups/mqb/mqbnet/mqbnet_channel.h index 66f1c104f8..4a5df5e840 100644 --- a/src/groups/mqb/mqbnet/mqbnet_channel.h +++ b/src/groups/mqb/mqbnet/mqbnet_channel.h @@ -123,12 +123,17 @@ class Channel { // PRIVATE TYPES struct Item; + typedef bmqc::MonitoredQueue< + bdlcc::SingleConsumerQueue > > + ItemQueue; + + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + /// Const references to everything needed to writeBufferedItem PUT. /// This is template parameter to generalized writing code. struct PutArgs { const bmqp::PutHeader& d_putHeader; - const bsl::shared_ptr& d_data; - const bool d_hasWeakPtr; + const bsl::shared_ptr& d_data_sp; PutArgs(Item& item); @@ -157,7 +162,7 @@ class Channel { /// data. /// This is template parameter to generalized writing code. struct ExplicitPushArgs : PushArgsBase { - const bsl::shared_ptr& d_data; + const bsl::shared_ptr& d_data_sp; const bmqp::Protocol::SubQueueInfosArray& d_subQueueInfos; @@ -220,7 +225,7 @@ class Channel { /// `control` builder. struct ControlArgs { bmqp::EventType::Enum d_type; - const bdlbb::Blob& d_data; + const bsl::shared_ptr& d_data_sp; int d_messageCount; ControlArgs(Item& item); @@ -243,8 +248,6 @@ class Channel { // union of event data copies const bmqp::PutHeader d_putHeader; - const bsl::weak_ptr d_data_wp; - const bool d_hasWeakPtr; const bsl::shared_ptr d_data_sp; const int d_queueId; const int d_subQueueId; @@ -252,23 +255,18 @@ class Channel { const int d_flags; const bmqt::CompressionAlgorithmType::Enum d_compressionAlgorithmType; const bmqp::MessagePropertiesInfo d_messagePropertiesInfo; - const bdlbb::Blob d_data; const bmqp::Protocol::SubQueueInfosArray d_subQueueInfos; const int d_correlationId; const int d_status; const bsl::shared_ptr d_state; - bsl::shared_ptr d_tempData_sp; - bsl::shared_ptr d_tempOptions_sp; - size_t d_numBytes; Item(bslma::Allocator* allocator); Item(const bmqp::PutHeader& ph, const bsl::shared_ptr& data, - bool keepWeakPtr, const bsl::shared_ptr& state, bslma::Allocator* allocator); @@ -305,7 +303,7 @@ class Channel { bmqp::EventType::Enum type, bslma::Allocator* allocator); - Item(const bdlbb::Blob& data, + Item(const bsl::shared_ptr& data, bmqp::EventType::Enum type, const bsl::shared_ptr& state, bslma::Allocator* allocator); @@ -348,9 +346,6 @@ class Channel { public: // PUBLIC TYPES - typedef bmqc::MonitoredQueue< - bdlcc::SingleConsumerQueue > > - ItemQueue; enum EnumState { e_INITIAL = 0 // Not connected , @@ -375,6 +370,8 @@ class Channel { /// Counting allocator bslma::Allocator* d_allocator_p; + BlobSpPool d_blobSpPool; + bmqp::PutEventBuilder d_putBuilder; bmqp::PushEventBuilder d_pushBuilder; @@ -525,14 +522,11 @@ class Channel { void closeChannel(); /// Write PUT message using the specified `ph`, `data`, and `state`. - /// Return e_SUCCESS even if the channel is in HWM. If the specified - /// `keepWeakPtr` is `true`, keep `weak_ptr` when enqueueing thus - /// allowing caller to release the blobs before processing. + /// Return e_SUCCESS even if the channel is in HWM. bmqt::GenericResult::Enum writePut(const bmqp::PutHeader& ph, const bsl::shared_ptr& data, - const bsl::shared_ptr& state, - bool keepWeakPtr = false); + const bsl::shared_ptr& state); /// Write `explicit` PUSH message using the specified `payload`, /// `queueId`, `msgId`, `flags`, `compressionType`, `subQueueInfos`, and @@ -597,7 +591,7 @@ class Channel { /// Replication Receipt). Return e_SUCCESS even if the channel is in /// High WaterMark. bmqt::GenericResult::Enum - writeBlob(const bdlbb::Blob& data, + writeBlob(const bsl::shared_ptr& data, bmqp::EventType::Enum type, const bsl::shared_ptr& state = 0); @@ -636,8 +630,7 @@ inline Channel::PutArgs::~PutArgs() inline Channel::PutArgs::PutArgs(Item& item) : d_putHeader(item.d_putHeader) -, d_data(item.data()) -, d_hasWeakPtr(item.d_hasWeakPtr) +, d_data_sp(item.d_data_sp) { // NOTHING } @@ -676,7 +669,7 @@ inline Channel::ExplicitPushArgs::ExplicitPushArgs(Item& item) item.d_flags, item.d_compressionAlgorithmType, item.d_messagePropertiesInfo) -, d_data(item.d_data_sp) +, d_data_sp(item.d_data_sp) , d_subQueueInfos(item.d_subQueueInfos) { // NOTHING @@ -764,7 +757,7 @@ inline Channel::RejectArgs::~RejectArgs() inline Channel::ControlArgs::ControlArgs(Item& item) : d_type(item.d_type) -, d_data(item.d_data) +, d_data_sp(item.d_data_sp) , d_messageCount(1) { // NOTHING @@ -777,7 +770,7 @@ inline Channel::ControlArgs::~ControlArgs() inline const bdlbb::Blob& Channel::ControlArgs::blob() const { - return d_data; + return *d_data_sp; } inline size_t Channel::ControlArgs::messageCount() const @@ -797,35 +790,35 @@ inline void Channel::ControlArgs::reset() // CREATORS inline Channel::Item::Item(bslma::Allocator* allocator) : d_type(bmqp::EventType::e_UNDEFINED) -, d_hasWeakPtr(false) +, d_putHeader() +, d_data_sp(0, allocator) , d_queueId(0) , d_subQueueId(0) +, d_msgId() , d_flags(0) , d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE) -, d_data(allocator) , d_subQueueInfos(allocator) , d_correlationId(0) , d_status(0) +, d_state(0) , d_numBytes(0) { // NOTHING } -inline Channel::Item::Item(const bmqp::PutHeader& ph, - const bsl::shared_ptr& data, - bool keepWeakPtr, +inline Channel::Item::Item(const bmqp::PutHeader& ph, + const bsl::shared_ptr& data, const bsl::shared_ptr& state, bslma::Allocator* allocator) : d_type(bmqp::EventType::e_PUT) , d_putHeader(ph) -, d_data_wp(keepWeakPtr ? data : 0) -, d_hasWeakPtr(false) -, d_data_sp(keepWeakPtr ? 0 : data) +, d_data_sp(data) , d_queueId(0) , d_subQueueId(0) +, d_msgId() , d_flags(0) , d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE) -, d_data(allocator) +, d_messagePropertiesInfo() , d_subQueueInfos(allocator) , d_correlationId(0) , d_status(0) @@ -846,7 +839,7 @@ inline Channel::Item::Item( const bsl::shared_ptr& state, bslma::Allocator* allocator) : d_type(bmqp::EventType::e_PUSH) -, d_hasWeakPtr(false) +, d_putHeader() , d_data_sp(payload) , d_queueId(queueId) , d_subQueueId(0) @@ -854,7 +847,6 @@ inline Channel::Item::Item( , d_flags(flags) , d_compressionAlgorithmType(compressionAlgorithmType) , d_messagePropertiesInfo(messagePropertiesInfo) -, d_data(allocator) , d_subQueueInfos(subQueueInfos, allocator) , d_correlationId(0) , d_status(0) @@ -874,14 +866,14 @@ inline Channel::Item::Item( const bsl::shared_ptr& state, bslma::Allocator* allocator) : d_type(bmqp::EventType::e_PUSH) -, d_hasWeakPtr(false) +, d_putHeader() +, d_data_sp(0, allocator) , d_queueId(queueId) , d_subQueueId(0) , d_msgId(msgId) , d_flags(flags) , d_compressionAlgorithmType(compressionAlgorithmType) , d_messagePropertiesInfo(messagePropertiesInfo) -, d_data(allocator) , d_subQueueInfos(subQueueInfos, allocator) , d_correlationId(0) , d_status(0) @@ -899,13 +891,14 @@ inline Channel::Item::Item(int status, const bsl::shared_ptr& state, bslma::Allocator* allocator) : d_type(bmqp::EventType::e_ACK) -, d_hasWeakPtr(false) +, d_putHeader() +, d_data_sp(0, allocator) , d_queueId(queueId) , d_subQueueId(0) , d_msgId(guid) , d_flags(0) , d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE) -, d_data(allocator) +, d_messagePropertiesInfo() , d_subQueueInfos(allocator) , d_correlationId(correlationId) , d_status(status) @@ -922,13 +915,14 @@ inline Channel::Item::Item(int queueId, bmqp::EventType::Enum type, bslma::Allocator* allocator) : d_type(type) -, d_hasWeakPtr(false) +, d_putHeader() +, d_data_sp(0, allocator) , d_queueId(queueId) , d_subQueueId(subQueueId) , d_msgId(guid) , d_flags(0) , d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE) -, d_data(allocator) +, d_messagePropertiesInfo() , d_subQueueInfos(allocator) , d_correlationId(0) , d_status(0) @@ -947,22 +941,24 @@ inline Channel::Item::Item(int queueId, } } -inline Channel::Item::Item(const bdlbb::Blob& data, +inline Channel::Item::Item(const bsl::shared_ptr& data, bmqp::EventType::Enum type, const bsl::shared_ptr& state, bslma::Allocator* allocator) : d_type(type) -, d_hasWeakPtr(false) +, d_putHeader() +, d_data_sp(data) , d_queueId(0) , d_subQueueId(0) +, d_msgId() , d_flags(0) , d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE) -, d_data(data, allocator) +, d_messagePropertiesInfo() , d_subQueueInfos(allocator) , d_correlationId(0) , d_status(0) , d_state(state) -, d_numBytes(data.length()) +, d_numBytes(data->length()) { // NOTHING } @@ -974,10 +970,6 @@ inline Channel::Item::~Item() inline const bsl::shared_ptr& Channel::Item::data() { - if (d_hasWeakPtr) { - d_tempData_sp = d_data_wp.lock(); - return d_tempData_sp; // RETURN - } return d_data_sp; } @@ -1066,7 +1058,7 @@ Channel::flushBuilder(Builder& builder, bmqio::Status st; if (builder.messageCount()) { - channel->write(&st, builder.blob()); + channel->write(&st, *builder.blob()); if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY( st.category() == bmqio::StatusCategory::e_SUCCESS)) { diff --git a/src/groups/mqb/mqbnet/mqbnet_channel.t.cpp b/src/groups/mqb/mqbnet/mqbnet_channel.t.cpp index ce852cca7c..e32f514521 100644 --- a/src/groups/mqb/mqbnet/mqbnet_channel.t.cpp +++ b/src/groups/mqb/mqbnet/mqbnet_channel.t.cpp @@ -54,16 +54,17 @@ namespace bmqio { class TestChannelEx : public TestChannel { private: - size_t d_limit; - mqbnet::Channel& d_channel; - bool d_isInHWM; - bslmt::ReaderWriterMutex d_mutex; - bdlbb::Blob d_eof; + size_t d_limit; + mqbnet::Channel& d_channel; + bool d_isInHWM; + bslmt::ReaderWriterMutex d_mutex; + bsl::shared_ptr d_eof_sp; public: - TestChannelEx(mqbnet::Channel& channel, - bdlbb::BlobBufferFactory* factory, - bslma::Allocator* basicAllocator); + TestChannelEx(mqbnet::Channel& channel, + bdlbb::BlobBufferFactory* factory, + bmqp::BlobPoolUtil::BlobSpPool* blobSpPool_p, + bslma::Allocator* basicAllocator); ~TestChannelEx() BSLS_KEYWORD_OVERRIDE; void write(bmqio::Status* status, @@ -84,16 +85,21 @@ const char k_CONTENT[] = "Being is always the Being of a being"; const size_t k_BUFFER_SIZE = sizeof(k_CONTENT) * 100; struct PseudoBuilder { - bdlbb::Blob d_payload; - PseudoBuilder(bdlbb::PooledBlobBufferFactory* bufferFactory, + bslma::Allocator* d_allocator_p; + bmqp::BlobPoolUtil::BlobSpPool* d_blobSpPool_p; + bsl::shared_ptr d_payload_sp; + + PseudoBuilder(bmqp::BlobPoolUtil::BlobSpPool* blobSpPool_p, bslma::Allocator* allocator_p) - : d_payload(bufferFactory, allocator_p) + : d_allocator_p(bslma::Default::allocator(allocator_p)) + , d_blobSpPool_p(blobSpPool_p) + , d_payload_sp(d_blobSpPool_p->getObject()) { // NOTHING } - int messageCount() const { return d_payload.length() ? 1 : 0; } - void reset() { d_payload.removeAll(); } - const bdlbb::Blob& blob() const { return d_payload; } + int messageCount() const { return d_payload_sp->length() ? 1 : 0; } + void reset() { d_payload_sp = d_blobSpPool_p->getObject(); } + bsl::shared_ptr blob() const { return d_payload_sp; } }; template struct Iterator { @@ -104,11 +110,15 @@ struct Iterator { template class Tester { + public: + typedef bsl::deque > BlobDeque; + private: Builder d_builder; bdlbb::PooledBlobBufferFactory& d_bufferFactory; + bmqp::BlobPoolUtil::BlobSpPool& d_blobSpPool; mqbnet::Channel& d_channel; - bsl::deque d_history; + BlobDeque d_history; bslmt::ThreadUtil::Handle d_threadHandle; bsls::AtomicBool d_stop; bslma::Allocator* d_allocator_p; @@ -122,6 +132,7 @@ class Tester { Tester(mqbnet::Channel& channel, bdlbb::PooledBlobBufferFactory& bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool& blobSpPool, bslma::Allocator* allocator_p); void test(); @@ -290,15 +301,17 @@ inline void setContent(bdlbb::BlobBuffer* buffer) namespace BloombergLP { namespace bmqio { -TestChannelEx::TestChannelEx(mqbnet::Channel& channel, - bdlbb::BlobBufferFactory* factory, - bslma::Allocator* basicAllocator) +TestChannelEx::TestChannelEx(mqbnet::Channel& channel, + bdlbb::BlobBufferFactory* factory, + bmqp::BlobPoolUtil::BlobSpPool* blobSpPool_p, + bslma::Allocator* basicAllocator) : TestChannel(basicAllocator) , d_limit(0) , d_channel(channel) , d_isInHWM(false) -, d_eof(factory, basicAllocator) +, d_eof_sp(0, basicAllocator) { + d_eof_sp = blobSpPool_p->getObject(); static const char signature[] = "12345"; bdlbb::BlobBuffer blobBuffer; factory->allocate(&blobBuffer); @@ -307,7 +320,7 @@ TestChannelEx::TestChannelEx(mqbnet::Channel& channel, bsl::memcpy(blobBuffer.data(), signature, sizeof(signature)); - d_eof.appendDataBuffer(blobBuffer); + d_eof_sp->appendDataBuffer(blobBuffer); } TestChannelEx::~TestChannelEx() @@ -380,10 +393,10 @@ void TestChannelEx::write(bmqio::Status* status, bool TestChannelEx::waitForChannel(const bsls::TimeInterval& interval) { - ASSERT_EQ(d_channel.writeBlob(d_eof, bmqp::EventType::e_CONTROL), + ASSERT_EQ(d_channel.writeBlob(d_eof_sp, bmqp::EventType::e_CONTROL), bmqt::GenericResult::e_SUCCESS); - return waitFor(d_eof, interval); + return waitFor(*d_eof_sp, interval); } } @@ -396,9 +409,11 @@ bool TestChannelEx::waitForChannel(const bsls::TimeInterval& interval) template inline Tester::Tester(mqbnet::Channel& channel, bdlbb::PooledBlobBufferFactory& bufferFactory, + bmqp::BlobPoolUtil::BlobSpPool& blobSpPool, bslma::Allocator* allocator_p) -: d_builder(&bufferFactory, allocator_p) +: d_builder(&blobSpPool, allocator_p) , d_bufferFactory(bufferFactory) +, d_blobSpPool(blobSpPool) , d_channel(channel) , d_history(allocator_p) , d_threadHandle() @@ -432,9 +447,7 @@ inline bmqt::EventBuilderResult::Enum Tester::build() static int queueId = 0; bmqp::PutHeader ph; const int flags = 0; - bsl::shared_ptr payload( - new (*d_allocator_p) bdlbb::Blob(&d_bufferFactory, d_allocator_p), - d_allocator_p); + bsl::shared_ptr payload_sp = d_blobSpPool.getObject(); bdlbb::BlobBuffer blobBuffer; bsl::shared_ptr state(new (*d_allocator_p) bmqu::AtomicState, @@ -444,7 +457,7 @@ inline bmqt::EventBuilderResult::Enum Tester::build() setContent(&blobBuffer); - payload->appendDataBuffer(blobBuffer); + payload_sp->appendDataBuffer(blobBuffer); ph.setCorrelationId(++id); ph.setMessageGUID(bmqp::MessageGUIDGenerator::testGUID()); @@ -456,14 +469,14 @@ inline bmqt::EventBuilderResult::Enum Tester::build() d_builder.setMessageGUID(ph.messageGUID()) .setFlags(ph.flags()) - .setMessagePayload(payload.get()) + .setMessagePayload(payload_sp.get()) .setCompressionAlgorithmType(ph.compressionAlgorithmType()) .setCrc32c(ph.crc32c()); bmqt::EventBuilderResult::Enum rc = d_builder.packMessage(queueId); if (rc == bmqt::EventBuilderResult::e_SUCCESS) { - d_channel.writePut(ph, payload, state); + d_channel.writePut(ph, payload_sp, state); } return rc; } @@ -501,24 +514,23 @@ inline bmqt::EventBuilderResult::Enum Tester::build() } } else { - bsl::shared_ptr payload( - new (*d_allocator_p) bdlbb::Blob(&d_bufferFactory, d_allocator_p), - d_allocator_p); + bsl::shared_ptr payload_sp = d_blobSpPool.getObject(); bdlbb::BlobBuffer blobBuffer; - d_bufferFactory.allocate(&blobBuffer); + ASSERT(0 != payload_sp->factory()); + payload_sp->factory()->allocate(&blobBuffer); setContent(&blobBuffer); - payload->appendDataBuffer(blobBuffer); + payload_sp->appendDataBuffer(blobBuffer); - rc = d_builder.packMessage(*payload, + rc = d_builder.packMessage(*payload_sp, queueId, guid, flags, bmqt::CompressionAlgorithmType::e_NONE); if (rc == bmqt::EventBuilderResult::e_SUCCESS) { - d_channel.writePush(payload, + d_channel.writePush(payload_sp, queueId, guid, flags, @@ -590,23 +602,24 @@ inline bmqt::EventBuilderResult::Enum Tester::build() template <> inline bmqt::EventBuilderResult::Enum Tester::build() { - d_builder.d_payload.setLength(sizeof(bmqp::EventHeader)); + d_builder.d_payload_sp->setLength(sizeof(bmqp::EventHeader)); - bmqp::EventHeader* eventHeader = new (d_builder.d_payload.buffer(0).data()) + bmqp::EventHeader* eventHeader = new ( + d_builder.d_payload_sp->buffer(0).data()) bmqp::EventHeader(bmqp::EventType::e_CONTROL); bdlbb::BlobBuffer blobBuffer; d_bufferFactory.allocate(&blobBuffer); setContent(&blobBuffer); - d_builder.d_payload.appendDataBuffer(blobBuffer); + d_builder.d_payload_sp->appendDataBuffer(blobBuffer); - eventHeader->setLength(d_builder.d_payload.length()); + eventHeader->setLength(d_builder.d_payload_sp->length()); - d_channel.writeBlob(d_builder.d_payload, bmqp::EventType::e_CONTROL); + d_channel.writeBlob(d_builder.d_payload_sp, bmqp::EventType::e_CONTROL); // never return e_EVENT_TOO_BIG - d_history.push_back(d_builder.d_payload); + d_history.push_back(d_builder.d_payload_sp); d_builder.reset(); return bmqt::EventBuilderResult::e_SUCCESS; @@ -628,11 +641,11 @@ inline size_t Tester::verify( size_t counter = 0; size_t writeBlobs = 0; - for (bsl::deque::iterator itHistory = d_history.begin(); + for (BlobDeque::iterator itHistory = d_history.begin(); itHistory != d_history.end(); ++itHistory) { - const bdlbb::Blob& blob = *itHistory; - bmqp::Event eventHistory(&blob, d_allocator_p); + const bsl::shared_ptr& blob_sp = *itHistory; + bmqp::Event eventHistory(blob_sp.get(), d_allocator_p); Iterator itHistoryEvents(&d_bufferFactory, d_allocator_p); itHistoryEvents.load(eventHistory); @@ -727,6 +740,10 @@ static void test1_write() bdlbb::PooledBlobBufferFactory bufferFactory( k_BUFFER_SIZE, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); mqbnet::Channel channel(&bufferFactory, "test", bmqtst::TestHelperUtil::allocator()); @@ -735,25 +752,31 @@ static void test1_write() new (*bmqtst::TestHelperUtil::allocator()) bmqio::TestChannelEx(channel, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()), bmqtst::TestHelperUtil::allocator()); Tester put(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester push(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester ack(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester confirm( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester reject( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); channel.setChannel(bsl::weak_ptr(testChannel)); @@ -807,6 +830,10 @@ static void test2_highWatermark() bdlbb::PooledBlobBufferFactory bufferFactory( k_BUFFER_SIZE, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); mqbnet::Channel channel(&bufferFactory, "test", bmqtst::TestHelperUtil::allocator()); @@ -815,28 +842,35 @@ static void test2_highWatermark() new (*bmqtst::TestHelperUtil::allocator()) bmqio::TestChannelEx(channel, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()), bmqtst::TestHelperUtil::allocator()); Tester put(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester push(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester ack(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester confirm( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester control(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester reject( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); bslmt::Barrier phase1(6 + 1); @@ -913,6 +947,10 @@ static void test3_highWatermarkInWriteCb() bdlbb::PooledBlobBufferFactory bufferFactory( k_BUFFER_SIZE, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); mqbnet::Channel channel(&bufferFactory, "test", bmqtst::TestHelperUtil::allocator()); @@ -921,25 +959,31 @@ static void test3_highWatermarkInWriteCb() new (*bmqtst::TestHelperUtil::allocator()) bmqio::TestChannelEx(channel, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()), bmqtst::TestHelperUtil::allocator()); Tester put(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester push(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester ack(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester confirm( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester reject( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); bslmt::Barrier phase1(5 + 1); @@ -1017,6 +1061,10 @@ static void test4_controlBlob() bdlbb::PooledBlobBufferFactory bufferFactory( k_BUFFER_SIZE, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); mqbnet::Channel channel(&bufferFactory, "test", bmqtst::TestHelperUtil::allocator()); @@ -1025,25 +1073,31 @@ static void test4_controlBlob() new (*bmqtst::TestHelperUtil::allocator()) bmqio::TestChannelEx(channel, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()), bmqtst::TestHelperUtil::allocator()); Tester put(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester push(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester ack(channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester confirm( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); Tester reject( channel, bufferFactory, + blobSpPool, bmqtst::TestHelperUtil::allocator()); channel.setChannel(bsl::weak_ptr(testChannel)); @@ -1056,19 +1110,18 @@ static void test4_controlBlob() // cannot assert 'writeCalls().size() == 0' because of auto-flushing - bdlbb::Blob payload = bdlbb::Blob(&bufferFactory, - bmqtst::TestHelperUtil::allocator()); + bsl::shared_ptr payload_sp = blobSpPool.getObject(); bdlbb::BlobBuffer blobBuffer; bufferFactory.allocate(&blobBuffer); bsl::memset(blobBuffer.data(), 0, blobBuffer.size()); - payload.appendDataBuffer(blobBuffer); + payload_sp->appendDataBuffer(blobBuffer); // Flush ACKs which are secondary channel.flush(); - ASSERT_EQ(channel.writeBlob(payload, bmqp::EventType::e_CONTROL), + ASSERT_EQ(channel.writeBlob(payload_sp, bmqp::EventType::e_CONTROL), bmqt::GenericResult::e_SUCCESS); ASSERT_EQ(testChannel->waitForChannel(bsls::TimeInterval(1)), true); @@ -1086,7 +1139,7 @@ static void test4_controlBlob() const bdlbb::Blob& lastWrite = (--testChannel->writeCalls().end())->d_blob; // make sure the control is the last - ASSERT_EQ(bdlbb::BlobUtil::compare(payload, lastWrite), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*payload_sp, lastWrite), 0); } static void test5_reconnect() @@ -1101,6 +1154,10 @@ static void test5_reconnect() bdlbb::PooledBlobBufferFactory bufferFactory( k_BUFFER_SIZE, bmqtst::TestHelperUtil::allocator()); + bmqp::BlobPoolUtil::BlobSpPool blobSpPool( + bmqp::BlobPoolUtil::createBlobPool( + &bufferFactory, + bmqtst::TestHelperUtil::allocator())); mqbnet::Channel channel(&bufferFactory, "test", bmqtst::TestHelperUtil::allocator()); @@ -1109,42 +1166,41 @@ static void test5_reconnect() new (*bmqtst::TestHelperUtil::allocator()) bmqio::TestChannelEx(channel, &bufferFactory, + &blobSpPool, bmqtst::TestHelperUtil::allocator()), bmqtst::TestHelperUtil::allocator()); channel.setChannel(bsl::weak_ptr(testChannel)); { - bdlbb::Blob payload = bdlbb::Blob(&bufferFactory, - bmqtst::TestHelperUtil::allocator()); + bsl::shared_ptr payload_sp = blobSpPool.getObject(); bdlbb::BlobBuffer blobBuffer; bufferFactory.allocate(&blobBuffer); setContent(&blobBuffer); - payload.appendDataBuffer(blobBuffer); + payload_sp->appendDataBuffer(blobBuffer); - ASSERT_EQ(channel.writeBlob(payload, bmqp::EventType::e_CONTROL), + ASSERT_EQ(channel.writeBlob(payload_sp, bmqp::EventType::e_CONTROL), bmqt::GenericResult::e_SUCCESS); ASSERT_EQ(testChannel->waitForChannel(bsls::TimeInterval(1)), true); const bdlbb::Blob& write = testChannel->writeCalls().begin()->d_blob; - ASSERT_EQ(bdlbb::BlobUtil::compare(payload, write), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*payload_sp, write), 0); } ASSERT_EQ(testChannel->writeCalls().size(), 1U); testChannel->setWriteStatus(bmqio::StatusCategory::e_CONNECTION); { - bdlbb::Blob payload = bdlbb::Blob(&bufferFactory, - bmqtst::TestHelperUtil::allocator()); + bsl::shared_ptr payload_sp = blobSpPool.getObject(); bdlbb::BlobBuffer blobBuffer; bufferFactory.allocate(&blobBuffer); setContent(&blobBuffer); - payload.appendDataBuffer(blobBuffer); + payload_sp->appendDataBuffer(blobBuffer); - ASSERT_EQ(channel.writeBlob(payload, bmqp::EventType::e_CONTROL), + ASSERT_EQ(channel.writeBlob(payload_sp, bmqp::EventType::e_CONTROL), bmqt::GenericResult::e_SUCCESS); } ASSERT_EQ(testChannel->writeCalls().size(), 1U); @@ -1156,109 +1212,26 @@ static void test5_reconnect() testChannel->setWriteStatus(bmqio::StatusCategory::e_SUCCESS); { - bdlbb::Blob payload = bdlbb::Blob(&bufferFactory, - bmqtst::TestHelperUtil::allocator()); + bsl::shared_ptr payload_sp = blobSpPool.getObject(); bdlbb::BlobBuffer blobBuffer; bufferFactory.allocate(&blobBuffer); setContent(&blobBuffer); - payload.appendDataBuffer(blobBuffer); + payload_sp->appendDataBuffer(blobBuffer); - ASSERT_EQ(channel.writeBlob(payload, bmqp::EventType::e_CONTROL), + ASSERT_EQ(channel.writeBlob(payload_sp, bmqp::EventType::e_CONTROL), bmqt::GenericResult::e_SUCCESS); ASSERT_EQ(testChannel->waitForChannel(bsls::TimeInterval(1)), true); const bdlbb::Blob& write = (++testChannel->writeCalls().begin())->d_blob; - ASSERT_EQ(bdlbb::BlobUtil::compare(payload, write), 0); + ASSERT_EQ(bdlbb::BlobUtil::compare(*payload_sp, write), 0); } ASSERT_EQ(testChannel->writeCalls().size(), 2U); } -static void test6_weakData() -// ------------------------------------------------------------------------ -// -// Call writePut which takes weak_ptr under HWM causing the channel to -// buffer data. Release the data, simulate LWM, and observe negative -// return code, -// -// ------------------------------------------------------------------------ -{ - bdlbb::PooledBlobBufferFactory bufferFactory( - k_BUFFER_SIZE, - bmqtst::TestHelperUtil::allocator()); - mqbnet::Channel channel(&bufferFactory, - "test", - bmqtst::TestHelperUtil::allocator()); - - bsl::shared_ptr testChannel( - new (*bmqtst::TestHelperUtil::allocator()) - bmqio::TestChannelEx(channel, - &bufferFactory, - bmqtst::TestHelperUtil::allocator()), - bmqtst::TestHelperUtil::allocator()); - - channel.setChannel(bsl::weak_ptr(testChannel)); - - // Saturate the channel causing it to buffer next write - channel.onWatermark(bmqio::ChannelWatermarkType::e_HIGH_WATERMARK); - - { - bsl::shared_ptr payload( - new (*bmqtst::TestHelperUtil::allocator()) - bdlbb::Blob(&bufferFactory, - bmqtst::TestHelperUtil::allocator()), - bmqtst::TestHelperUtil::allocator()); - bdlbb::BlobBuffer blobBuffer; - bsl::shared_ptr state( - new (*bmqtst::TestHelperUtil::allocator()) bmqu::AtomicState, - bmqtst::TestHelperUtil::allocator()); - bmqp::PutHeader ph; - - bufferFactory.allocate(&blobBuffer); - - payload->appendDataBuffer(blobBuffer); - ph.setMessageGUID(bmqp::MessageGUIDGenerator::testGUID()); - - // This write ends up in the builder and cannot be canceled. - ASSERT_EQ(channel.writePut(ph, payload, state, false), - bmqt::GenericResult::e_SUCCESS); - // After 'onWatermark', the channel starts buffering. - } - ASSERT_EQ(testChannel->writeCalls().size(), 0U); - - // Next write - { - bsl::shared_ptr payload( - new (*bmqtst::TestHelperUtil::allocator()) - bdlbb::Blob(&bufferFactory, - bmqtst::TestHelperUtil::allocator()), - bmqtst::TestHelperUtil::allocator()); - bdlbb::BlobBuffer blobBuffer; - bsl::shared_ptr state( - new (*bmqtst::TestHelperUtil::allocator()) bmqu::AtomicState, - bmqtst::TestHelperUtil::allocator()); - bmqp::PutHeader ph; - - bufferFactory.allocate(&blobBuffer); - - payload->appendDataBuffer(blobBuffer); - ph.setMessageGUID(bmqp::MessageGUIDGenerator::testGUID()); - - ASSERT_EQ(channel.writePut(ph, payload, state, true), - bmqt::GenericResult::e_SUCCESS); - } - - channel.onWatermark(bmqio::ChannelWatermarkType::e_LOW_WATERMARK); - - ASSERT_EQ(testChannel->waitForChannel(bsls::TimeInterval(1)), true); - - // Only the first write makes it to IO. - ASSERT_EQ(testChannel->writeCalls().size(), 1U); -} - // ============================================================================ // MAIN PROGRAM // ---------------------------------------------------------------------------- @@ -1279,7 +1252,6 @@ int main(int argc, char* argv[]) case 3: test3_highWatermarkInWriteCb(); break; case 4: test4_controlBlob(); break; case 5: test5_reconnect(); break; - case 6: test6_weakData(); break; default: { cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl; bmqtst::TestHelperUtil::testStatus() = -1; diff --git a/src/groups/mqb/mqbnet/mqbnet_cluster.h b/src/groups/mqb/mqbnet/mqbnet_cluster.h index dfd2192b20..15e0853341 100644 --- a/src/groups/mqb/mqbnet/mqbnet_cluster.h +++ b/src/groups/mqb/mqbnet/mqbnet_cluster.h @@ -147,8 +147,9 @@ class ClusterNode { /// success, and a non-zero value otherwise. Note that success does not /// imply that the data has been written or will be successfully written /// to the underlying stream used by this channel. - virtual bmqt::GenericResult::Enum write(const bdlbb::Blob& blob, - bmqp::EventType::Enum type) = 0; + virtual bmqt::GenericResult::Enum + write(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) = 0; // ACCESSORS @@ -214,13 +215,13 @@ class Cluster { /// nodes of this cluster (with the exception of the current node). /// Return the maximum number of pending items across all cluster /// channels prior to broadcasting. - virtual int writeAll(const bdlbb::Blob& blob, - bmqp::EventType::Enum type) = 0; + virtual int writeAll(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) = 0; /// Send the specified `blob` to all currently up nodes of this cluster /// (exception of the current node). Return the maximum number of /// pending items across all cluster channels prior to broadcasting. - virtual int broadcast(const bdlbb::Blob& blob) = 0; + virtual int broadcast(const bsl::shared_ptr& blob) = 0; /// Close the channels associated to all nodes in this cluster. virtual void closeChannels() = 0; diff --git a/src/groups/mqb/mqbnet/mqbnet_cluster.t.cpp b/src/groups/mqb/mqbnet/mqbnet_cluster.t.cpp index a7aee7fbf9..0863d5b2c9 100644 --- a/src/groups/mqb/mqbnet/mqbnet_cluster.t.cpp +++ b/src/groups/mqb/mqbnet/mqbnet_cluster.t.cpp @@ -76,7 +76,7 @@ struct ClusterNodeTestImp : bsls::ProtocolTestImp { void closeChannel() BSLS_KEYWORD_OVERRIDE { markDone(); } bmqt::GenericResult::Enum - write(const bdlbb::Blob& blob, + write(const bsl::shared_ptr& blob, bmqp::EventType::Enum type = bmqp::EventType::e_CONTROL) BSLS_KEYWORD_OVERRIDE { @@ -129,14 +129,15 @@ struct ClusterTestImp : bsls::ProtocolTestImp { return markDone(); } - int writeAll(const bdlbb::Blob& blob, + int writeAll(const bsl::shared_ptr& blob, bmqp::EventType::Enum type = bmqp::EventType::e_CONTROL) BSLS_KEYWORD_OVERRIDE { return markDone(); } - int broadcast(const bdlbb::Blob& blob) BSLS_KEYWORD_OVERRIDE + int + broadcast(const bsl::shared_ptr& blob) BSLS_KEYWORD_OVERRIDE { return markDone(); } @@ -304,7 +305,7 @@ static void test2_ClusterNode() PV("Verify that methods are public and virtual"); bsl::weak_ptr dummyWeakChannel; - bdlbb::Blob dummyBlob; + bsl::shared_ptr dummyBlob_sp; bmqp_ctrlmsg::ClientIdentity identity; BSLS_PROTOCOLTEST_ASSERT(testObj, @@ -315,7 +316,8 @@ static void test2_ClusterNode() BSLS_PROTOCOLTEST_ASSERT(testObj, closeChannel()); BSLS_PROTOCOLTEST_ASSERT(testObj, resetChannel()); BSLS_PROTOCOLTEST_ASSERT(testObj, - write(dummyBlob, bmqp::EventType::e_CONTROL)); + write(dummyBlob_sp, + bmqp::EventType::e_CONTROL)); BSLS_PROTOCOLTEST_ASSERT(testObj, channel()); BSLS_PROTOCOLTEST_ASSERT(testObj, identity()); BSLS_PROTOCOLTEST_ASSERT(testObj, nodeId()); @@ -386,7 +388,7 @@ static void test3_Cluster() PV("Verify that methods are public and virtual"); mqbnet::ClusterObserver* dummyClusterObserver_p = 0; - bdlbb::Blob dummyBlob; + bsl::shared_ptr dummyBlob_sp; int dummyInt = 0; BSLS_PROTOCOLTEST_ASSERT(testObj, @@ -394,9 +396,9 @@ static void test3_Cluster() BSLS_PROTOCOLTEST_ASSERT(testObj, unregisterObserver(dummyClusterObserver_p)); BSLS_PROTOCOLTEST_ASSERT(testObj, - writeAll(dummyBlob, + writeAll(dummyBlob_sp, bmqp::EventType::e_CONTROL)); - BSLS_PROTOCOLTEST_ASSERT(testObj, broadcast(dummyBlob)); + BSLS_PROTOCOLTEST_ASSERT(testObj, broadcast(dummyBlob_sp)); BSLS_PROTOCOLTEST_ASSERT(testObj, closeChannels()); BSLS_PROTOCOLTEST_ASSERT(testObj, lookupNode(dummyInt)); BSLS_PROTOCOLTEST_ASSERT(testObj, enableRead()); diff --git a/src/groups/mqb/mqbnet/mqbnet_clusterimp.cpp b/src/groups/mqb/mqbnet/mqbnet_clusterimp.cpp index a5c4ccdb20..c082df619f 100644 --- a/src/groups/mqb/mqbnet/mqbnet_clusterimp.cpp +++ b/src/groups/mqb/mqbnet/mqbnet_clusterimp.cpp @@ -142,8 +142,9 @@ void ClusterNodeImp::closeChannel() d_channel.closeChannel(); } -bmqt::GenericResult::Enum ClusterNodeImp::write(const bdlbb::Blob& blob, - bmqp::EventType::Enum type) +bmqt::GenericResult::Enum +ClusterNodeImp::write(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) { return d_channel.writeBlob(blob, type); } @@ -231,7 +232,8 @@ Cluster* ClusterImp::unregisterObserver(ClusterObserver* observer) return this; } -int ClusterImp::writeAll(const bdlbb::Blob& blob, bmqp::EventType::Enum type) +int ClusterImp::writeAll(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) { unsigned int maxPushChannelPendingItems = 0; unsigned int maxChannelPendingItems = 0; @@ -262,7 +264,7 @@ int ClusterImp::writeAll(const bdlbb::Blob& blob, bmqp::EventType::Enum type) if (d_failedWritesThrottler.requestPermission()) { BALL_LOG_ERROR << "#CLUSTER_SEND_FAILURE " << "Failed to write blob of length [" - << blob.length() << "] bytes, to node " + << blob->length() << "] bytes, to node " << it->nodeDescription() << ", rc: " << rc << "."; } @@ -277,7 +279,7 @@ int ClusterImp::writeAll(const bdlbb::Blob& blob, bmqp::EventType::Enum type) return maxPushChannelPendingItems; } -int ClusterImp::broadcast(const bdlbb::Blob& blob) +int ClusterImp::broadcast(const bsl::shared_ptr& blob) { return writeAll(blob, bmqp::EventType::e_STORAGE); } diff --git a/src/groups/mqb/mqbnet/mqbnet_clusterimp.h b/src/groups/mqb/mqbnet/mqbnet_clusterimp.h index ce23a0f8a1..5122ff90d3 100644 --- a/src/groups/mqb/mqbnet/mqbnet_clusterimp.h +++ b/src/groups/mqb/mqbnet/mqbnet_clusterimp.h @@ -151,8 +151,8 @@ class ClusterNodeImp : public ClusterNode { /// imply that the data has been written or will be successfully written /// to the underlying stream used by this channel. bmqt::GenericResult::Enum - write(const bdlbb::Blob& blob, - bmqp::EventType::Enum type) BSLS_KEYWORD_OVERRIDE; + write(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) BSLS_KEYWORD_OVERRIDE; // ACCESSORS const bmqp_ctrlmsg::ClientIdentity& identity() const BSLS_KEYWORD_OVERRIDE; @@ -296,13 +296,14 @@ class ClusterImp : public Cluster { /// nodes of this cluster (with the exception of the current node). /// Return the maximum number of pending items across all cluster /// channels prior to broadcasting. - int writeAll(const bdlbb::Blob& blob, + int writeAll(const bsl::shared_ptr& blob, bmqp::EventType::Enum type) BSLS_KEYWORD_OVERRIDE; /// Send the specified `blob` to all currently up nodes of this cluster /// (exception of the current node). Return the maximum number of /// pending items across all cluster channels prior to broadcasting. - int broadcast(const bdlbb::Blob& blob) BSLS_KEYWORD_OVERRIDE; + int + broadcast(const bsl::shared_ptr& blob) BSLS_KEYWORD_OVERRIDE; /// Close the channels associated to all nodes in this cluster. void closeChannels() BSLS_KEYWORD_OVERRIDE; diff --git a/src/groups/mqb/mqbnet/mqbnet_elector.cpp b/src/groups/mqb/mqbnet/mqbnet_elector.cpp index 5b6f717986..9d25d1f64a 100644 --- a/src/groups/mqb/mqbnet/mqbnet_elector.cpp +++ b/src/groups/mqb/mqbnet/mqbnet_elector.cpp @@ -2078,7 +2078,9 @@ void Elector::emitIOEvent(const ElectorStateMachineOutput& output) // 'emitIOEvent' is currently always called while 'd_lock' is held, but // that's an implementation side effect, not part of contract. That's why // we create the builder on stack instead of making it a class member. - bmqp::SchemaEventBuilder builder(d_bufferFactory_p, d_allocator_p); + bmqp::SchemaEventBuilder builder(d_blobSpPool_p, + bmqp::EncodingType::e_BER, + d_allocator_p); int rc = builder.setMessage(message, bmqp::EventType::e_ELECTOR); if (0 != rc) { @@ -2089,7 +2091,7 @@ void Elector::emitIOEvent(const ElectorStateMachineOutput& output) } // Retrieve the encoded event - const bdlbb::Blob& blob = builder.blob(); + const bsl::shared_ptr blob = builder.blob(); if (k_ALL_NODES_ID == output.destination()) { // Broadcast to cluster, using the unicast channel to ensure ordering // of events @@ -2201,10 +2203,10 @@ Elector::Elector(mqbcfg::ElectorConfig& config, mqbi::Cluster* cluster, const ElectorStateCallback& callback, bsls::Types::Uint64 initialTerm, - bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator) : d_allocator_p(allocator) -, d_bufferFactory_p(bufferFactory) +, d_blobSpPool_p(blobSpPool_p) , d_cluster_p(cluster) , d_netCluster_p(0) , d_config(config) @@ -2223,7 +2225,7 @@ Elector::Elector(mqbcfg::ElectorConfig& config, , d_previousEventAge(0) // first state transition's age will be 1 { BSLS_ASSERT_SAFE(d_allocator_p); - BSLS_ASSERT_SAFE(d_bufferFactory_p); + BSLS_ASSERT_SAFE(d_blobSpPool_p); BSLS_ASSERT_SAFE(d_cluster_p); BSLS_ASSERT_SAFE(d_callback); diff --git a/src/groups/mqb/mqbnet/mqbnet_elector.h b/src/groups/mqb/mqbnet/mqbnet_elector.h index 59a1145c24..90c203aa8c 100644 --- a/src/groups/mqb/mqbnet/mqbnet_elector.h +++ b/src/groups/mqb/mqbnet/mqbnet_elector.h @@ -790,6 +790,9 @@ class Elector : public SessionEventProcessor { BALL_LOG_SET_CLASS_CATEGORY("MQBNET.ELECTOR"); public: + // TYPES + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + // PUBLIC CLASS DATA static const bsls::Types::Uint64 k_INVALID_TERM = ElectorStateMachine::k_INVALID_TERM; @@ -833,7 +836,7 @@ class Elector : public SessionEventProcessor { // DATA bslma::Allocator* d_allocator_p; - bdlbb::BlobBufferFactory* d_bufferFactory_p; + BlobSpPool* d_blobSpPool_p; mqbi::Cluster* d_cluster_p; @@ -1008,13 +1011,13 @@ class Elector : public SessionEventProcessor { /// Create an elector instance with the specified `config`, invoking the /// specified `callback` whenever elector state changes, using the /// specified `cluster` for emitting I/O events, using the specified - /// `initalTerm` and using the specified `bufferFactory` for blobs + /// `initalTerm` and using the specified `blobSpPool_p` for blobs /// allocation and `allocator` for memory allocation. Elector(mqbcfg::ElectorConfig& config, mqbi::Cluster* cluster, const ElectorStateCallback& callback, bsls::Types::Uint64 initialTerm, - bdlbb::BlobBufferFactory* bufferFactory, + BlobSpPool* blobSpPool_p, bslma::Allocator* allocator); /// Destroy this instance. Behavior is undefined unless this instance diff --git a/src/groups/mqb/mqbnet/mqbnet_mockcluster.cpp b/src/groups/mqb/mqbnet/mqbnet_mockcluster.cpp index 7596f10661..4c30f94086 100644 --- a/src/groups/mqb/mqbnet/mqbnet_mockcluster.cpp +++ b/src/groups/mqb/mqbnet/mqbnet_mockcluster.cpp @@ -118,8 +118,9 @@ void MockClusterNode::closeChannel() d_channel.closeChannel(); } -bmqt::GenericResult::Enum MockClusterNode::write(const bdlbb::Blob& blob, - bmqp::EventType::Enum type) +bmqt::GenericResult::Enum +MockClusterNode::write(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) { return d_channel.writeBlob(blob, type); } @@ -195,7 +196,8 @@ Cluster* MockCluster::unregisterObserver(ClusterObserver* observer) return this; } -int MockCluster::writeAll(const bdlbb::Blob& blob, bmqp::EventType::Enum type) +int MockCluster::writeAll(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) { for (bsl::list::iterator it = d_nodes.begin(); it != d_nodes.end(); @@ -209,7 +211,7 @@ int MockCluster::writeAll(const bdlbb::Blob& blob, bmqp::EventType::Enum type) return 0; } -int MockCluster::broadcast(const bdlbb::Blob& blob) +int MockCluster::broadcast(const bsl::shared_ptr& blob) { if (d_disableBroadcast) { return 0; // RETURN diff --git a/src/groups/mqb/mqbnet/mqbnet_mockcluster.h b/src/groups/mqb/mqbnet/mqbnet_mockcluster.h index 44582d10e6..50bade48c9 100644 --- a/src/groups/mqb/mqbnet/mqbnet_mockcluster.h +++ b/src/groups/mqb/mqbnet/mqbnet_mockcluster.h @@ -136,8 +136,8 @@ class MockClusterNode : public ClusterNode { /// imply that the data has been written or will be successfully written /// to the underlying stream used by this channel. bmqt::GenericResult::Enum - write(const bdlbb::Blob& blob, - bmqp::EventType::Enum type) BSLS_KEYWORD_OVERRIDE; + write(const bsl::shared_ptr& blob, + bmqp::EventType::Enum type) BSLS_KEYWORD_OVERRIDE; // ACCESSORS // (virtual mqbnet::ClusterNode) @@ -271,13 +271,14 @@ class MockCluster : public Cluster { /// nodes of this cluster (with the exception of the current node). /// Return the maximum number of pending items across all cluster /// channels prior to broadcasting. - int writeAll(const bdlbb::Blob& blob, + int writeAll(const bsl::shared_ptr& blob, bmqp::EventType::Enum type) BSLS_KEYWORD_OVERRIDE; /// Send the specified `blob` to all currently up nodes of this cluster /// (exception of the current node). Return the maximum number of /// pending items across all cluster channels prior to broadcasting. - int broadcast(const bdlbb::Blob& blob) BSLS_KEYWORD_OVERRIDE; + int + broadcast(const bsl::shared_ptr& blob) BSLS_KEYWORD_OVERRIDE; /// Close the channels associated to all nodes in this cluster. void closeChannels() BSLS_KEYWORD_OVERRIDE; diff --git a/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.h b/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.h index 411de3e28c..c15eaea525 100644 --- a/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.h +++ b/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.h @@ -196,8 +196,9 @@ class MultiRequestManager { private: // PRIVATE MANIPULATORS - static bmqt::GenericResult::Enum sendHelper(bmqio::Channel* channel, - const bdlbb::Blob& blob); + static bmqt::GenericResult::Enum + sendHelper(bmqio::Channel* channel, + const bsl::shared_ptr& blob); /// Create a `MultiRequestManagerRequestContext` object at the specified /// `address` using the supplied `allocator`. This is used by the @@ -336,11 +337,11 @@ MultiRequestManagerRequestContext::response() const template inline bmqt::GenericResult::Enum MultiRequestManager::sendHelper( - bmqio::Channel* channel, - const bdlbb::Blob& blob) + bmqio::Channel* channel, + const bsl::shared_ptr& blob) { bmqio::Status status; - channel->write(&status, blob); + channel->write(&status, *blob); switch (status.category()) { case bmqio::StatusCategory::e_SUCCESS: diff --git a/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.t.cpp b/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.t.cpp index ad2d5b0a31..4d8cf110ce 100644 --- a/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.t.cpp +++ b/src/groups/mqb/mqbnet/mqbnet_multirequestmanager.t.cpp @@ -122,6 +122,9 @@ class TestContext { bdlbb::PooledBlobBufferFactory d_blobBufferFactory; // Buffer factory provided to the various builders + /// Blob shared pointer pool used in event builders. + bmqp::BlobPoolUtil::BlobSpPool d_blobSpPool; + ReqManagerTypeSp d_requestManager; // RequestManager object under testing @@ -233,6 +236,9 @@ class TestContext { TestContext::TestContext(int nodesCount, bslma::Allocator* allocator) : d_blobBufferFactory(1024, allocator) +, d_blobSpPool( + bmqp::BlobPoolUtil::createBlobPool(&d_blobBufferFactory, + bmqtst::TestHelperUtil::allocator())) , d_requestManager(0) , d_multiRequestManager(0) , d_requestContextSp(0) @@ -260,7 +266,7 @@ TestContext::TestContext(int nodesCount, bslma::Allocator* allocator) d_requestManager = bsl::make_shared( bmqp::EventType::e_CONTROL, - &d_blobBufferFactory, + &d_blobSpPool, &d_cluster_mp->_scheduler(), false, // lateResponseMode d_allocator_p); diff --git a/src/groups/mqb/mqbs/mqbs_filestore.cpp b/src/groups/mqb/mqbs/mqbs_filestore.cpp index ddd5fceb22..bdf5c9106e 100644 --- a/src/groups/mqb/mqbs/mqbs_filestore.cpp +++ b/src/groups/mqb/mqbs/mqbs_filestore.cpp @@ -3904,9 +3904,8 @@ void FileStore::processReceiptEvent(unsigned int primaryLeaseId, if (itNode == d_nodes.end()) { // no prior history about this node - d_nodes.insert(bsl::make_pair( - nodeId, - NodeContext(d_config.bufferFactory(), recordKey, d_allocator_p))); + d_nodes.insert( + bsl::make_pair(nodeId, NodeContext(d_blobSpPool_p, recordKey))); from = d_unreceipted.begin(); } else if (itNode->second.d_key < recordKey) { @@ -5241,7 +5240,7 @@ FileStore::FileStore(const DataStoreConfig& config, , d_nagglePacketCount(k_NAGLE_PACKET_COUNT) , d_storageEventBuilder(FileStoreProtocol::k_VERSION, bmqp::EventType::e_STORAGE, - config.bufferFactory(), + d_blobSpPool_p, allocator) { // PRECONDITIONS @@ -6524,11 +6523,9 @@ FileStore::generateReceipt(NodeContext* nodeContext, if (itNode == d_nodes.end()) { // no prior history about this node itNode = d_nodes - .insert(bsl::make_pair( - nodeId, - NodeContext(d_config.bufferFactory(), - key, - d_allocator_p))) + .insert( + bsl::make_pair(nodeId, + NodeContext(d_blobSpPool_p, key))) .first; } nodeContext = &itNode->second; @@ -6542,7 +6539,7 @@ FileStore::generateReceipt(NodeContext* nodeContext, } if (nodeContext->d_state && nodeContext->d_state->tryLock()) { - char* buffer = nodeContext->d_blob.buffer(0).data(); + char* buffer = nodeContext->d_blob_sp->buffer(0).data(); bmqp::ReplicationReceipt* receipt = reinterpret_cast( buffer + sizeof(bmqp::EventHeader)); @@ -6555,7 +6552,11 @@ FileStore::generateReceipt(NodeContext* nodeContext, nodeContext->d_state->unlock(); } else { - bmqp::ProtocolUtil::buildReceipt(&nodeContext->d_blob, + // The pointer `nodeContext->d_blob_sp` might be in a write queue, so + // it's not safe to modify or replace the blob under this pointer. + // Instead, we get another shared pointer to another blob. + nodeContext->d_blob_sp = d_blobSpPool_p->getObject(); + bmqp::ProtocolUtil::buildReceipt(nodeContext->d_blob_sp.get(), d_config.partitionId(), primaryLeaseId, sequenceNumber); @@ -6572,7 +6573,7 @@ void FileStore::sendReceipt(mqbnet::ClusterNode* node, return; // RETURN } - int rc = node->channel().writeBlob(nodeContext->d_blob, + int rc = node->channel().writeBlob(nodeContext->d_blob_sp, bmqp::EventType::e_REPLICATION_RECEIPT, nodeContext->d_state); diff --git a/src/groups/mqb/mqbs/mqbs_filestore.h b/src/groups/mqb/mqbs/mqbs_filestore.h index 4abdb64c35..532f55ddf4 100644 --- a/src/groups/mqb/mqbs/mqbs_filestore.h +++ b/src/groups/mqb/mqbs/mqbs_filestore.h @@ -142,13 +142,9 @@ class FileStore BSLS_KEYWORD_FINAL : public DataStore { public: // TYPES - /// Pool of shared pointers to Blobs - typedef bdlcc::SharedObjectPool< - bdlbb::Blob, - bdlcc::ObjectPoolFunctors::DefaultCreator, - bdlcc::ObjectPoolFunctors::RemoveAll > - BlobSpPool; + typedef bmqp::BlobPoolUtil::BlobSpPool BlobSpPool; + /// Pool of shared pointers to AtomicStates typedef bdlcc::SharedObjectPool< bmqu::AtomicState, bdlcc::ObjectPoolFunctors::DefaultCreator, @@ -241,16 +237,15 @@ class FileStore BSLS_KEYWORD_FINAL : public DataStore { }; struct NodeContext { + /// Last Receipt from/to this node (Replica/Primary). DataStoreRecordKey d_key; - // last Receipt from/to this - // node (Replica/Primary). - bdlbb::Blob d_blob; - // Receipt to this node. + + /// Receipt to this node. + bsl::shared_ptr d_blob_sp; + bsl::shared_ptr d_state; - NodeContext(bdlbb::BlobBufferFactory* factory, - const DataStoreRecordKey& key, - bslma::Allocator* basicAllocator = 0); + NodeContext(BlobSpPool* blobSpPool_p, const DataStoreRecordKey& key); }; typedef bmqc::OrderedHashMapgetObject()) { // NOTHING } diff --git a/src/groups/mqb/mqbs/mqbs_filestore.t.cpp b/src/groups/mqb/mqbs/mqbs_filestore.t.cpp index 33a176f3bf..9859289882 100644 --- a/src/groups/mqb/mqbs/mqbs_filestore.t.cpp +++ b/src/groups/mqb/mqbs/mqbs_filestore.t.cpp @@ -31,6 +31,7 @@ #include // BMQ +#include #include #include #include @@ -89,12 +90,6 @@ typedef mqbs::DataStore::AppInfos AppInfos; typedef mqbs::FileStore::SyncPointOffsetPairs SyncPointOffsetPairs; typedef bsl::pair HandleRecordPair; -typedef bdlcc::SharedObjectPool< - bdlbb::Blob, - bdlcc::ObjectPoolFunctors::DefaultCreator, - bdlcc::ObjectPoolFunctors::RemoveAll > - BlobSpPool; - // FUNCTIONS /// Create a new blob at the specified `arena` address, using the specified @@ -147,7 +142,7 @@ struct Tester { bdlbb::PooledBlobBufferFactory d_bufferFactory; bsl::string d_clusterLocation; bsl::string d_clusterArchiveLocation; - BlobSpPool d_blobSpPool; + bmqp::BlobPoolUtil::BlobSpPool d_blobSpPool; mqbcfg::PartitionConfig d_partitionCfg; mqbcfg::ClusterDefinition d_clusterCfg; bsl::vector d_clusterNodesCfg; @@ -172,12 +167,9 @@ struct Tester { , d_bufferFactory(1024, bmqtst::TestHelperUtil::allocator()) , d_clusterLocation(location, bmqtst::TestHelperUtil::allocator()) , d_clusterArchiveLocation(location, bmqtst::TestHelperUtil::allocator()) - , d_blobSpPool(bdlf::BindUtil::bind(&createBlob, - &d_bufferFactory, - bdlf::PlaceHolders::_1, // arena - bdlf::PlaceHolders::_2), // alloc - 1024, // blob pool growth strategy - bmqtst::TestHelperUtil::allocator()) + , d_blobSpPool(bmqp::BlobPoolUtil::createBlobPool( + &d_bufferFactory, + bmqtst::TestHelperUtil::allocator())) , d_partitionCfg(bmqtst::TestHelperUtil::allocator()) , d_clusterCfg(bmqtst::TestHelperUtil::allocator()) , d_clusterNodesCfg(bmqtst::TestHelperUtil::allocator()) From 90b398b0b9bec2e1be4bff7a667bb1c8537f9dcf Mon Sep 17 00:00:00 2001 From: Anton Pryakhin Date: Fri, 6 Dec 2024 23:18:55 +0200 Subject: [PATCH 03/17] Feat: Log dumper (#445) Signed-off-by: Anton Pryakhin --- .../bmq/bmqtsk/bmqtsk_logcontroller.cpp | 196 +------ src/groups/bmq/bmqtsk/bmqtsk_logcontroller.h | 72 ++- .../bmq/bmqtsk/bmqtsk_logcontroller.t.cpp | 106 ++-- src/groups/bmq/group/bmq.t.dep | 1 + src/groups/mqb/mqbcfg/mqbcfg.xsd | 9 + src/groups/mqb/mqbcfg/mqbcfg_messages.cpp | 168 +++++- src/groups/mqb/mqbcfg/mqbcfg_messages.h | 484 +++++++++++++++++- 7 files changed, 773 insertions(+), 263 deletions(-) diff --git a/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.cpp b/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.cpp index 9f38012bd5..86128953e3 100644 --- a/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.cpp +++ b/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.cpp @@ -147,6 +147,9 @@ LogControllerConfig::LogControllerConfig(bslma::Allocator* allocator) , d_syslogAppName("") , d_syslogVerbosity(ball::Severity::ERROR) , d_categories(allocator) +, d_recordBufferSizeBytes(32 * 1024) // 32 KB +, d_recordingVerbosity(ball::Severity::OFF) +, d_triggerVerbosity(ball::Severity::OFF) { // NOTHING } @@ -167,6 +170,9 @@ LogControllerConfig::LogControllerConfig(const LogControllerConfig& other, , d_syslogAppName(other.d_syslogAppName, allocator) , d_syslogVerbosity(other.d_syslogVerbosity) , d_categories(other.d_categories, allocator) +, d_recordBufferSizeBytes(other.d_recordBufferSizeBytes) +, d_recordingVerbosity(other.d_recordingVerbosity) +, d_triggerVerbosity(other.d_triggerVerbosity) { // NOTHING } @@ -189,6 +195,9 @@ LogControllerConfig::operator=(const LogControllerConfig& rhs) d_syslogAppName = rhs.d_syslogAppName; d_syslogVerbosity = rhs.d_syslogVerbosity; d_categories = rhs.d_categories; + d_recordBufferSizeBytes = rhs.d_recordBufferSizeBytes; + d_recordingVerbosity = rhs.d_recordingVerbosity; + d_triggerVerbosity = rhs.d_triggerVerbosity; } return *this; @@ -229,169 +238,6 @@ void LogControllerConfig::clearCategoriesProperties() d_categories.clear(); } -int LogControllerConfig::fromDatum(bsl::ostream& errorDescription, - const bdld::Datum& datum) -{ - enum RcEnum { - // Value for the various RC error categories - rc_SUCCESS = 0, - rc_INVALID_DATUM = -1, - rc_INVALID_KEY_TYPE = -2, - rc_INVALID_KEY_VALUE = -3, - rc_UNSET_VALUE = -4, - rc_UNKNOWN_KEY = -5 - }; - - if (!datum.isMap()) { - errorDescription << "The specified datum must be a map"; - return rc_INVALID_DATUM; // RETURN - } - -#define PARSE_ENTRY(ENTRY, FIELD, TYPE, KEY_STR, KEY_PATH) \ - if (bdlb::String::areEqualCaseless(ENTRY.key(), KEY_STR)) { \ - if (!ENTRY.value().is##TYPE()) { \ - errorDescription << "Key '" << #KEY_PATH << "' type must be a " \ - << #TYPE; \ - return rc_INVALID_KEY_TYPE; \ - } \ - FIELD = ENTRY.value().the##TYPE(); \ - continue; \ - } - -#define PARSE_CONF(FIELD, TYPE, KEY_STR) \ - PARSE_ENTRY(entry, FIELD, TYPE, KEY_STR, KEY_STR) - -#define PARSE_SYSLOG(FIELD, TYPE, KEY_STR) \ - PARSE_ENTRY(syslog, FIELD, TYPE, KEY_STR, "syslog/" + KEY_STR) - - double fileMaxAgeDays = -1; - double rotationBytes = -1; - bsl::string loggingVerbosityStr; - bsl::string bslsLogSeverityStr; - bsl::string consoleSeverityStr; - bsl::string syslogVerbosityStr; - - // Iterate over each keys of the datum map.. - for (bsl::size_t i = 0; i < datum.theMap().size(); ++i) { - const bdld::DatumMapEntry& entry = datum.theMap().data()[i]; - PARSE_CONF(d_fileName, String, "fileName"); - PARSE_CONF(fileMaxAgeDays, Double, "fileMaxAgeDays"); - PARSE_CONF(rotationBytes, Double, "rotationBytes"); - PARSE_CONF(d_logfileFormat, String, "logfileFormat"); - PARSE_CONF(d_consoleFormat, String, "consoleFormat"); - PARSE_CONF(loggingVerbosityStr, String, "loggingVerbosity"); - PARSE_CONF(bslsLogSeverityStr, String, "bslsLogSeverityThreshold"); - PARSE_CONF(consoleSeverityStr, String, "consoleSeverityThreshold"); - - if (bdlb::String::areEqualCaseless(entry.key(), "categories")) { - if (!entry.value().isArray()) { - errorDescription << "Key 'categories' must be an array"; - return rc_INVALID_KEY_TYPE; // RETURN - } - bdld::DatumArrayRef array = entry.value().theArray(); - for (bsls::Types::size_type idx = 0; idx < array.length(); ++idx) { - if (!array[idx].isString()) { - errorDescription << "Invalid type for categories[" << idx - << "]: must be a string"; - return rc_INVALID_KEY_TYPE; // RETURN - } - int rc = addCategoryProperties(array[idx].theString()); - if (rc != 0) { - errorDescription << "Invalid string format for categories" - << "[" << idx << "] [rc: " << rc << "]"; - return rc_INVALID_KEY_VALUE; // RETURN - } - } - continue; // CONTINUE - } - - if (bdlb::String::areEqualCaseless(entry.key(), "syslog")) { - if (!entry.value().isMap()) { - errorDescription << "Key 'syslog' must be a map"; - return rc_INVALID_KEY_TYPE; // RETURN - } - - bdld::DatumMapRef syslogConfig = entry.value().theMap(); - for (bsl::size_t j = 0; j < syslogConfig.size(); ++j) { - const bdld::DatumMapEntry& syslog = syslogConfig.data()[j]; - - PARSE_SYSLOG(d_syslogEnabled, Boolean, "enabled"); - PARSE_SYSLOG(d_syslogFormat, String, "logFormat"); - PARSE_SYSLOG(d_syslogAppName, String, "appName"); - PARSE_SYSLOG(syslogVerbosityStr, String, "verbosity"); - - // In a normal workflow should just 'continue' - errorDescription << "Unknown key 'syslog/" << syslog.key() - << "'"; - return rc_UNKNOWN_KEY; // RETURN - } - - continue; // CONTINUE - } - - // In a normal workflow should just 'continue' - errorDescription << "Unknown key '" << entry.key() << "'"; - return rc_UNKNOWN_KEY; // RETURN - } - -#undef PARSE_SYSLOG -#undef PARSE_CONF -#undef PARSE_ENTRY - - if (fileMaxAgeDays <= 0) { - errorDescription << "Unset key 'fileMaxAgeDays'"; - return rc_UNSET_VALUE; // RETURN - } - else { - d_fileMaxAgeDays = static_cast(fileMaxAgeDays); - } - - if (rotationBytes <= 0) { - errorDescription << "Unset key 'rotationBytes'"; - return rc_UNSET_VALUE; // RETURN - } - else { - d_rotationBytes = static_cast(rotationBytes); - } - - if (ball::SeverityUtil::fromAsciiCaseless(&d_loggingVerbosity, - loggingVerbosityStr.c_str()) != - 0) { - errorDescription << "Invalid value for 'loggingVerbosity' ('" - << loggingVerbosityStr << "')"; - return rc_INVALID_KEY_VALUE; // RETURN - } - - ball::Severity::Level bslsSeverityAsBal; - if (ball::SeverityUtil::fromAsciiCaseless(&bslsSeverityAsBal, - bslsLogSeverityStr.c_str()) != - 0) { - errorDescription << "Invalid value for 'bslsLogSeverityThreshold' ('" - << bslsLogSeverityStr << "')"; - return rc_INVALID_KEY_VALUE; // RETURN - } - d_bslsLogSeverityThreshold = LogControllerConfig::balToBslsLogLevel( - bslsSeverityAsBal); - - if (ball::SeverityUtil::fromAsciiCaseless(&d_consoleSeverityThreshold, - consoleSeverityStr.c_str()) != - 0) { - errorDescription << "Invalid value for 'consoleSeverityThreshold' ('" - << consoleSeverityStr << "')"; - return rc_INVALID_KEY_VALUE; // RETURN - } - - if (d_syslogEnabled && ball::SeverityUtil::fromAsciiCaseless( - &d_syslogVerbosity, - syslogVerbosityStr.c_str()) != 0) { - errorDescription << "Invalid value for 'syslog/verbosity' ('" - << syslogVerbosityStr << "')"; - return rc_INVALID_KEY_VALUE; // RETURN - } - - return rc_SUCCESS; -} - // ------------------- // class LogController // ------------------- @@ -642,7 +488,7 @@ int LogController::initialize(bsl::ostream& errorDescription, // ------------- // LoggerManager ball::LoggerManagerConfiguration lmc; - lmc.setLogOrder(ball::LoggerManagerConfiguration::LIFO); + lmc.setLogOrder(ball::LoggerManagerConfiguration::FIFO); lmc.setDefaultThresholdLevelsCallback(bdlf::BindUtil::bind( &ball::LoggerFunctorPayloads::loadParentCategoryThresholdValues, bdlf::PlaceHolders::_1, @@ -651,7 +497,7 @@ int LogController::initialize(bsl::ostream& errorDescription, bdlf::PlaceHolders::_4, bdlf::PlaceHolders::_5, '.')); - rc = lmc.setDefaultRecordBufferSizeIfValid(32768); + rc = lmc.setDefaultRecordBufferSizeIfValid(config.recordBufferSizeBytes()); if (rc != 0) { errorDescription << "Unable to set default record buffer size on lmc " << "[rc: " << rc << "]"; @@ -740,7 +586,9 @@ int LogController::initialize(bsl::ostream& errorDescription, // ------------- // Configuration - setVerbosityLevel(config.loggingVerbosity()); + setVerbosityLevel(config.loggingVerbosity(), + config.recordingVerbosity(), + config.triggerVerbosity()); const LogControllerConfig::CategoryPropertiesMap& categories = config.categoriesProperties(); @@ -828,18 +676,20 @@ void LogController::shutdown() d_isInitialized = false; } -void LogController::setVerbosityLevel(ball::Severity::Level verbosity) +void LogController::setVerbosityLevel(ball::Severity::Level passVerbosity, + ball::Severity::Level recordVerbosity, + ball::Severity::Level triggerVerbosity) { ball::Administration::setDefaultThresholdLevels( - ball::Severity::OFF, // recording level - verbosity, // passthrough level - ball::Severity::OFF, // trigger level + recordVerbosity, // recording level + passVerbosity, // passthrough level + triggerVerbosity, // trigger level ball::Severity::OFF); // triggerAll level ball::Administration::setThresholdLevels( "*", - ball::Severity::OFF, // recording level - verbosity, // passthrough level - ball::Severity::OFF, // trigger level + recordVerbosity, // recording level + passVerbosity, // passthrough level + triggerVerbosity, // trigger level ball::Severity::OFF); // triggerAll level } diff --git a/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.h b/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.h index 1c49ec100a..2f62308049 100644 --- a/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.h +++ b/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.h @@ -227,6 +227,20 @@ class LogControllerConfig { CategoryPropertiesMap d_categories; // Map of category properties + int d_recordBufferSizeBytes; + // Size in bytes of the logger's record buffer + + ball::Severity::Level d_recordingVerbosity; + // If the severity level of the record is at least as severe as the + // d_recordingVerbosity, then the record will be stored by the logger in + // its log record buffer (i.e., it will be recorded). + + ball::Severity::Level d_triggerVerbosity; + // If the severity of the record is at least as severe as the + // d_triggerVerbosity, then the record will cause immediate publication + // of that record and any records in the logger's log record buffer (i.e., + // this record will trigger a log record dump). + private: /// Convert specified BALL severity `level` to the corresponding /// BSLS_LOG severity level. @@ -269,6 +283,7 @@ class LogControllerConfig { LogControllerConfig& setSyslogEnabled(bool value); LogControllerConfig& setSyslogFormat(const bslstl::StringRef& value); LogControllerConfig& setSyslogAppName(const bslstl::StringRef& value); + LogControllerConfig& setRecordBufferSize(int value); /// Set the corresponding attribute to the specified `value` and return /// a reference offering modifiable access to this object. @@ -283,16 +298,6 @@ class LogControllerConfig { /// Clear the registered list of category properties. void clearCategoriesProperties(); - /// Populate members of this object from the corresponding fields in the - /// specified `datum`. Return 0 on success, or a non-zero return code - /// on error, populating the specified `errorDescription` with a - /// description of the error. Note that in case of error, some of the - /// values from `datum` may have already been applied and so this object - /// might be partially altered. Refer to the component level - /// documentation (section: "LogControllerConfig: Datum format") for the - /// expected format of the `datum`. - int fromDatum(bsl::ostream& errorDescription, const bdld::Datum& datum); - /// Populate members of this object from the corresponding fields in the /// specified `obj` (which should be of a type compatible with one /// generated from a schema as described at the top in the component @@ -316,6 +321,9 @@ class LogControllerConfig { const bsl::string& syslogFormat() const; const bsl::string& syslogAppName() const; ball::Severity::Level syslogVerbosity() const; + int recordBufferSizeBytes() const; + ball::Severity::Level recordingVerbosity() const; + ball::Severity::Level triggerVerbosity() const; /// Return the value of the corresponding attribute. const CategoryPropertiesMap& categoriesProperties() const; @@ -456,11 +464,18 @@ class LogController { /// will no longer be available. void shutdown(); - /// Change the logging severity threshold to the specified `verbosity`: - /// any record with a severity of at least `verbosity` will be printed - /// to the log file, and eventually to the console if the configured - /// console severity threshold allows it. - void setVerbosityLevel(ball::Severity::Level verbosity); + /// Change the logging severity threshold to the specified verbosity + /// levels: any record with a severity of at least `passVerbosity` will + /// be printed immediately to the log file, and eventually to the + /// console if the configured console severity threshold allows it. + /// any record with a severity of at least `recordingVerbosity` will be + /// stored by the logger in its log record buffer. Any record with a + /// severity of at least `triggerVerbosity` will cause immediate + /// publication of that record and any records in the logger's buffer. + void setVerbosityLevel( + ball::Severity::Level passVerbosity, + ball::Severity::Level recordVerbosity = ball::Severity::OFF, + ball::Severity::Level triggerVerbosity = ball::Severity::OFF); /// Change the verbosity of the specified `category` to the specified /// `verbosity`. `category` can be an expression, with a terminating @@ -512,7 +527,8 @@ int LogControllerConfig::fromObj(bsl::ostream& errorDescription, .setConsoleFormat(obj.consoleFormat()) .setSyslogEnabled(obj.syslog().enabled()) .setSyslogAppName(obj.syslog().appName()) - .setSyslogFormat(obj.syslog().logFormat()); + .setSyslogFormat(obj.syslog().logFormat()) + .setRecordBufferSize(32768); if (ball::SeverityUtil::fromAsciiCaseless( &d_loggingVerbosity, @@ -522,6 +538,9 @@ int LogControllerConfig::fromObj(bsl::ostream& errorDescription, return -1; // RETURN } + d_recordingVerbosity = ball::Severity::OFF; + d_triggerVerbosity = ball::Severity::OFF; + ball::Severity::Level bslsSeverityAsBal = ball::Severity::e_ERROR; // TODO: enforcing 'obj' to have 'bslsLogSeverityThreshold' accessor is a // backward incompatible change from build perspective, and will require a @@ -651,6 +670,12 @@ LogControllerConfig::setSyslogAppName(const bslstl::StringRef& value) return *this; } +inline LogControllerConfig& LogControllerConfig::setRecordBufferSize(int value) +{ + d_recordBufferSizeBytes = value; + return *this; +} + inline LogControllerConfig& LogControllerConfig::setSyslogVerbosity(ball::Severity::Level value) { @@ -725,6 +750,21 @@ inline ball::Severity::Level LogControllerConfig::syslogVerbosity() const return d_syslogVerbosity; } +inline int LogControllerConfig::recordBufferSizeBytes() const +{ + return d_recordBufferSizeBytes; +} + +inline ball::Severity::Level LogControllerConfig::recordingVerbosity() const +{ + return d_recordingVerbosity; +} + +inline ball::Severity::Level LogControllerConfig::triggerVerbosity() const +{ + return d_triggerVerbosity; +} + inline const LogControllerConfig::CategoryPropertiesMap& LogControllerConfig::categoriesProperties() const { diff --git a/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.t.cpp b/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.t.cpp index 84142125f2..e7e20a4772 100644 --- a/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.t.cpp +++ b/src/groups/bmq/bmqtsk/bmqtsk_logcontroller.t.cpp @@ -18,10 +18,8 @@ #include -// BDE -#include -#include -#include +// MQB +#include // TEST DRIVER #include @@ -34,93 +32,67 @@ using namespace bsl; // TESTS // ---------------------------------------------------------------------------- -static void test1_logControllerConfigFromDatum() +static void test1_logControllerConfigFromObj() // ------------------------------------------------------------------------ -// LOG CONTROLLER CONFIG FROM DATUM +// LOG CONTROLLER CONFIG FROM OBJ // // Concerns: // - Should be able to initialize LogControllerConfig with bdld::Datum. // - Inner map with SyslogConfig should be processed correctly too. // // Plan: -// 1. Fill the bdld::Datum structure representing LogControllerConfig. -// 2. Initialize the LogControllerConfig with the given bdld::Datum. -// 3. Verify that fromDatum call succeeded. +// 1. Fill the MockObj structure representing LogControllerConfig. +// 2. Initialize the LogControllerConfig with the given MockObj. +// 3. Verify that fromObj call succeeded. // 4. Verify that syslog properties were correctly set. +// 5. Verify that logDump properties were correctly set. // // Testing: -// - LogControllerConfig::fromDatum +// - LogControllerConfig::fromObj // ------------------------------------------------------------------------ { - bmqtst::TestHelper::printTestName("LogControllerConfig::fromDatum Test"); - - bdld::DatumMapBuilder syslogBuilder(bmqtst::TestHelperUtil::allocator()); - syslogBuilder.pushBack("enabled", bdld::Datum::createBoolean(true)); - syslogBuilder.pushBack( - "appName", - bdld::Datum::createStringRef("testapp", - bmqtst::TestHelperUtil::allocator())); - syslogBuilder.pushBack( - "logFormat", - bdld::Datum::createStringRef("test %d (%t) %s %F:%l %m\n\n", - bmqtst::TestHelperUtil::allocator())); - syslogBuilder.pushBack( - "verbosity", - bdld::Datum::createStringRef("info", - bmqtst::TestHelperUtil::allocator())); - - bdld::DatumArrayBuilder categoriesBuilder( - bmqtst::TestHelperUtil::allocator()); - categoriesBuilder.pushBack( - bdld::Datum::copyString("category:info:red", - bmqtst::TestHelperUtil::allocator())); - - bdld::DatumMapBuilder logControllerBuilder( - bmqtst::TestHelperUtil::allocator()); - logControllerBuilder.pushBack( - "fileName", - bdld::Datum::copyString("fileName", - bmqtst::TestHelperUtil::allocator())); - logControllerBuilder.pushBack("fileMaxAgeDays", - bdld::Datum::createDouble(8.2)); - logControllerBuilder.pushBack("rotationBytes", - bdld::Datum::createDouble(2048)); - logControllerBuilder.pushBack( - "logfileFormat", - bdld::Datum::copyString("%d (%t) %s %F:%l %m\n\n", - bmqtst::TestHelperUtil::allocator())); - logControllerBuilder.pushBack( - "consoleFormat", - bdld::Datum::copyString("%d (%t) %s %F:%l %m\n\n", - bmqtst::TestHelperUtil::allocator())); - logControllerBuilder.pushBack( - "loggingVerbosity", - bdld::Datum::copyString("debug", bmqtst::TestHelperUtil::allocator())); - logControllerBuilder.pushBack( - "bslsLogSeverityThreshold", - bdld::Datum::copyString("info", bmqtst::TestHelperUtil::allocator())); - logControllerBuilder.pushBack( - "consoleSeverityThreshold", - bdld::Datum::copyString("info", bmqtst::TestHelperUtil::allocator())); - logControllerBuilder.pushBack("categories", categoriesBuilder.commit()); - logControllerBuilder.pushBack("syslog", syslogBuilder.commit()); - - bdld::Datum datum = logControllerBuilder.commit(); + bmqtst::TestHelper::printTestName("LogControllerConfig::fromObj Test"); + mqbcfg::LogController lc(bmqtst::TestHelperUtil::allocator()); + + lc.syslog().enabled() = true; + lc.syslog().appName() = "testapp"; + lc.syslog().logFormat() = "test %d (%t) %s %F:%l %m\n\n"; + lc.syslog().verbosity() = "INFO"; + + lc.categories().push_back("category:info:red"); + + lc.fileName() = "fileName"; + lc.fileMaxAgeDays() = 8; + lc.rotationBytes() = 2048; + lc.logfileFormat() = "%d (%t) %s %F:%l %m\n\n"; + lc.consoleFormat() = "%d (%t) %s %F:%l %m\n\n"; + lc.loggingVerbosity() = "debug"; + lc.consoleSeverityThreshold() = "info"; + bmqtsk::LogControllerConfig config(bmqtst::TestHelperUtil::allocator()); bmqu::MemOutStream errorDesc(bmqtst::TestHelperUtil::allocator()); - config.fromDatum(errorDesc, datum); - bdld::Datum::destroy(datum, bmqtst::TestHelperUtil::allocator()); + + ASSERT_EQ(config.fromObj(errorDesc, lc), 0); ASSERT_D(errorDesc.str(), errorDesc.str().empty()); + ASSERT_EQ(config.fileName(), "fileName"); ASSERT_EQ(config.fileMaxAgeDays(), 8); ASSERT_EQ(config.rotationBytes(), 2048); + ASSERT_EQ(config.logfileFormat(), "%d (%t) %s %F:%l %m\n\n"); + ASSERT_EQ(config.consoleFormat(), "%d (%t) %s %F:%l %m\n\n"); ASSERT_EQ(config.loggingVerbosity(), ball::Severity::DEBUG); + ASSERT_EQ(config.bslsLogSeverityThreshold(), bsls::LogSeverity::e_ERROR); + ASSERT_EQ(config.consoleSeverityThreshold(), ball::Severity::INFO); ASSERT_EQ(config.syslogEnabled(), true); ASSERT_EQ(config.syslogFormat(), "test %d (%t) %s %F:%l %m\n\n"); ASSERT_EQ(config.syslogAppName(), "testapp"); ASSERT_EQ(config.syslogVerbosity(), ball::Severity::INFO); + + ASSERT_EQ(config.recordBufferSizeBytes(), 32768); + ASSERT_EQ(config.recordingVerbosity(), ball::Severity::OFF); + ASSERT_EQ(config.triggerVerbosity(), ball::Severity::OFF); } // ============================================================================ @@ -133,7 +105,7 @@ int main(int argc, char* argv[]) switch (_testCase) { case 0: - case 1: test1_logControllerConfigFromDatum(); break; + case 1: test1_logControllerConfigFromObj(); break; default: { cerr << "WARNING: CASE '" << _testCase << "' NOT FOUND." << endl; bmqtst::TestHelperUtil::testStatus() = -1; diff --git a/src/groups/bmq/group/bmq.t.dep b/src/groups/bmq/group/bmq.t.dep index 0ff1419205..6e06777fa6 100644 --- a/src/groups/bmq/group/bmq.t.dep +++ b/src/groups/bmq/group/bmq.t.dep @@ -1,2 +1,3 @@ benchmark bmq +mqb diff --git a/src/groups/mqb/mqbcfg/mqbcfg.xsd b/src/groups/mqb/mqbcfg/mqbcfg.xsd index c970f6b312..7f88de83a6 100644 --- a/src/groups/mqb/mqbcfg/mqbcfg.xsd +++ b/src/groups/mqb/mqbcfg/mqbcfg.xsd @@ -38,6 +38,14 @@ + + + + + + + + @@ -51,6 +59,7 @@ + diff --git a/src/groups/mqb/mqbcfg/mqbcfg_messages.cpp b/src/groups/mqb/mqbcfg/mqbcfg_messages.cpp index 42968e1833..d208db048e 100644 --- a/src/groups/mqb/mqbcfg/mqbcfg_messages.cpp +++ b/src/groups/mqb/mqbcfg/mqbcfg_messages.cpp @@ -852,6 +852,155 @@ Heartbeat::print(bsl::ostream& stream, int level, int spacesPerLevel) const return stream; } +// ------------------- +// class LogDumpConfig +// ------------------- + +// CONSTANTS + +const char LogDumpConfig::CLASS_NAME[] = "LogDumpConfig"; + +const int LogDumpConfig::DEFAULT_INITIALIZER_RECORD_BUFFER_SIZE = 32768; + +const char LogDumpConfig::DEFAULT_INITIALIZER_RECORDING_LEVEL[] = "OFF"; + +const char LogDumpConfig::DEFAULT_INITIALIZER_TRIGGER_LEVEL[] = "OFF"; + +const bdlat_AttributeInfo LogDumpConfig::ATTRIBUTE_INFO_ARRAY[] = { + {ATTRIBUTE_ID_RECORD_BUFFER_SIZE, + "recordBufferSize", + sizeof("recordBufferSize") - 1, + "", + bdlat_FormattingMode::e_DEC}, + {ATTRIBUTE_ID_RECORDING_LEVEL, + "recordingLevel", + sizeof("recordingLevel") - 1, + "", + bdlat_FormattingMode::e_TEXT}, + {ATTRIBUTE_ID_TRIGGER_LEVEL, + "triggerLevel", + sizeof("triggerLevel") - 1, + "", + bdlat_FormattingMode::e_TEXT}}; + +// CLASS METHODS + +const bdlat_AttributeInfo* LogDumpConfig::lookupAttributeInfo(const char* name, + int nameLength) +{ + for (int i = 0; i < 3; ++i) { + const bdlat_AttributeInfo& attributeInfo = + LogDumpConfig::ATTRIBUTE_INFO_ARRAY[i]; + + if (nameLength == attributeInfo.d_nameLength && + 0 == bsl::memcmp(attributeInfo.d_name_p, name, nameLength)) { + return &attributeInfo; + } + } + + return 0; +} + +const bdlat_AttributeInfo* LogDumpConfig::lookupAttributeInfo(int id) +{ + switch (id) { + case ATTRIBUTE_ID_RECORD_BUFFER_SIZE: + return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORD_BUFFER_SIZE]; + case ATTRIBUTE_ID_RECORDING_LEVEL: + return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORDING_LEVEL]; + case ATTRIBUTE_ID_TRIGGER_LEVEL: + return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_TRIGGER_LEVEL]; + default: return 0; + } +} + +// CREATORS + +LogDumpConfig::LogDumpConfig(bslma::Allocator* basicAllocator) +: d_recordingLevel(DEFAULT_INITIALIZER_RECORDING_LEVEL, basicAllocator) +, d_triggerLevel(DEFAULT_INITIALIZER_TRIGGER_LEVEL, basicAllocator) +, d_recordBufferSize(DEFAULT_INITIALIZER_RECORD_BUFFER_SIZE) +{ +} + +LogDumpConfig::LogDumpConfig(const LogDumpConfig& original, + bslma::Allocator* basicAllocator) +: d_recordingLevel(original.d_recordingLevel, basicAllocator) +, d_triggerLevel(original.d_triggerLevel, basicAllocator) +, d_recordBufferSize(original.d_recordBufferSize) +{ +} + +#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ + defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) +LogDumpConfig::LogDumpConfig(LogDumpConfig&& original) noexcept +: d_recordingLevel(bsl::move(original.d_recordingLevel)), + d_triggerLevel(bsl::move(original.d_triggerLevel)), + d_recordBufferSize(bsl::move(original.d_recordBufferSize)) +{ +} + +LogDumpConfig::LogDumpConfig(LogDumpConfig&& original, + bslma::Allocator* basicAllocator) +: d_recordingLevel(bsl::move(original.d_recordingLevel), basicAllocator) +, d_triggerLevel(bsl::move(original.d_triggerLevel), basicAllocator) +, d_recordBufferSize(bsl::move(original.d_recordBufferSize)) +{ +} +#endif + +LogDumpConfig::~LogDumpConfig() +{ +} + +// MANIPULATORS + +LogDumpConfig& LogDumpConfig::operator=(const LogDumpConfig& rhs) +{ + if (this != &rhs) { + d_recordBufferSize = rhs.d_recordBufferSize; + d_recordingLevel = rhs.d_recordingLevel; + d_triggerLevel = rhs.d_triggerLevel; + } + + return *this; +} + +#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ + defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) +LogDumpConfig& LogDumpConfig::operator=(LogDumpConfig&& rhs) +{ + if (this != &rhs) { + d_recordBufferSize = bsl::move(rhs.d_recordBufferSize); + d_recordingLevel = bsl::move(rhs.d_recordingLevel); + d_triggerLevel = bsl::move(rhs.d_triggerLevel); + } + + return *this; +} +#endif + +void LogDumpConfig::reset() +{ + d_recordBufferSize = DEFAULT_INITIALIZER_RECORD_BUFFER_SIZE; + d_recordingLevel = DEFAULT_INITIALIZER_RECORDING_LEVEL; + d_triggerLevel = DEFAULT_INITIALIZER_TRIGGER_LEVEL; +} + +// ACCESSORS + +bsl::ostream& +LogDumpConfig::print(bsl::ostream& stream, int level, int spacesPerLevel) const +{ + bslim::Printer printer(&stream, level, spacesPerLevel); + printer.start(); + printer.printAttribute("recordBufferSize", this->recordBufferSize()); + printer.printAttribute("recordingLevel", this->recordingLevel()); + printer.printAttribute("triggerLevel", this->triggerLevel()); + printer.end(); + return stream; +} + // ------------------------------- // class MasterAssignmentAlgorithm // ------------------------------- @@ -2913,6 +3062,11 @@ const bdlat_AttributeInfo LogController::ATTRIBUTE_INFO_ARRAY[] = { "syslog", sizeof("syslog") - 1, "", + bdlat_FormattingMode::e_DEFAULT}, + {ATTRIBUTE_ID_LOG_DUMP, + "logDump", + sizeof("logDump") - 1, + "", bdlat_FormattingMode::e_DEFAULT}}; // CLASS METHODS @@ -2920,7 +3074,7 @@ const bdlat_AttributeInfo LogController::ATTRIBUTE_INFO_ARRAY[] = { const bdlat_AttributeInfo* LogController::lookupAttributeInfo(const char* name, int nameLength) { - for (int i = 0; i < 10; ++i) { + for (int i = 0; i < 11; ++i) { const bdlat_AttributeInfo& attributeInfo = LogController::ATTRIBUTE_INFO_ARRAY[i]; @@ -2958,6 +3112,8 @@ const bdlat_AttributeInfo* LogController::lookupAttributeInfo(int id) return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_CATEGORIES]; case ATTRIBUTE_ID_SYSLOG: return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SYSLOG]; + case ATTRIBUTE_ID_LOG_DUMP: + return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_LOG_DUMP]; default: return 0; } } @@ -2974,6 +3130,7 @@ LogController::LogController(bslma::Allocator* basicAllocator) basicAllocator) , d_consoleSeverityThreshold(basicAllocator) , d_syslog(basicAllocator) +, d_logDump(basicAllocator) , d_fileMaxAgeDays() , d_rotationBytes() { @@ -2991,6 +3148,7 @@ LogController::LogController(const LogController& original, , d_consoleSeverityThreshold(original.d_consoleSeverityThreshold, basicAllocator) , d_syslog(original.d_syslog, basicAllocator) +, d_logDump(original.d_logDump, basicAllocator) , d_fileMaxAgeDays(original.d_fileMaxAgeDays) , d_rotationBytes(original.d_rotationBytes) { @@ -3007,6 +3165,7 @@ LogController::LogController(LogController&& original) noexcept d_bslsLogSeverityThreshold(bsl::move(original.d_bslsLogSeverityThreshold)), d_consoleSeverityThreshold(bsl::move(original.d_consoleSeverityThreshold)), d_syslog(bsl::move(original.d_syslog)), + d_logDump(bsl::move(original.d_logDump)), d_fileMaxAgeDays(bsl::move(original.d_fileMaxAgeDays)), d_rotationBytes(bsl::move(original.d_rotationBytes)) { @@ -3024,6 +3183,7 @@ LogController::LogController(LogController&& original, , d_consoleSeverityThreshold(bsl::move(original.d_consoleSeverityThreshold), basicAllocator) , d_syslog(bsl::move(original.d_syslog), basicAllocator) +, d_logDump(bsl::move(original.d_logDump), basicAllocator) , d_fileMaxAgeDays(bsl::move(original.d_fileMaxAgeDays)) , d_rotationBytes(bsl::move(original.d_rotationBytes)) { @@ -3049,6 +3209,7 @@ LogController& LogController::operator=(const LogController& rhs) d_consoleSeverityThreshold = rhs.d_consoleSeverityThreshold; d_categories = rhs.d_categories; d_syslog = rhs.d_syslog; + d_logDump = rhs.d_logDump; } return *this; @@ -3069,6 +3230,7 @@ LogController& LogController::operator=(LogController&& rhs) d_consoleSeverityThreshold = bsl::move(rhs.d_consoleSeverityThreshold); d_categories = bsl::move(rhs.d_categories); d_syslog = bsl::move(rhs.d_syslog); + d_logDump = bsl::move(rhs.d_logDump); } return *this; @@ -3088,6 +3250,7 @@ void LogController::reset() bdlat_ValueTypeFunctions::reset(&d_consoleSeverityThreshold); bdlat_ValueTypeFunctions::reset(&d_categories); bdlat_ValueTypeFunctions::reset(&d_syslog); + bdlat_ValueTypeFunctions::reset(&d_logDump); } // ACCESSORS @@ -3109,6 +3272,7 @@ LogController::print(bsl::ostream& stream, int level, int spacesPerLevel) const this->consoleSeverityThreshold()); printer.printAttribute("categories", this->categories()); printer.printAttribute("syslog", this->syslog()); + printer.printAttribute("logDump", this->logDump()); printer.end(); return stream; } @@ -5967,6 +6131,6 @@ Configuration::print(bsl::ostream& stream, int level, int spacesPerLevel) const } // close package namespace } // close enterprise namespace -// GENERATED BY BLP_BAS_CODEGEN_2024.07.18 +// GENERATED BY BLP_BAS_CODEGEN_2024.10.17 // USING bas_codegen.pl -m msg --noAggregateConversion --noExternalization // --noIdent --package mqbcfg --msgComponent messages mqbcfg.xsd diff --git a/src/groups/mqb/mqbcfg/mqbcfg_messages.h b/src/groups/mqb/mqbcfg/mqbcfg_messages.h index 99d95c47e1..69918e2328 100644 --- a/src/groups/mqb/mqbcfg/mqbcfg_messages.h +++ b/src/groups/mqb/mqbcfg/mqbcfg_messages.h @@ -74,6 +74,9 @@ namespace mqbcfg { class Heartbeat; } namespace mqbcfg { +class LogDumpConfig; +} +namespace mqbcfg { class MessagePropertiesV2; } namespace mqbcfg { @@ -1658,6 +1661,249 @@ BDLAT_DECL_SEQUENCE_WITH_BITWISEMOVEABLE_TRAITS(mqbcfg::Heartbeat) namespace mqbcfg { +// =================== +// class LogDumpConfig +// =================== + +class LogDumpConfig { + // INSTANCE DATA + bsl::string d_recordingLevel; + bsl::string d_triggerLevel; + int d_recordBufferSize; + + // PRIVATE ACCESSORS + template + void hashAppendImpl(t_HASH_ALGORITHM& hashAlgorithm) const; + + public: + // TYPES + enum { + ATTRIBUTE_ID_RECORD_BUFFER_SIZE = 0, + ATTRIBUTE_ID_RECORDING_LEVEL = 1, + ATTRIBUTE_ID_TRIGGER_LEVEL = 2 + }; + + enum { NUM_ATTRIBUTES = 3 }; + + enum { + ATTRIBUTE_INDEX_RECORD_BUFFER_SIZE = 0, + ATTRIBUTE_INDEX_RECORDING_LEVEL = 1, + ATTRIBUTE_INDEX_TRIGGER_LEVEL = 2 + }; + + // CONSTANTS + static const char CLASS_NAME[]; + + static const int DEFAULT_INITIALIZER_RECORD_BUFFER_SIZE; + + static const char DEFAULT_INITIALIZER_RECORDING_LEVEL[]; + + static const char DEFAULT_INITIALIZER_TRIGGER_LEVEL[]; + + static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[]; + + public: + // CLASS METHODS + static const bdlat_AttributeInfo* lookupAttributeInfo(int id); + // Return attribute information for the attribute indicated by the + // specified 'id' if the attribute exists, and 0 otherwise. + + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, + int nameLength); + // Return attribute information for the attribute indicated by the + // specified 'name' of the specified 'nameLength' if the attribute + // exists, and 0 otherwise. + + // CREATORS + explicit LogDumpConfig(bslma::Allocator* basicAllocator = 0); + // Create an object of type 'LogDumpConfig' having the default value. + // Use the optionally specified 'basicAllocator' to supply memory. If + // 'basicAllocator' is 0, the currently installed default allocator is + // used. + + LogDumpConfig(const LogDumpConfig& original, + bslma::Allocator* basicAllocator = 0); + // Create an object of type 'LogDumpConfig' having the value of the + // specified 'original' object. Use the optionally specified + // 'basicAllocator' to supply memory. If 'basicAllocator' is 0, the + // currently installed default allocator is used. + +#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ + defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) + LogDumpConfig(LogDumpConfig&& original) noexcept; + // Create an object of type 'LogDumpConfig' having the value of the + // specified 'original' object. After performing this action, the + // 'original' object will be left in a valid, but unspecified state. + + LogDumpConfig(LogDumpConfig&& original, bslma::Allocator* basicAllocator); + // Create an object of type 'LogDumpConfig' having the value of the + // specified 'original' object. After performing this action, the + // 'original' object will be left in a valid, but unspecified state. + // Use the optionally specified 'basicAllocator' to supply memory. If + // 'basicAllocator' is 0, the currently installed default allocator is + // used. +#endif + + ~LogDumpConfig(); + // Destroy this object. + + // MANIPULATORS + LogDumpConfig& operator=(const LogDumpConfig& rhs); + // Assign to this object the value of the specified 'rhs' object. + +#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ + defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) + LogDumpConfig& operator=(LogDumpConfig&& rhs); + // Assign to this object the value of the specified 'rhs' object. + // After performing this action, the 'rhs' object will be left in a + // valid, but unspecified state. +#endif + + void reset(); + // Reset this object to the default value (i.e., its value upon + // default construction). + + template + int manipulateAttributes(t_MANIPULATOR& manipulator); + // Invoke the specified 'manipulator' sequentially on the address of + // each (modifiable) attribute of this object, supplying 'manipulator' + // with the corresponding attribute information structure until such + // invocation returns a non-zero value. Return the value from the + // last invocation of 'manipulator' (i.e., the invocation that + // terminated the sequence). + + template + int manipulateAttribute(t_MANIPULATOR& manipulator, int id); + // Invoke the specified 'manipulator' on the address of + // the (modifiable) attribute indicated by the specified 'id', + // supplying 'manipulator' with the corresponding attribute + // information structure. Return the value returned from the + // invocation of 'manipulator' if 'id' identifies an attribute of this + // class, and -1 otherwise. + + template + int manipulateAttribute(t_MANIPULATOR& manipulator, + const char* name, + int nameLength); + // Invoke the specified 'manipulator' on the address of + // the (modifiable) attribute indicated by the specified 'name' of the + // specified 'nameLength', supplying 'manipulator' with the + // corresponding attribute information structure. Return the value + // returned from the invocation of 'manipulator' if 'name' identifies + // an attribute of this class, and -1 otherwise. + + int& recordBufferSize(); + // Return a reference to the modifiable "RecordBufferSize" attribute of + // this object. + + bsl::string& recordingLevel(); + // Return a reference to the modifiable "RecordingLevel" attribute of + // this object. + + bsl::string& triggerLevel(); + // Return a reference to the modifiable "TriggerLevel" attribute of + // this object. + + // ACCESSORS + bsl::ostream& + print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const; + // Format this object to the specified output 'stream' at the + // optionally specified indentation 'level' and return a reference to + // the modifiable 'stream'. If 'level' is specified, optionally + // specify 'spacesPerLevel', the number of spaces per indentation level + // for this and all of its nested objects. Each line is indented by + // the absolute value of 'level * spacesPerLevel'. If 'level' is + // negative, suppress indentation of the first line. If + // 'spacesPerLevel' is negative, suppress line breaks and format the + // entire output on one line. If 'stream' is initially invalid, this + // operation has no effect. Note that a trailing newline is provided + // in multiline mode only. + + template + int accessAttributes(t_ACCESSOR& accessor) const; + // Invoke the specified 'accessor' sequentially on each + // (non-modifiable) attribute of this object, supplying 'accessor' + // with the corresponding attribute information structure until such + // invocation returns a non-zero value. Return the value from the + // last invocation of 'accessor' (i.e., the invocation that terminated + // the sequence). + + template + int accessAttribute(t_ACCESSOR& accessor, int id) const; + // Invoke the specified 'accessor' on the (non-modifiable) attribute + // of this object indicated by the specified 'id', supplying 'accessor' + // with the corresponding attribute information structure. Return the + // value returned from the invocation of 'accessor' if 'id' identifies + // an attribute of this class, and -1 otherwise. + + template + int accessAttribute(t_ACCESSOR& accessor, + const char* name, + int nameLength) const; + // Invoke the specified 'accessor' on the (non-modifiable) attribute + // of this object indicated by the specified 'name' of the specified + // 'nameLength', supplying 'accessor' with the corresponding attribute + // information structure. Return the value returned from the + // invocation of 'accessor' if 'name' identifies an attribute of this + // class, and -1 otherwise. + + int recordBufferSize() const; + // Return the value of the "RecordBufferSize" attribute of this object. + + const bsl::string& recordingLevel() const; + // Return a reference offering non-modifiable access to the + // "RecordingLevel" attribute of this object. + + const bsl::string& triggerLevel() const; + // Return a reference offering non-modifiable access to the + // "TriggerLevel" attribute of this object. + + // HIDDEN FRIENDS + friend bool operator==(const LogDumpConfig& lhs, const LogDumpConfig& rhs) + // Return 'true' if the specified 'lhs' and 'rhs' attribute objects + // have the same value, and 'false' otherwise. Two attribute objects + // have the same value if each respective attribute has the same value. + { + return lhs.recordBufferSize() == rhs.recordBufferSize() && + lhs.recordingLevel() == rhs.recordingLevel() && + lhs.triggerLevel() == rhs.triggerLevel(); + } + + friend bool operator!=(const LogDumpConfig& lhs, const LogDumpConfig& rhs) + // Returns '!(lhs == rhs)' + { + return !(lhs == rhs); + } + + friend bsl::ostream& operator<<(bsl::ostream& stream, + const LogDumpConfig& rhs) + // Format the specified 'rhs' to the specified output 'stream' and + // return a reference to the modifiable 'stream'. + { + return rhs.print(stream, 0, -1); + } + + template + friend void hashAppend(t_HASH_ALGORITHM& hashAlg, + const LogDumpConfig& object) + // Pass the specified 'object' to the specified 'hashAlg'. This + // function integrates with the 'bslh' modular hashing system and + // effectively provides a 'bsl::hash' specialization for + // 'LogDumpConfig'. + { + object.hashAppendImpl(hashAlg); + } +}; + +} // close package namespace + +// TRAITS + +BDLAT_DECL_SEQUENCE_WITH_ALLOCATOR_BITWISEMOVEABLE_TRAITS( + mqbcfg::LogDumpConfig) + +namespace mqbcfg { + // =============================== // class MasterAssignmentAlgorithm // =============================== @@ -4896,6 +5142,7 @@ class LogController { bsl::string d_bslsLogSeverityThreshold; bsl::string d_consoleSeverityThreshold; SyslogConfig d_syslog; + LogDumpConfig d_logDump; int d_fileMaxAgeDays; int d_rotationBytes; @@ -4917,10 +5164,11 @@ class LogController { ATTRIBUTE_ID_BSLS_LOG_SEVERITY_THRESHOLD = 6, ATTRIBUTE_ID_CONSOLE_SEVERITY_THRESHOLD = 7, ATTRIBUTE_ID_CATEGORIES = 8, - ATTRIBUTE_ID_SYSLOG = 9 + ATTRIBUTE_ID_SYSLOG = 9, + ATTRIBUTE_ID_LOG_DUMP = 10 }; - enum { NUM_ATTRIBUTES = 10 }; + enum { NUM_ATTRIBUTES = 11 }; enum { ATTRIBUTE_INDEX_FILE_NAME = 0, @@ -4932,7 +5180,8 @@ class LogController { ATTRIBUTE_INDEX_BSLS_LOG_SEVERITY_THRESHOLD = 6, ATTRIBUTE_INDEX_CONSOLE_SEVERITY_THRESHOLD = 7, ATTRIBUTE_INDEX_CATEGORIES = 8, - ATTRIBUTE_INDEX_SYSLOG = 9 + ATTRIBUTE_INDEX_SYSLOG = 9, + ATTRIBUTE_INDEX_LOG_DUMP = 10 }; // CONSTANTS @@ -5072,6 +5321,10 @@ class LogController { // Return a reference to the modifiable "Syslog" attribute of this // object. + LogDumpConfig& logDump(); + // Return a reference to the modifiable "LogDump" attribute of this + // object. + // ACCESSORS bsl::ostream& print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const; @@ -5153,6 +5406,10 @@ class LogController { // Return a reference offering non-modifiable access to the "Syslog" // attribute of this object. + const LogDumpConfig& logDump() const; + // Return a reference offering non-modifiable access to the "LogDump" + // attribute of this object. + // HIDDEN FRIENDS friend bool operator==(const LogController& lhs, const LogController& rhs) // Return 'true' if the specified 'lhs' and 'rhs' attribute objects @@ -10778,6 +11035,186 @@ inline int Heartbeat::clusterPeer() const return d_clusterPeer; } +// ------------------- +// class LogDumpConfig +// ------------------- + +// PRIVATE ACCESSORS +template +void LogDumpConfig::hashAppendImpl(t_HASH_ALGORITHM& hashAlgorithm) const +{ + using bslh::hashAppend; + hashAppend(hashAlgorithm, this->recordBufferSize()); + hashAppend(hashAlgorithm, this->recordingLevel()); + hashAppend(hashAlgorithm, this->triggerLevel()); +} + +// CLASS METHODS +// MANIPULATORS +template +int LogDumpConfig::manipulateAttributes(t_MANIPULATOR& manipulator) +{ + int ret; + + ret = manipulator( + &d_recordBufferSize, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORD_BUFFER_SIZE]); + if (ret) { + return ret; + } + + ret = manipulator(&d_recordingLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORDING_LEVEL]); + if (ret) { + return ret; + } + + ret = manipulator(&d_triggerLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_TRIGGER_LEVEL]); + if (ret) { + return ret; + } + + return 0; +} + +template +int LogDumpConfig::manipulateAttribute(t_MANIPULATOR& manipulator, int id) +{ + enum { NOT_FOUND = -1 }; + + switch (id) { + case ATTRIBUTE_ID_RECORD_BUFFER_SIZE: { + return manipulator( + &d_recordBufferSize, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORD_BUFFER_SIZE]); + } + case ATTRIBUTE_ID_RECORDING_LEVEL: { + return manipulator( + &d_recordingLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORDING_LEVEL]); + } + case ATTRIBUTE_ID_TRIGGER_LEVEL: { + return manipulator( + &d_triggerLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_TRIGGER_LEVEL]); + } + default: return NOT_FOUND; + } +} + +template +int LogDumpConfig::manipulateAttribute(t_MANIPULATOR& manipulator, + const char* name, + int nameLength) +{ + enum { NOT_FOUND = -1 }; + + const bdlat_AttributeInfo* attributeInfo = lookupAttributeInfo(name, + nameLength); + if (0 == attributeInfo) { + return NOT_FOUND; + } + + return manipulateAttribute(manipulator, attributeInfo->d_id); +} + +inline int& LogDumpConfig::recordBufferSize() +{ + return d_recordBufferSize; +} + +inline bsl::string& LogDumpConfig::recordingLevel() +{ + return d_recordingLevel; +} + +inline bsl::string& LogDumpConfig::triggerLevel() +{ + return d_triggerLevel; +} + +// ACCESSORS +template +int LogDumpConfig::accessAttributes(t_ACCESSOR& accessor) const +{ + int ret; + + ret = accessor(d_recordBufferSize, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORD_BUFFER_SIZE]); + if (ret) { + return ret; + } + + ret = accessor(d_recordingLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORDING_LEVEL]); + if (ret) { + return ret; + } + + ret = accessor(d_triggerLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_TRIGGER_LEVEL]); + if (ret) { + return ret; + } + + return 0; +} + +template +int LogDumpConfig::accessAttribute(t_ACCESSOR& accessor, int id) const +{ + enum { NOT_FOUND = -1 }; + + switch (id) { + case ATTRIBUTE_ID_RECORD_BUFFER_SIZE: { + return accessor( + d_recordBufferSize, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORD_BUFFER_SIZE]); + } + case ATTRIBUTE_ID_RECORDING_LEVEL: { + return accessor(d_recordingLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_RECORDING_LEVEL]); + } + case ATTRIBUTE_ID_TRIGGER_LEVEL: { + return accessor(d_triggerLevel, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_TRIGGER_LEVEL]); + } + default: return NOT_FOUND; + } +} + +template +int LogDumpConfig::accessAttribute(t_ACCESSOR& accessor, + const char* name, + int nameLength) const +{ + enum { NOT_FOUND = -1 }; + + const bdlat_AttributeInfo* attributeInfo = lookupAttributeInfo(name, + nameLength); + if (0 == attributeInfo) { + return NOT_FOUND; + } + + return accessAttribute(accessor, attributeInfo->d_id); +} + +inline int LogDumpConfig::recordBufferSize() const +{ + return d_recordBufferSize; +} + +inline const bsl::string& LogDumpConfig::recordingLevel() const +{ + return d_recordingLevel; +} + +inline const bsl::string& LogDumpConfig::triggerLevel() const +{ + return d_triggerLevel; +} + // ------------------------------- // class MasterAssignmentAlgorithm // ------------------------------- @@ -13490,6 +13927,7 @@ void LogController::hashAppendImpl(t_HASH_ALGORITHM& hashAlgorithm) const hashAppend(hashAlgorithm, this->consoleSeverityThreshold()); hashAppend(hashAlgorithm, this->categories()); hashAppend(hashAlgorithm, this->syslog()); + hashAppend(hashAlgorithm, this->logDump()); } inline bool LogController::isEqualTo(const LogController& rhs) const @@ -13505,7 +13943,7 @@ inline bool LogController::isEqualTo(const LogController& rhs) const this->consoleSeverityThreshold() == rhs.consoleSeverityThreshold() && this->categories() == rhs.categories() && - this->syslog() == rhs.syslog(); + this->syslog() == rhs.syslog() && this->logDump() == rhs.logDump(); } // CLASS METHODS @@ -13576,6 +14014,12 @@ int LogController::manipulateAttributes(t_MANIPULATOR& manipulator) return ret; } + ret = manipulator(&d_logDump, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_LOG_DUMP]); + if (ret) { + return ret; + } + return 0; } @@ -13632,6 +14076,10 @@ int LogController::manipulateAttribute(t_MANIPULATOR& manipulator, int id) return manipulator(&d_syslog, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SYSLOG]); } + case ATTRIBUTE_ID_LOG_DUMP: { + return manipulator(&d_logDump, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_LOG_DUMP]); + } default: return NOT_FOUND; } } @@ -13702,6 +14150,11 @@ inline SyslogConfig& LogController::syslog() return d_syslog; } +inline LogDumpConfig& LogController::logDump() +{ + return d_logDump; +} + // ACCESSORS template int LogController::accessAttributes(t_ACCESSOR& accessor) const @@ -13769,6 +14222,11 @@ int LogController::accessAttributes(t_ACCESSOR& accessor) const return ret; } + ret = accessor(d_logDump, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_LOG_DUMP]); + if (ret) { + return ret; + } + return 0; } @@ -13822,6 +14280,10 @@ int LogController::accessAttribute(t_ACCESSOR& accessor, int id) const return accessor(d_syslog, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_SYSLOG]); } + case ATTRIBUTE_ID_LOG_DUMP: { + return accessor(d_logDump, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_LOG_DUMP]); + } default: return NOT_FOUND; } } @@ -13892,6 +14354,11 @@ inline const SyslogConfig& LogController::syslog() const return d_syslog; } +inline const LogDumpConfig& LogController::logDump() const +{ + return d_logDump; +} + // --------------------- // class PartitionConfig // --------------------- @@ -18094,6 +18561,13 @@ inline const AppConfig& Configuration::appConfig() const } // close enterprise namespace #endif -// GENERATED BY BLP_BAS_CODEGEN_2024.07.18 +// GENERATED BY BLP_BAS_CODEGEN_2024.10.17 // USING bas_codegen.pl -m msg --noAggregateConversion --noExternalization // --noIdent --package mqbcfg --msgComponent messages mqbcfg.xsd +// ---------------------------------------------------------------------------- +// NOTICE: +// Copyright 2024 Bloomberg Finance L.P. All rights reserved. +// Property of Bloomberg Finance L.P. (BFLP) +// This software is made available solely pursuant to the +// terms of a BFLP license agreement which governs its use. +// ------------------------------- END-OF-FILE -------------------------------- From 1739af070f899680291bb2c1b4bf0f93f9690c80 Mon Sep 17 00:00:00 2001 From: Taylor Foxhall Date: Fri, 6 Dec 2024 17:19:37 -0500 Subject: [PATCH 04/17] Rename gtest conflicting test macros bmqtst provides several gtest-like compatibility macros, but this prevents us from using gtest or gmock directly because it uses the exact same names as the test macros from that library. Since we want to support at least using gmock in our tests, we rename them to avoid conflict. Signed-off-by: Taylor Foxhall --- ...qstoragetool_commandprocessorfactory.t.cpp | 3 +- .../m_bmqstoragetool_filemanagermock.h | 29 - ..._bmqstoragetool_journalfileprocessor.t.cpp | 124 +- ...m_bmqstoragetool_searchresultfactory.t.cpp | 2 +- .../bmqtool/m_bmqtool_inpututil.t.cpp | 20 +- .../bmq/bmqa/bmqa_abstractsession.t.cpp | 239 +- .../bmq/bmqa/bmqa_closequeuestatus.t.cpp | 40 +- .../bmq/bmqa/bmqa_configurequeuestatus.t.cpp | 40 +- src/groups/bmq/bmqa/bmqa_event.t.cpp | 16 +- src/groups/bmq/bmqa/bmqa_message.t.cpp | 181 +- src/groups/bmq/bmqa/bmqa_messageevent.t.cpp | 22 +- .../bmq/bmqa/bmqa_messageeventbuilder.t.cpp | 32 +- src/groups/bmq/bmqa/bmqa_mocksession.h | 52 +- src/groups/bmq/bmqa/bmqa_mocksession.t.cpp | 350 +-- .../bmq/bmqa/bmqa_openqueuestatus.t.cpp | 40 +- src/groups/bmq/bmqa/bmqa_queueid.t.cpp | 89 +- src/groups/bmq/bmqc/bmqc_array.t.cpp | 310 +-- src/groups/bmq/bmqc/bmqc_monitoredqueue.t.cpp | 8 +- .../bmqc_monitoredqueue_bdlccfixedqueue.t.cpp | 132 +- ...itoredqueue_bdlccsingleconsumerqueue.t.cpp | 100 +- .../bmq/bmqc/bmqc_multiqueuethreadpool.t.cpp | 34 +- src/groups/bmq/bmqc/bmqc_orderedhashmap.t.cpp | 388 +-- .../bmqc/bmqc_orderedhashmapwithhistory.t.cpp | 82 +- src/groups/bmq/bmqc/bmqc_twokeyhashmap.t.cpp | 844 +++--- .../bmq/bmqeval/bmqeval_simpleevaluator.t.cpp | 26 +- .../bmqex_bdlmteventschedulerexecutor.t.cpp | 48 +- .../bmqex_bdlmtfixedthreadpoolexecutor.t.cpp | 38 +- ...bdlmtmultiprioritythreadpoolexecutor.t.cpp | 42 +- ...ex_bdlmtmultiqueuethreadpoolexecutor.t.cpp | 96 +- .../bmqex/bmqex_bdlmtthreadpoolexecutor.t.cpp | 38 +- src/groups/bmq/bmqex/bmqex_bindutil.t.cpp | 32 +- .../bmq/bmqex/bmqex_executionpolicy.t.cpp | 142 +- .../bmq/bmqex/bmqex_executionutil.t.cpp | 329 +-- src/groups/bmq/bmqex/bmqex_executor.t.cpp | 210 +- .../bmq/bmqex/bmqex_executortraits.t.cpp | 30 +- src/groups/bmq/bmqex/bmqex_future.t.cpp | 257 +- src/groups/bmq/bmqex/bmqex_job.t.cpp | 8 +- src/groups/bmq/bmqex/bmqex_promise.t.cpp | 26 +- .../bmq/bmqex/bmqex_sequentialcontext.t.cpp | 76 +- src/groups/bmq/bmqex/bmqex_strand.t.cpp | 96 +- .../bmq/bmqex/bmqex_systemexecutor.t.cpp | 78 +- .../bmq/bmqimp/bmqimp_application.t.cpp | 37 +- .../bmq/bmqimp/bmqimp_brokersession.t.cpp | 2195 ++++++++-------- src/groups/bmq/bmqimp/bmqimp_event.t.cpp | 432 ++-- src/groups/bmq/bmqimp/bmqimp_eventqueue.h | 2 +- src/groups/bmq/bmqimp/bmqimp_eventqueue.t.cpp | 59 +- ...bmqimp_messagecorrelationidcontainer.t.cpp | 51 +- .../bmq/bmqimp/bmqimp_messagedumper.t.cpp | 420 +-- src/groups/bmq/bmqimp/bmqimp_queue.t.cpp | 143 +- .../bmq/bmqimp/bmqimp_queuemanager.t.cpp | 153 +- src/groups/bmq/bmqio/bmqio_channelutil.t.cpp | 119 +- src/groups/bmq/bmqio/bmqio_ntcchannel.t.cpp | 26 +- .../bmq/bmqio/bmqio_ntcchannelfactory.t.cpp | 66 +- .../bmqio_reconnectingchannelfactory.t.cpp | 113 +- src/groups/bmq/bmqio/bmqio_resolveutil.t.cpp | 24 +- .../bmqio/bmqio_resolvingchannelfactory.t.cpp | 28 +- .../bmq/bmqma/bmqma_countingallocator.t.cpp | 83 +- .../bmqma/bmqma_countingallocatorstore.t.cpp | 12 +- .../bmqma/bmqma_countingallocatorutil.t.cpp | 37 +- .../bmq/bmqp/bmqp_ackeventbuilder.t.cpp | 79 +- .../bmq/bmqp/bmqp_ackmessageiterator.t.cpp | 171 +- src/groups/bmq/bmqp/bmqp_compression.t.cpp | 52 +- .../bmq/bmqp/bmqp_confirmeventbuilder.t.cpp | 77 +- .../bmqp/bmqp_confirmmessageiterator.t.cpp | 119 +- .../bmq/bmqp/bmqp_controlmessageutil.t.cpp | 12 +- src/groups/bmq/bmqp/bmqp_crc32c.t.cpp | 160 +- src/groups/bmq/bmqp/bmqp_event.t.cpp | 208 +- src/groups/bmq/bmqp/bmqp_eventutil.t.cpp | 82 +- .../bmq/bmqp/bmqp_messageguidgenerator.t.cpp | 87 +- .../bmq/bmqp/bmqp_messageproperties.t.cpp | 499 ++-- src/groups/bmq/bmqp/bmqp_optionsview.t.cpp | 240 +- src/groups/bmq/bmqp/bmqp_optionutil.t.cpp | 90 +- src/groups/bmq/bmqp/bmqp_protocol.t.cpp | 690 ++--- src/groups/bmq/bmqp/bmqp_protocolutil.t.cpp | 222 +- .../bmq/bmqp/bmqp_pusheventbuilder.t.cpp | 539 ++-- .../bmq/bmqp/bmqp_pushmessageiterator.t.cpp | 405 +-- .../bmq/bmqp/bmqp_puteventbuilder.t.cpp | 1111 ++++---- .../bmq/bmqp/bmqp_putmessageiterator.t.cpp | 760 +++--- src/groups/bmq/bmqp/bmqp_queueid.t.cpp | 35 +- src/groups/bmq/bmqp/bmqp_queueutil.t.cpp | 67 +- .../bmq/bmqp/bmqp_recoveryeventbuilder.t.cpp | 163 +- .../bmqp/bmqp_recoverymessageiterator.t.cpp | 256 +- .../bmq/bmqp/bmqp_rejecteventbuilder.t.cpp | 77 +- .../bmq/bmqp/bmqp_rejectmessageiterator.t.cpp | 119 +- src/groups/bmq/bmqp/bmqp_requestmanager.t.cpp | 210 +- .../bmqp/bmqp_routingconfigurationutils.t.cpp | 54 +- .../bmq/bmqp/bmqp_schemaeventbuilder.t.cpp | 157 +- .../bmq/bmqp/bmqp_schemagenerator.t.cpp | 22 +- src/groups/bmq/bmqp/bmqp_schemalearner.t.cpp | 199 +- .../bmq/bmqp/bmqp_storageeventbuilder.t.cpp | 224 +- .../bmqp/bmqp_storagemessageiterator.t.cpp | 211 +- src/groups/bmq/bmqpi/bmqpi_dtcontext.t.cpp | 6 +- src/groups/bmq/bmqpi/bmqpi_dtspan.t.cpp | 6 +- src/groups/bmq/bmqpi/bmqpi_dttracer.t.cpp | 6 +- .../bmq/bmqpi/bmqpi_hosthealthmonitor.t.cpp | 6 +- src/groups/bmq/bmqsys/bmqsys_mocktime.t.cpp | 24 +- .../bmq/bmqsys/bmqsys_statmonitor.t.cpp | 148 +- .../bmqsys_statmonitorsnapshotrecorder.t.cpp | 96 +- src/groups/bmq/bmqsys/bmqsys_time.t.cpp | 36 +- .../bmqt/bmqt_compressionalgorithmtype.t.cpp | 6 +- src/groups/bmq/bmqt/bmqt_correlationid.t.cpp | 150 +- src/groups/bmq/bmqt/bmqt_encodingtype.t.cpp | 22 +- .../bmq/bmqt/bmqt_hosthealthstate.t.cpp | 22 +- .../bmq/bmqt/bmqt_messageeventtype.t.cpp | 20 +- src/groups/bmq/bmqt/bmqt_messageguid.t.cpp | 66 +- src/groups/bmq/bmqt/bmqt_propertytype.t.cpp | 22 +- src/groups/bmq/bmqt/bmqt_queueflags.t.cpp | 114 +- src/groups/bmq/bmqt/bmqt_queueoptions.t.cpp | 145 +- src/groups/bmq/bmqt/bmqt_resultcode.t.cpp | 75 +- .../bmq/bmqt/bmqt_sessioneventtype.t.cpp | 22 +- src/groups/bmq/bmqt/bmqt_sessionoptions.t.cpp | 71 +- src/groups/bmq/bmqt/bmqt_uri.t.cpp | 313 +-- src/groups/bmq/bmqt/bmqt_version.t.cpp | 68 +- .../bmq/bmqtsk/bmqtsk_logcontroller.t.cpp | 43 +- src/groups/bmq/bmqtst/bmqtst_blobtestutil.h | 14 +- .../bmq/bmqtst/bmqtst_blobtestutil.t.cpp | 44 +- .../bmq/bmqtst/bmqtst_scopedlogobserver.t.cpp | 48 +- src/groups/bmq/bmqtst/bmqtst_testhelper.h | 128 +- src/groups/bmq/bmqu/bmqu_atomicstate.t.cpp | 20 +- .../bmq/bmqu/bmqu_atomicvalidator.t.cpp | 52 +- src/groups/bmq/bmqu/bmqu_blob.t.cpp | 281 +- src/groups/bmq/bmqu/bmqu_blobiterator.t.cpp | 54 +- .../bmq/bmqu/bmqu_blobobjectproxy.t.cpp | 106 +- src/groups/bmq/bmqu/bmqu_memoutstream.t.cpp | 50 +- .../bmq/bmqu/bmqu_objectplaceholder.t.cpp | 40 +- src/groups/bmq/bmqu/bmqu_operationchain.t.cpp | 249 +- .../bmq/bmqu/bmqu_outstreamformatsaver.t.cpp | 8 +- src/groups/bmq/bmqu/bmqu_printutil.t.cpp | 24 +- .../bmq/bmqu/bmqu_samethreadchecker.t.cpp | 6 +- src/groups/bmq/bmqu/bmqu_sharedresource.t.cpp | 72 +- src/groups/bmq/bmqu/bmqu_stringutil.t.cpp | 61 +- .../bmq/bmqu/bmqu_throttledaction.t.cpp | 223 +- src/groups/bmq/bmqu/bmqu_tlsbool.t.cpp | 94 +- src/groups/bmq/bmqu/bmqu_weakmemfn.t.cpp | 93 +- src/groups/bmq/bmqvt/bmqvt_propertybag.h | 2 +- src/groups/bmq/bmqvt/bmqvt_propertybag.t.cpp | 57 +- .../bmq/bmqvt/bmqvt_rcdescriptionerror.t.cpp | 26 +- src/groups/bmq/bmqvt/bmqvt_valueorerror.t.cpp | 80 +- src/groups/mqb/mqba/mqba_adminsession.t.cpp | 12 +- src/groups/mqb/mqba/mqba_application.t.cpp | 2 +- src/groups/mqb/mqba/mqba_clientsession.t.cpp | 233 +- src/groups/mqb/mqba/mqba_dispatcher.t.cpp | 50 +- .../mqbblp/mqbblp_clusterstatemonitor.t.cpp | 238 +- .../mqbblp/mqbblp_messagegroupidmanager.t.cpp | 135 +- src/groups/mqb/mqbblp/mqbblp_pushstream.t.cpp | 32 +- .../mqbblp_queueconsumptionmonitor.t.cpp | 189 +- .../mqb/mqbblp/mqbblp_queueenginetester.h | 12 +- .../mqb/mqbblp/mqbblp_relayqueueengine.t.cpp | 351 +-- .../mqb/mqbblp/mqbblp_remotequeue.t.cpp | 133 +- .../mqb/mqbblp/mqbblp_rootqueueengine.t.cpp | 1408 +++++----- src/groups/mqb/mqbblp/mqbblp_routers.t.cpp | 158 +- .../mqb/mqbc/mqbc_clusterstateledger.t.cpp | 34 +- .../mqbc_clusterstateledgeriterator.t.cpp | 6 +- .../mqbc_clusterstateledgerprotocol.t.cpp | 43 +- .../mqbc/mqbc_clusterstateledgerutil.t.cpp | 135 +- .../mqb/mqbc/mqbc_clusterstatemanager.t.cpp | 345 +-- .../mqbc/mqbc_incoreclusterstateledger.t.cpp | 450 ++-- ...qbc_incoreclusterstateledgeriterator.t.cpp | 30 +- src/groups/mqb/mqbc/mqbc_storagemanager.t.cpp | 234 +- .../mqb/mqbc/test/mqbc_clusterstate.t.cpp | 2 +- .../mqb/mqbcfg/mqbcfg_brokerconfig.t.cpp | 8 +- .../mqbcfg_tcpinterfaceconfigvalidator.t.cpp | 31 +- src/groups/mqb/mqbcmd/mqbcmd_parseutil.t.cpp | 13 +- src/groups/mqb/mqbi/mqbi_queue.t.cpp | 26 +- src/groups/mqb/mqbi/mqbi_queueengine.t.cpp | 26 +- src/groups/mqb/mqbnet/mqbnet_channel.t.cpp | 82 +- src/groups/mqb/mqbnet/mqbnet_cluster.t.cpp | 28 +- .../mqb/mqbnet/mqbnet_dummysession.t.cpp | 10 +- src/groups/mqb/mqbnet/mqbnet_elector.t.cpp | 2301 +++++++++-------- .../mqbnet/mqbnet_multirequestmanager.t.cpp | 65 +- src/groups/mqb/mqbnet/mqbnet_negotiator.t.cpp | 34 +- src/groups/mqb/mqbnet/mqbnet_session.t.cpp | 12 +- .../mqb/mqbs/mqbs_datafileiterator.t.cpp | 90 +- src/groups/mqb/mqbs/mqbs_datastore.t.cpp | 54 +- .../mqb/mqbs/mqbs_filebackedstorage.t.cpp | 659 ++--- src/groups/mqb/mqbs/mqbs_fileset.t.cpp | 42 +- src/groups/mqb/mqbs/mqbs_filestore.t.cpp | 64 +- .../mqb/mqbs/mqbs_filestoreprotocol.t.cpp | 278 +- .../mqb/mqbs/mqbs_filestoreprotocolutil.t.cpp | 109 +- src/groups/mqb/mqbs/mqbs_filestoreset.t.cpp | 60 +- .../mqb/mqbs/mqbs_inmemorystorage.t.cpp | 566 ++-- .../mqb/mqbs/mqbs_journalfileiterator.t.cpp | 288 ++- .../mqb/mqbs/mqbs_mappedfiledescriptor.t.cpp | 40 +- src/groups/mqb/mqbs/mqbs_memoryblock.t.cpp | 28 +- .../mqb/mqbs/mqbs_memoryblockiterator.t.cpp | 174 +- src/groups/mqb/mqbs/mqbs_offsetptr.t.cpp | 8 +- .../mqb/mqbs/mqbs_qlistfileiterator.t.cpp | 217 +- .../mqb/mqbs/mqbs_storageprintutil.t.cpp | 4 +- src/groups/mqb/mqbs/mqbs_storageutil.t.cpp | 61 +- src/groups/mqb/mqbsi/mqbsi_ledger.t.cpp | 6 +- src/groups/mqb/mqbsi/mqbsi_log.t.cpp | 6 +- src/groups/mqb/mqbsl/mqbsl_inmemorylog.t.cpp | 280 +- src/groups/mqb/mqbsl/mqbsl_ledger.t.cpp | 882 ++++--- .../mqbsl/mqbsl_memorymappedondisklog.t.cpp | 341 +-- .../mqb/mqbsl/mqbsl_readwriteondisklog.t.cpp | 278 +- .../mqb/mqbstat/mqbstat_queuestats.t.cpp | 344 +-- .../mqb/mqbstat/mqbstat_statcontroller.t.cpp | 2 +- src/groups/mqb/mqbu/mqbu_capacitymeter.t.cpp | 58 +- src/groups/mqb/mqbu/mqbu_exit.t.cpp | 33 +- src/groups/mqb/mqbu/mqbu_loadbalancer.t.cpp | 60 +- .../mqb/mqbu/mqbu_messageguidutil.t.cpp | 42 +- .../mqb/mqbu/mqbu_resourceusagemonitor.t.cpp | 931 +++---- src/groups/mqb/mqbu/mqbu_storagekey.t.cpp | 105 +- 203 files changed, 16790 insertions(+), 15653 deletions(-) diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_commandprocessorfactory.t.cpp b/src/applications/bmqstoragetool/m_bmqstoragetool_commandprocessorfactory.t.cpp index f4a3a62eee..f6e13b84bb 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_commandprocessorfactory.t.cpp +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_commandprocessorfactory.t.cpp @@ -54,7 +54,8 @@ static void test1_breathingTest() fileManager, bsl::cout, bmqtst::TestHelperUtil::allocator()); - ASSERT(dynamic_cast(cmdProcessor.get()) != 0); + BMQTST_ASSERT(dynamic_cast(cmdProcessor.get()) != + 0); } // ============================================================================ diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_filemanagermock.h b/src/applications/bmqstoragetool/m_bmqstoragetool_filemanagermock.h index c0084be135..804f0948f7 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_filemanagermock.h +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_filemanagermock.h @@ -27,37 +27,8 @@ #include #include -// GMOCK -// If bmqst_testhelper.h was defined before gtest.h, preserve macroses values. -// If not, undefine values from gtest.h. -#pragma push_macro("ASSERT_EQ") -#pragma push_macro("ASSERT_NE") -#pragma push_macro("ASSERT_LT") -#pragma push_macro("ASSERT_LE") -#pragma push_macro("ASSERT_GT") -#pragma push_macro("ASSERT_GE") -#pragma push_macro("TEST_F") -#pragma push_macro("TEST") - #include -#undef ASSERT_EQ -#undef ASSERT_NE -#undef ASSERT_LT -#undef ASSERT_LE -#undef ASSERT_GT -#undef ASSERT_GE -#undef TEST_F -#undef TEST -#pragma pop_macro("ASSERT_EQ") -#pragma pop_macro("ASSERT_NE") -#pragma pop_macro("ASSERT_LT") -#pragma pop_macro("ASSERT_LE") -#pragma pop_macro("ASSERT_GT") -#pragma pop_macro("ASSERT_GE") -#pragma pop_macro("TEST_F") -#pragma pop_macro("TEST") - namespace BloombergLP { namespace m_bmqstoragetool { diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_journalfileprocessor.t.cpp b/src/applications/bmqstoragetool/m_bmqstoragetool_journalfileprocessor.t.cpp index b5fd761784..7bfe25df49 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_journalfileprocessor.t.cpp +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_journalfileprocessor.t.cpp @@ -220,7 +220,7 @@ static void test1_breathingTest() expectedStream << foundMessagesCount << " message GUID(s) found." << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test2_searchGuidTest() @@ -288,7 +288,7 @@ static void test2_searchGuidTest() expectedStream << searchGuids.size() << " message GUID(s) found." << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test3_searchNonExistingGuidTest() @@ -349,7 +349,7 @@ static void test3_searchNonExistingGuidTest() expectedStream << searchGuids[0] << bsl::endl << searchGuids[1] << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test4_searchExistingAndNonExistingGuidTest() @@ -433,7 +433,7 @@ static void test4_searchExistingAndNonExistingGuidTest() expectedStream << searchGuids[2] << bsl::endl << searchGuids[3] << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test5_searchOutstandingMessagesTest() @@ -498,7 +498,7 @@ static void test5_searchOutstandingMessagesTest() << outstandingGUIDS.size() << "/" << messageCount << ")" << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test6_searchConfirmedMessagesTest() @@ -562,7 +562,7 @@ static void test6_searchConfirmedMessagesTest() << (messageCount - confirmedGUIDS.size()) << "/" << messageCount << ")" << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test7_searchPartiallyConfirmedMessagesTest() @@ -629,7 +629,7 @@ static void test7_searchPartiallyConfirmedMessagesTest() << partiallyConfirmedGUIDS.size() + 1 << "/" << messageCount << ")" << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test8_searchMessagesByQueueKeyTest() @@ -690,7 +690,7 @@ static void test8_searchMessagesByQueueKeyTest() expectedStream << foundMessagesCount << " message GUID(s) found." << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test9_searchMessagesByQueueNameTest() @@ -761,7 +761,7 @@ static void test9_searchMessagesByQueueNameTest() expectedStream << foundMessagesCount << " message GUID(s) found." << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test10_searchMessagesByQueueNameAndQueueKeyTest() @@ -836,7 +836,7 @@ static void test10_searchMessagesByQueueNameAndQueueKeyTest() expectedStream << foundMessagesCount << " message GUID(s) found." << bsl::endl; - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test11_searchMessagesByTimestamp() @@ -902,7 +902,7 @@ static void test11_searchMessagesByTimestamp() bmqtst::TestHelperUtil::allocator()); searchProcessor->process(); - ASSERT_EQ(resultStream.str(), expectedStream.str()); + BMQTST_ASSERT_EQ(resultStream.str(), expectedStream.str()); } static void test12_printMessagesDetailsTest() @@ -965,8 +965,8 @@ static void test12_printMessagesDetailsTest() for (size_t i = 0; i < confirmedGUIDS.size(); i++) { // Check Message type size_t foundIdx = resultString.find(messageRecordCaption, startIdx); - ASSERT_D(messageRecordCaption, (foundIdx != bsl::string::npos)); - ASSERT_D(messageRecordCaption, (foundIdx >= startIdx)); + BMQTST_ASSERT_D(messageRecordCaption, (foundIdx != bsl::string::npos)); + BMQTST_ASSERT_D(messageRecordCaption, (foundIdx >= startIdx)); startIdx = foundIdx + bsl::strlen(messageRecordCaption); // Check GUID @@ -974,20 +974,20 @@ static void test12_printMessagesDetailsTest() outputGuidString(ss, confirmedGUIDS.at(i)); bsl::string guidStr(ss.str(), bmqtst::TestHelperUtil::allocator()); foundIdx = resultString.find(guidStr, startIdx); - ASSERT_D(guidStr, (foundIdx != bsl::string::npos)); - ASSERT_D(guidStr, (foundIdx >= startIdx)); + BMQTST_ASSERT_D(guidStr, (foundIdx != bsl::string::npos)); + BMQTST_ASSERT_D(guidStr, (foundIdx >= startIdx)); startIdx = foundIdx + guidStr.length(); // Check Confirm type foundIdx = resultString.find(confirmRecordCaption, startIdx); - ASSERT_D(confirmRecordCaption, (foundIdx != bsl::string::npos)); - ASSERT_D(confirmRecordCaption, (foundIdx >= startIdx)); + BMQTST_ASSERT_D(confirmRecordCaption, (foundIdx != bsl::string::npos)); + BMQTST_ASSERT_D(confirmRecordCaption, (foundIdx >= startIdx)); startIdx = foundIdx + bsl::strlen(messageRecordCaption); // Check Delete type foundIdx = resultString.find(deleteRecordCaption, startIdx); - ASSERT_D(deleteRecordCaption, (foundIdx != bsl::string::npos)); - ASSERT_D(deleteRecordCaption, (foundIdx >= startIdx)); + BMQTST_ASSERT_D(deleteRecordCaption, (foundIdx != bsl::string::npos)); + BMQTST_ASSERT_D(deleteRecordCaption, (foundIdx >= startIdx)); startIdx = foundIdx + bsl::strlen(messageRecordCaption); } } @@ -1047,8 +1047,8 @@ static void test13_searchMessagesWithPayloadDumpTest() MESSAGES, k_NUM_MSGS, messageOffsets); - ASSERT(pd != 0); - ASSERT_GT(mfdData.fileSize(), 0ULL); + BMQTST_ASSERT(pd != 0); + BMQTST_ASSERT_GT(mfdData.fileSize(), 0ULL); // Create data file iterator DataFileIterator dataIt(&mfdData, fileHeader); @@ -1115,8 +1115,8 @@ static void test13_searchMessagesWithPayloadDumpTest() bsl::string guidStr(ss.str(), bmqtst::TestHelperUtil::allocator()); size_t foundIdx = resultString.find(guidStr, startIdx); - ASSERT_D(guidStr, (foundIdx != bsl::string::npos)); - ASSERT_D(guidStr, (foundIdx >= startIdx)); + BMQTST_ASSERT_D(guidStr, (foundIdx != bsl::string::npos)); + BMQTST_ASSERT_D(guidStr, (foundIdx >= startIdx)); startIdx = foundIdx + guidStr.length(); @@ -1124,8 +1124,8 @@ static void test13_searchMessagesWithPayloadDumpTest() bsl::string dumpStr = expectedPayloadSubstring[i]; foundIdx = resultString.find(dumpStr, startIdx); - ASSERT_D(dumpStr, (foundIdx != bsl::string::npos)); - ASSERT_D(guidStr, (foundIdx >= startIdx)); + BMQTST_ASSERT_D(dumpStr, (foundIdx != bsl::string::npos)); + BMQTST_ASSERT_D(guidStr, (foundIdx >= startIdx)); startIdx = foundIdx + dumpStr.length(); } @@ -1183,7 +1183,7 @@ static void test14_summaryTest() "Number of outstanding messages: 2\nOutstanding ratio: 40% (2/5)\n"; bsl::string res(resultStream.str(), bmqtst::TestHelperUtil::allocator()); - ASSERT(res.starts_with(expectedStream.str())); + BMQTST_ASSERT(res.starts_with(expectedStream.str())); } static void test15_timestampSearchTest() @@ -1211,15 +1211,15 @@ static void test15_timestampSearchTest() static void check(mqbs::JournalFileIterator& it, const bsls::Types::Uint64& ts) { - ASSERT_GT(it.recordHeader().timestamp(), ts); - ASSERT(!it.isReverseMode()); + BMQTST_ASSERT_GT(it.recordHeader().timestamp(), ts); + BMQTST_ASSERT(!it.isReverseMode()); // Check previous record it.flipDirection(); - ASSERT_EQ(it.nextRecord(), 1); - ASSERT_LE(it.recordHeader().timestamp(), ts); + BMQTST_ASSERT_EQ(it.nextRecord(), 1); + BMQTST_ASSERT_LE(it.recordHeader().timestamp(), ts); // Set 'it' to its original state it.flipDirection(); - ASSERT_EQ(it.nextRecord(), 1); + BMQTST_ASSERT_EQ(it.nextRecord(), 1); } }; @@ -1232,8 +1232,10 @@ static void test15_timestampSearchTest() journalFile.fileHeader(), false); // Move the iterator to the beginning of the file - ASSERT_EQ(journalFileIt.nextRecord(), 1); - ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts), 1); + BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1); + BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, + ts), + 1); ResultChecker::check(journalFileIt, ts); } @@ -1247,35 +1249,43 @@ static void test15_timestampSearchTest() false); // Move the iterator to the center of the file - ASSERT_EQ(journalFileIt.nextRecord(), 1); - ASSERT_EQ(journalFileIt.advance(k_NUM_RECORDS / 2), 1); + BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1); + BMQTST_ASSERT_EQ(journalFileIt.advance(k_NUM_RECORDS / 2), 1); // Find record with lower timestamp than the record pointed by the // specified iterator, which is initially forward - ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1); - ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts1), 1); + BMQTST_ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1); + BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, + ts1), + 1); ResultChecker::check(journalFileIt, ts1); // Find record with higher timestamp than the record pointed by the // specified iterator, which is initially forward - ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2); - ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts2), 1); + BMQTST_ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2); + BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, + ts2), + 1); ResultChecker::check(journalFileIt, ts2); // Find record with lower timestamp than the record pointed by the // specified iterator, which is initially backward - ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1); + BMQTST_ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts1); journalFileIt.flipDirection(); - ASSERT(journalFileIt.isReverseMode()); - ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts1), 1); + BMQTST_ASSERT(journalFileIt.isReverseMode()); + BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, + ts1), + 1); ResultChecker::check(journalFileIt, ts1); // Find record with higher timestamp than the record pointed by the // specified iterator, which is initially backward - ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2); + BMQTST_ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts2); journalFileIt.flipDirection(); - ASSERT(journalFileIt.isReverseMode()); - ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts2), 1); + BMQTST_ASSERT(journalFileIt.isReverseMode()); + BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, + ts2), + 1); ResultChecker::check(journalFileIt, ts2); } @@ -1288,11 +1298,13 @@ static void test15_timestampSearchTest() journalFile.fileHeader(), false); // Move the iterator to the beginning of the file - ASSERT_EQ(journalFileIt.nextRecord(), 1); - ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts), 0); - ASSERT_EQ(journalFileIt.recordIndex(), k_NUM_RECORDS - 1); - ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts); - ASSERT(!journalFileIt.isReverseMode()); + BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1); + BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, + ts), + 0); + BMQTST_ASSERT_EQ(journalFileIt.recordIndex(), k_NUM_RECORDS - 1); + BMQTST_ASSERT_LT(journalFileIt.recordHeader().timestamp(), ts); + BMQTST_ASSERT(!journalFileIt.isReverseMode()); } { @@ -1303,11 +1315,13 @@ static void test15_timestampSearchTest() journalFile.fileHeader(), false); // Move the iterator to the beginning of the file - ASSERT_EQ(journalFileIt.nextRecord(), 1); - ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, ts), 1); - ASSERT_EQ(journalFileIt.recordIndex(), 0U); - ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts); - ASSERT(!journalFileIt.isReverseMode()); + BMQTST_ASSERT_EQ(journalFileIt.nextRecord(), 1); + BMQTST_ASSERT_EQ(m_bmqstoragetool::moveToLowerBound(&journalFileIt, + ts), + 1); + BMQTST_ASSERT_EQ(journalFileIt.recordIndex(), 0U); + BMQTST_ASSERT_GT(journalFileIt.recordHeader().timestamp(), ts); + BMQTST_ASSERT(!journalFileIt.isReverseMode()); } } diff --git a/src/applications/bmqstoragetool/m_bmqstoragetool_searchresultfactory.t.cpp b/src/applications/bmqstoragetool/m_bmqstoragetool_searchresultfactory.t.cpp index 1c1aa77f9b..d1d9f87477 100644 --- a/src/applications/bmqstoragetool/m_bmqstoragetool_searchresultfactory.t.cpp +++ b/src/applications/bmqstoragetool/m_bmqstoragetool_searchresultfactory.t.cpp @@ -55,7 +55,7 @@ static void test1_breathingTest() fileManager, bsl::cout, bmqtst::TestHelperUtil::allocator()); - ASSERT(dynamic_cast(searchResult.get()) != 0); + BMQTST_ASSERT(dynamic_cast(searchResult.get()) != 0); } // ============================================================================ diff --git a/src/applications/bmqtool/m_bmqtool_inpututil.t.cpp b/src/applications/bmqtool/m_bmqtool_inpututil.t.cpp index 37fba0b55d..dc8e7dc8fb 100644 --- a/src/applications/bmqtool/m_bmqtool_inpututil.t.cpp +++ b/src/applications/bmqtool/m_bmqtool_inpututil.t.cpp @@ -113,11 +113,11 @@ static void test1_decodeHexDumpTest() input, bmqtst::TestHelperUtil::allocator()); // Check rc - ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc); + BMQTST_ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc); // Check error - ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError); + BMQTST_ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError); // Check output - ASSERT_EQ_D(test.d_line, output.str(), test.d_expectedOutput); + BMQTST_ASSERT_EQ_D(test.d_line, output.str(), test.d_expectedOutput); } } @@ -264,8 +264,8 @@ static void test2_loadMessageFromFileTest() &error, "wrongFilePath", bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(rc, false); - ASSERT_EQ(error.str(), "Failed to open file: wrongFilePath"); + BMQTST_ASSERT_EQ(rc, false); + BMQTST_ASSERT_EQ(error.str(), "Failed to open file: wrongFilePath"); } const size_t k_NUM_DATA = sizeof(k_DATA) / sizeof(*k_DATA); @@ -277,7 +277,7 @@ static void test2_loadMessageFromFileTest() const bsl::string filePath = tempFile.path(); { bsl::ofstream ofs(filePath.c_str()); - ASSERT_EQ(ofs.is_open(), true); + BMQTST_ASSERT_EQ(ofs.is_open(), true); ofs << test.d_fileContent; } @@ -291,11 +291,11 @@ static void test2_loadMessageFromFileTest() filePath, bmqtst::TestHelperUtil::allocator()); // Check rc - ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc); + BMQTST_ASSERT_EQ_D(test.d_line, rc, test.d_expectedRc); // Check error - ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError); + BMQTST_ASSERT_EQ_D(test.d_line, error.str(), test.d_expectedError); // Check payload - ASSERT_EQ_D(test.d_line, payload.str(), test.d_expectedPayload); + BMQTST_ASSERT_EQ_D(test.d_line, payload.str(), test.d_expectedPayload); // Check properties (deserialize into properties instance) bdlbb::PooledBlobBufferFactory bufferFactory( 128, @@ -306,7 +306,7 @@ static void test2_loadMessageFromFileTest() bdlbb::BlobUtil::append(&blob, properties.str().c_str(), static_cast(properties.str().size())); - ASSERT_EQ_D(test.d_line, messageProperties.streamIn(blob), 0); + BMQTST_ASSERT_EQ_D(test.d_line, messageProperties.streamIn(blob), 0); } } diff --git a/src/groups/bmq/bmqa/bmqa_abstractsession.t.cpp b/src/groups/bmq/bmqa/bmqa_abstractsession.t.cpp index 3355f20be6..dcf0c0502c 100644 --- a/src/groups/bmq/bmqa/bmqa_abstractsession.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_abstractsession.t.cpp @@ -306,13 +306,13 @@ static void test1_breathingTest() bmqtst::TestHelperUtil::verbosityLevel() > 2); PV("Verify that the protocol is NOT abstract"); - ASSERT(!testObj.testAbstract()); + BMQTST_ASSERT(!testObj.testAbstract()); PV("Verify that there are no data members"); - ASSERT(testObj.testNoDataMembers()); + BMQTST_ASSERT(testObj.testNoDataMembers()); PV("Verify that the destructor is virtual"); - ASSERT(testObj.testVirtualDestructor()); + BMQTST_ASSERT(testObj.testVirtualDestructor()); PV("Verify that methods are public and virtual"); @@ -481,136 +481,143 @@ static void test2_instanceInvariants() const bmqa::AbstractSession::CloseQueueCallback closeQueueCallback; // Base class instance - ASSERT_OPT_FAIL(concreteObj.start(dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.startAsync(dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.stop()); - ASSERT_OPT_FAIL(concreteObj.stopAsync()); - ASSERT_OPT_FAIL(concreteObj.finalizeStop()); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL(concreteObj.start(dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.startAsync(dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.stop()); + BMQTST_ASSERT_OPT_FAIL(concreteObj.stopAsync()); + BMQTST_ASSERT_OPT_FAIL(concreteObj.finalizeStop()); + BMQTST_ASSERT_OPT_FAIL( concreteObj.loadMessageEventBuilder(dummyMessageEventBuilderPtr)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL( concreteObj.loadConfirmEventBuilder(dummyConfirmEventBuilderPtr)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL( concreteObj.loadMessageProperties(dummyMessagePropertiesPtr)); - ASSERT_OPT_FAIL(concreteObj.getQueueId(dummyQueueIdPtr, dummyUri)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL(concreteObj.getQueueId(dummyQueueIdPtr, dummyUri)); + BMQTST_ASSERT_OPT_FAIL( concreteObj.getQueueId(dummyQueueIdPtr, dummyCorrelationId)); - ASSERT_OPT_FAIL(concreteObj.openQueue(dummyQueueIdPtr, - dummyUri, - 0, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.openQueueSync(dummyQueueIdPtr, - dummyUri, - 0, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.openQueueAsync(dummyQueueIdPtr, - dummyUri, - 0, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.openQueueAsync(dummyQueueIdPtr, - dummyUri, - 0, - openQueueCallback, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.configureQueue(dummyQueueIdPtr, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.configureQueueSync(dummyQueueIdPtr, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.configureQueueAsync(dummyQueueIdPtr, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.configureQueueAsync(dummyQueueIdPtr, - dummyQueueOptions, - configureQueueCallback, - dummyTimeInterval)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL(concreteObj.openQueue(dummyQueueIdPtr, + dummyUri, + 0, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.openQueueSync(dummyQueueIdPtr, + dummyUri, + 0, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.openQueueAsync(dummyQueueIdPtr, + dummyUri, + 0, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.openQueueAsync(dummyQueueIdPtr, + dummyUri, + 0, + openQueueCallback, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.configureQueue(dummyQueueIdPtr, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.configureQueueSync(dummyQueueIdPtr, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.configureQueueAsync(dummyQueueIdPtr, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL( + concreteObj.configureQueueAsync(dummyQueueIdPtr, + dummyQueueOptions, + configureQueueCallback, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL( concreteObj.closeQueue(dummyQueueIdPtr, dummyTimeInterval)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL( concreteObj.closeQueueSync(dummyQueueIdPtr, dummyTimeInterval)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL( concreteObj.closeQueueAsync(dummyQueueIdPtr, dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.closeQueueAsync(dummyQueueIdPtr, - closeQueueCallback, - dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.nextEvent(dummyTimeInterval)); - ASSERT_OPT_FAIL(concreteObj.post(dummyMessageEvent)); - ASSERT_OPT_FAIL(concreteObj.confirmMessage(dummyMessage)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL(concreteObj.closeQueueAsync(dummyQueueIdPtr, + closeQueueCallback, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.nextEvent(dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.post(dummyMessageEvent)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.confirmMessage(dummyMessage)); + BMQTST_ASSERT_OPT_FAIL( concreteObj.confirmMessage(dummyMessageConfirmationCookie)); - ASSERT_OPT_FAIL(concreteObj.confirmMessages(dummyConfirmEventBuilderPtr)); - ASSERT_OPT_FAIL(concreteObj.configureMessageDumping("")); + BMQTST_ASSERT_OPT_FAIL( + concreteObj.confirmMessages(dummyConfirmEventBuilderPtr)); + BMQTST_ASSERT_OPT_FAIL(concreteObj.configureMessageDumping("")); // Derived instance - ASSERT_OPT_FAIL(testObj.start(dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.startAsync(dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.stop()); - ASSERT_OPT_FAIL(testObj.stopAsync()); - ASSERT_OPT_FAIL(testObj.finalizeStop()); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL(testObj.start(dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.startAsync(dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.stop()); + BMQTST_ASSERT_OPT_FAIL(testObj.stopAsync()); + BMQTST_ASSERT_OPT_FAIL(testObj.finalizeStop()); + BMQTST_ASSERT_OPT_FAIL( testObj.loadMessageEventBuilder(dummyMessageEventBuilderPtr)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL( testObj.loadConfirmEventBuilder(dummyConfirmEventBuilderPtr)); - ASSERT_OPT_FAIL(testObj.loadMessageProperties(dummyMessagePropertiesPtr)); - ASSERT_OPT_FAIL(testObj.getQueueId(dummyQueueIdPtr, dummyUri)); - ASSERT_OPT_FAIL(testObj.getQueueId(dummyQueueIdPtr, dummyCorrelationId)); - ASSERT_OPT_FAIL(testObj.openQueue(dummyQueueIdPtr, - dummyUri, - 0, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.openQueueSync(dummyQueueIdPtr, - dummyUri, - 0, // flags - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.openQueueAsync(dummyQueueIdPtr, - dummyUri, - 0, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.openQueueAsync(dummyQueueIdPtr, - dummyUri, - 0, - openQueueCallback, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.configureQueue(dummyQueueIdPtr, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.configureQueueSync(dummyQueueIdPtr, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.configureQueueAsync(dummyQueueIdPtr, - dummyQueueOptions, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.configureQueueAsync(dummyQueueIdPtr, - dummyQueueOptions, - configureQueueCallback, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.closeQueue(dummyQueueIdPtr, dummyTimeInterval)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL( + testObj.loadMessageProperties(dummyMessagePropertiesPtr)); + BMQTST_ASSERT_OPT_FAIL(testObj.getQueueId(dummyQueueIdPtr, dummyUri)); + BMQTST_ASSERT_OPT_FAIL( + testObj.getQueueId(dummyQueueIdPtr, dummyCorrelationId)); + BMQTST_ASSERT_OPT_FAIL(testObj.openQueue(dummyQueueIdPtr, + dummyUri, + 0, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.openQueueSync(dummyQueueIdPtr, + dummyUri, + 0, // flags + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.openQueueAsync(dummyQueueIdPtr, + dummyUri, + 0, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.openQueueAsync(dummyQueueIdPtr, + dummyUri, + 0, + openQueueCallback, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.configureQueue(dummyQueueIdPtr, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.configureQueueSync(dummyQueueIdPtr, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.configureQueueAsync(dummyQueueIdPtr, + dummyQueueOptions, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.configureQueueAsync(dummyQueueIdPtr, + dummyQueueOptions, + configureQueueCallback, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL( + testObj.closeQueue(dummyQueueIdPtr, dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL( testObj.closeQueueSync(dummyQueueIdPtr, dummyTimeInterval)); - ASSERT_OPT_FAIL( + BMQTST_ASSERT_OPT_FAIL( testObj.closeQueueAsync(dummyQueueIdPtr, dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.closeQueueAsync(dummyQueueIdPtr, - closeQueueCallback, - dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.nextEvent(dummyTimeInterval)); - ASSERT_OPT_FAIL(testObj.post(dummyMessageEvent)); - ASSERT_OPT_FAIL(testObj.confirmMessage(dummyMessage)); - ASSERT_OPT_FAIL(testObj.confirmMessage(dummyMessageConfirmationCookie)); - ASSERT_OPT_FAIL(testObj.confirmMessages(dummyConfirmEventBuilderPtr)); + BMQTST_ASSERT_OPT_FAIL(testObj.closeQueueAsync(dummyQueueIdPtr, + closeQueueCallback, + dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.nextEvent(dummyTimeInterval)); + BMQTST_ASSERT_OPT_FAIL(testObj.post(dummyMessageEvent)); + BMQTST_ASSERT_OPT_FAIL(testObj.confirmMessage(dummyMessage)); + BMQTST_ASSERT_OPT_FAIL( + testObj.confirmMessage(dummyMessageConfirmationCookie)); + BMQTST_ASSERT_OPT_FAIL( + testObj.confirmMessages(dummyConfirmEventBuilderPtr)); PV("Verify that overriden methods execute as intended"); - ASSERT_OPT_PASS(testObj.configureMessageDumping("")); - ASSERT_EQ(testObj.configureMessageDumping(""), -1497); + BMQTST_ASSERT_OPT_PASS(testObj.configureMessageDumping("")); + BMQTST_ASSERT_EQ(testObj.configureMessageDumping(""), -1497); } // ============================================================================ diff --git a/src/groups/bmq/bmqa/bmqa_closequeuestatus.t.cpp b/src/groups/bmq/bmqa/bmqa_closequeuestatus.t.cpp index 31222e65b2..3fde374bb3 100644 --- a/src/groups/bmq/bmqa/bmqa_closequeuestatus.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_closequeuestatus.t.cpp @@ -56,10 +56,10 @@ static void test1_breathingTest() PV("Default Constructor"); { bmqa::CloseQueueStatus obj(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj), true); - ASSERT_EQ(obj.result(), bmqt::CloseQueueResult::e_SUCCESS); - ASSERT_EQ(obj.errorDescription(), - bsl::string("", bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(bool(obj), true); + BMQTST_ASSERT_EQ(obj.result(), bmqt::CloseQueueResult::e_SUCCESS); + BMQTST_ASSERT_EQ(obj.errorDescription(), + bsl::string("", bmqtst::TestHelperUtil::allocator())); } PV("Valued Constructor"); @@ -78,10 +78,10 @@ static void test1_breathingTest() errorDescription, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj), false); - ASSERT_EQ(obj.queueId(), queueId); - ASSERT_EQ(obj.result(), statusCode); - ASSERT_EQ(obj.errorDescription(), errorDescription); + BMQTST_ASSERT_EQ(bool(obj), false); + BMQTST_ASSERT_EQ(obj.queueId(), queueId); + BMQTST_ASSERT_EQ(obj.result(), statusCode); + BMQTST_ASSERT_EQ(obj.errorDescription(), errorDescription); } PV("Copy Constructor"); @@ -101,10 +101,10 @@ static void test1_breathingTest() bmqtst::TestHelperUtil::allocator()); bmqa::CloseQueueStatus obj2(obj1, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj1), bool(obj2)); - ASSERT_EQ(obj1.queueId(), obj2.queueId()); - ASSERT_EQ(obj1.result(), obj2.result()); - ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); + BMQTST_ASSERT_EQ(bool(obj1), bool(obj2)); + BMQTST_ASSERT_EQ(obj1.queueId(), obj2.queueId()); + BMQTST_ASSERT_EQ(obj1.result(), obj2.result()); + BMQTST_ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); } PV("Assignment Operator"); @@ -125,10 +125,10 @@ static void test1_breathingTest() bmqa::CloseQueueStatus obj2(bmqtst::TestHelperUtil::allocator()); obj2 = obj1; - ASSERT_EQ(bool(obj1), bool(obj2)); - ASSERT_EQ(obj1.queueId(), obj2.queueId()); - ASSERT_EQ(obj1.result(), obj2.result()); - ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); + BMQTST_ASSERT_EQ(bool(obj1), bool(obj2)); + BMQTST_ASSERT_EQ(obj1.queueId(), obj2.queueId()); + BMQTST_ASSERT_EQ(obj1.result(), obj2.result()); + BMQTST_ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); } } @@ -171,7 +171,7 @@ static void test2_comparison() bmqtst::TestHelperUtil::allocator()); bmqa::CloseQueueStatus obj2(obj1, bmqtst::TestHelperUtil::allocator()); - ASSERT(obj1 == obj2); + BMQTST_ASSERT(obj1 == obj2); } PV("Inequality"); @@ -196,7 +196,7 @@ static void test2_comparison() errorDescription, bmqtst::TestHelperUtil::allocator()); - ASSERT(obj1 != obj2); + BMQTST_ASSERT(obj1 != obj2); } } @@ -252,13 +252,13 @@ static void test3_print() // operator<< out << obj; - ASSERT_EQ(out.str(), expected); + BMQTST_ASSERT_EQ(out.str(), expected); // Print out.reset(); obj.print(out, 0, -1); - ASSERT_EQ(out.str(), expected); + BMQTST_ASSERT_EQ(out.str(), expected); } // ============================================================================ diff --git a/src/groups/bmq/bmqa/bmqa_configurequeuestatus.t.cpp b/src/groups/bmq/bmqa/bmqa_configurequeuestatus.t.cpp index f71925a137..252839e00a 100644 --- a/src/groups/bmq/bmqa/bmqa_configurequeuestatus.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_configurequeuestatus.t.cpp @@ -56,10 +56,10 @@ static void test1_breathingTest() PV("Default Constructor"); { bmqa::ConfigureQueueStatus obj(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj), true); - ASSERT_EQ(obj.result(), bmqt::ConfigureQueueResult::e_SUCCESS); - ASSERT_EQ(obj.errorDescription(), - bsl::string("", bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(bool(obj), true); + BMQTST_ASSERT_EQ(obj.result(), bmqt::ConfigureQueueResult::e_SUCCESS); + BMQTST_ASSERT_EQ(obj.errorDescription(), + bsl::string("", bmqtst::TestHelperUtil::allocator())); } PV("Valued Constructor"); @@ -78,10 +78,10 @@ static void test1_breathingTest() errorDescription, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj), false); - ASSERT_EQ(obj.queueId(), queueId); - ASSERT_EQ(obj.result(), result); - ASSERT_EQ(obj.errorDescription(), errorDescription); + BMQTST_ASSERT_EQ(bool(obj), false); + BMQTST_ASSERT_EQ(obj.queueId(), queueId); + BMQTST_ASSERT_EQ(obj.result(), result); + BMQTST_ASSERT_EQ(obj.errorDescription(), errorDescription); } PV("Copy Constructor"); @@ -102,10 +102,10 @@ static void test1_breathingTest() bmqa::ConfigureQueueStatus obj2(obj1, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj1), bool(obj2)); - ASSERT_EQ(obj1.queueId(), obj2.queueId()); - ASSERT_EQ(obj1.result(), obj2.result()); - ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); + BMQTST_ASSERT_EQ(bool(obj1), bool(obj2)); + BMQTST_ASSERT_EQ(obj1.queueId(), obj2.queueId()); + BMQTST_ASSERT_EQ(obj1.result(), obj2.result()); + BMQTST_ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); } PV("Assignment Operator"); @@ -126,10 +126,10 @@ static void test1_breathingTest() bmqa::ConfigureQueueStatus obj2(bmqtst::TestHelperUtil::allocator()); obj2 = obj1; - ASSERT_EQ(bool(obj1), bool(obj2)); - ASSERT_EQ(obj1.queueId(), obj2.queueId()); - ASSERT_EQ(obj1.result(), obj2.result()); - ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); + BMQTST_ASSERT_EQ(bool(obj1), bool(obj2)); + BMQTST_ASSERT_EQ(obj1.queueId(), obj2.queueId()); + BMQTST_ASSERT_EQ(obj1.result(), obj2.result()); + BMQTST_ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); } } @@ -173,7 +173,7 @@ static void test2_comparison() bmqa::ConfigureQueueStatus obj2(obj1, bmqtst::TestHelperUtil::allocator()); - ASSERT(obj1 == obj2); + BMQTST_ASSERT(obj1 == obj2); } PV("Inequality"); @@ -198,7 +198,7 @@ static void test2_comparison() errorDescription, bmqtst::TestHelperUtil::allocator()); - ASSERT(obj1 != obj2); + BMQTST_ASSERT(obj1 != obj2); } } @@ -254,13 +254,13 @@ static void test3_print() // operator<< out << obj; - ASSERT_EQ(out.str(), expected); + BMQTST_ASSERT_EQ(out.str(), expected); // Print out.reset(); obj.print(out, 0, -1); - ASSERT_EQ(out.str(), expected); + BMQTST_ASSERT_EQ(out.str(), expected); } // ============================================================================ diff --git a/src/groups/bmq/bmqa/bmqa_event.t.cpp b/src/groups/bmq/bmqa/bmqa_event.t.cpp index 2487288d51..c33ff49598 100644 --- a/src/groups/bmq/bmqa/bmqa_event.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_event.t.cpp @@ -72,8 +72,8 @@ static void test1_breathingTest() bmqtst::TestHelperUtil::allocator()); bmqa::Event event = convertEvent(eventImpl); - ASSERT_EQ(event.isSessionEvent(), false); - ASSERT_EQ(event.isMessageEvent(), false); + BMQTST_ASSERT_EQ(event.isSessionEvent(), false); + BMQTST_ASSERT_EQ(event.isMessageEvent(), false); PV("EmptyEvent: " << event); } @@ -91,15 +91,15 @@ static void test1_breathingTest() bmqa::Event event = convertEvent(eventImpl); // Validate type of the event - ASSERT_EQ(event.isSessionEvent(), true); - ASSERT_EQ(event.isMessageEvent(), false); + BMQTST_ASSERT_EQ(event.isSessionEvent(), true); + BMQTST_ASSERT_EQ(event.isMessageEvent(), false); // Validate session event values bmqa::SessionEvent se = event.sessionEvent(); - ASSERT_EQ(se.type(), bmqt::SessionEventType::e_TIMEOUT); - ASSERT_EQ(se.statusCode(), -3); - ASSERT_EQ(se.correlationId(), bmqt::CorrelationId(13)); - ASSERT_EQ(se.errorDescription(), "test"); + BMQTST_ASSERT_EQ(se.type(), bmqt::SessionEventType::e_TIMEOUT); + BMQTST_ASSERT_EQ(se.statusCode(), -3); + BMQTST_ASSERT_EQ(se.correlationId(), bmqt::CorrelationId(13)); + BMQTST_ASSERT_EQ(se.errorDescription(), "test"); PV("Event: " << event); } } diff --git a/src/groups/bmq/bmqa/bmqa_message.t.cpp b/src/groups/bmq/bmqa/bmqa_message.t.cpp index af2ecfb14a..f389e45135 100644 --- a/src/groups/bmq/bmqa/bmqa_message.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_message.t.cpp @@ -109,36 +109,36 @@ static void test1_messageOnStackIsInvalid() bmqa::Message msg; - ASSERT_SAFE_FAIL(msg.queueId()); - ASSERT_SAFE_FAIL(msg.correlationId()); + BMQTST_ASSERT_SAFE_FAIL(msg.queueId()); + BMQTST_ASSERT_SAFE_FAIL(msg.correlationId()); #ifdef BMQ_ENABLE_MSG_GROUPID - ASSERT_SAFE_FAIL(msg.groupId()); + BMQTST_ASSERT_SAFE_FAIL(msg.groupId()); #endif - ASSERT_SAFE_FAIL(msg.messageGUID()); - ASSERT_SAFE_FAIL(msg.confirmationCookie()); - ASSERT_SAFE_FAIL(msg.ackStatus()); - ASSERT_SAFE_FAIL(msg.dataSize()); - ASSERT_SAFE_FAIL(msg.hasProperties()); + BMQTST_ASSERT_SAFE_FAIL(msg.messageGUID()); + BMQTST_ASSERT_SAFE_FAIL(msg.confirmationCookie()); + BMQTST_ASSERT_SAFE_FAIL(msg.ackStatus()); + BMQTST_ASSERT_SAFE_FAIL(msg.dataSize()); + BMQTST_ASSERT_SAFE_FAIL(msg.hasProperties()); #ifdef BMQ_ENABLE_MSG_GROUPID - ASSERT_SAFE_FAIL(msg.hasGroupId()); + BMQTST_ASSERT_SAFE_FAIL(msg.hasGroupId()); #endif PV("Cloned object - uninitialized"); bmqa::Message clone = msg.clone(); - ASSERT_SAFE_FAIL(clone.queueId()); - ASSERT_SAFE_FAIL(clone.correlationId()); + BMQTST_ASSERT_SAFE_FAIL(clone.queueId()); + BMQTST_ASSERT_SAFE_FAIL(clone.correlationId()); #ifdef BMQ_ENABLE_MSG_GROUPID - ASSERT_SAFE_FAIL(clone.groupId()); + BMQTST_ASSERT_SAFE_FAIL(clone.groupId()); #endif - ASSERT_SAFE_FAIL(clone.messageGUID()); - ASSERT_SAFE_FAIL(clone.confirmationCookie()); - ASSERT_SAFE_FAIL(clone.ackStatus()); - ASSERT_SAFE_FAIL(clone.dataSize()); - ASSERT_SAFE_FAIL(clone.hasProperties()); + BMQTST_ASSERT_SAFE_FAIL(clone.messageGUID()); + BMQTST_ASSERT_SAFE_FAIL(clone.confirmationCookie()); + BMQTST_ASSERT_SAFE_FAIL(clone.ackStatus()); + BMQTST_ASSERT_SAFE_FAIL(clone.dataSize()); + BMQTST_ASSERT_SAFE_FAIL(clone.hasProperties()); #ifdef BMQ_ENABLE_MSG_GROUPID - ASSERT_SAFE_FAIL(clone.hasGroupId()); + BMQTST_ASSERT_SAFE_FAIL(clone.hasGroupId()); #endif } @@ -188,26 +188,28 @@ static void test2_validPushMessagePrint() bmqtst::TestHelperUtil::allocator()); bdlbb::Blob payload(&bufferFactory, bmqtst::TestHelperUtil::allocator()); bdlbb::BlobUtil::append(&payload, buffer, bsl::strlen(buffer)); - ASSERT_EQ(static_cast(payload.length()), - bsl::strlen(buffer)); + BMQTST_ASSERT_EQ(static_cast(payload.length()), + bsl::strlen(buffer)); // Create PushEventBuilder bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); - ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.blob()->length())); - ASSERT_EQ(0, peb.messageCount()); + BMQTST_ASSERT_EQ(sizeof(bmqp::EventHeader), + static_cast(peb.eventSize())); + BMQTST_ASSERT_EQ(sizeof(bmqp::EventHeader), + static_cast(peb.blob()->length())); + BMQTST_ASSERT_EQ(0, peb.messageCount()); // Add SubQueueInfo option generateSubQueueInfos(&subQueueInfos, numSubQueueInfos); bmqt::EventBuilderResult::Enum rc = peb.addSubQueueInfosOption( subQueueInfos); - ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); - ASSERT_EQ(sizeof(bmqp::EventHeader), static_cast(peb.eventSize())); + BMQTST_ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); + BMQTST_ASSERT_EQ(sizeof(bmqp::EventHeader), + static_cast(peb.eventSize())); // 'eventSize()' excludes unpacked messages - ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob()->length())); + BMQTST_ASSERT_LT(sizeof(bmqp::EventHeader), + static_cast(peb.blob()->length())); // But the option is written to the underlying blob rc = peb.packMessage(payload, queueId, @@ -215,9 +217,9 @@ static void test2_validPushMessagePrint() flags, bmqt::CompressionAlgorithmType::e_NONE); - ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); - ASSERT_LT(payload.length(), peb.eventSize()); - ASSERT_EQ(1, peb.messageCount()); + BMQTST_ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); + BMQTST_ASSERT_LT(payload.length(), peb.eventSize()); + BMQTST_ASSERT_EQ(1, peb.messageCount()); bmqp::Event bmqpEvent(peb.blob().get(), bmqtst::TestHelperUtil::allocator(), @@ -230,8 +232,8 @@ static void test2_validPushMessagePrint() bmqa::MessageIterator mIter = pushMsgEvt.messageIterator(); mIter.nextMessage(); bmqa::Message message = mIter.message(); - ASSERT_EQ(message.compressionAlgorithmType(), - bmqt::CompressionAlgorithmType::e_NONE); + BMQTST_ASSERT_EQ(message.compressionAlgorithmType(), + bmqt::CompressionAlgorithmType::e_NONE); } static void test3_messageProperties() @@ -294,7 +296,7 @@ static void test3_messageProperties() // Add SubQueueInfo option bmqt::EventBuilderResult::Enum rc = peb.addSubQueueInfosOption( subQueueInfos); - ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); + BMQTST_ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); rc = peb.packMessage(payload, queueId, @@ -303,9 +305,9 @@ static void test3_messageProperties() bmqt::CompressionAlgorithmType::e_NONE, input); - ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); - ASSERT_LT(payload.length(), peb.eventSize()); - ASSERT_EQ(1, peb.messageCount()); + BMQTST_ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); + BMQTST_ASSERT_LT(payload.length(), peb.eventSize()); + BMQTST_ASSERT_EQ(1, peb.messageCount()); bmqa::Event event; bsl::shared_ptr& implPtr = @@ -335,20 +337,20 @@ static void test3_messageProperties() bmqa::Message message = mIter.message(); bmqa::MessageProperties out1(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(0, message.loadProperties(&out1)); + BMQTST_ASSERT_EQ(0, message.loadProperties(&out1)); // 1st setProperty w/o getProperty and then getProperty { bmqa::MessageProperties out2(bmqtst::TestHelperUtil::allocator()); // The second read is/was optimized (only one MPS header) - ASSERT_EQ(0, message.loadProperties(&out2)); + BMQTST_ASSERT_EQ(0, message.loadProperties(&out2)); - ASSERT_EQ(0, out2.setPropertyAsString("y", mod)); - ASSERT_EQ(out1.totalSize() + sizeof(mod) - sizeof(y), - out2.totalSize()); + BMQTST_ASSERT_EQ(0, out2.setPropertyAsString("y", mod)); + BMQTST_ASSERT_EQ(out1.totalSize() + sizeof(mod) - sizeof(y), + out2.totalSize()); - ASSERT_EQ(out2.getPropertyAsString("z"), z); + BMQTST_ASSERT_EQ(out2.getPropertyAsString("z"), z); } // 2nd getProperty, setProperty and then load all @@ -356,10 +358,10 @@ static void test3_messageProperties() bmqa::MessageProperties out3(bmqtst::TestHelperUtil::allocator()); // The third read is/was optimized (only one MPS header) - ASSERT_EQ(0, message.loadProperties(&out3)); + BMQTST_ASSERT_EQ(0, message.loadProperties(&out3)); - ASSERT_EQ(y, out3.getPropertyAsString("y")); - ASSERT_EQ(0, out3.setPropertyAsString("y", mod)); + BMQTST_ASSERT_EQ(y, out3.getPropertyAsString("y")); + BMQTST_ASSERT_EQ(0, out3.setPropertyAsString("y", mod)); bmqu::MemOutStream os(bmqtst::TestHelperUtil::allocator()); out3.print(os, 0, -1); @@ -368,12 +370,12 @@ static void test3_messageProperties() bmqa::MessagePropertiesIterator it(&out3); - ASSERT(it.hasNext()); - ASSERT_EQ(it.getAsString(), x); - ASSERT(it.hasNext()); - ASSERT_EQ(it.getAsString(), mod); - ASSERT(it.hasNext()); - ASSERT_EQ(it.getAsString(), z); + BMQTST_ASSERT(it.hasNext()); + BMQTST_ASSERT_EQ(it.getAsString(), x); + BMQTST_ASSERT(it.hasNext()); + BMQTST_ASSERT_EQ(it.getAsString(), mod); + BMQTST_ASSERT(it.hasNext()); + BMQTST_ASSERT_EQ(it.getAsString(), z); } // 3rd getProperty, setProperty and then getProperty @@ -381,14 +383,14 @@ static void test3_messageProperties() bmqa::MessageProperties out4(bmqtst::TestHelperUtil::allocator()); // The fourth read is/was optimized (only one MPS header) - ASSERT_EQ(0, message.loadProperties(&out4)); + BMQTST_ASSERT_EQ(0, message.loadProperties(&out4)); - ASSERT_EQ(y, out4.getPropertyAsString("y")); - ASSERT_EQ(0, out4.setPropertyAsString("y", mod)); - ASSERT_EQ(out1.totalSize() + sizeof(mod) - sizeof(y), - out4.totalSize()); + BMQTST_ASSERT_EQ(y, out4.getPropertyAsString("y")); + BMQTST_ASSERT_EQ(0, out4.setPropertyAsString("y", mod)); + BMQTST_ASSERT_EQ(out1.totalSize() + sizeof(mod) - sizeof(y), + out4.totalSize()); - ASSERT_EQ(out4.getPropertyAsString("z"), z); + BMQTST_ASSERT_EQ(out4.getPropertyAsString("z"), z); } } @@ -439,8 +441,8 @@ static void test4_subscriptionHandle() queueSp->setId(queueId); bdlbb::BlobUtil::append(&payload, buffer, bsl::strlen(buffer)); - ASSERT_EQ(static_cast(payload.length()), - bsl::strlen(buffer)); + BMQTST_ASSERT_EQ(static_cast(payload.length()), + bsl::strlen(buffer)); PV("PUSH MESSAGE - SUBSCRIPTION") { @@ -459,19 +461,19 @@ static void test4_subscriptionHandle() // Create PushEventBuilder bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(0, peb.messageCount()); + BMQTST_ASSERT_EQ(0, peb.messageCount()); // Add SubQueueInfo option (subscription Id) subQueueInfos.push_back(bmqp::SubQueueInfo(sId)); bmqt::EventBuilderResult::Enum rc = peb.addSubQueueInfosOption( subQueueInfos); - ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); - ASSERT_EQ(sizeof(bmqp::EventHeader), - static_cast(peb.eventSize())); + BMQTST_ASSERT_EQ(bmqt::EventBuilderResult::e_SUCCESS, rc); + BMQTST_ASSERT_EQ(sizeof(bmqp::EventHeader), + static_cast(peb.eventSize())); // 'eventSize()' excludes unpacked messages - ASSERT_LT(sizeof(bmqp::EventHeader), - static_cast(peb.blob()->length())); + BMQTST_ASSERT_LT(sizeof(bmqp::EventHeader), + static_cast(peb.blob()->length())); // But the option is written to the underlying blob // Add message @@ -481,9 +483,9 @@ static void test4_subscriptionHandle() flags, bmqt::CompressionAlgorithmType::e_NONE); - ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); - ASSERT_LT(payload.length(), peb.eventSize()); - ASSERT_EQ(1, peb.messageCount()); + BMQTST_ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); + BMQTST_ASSERT_LT(payload.length(), peb.eventSize()); + BMQTST_ASSERT_EQ(1, peb.messageCount()); bmqp::Event bmqpEvent(peb.blob().get(), bmqtst::TestHelperUtil::allocator(), @@ -496,15 +498,16 @@ static void test4_subscriptionHandle() bmqa::MessageEvent pushMsgEvt = event.messageEvent(); bmqa::MessageIterator mIter = pushMsgEvt.messageIterator(); - ASSERT(mIter.nextMessage()); + BMQTST_ASSERT(mIter.nextMessage()); bmqa::Message message = mIter.message(); PVVV("Message: " << message); const bmqt::SubscriptionHandle& actualHandle = message.subscriptionHandle(); PVV("Non-empty subscription handle: " << actualHandle); - ASSERT_EQ(actualHandle.id(), sId); - ASSERT_EQ(actualHandle.correlationId(), sHandle.correlationId()); + BMQTST_ASSERT_EQ(actualHandle.id(), sId); + BMQTST_ASSERT_EQ(actualHandle.correlationId(), + sHandle.correlationId()); } PV("PUSH MESSAGE - NO SUBSCRIPTION") @@ -524,7 +527,7 @@ static void test4_subscriptionHandle() // Create PushEventBuilder bmqp::PushEventBuilder peb(&blobSpPool, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(0, peb.messageCount()); + BMQTST_ASSERT_EQ(0, peb.messageCount()); // Add message bmqt::EventBuilderResult::Enum rc = peb.packMessage( @@ -534,9 +537,9 @@ static void test4_subscriptionHandle() flags, bmqt::CompressionAlgorithmType::e_NONE); - ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); - ASSERT_LT(payload.length(), peb.eventSize()); - ASSERT_EQ(1, peb.messageCount()); + BMQTST_ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); + BMQTST_ASSERT_LT(payload.length(), peb.eventSize()); + BMQTST_ASSERT_EQ(1, peb.messageCount()); bmqp::Event bmqpEvent(peb.blob().get(), bmqtst::TestHelperUtil::allocator(), @@ -549,15 +552,15 @@ static void test4_subscriptionHandle() bmqa::MessageEvent pushMsgEvt = event.messageEvent(); bmqa::MessageIterator mIter = pushMsgEvt.messageIterator(); - ASSERT(mIter.nextMessage()); + BMQTST_ASSERT(mIter.nextMessage()); bmqa::Message message = mIter.message(); PVVV("Message: " << message); const bmqt::SubscriptionHandle& actualHandle = message.subscriptionHandle(); PVV("Empty subscription handle: " << actualHandle); - ASSERT_EQ(actualHandle.id(), defaultSubscriptionId); - ASSERT_EQ(actualHandle.correlationId(), emptyCorrelationId); + BMQTST_ASSERT_EQ(actualHandle.id(), defaultSubscriptionId); + BMQTST_ASSERT_EQ(actualHandle.correlationId(), emptyCorrelationId); } PV("PUT MESSAGE - FAIL") @@ -572,7 +575,7 @@ static void test4_subscriptionHandle() // Create PutEventBuilder bmqp::PutEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(0, builder.messageCount()); + BMQTST_ASSERT_EQ(0, builder.messageCount()); // Add message builder.startMessage(); @@ -581,8 +584,8 @@ static void test4_subscriptionHandle() bmqt::EventBuilderResult::Enum rc = builder.packMessage(queueId); - ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); - ASSERT_EQ(1, builder.messageCount()); + BMQTST_ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); + BMQTST_ASSERT_EQ(1, builder.messageCount()); bmqp::Event bmqpEvent(builder.blob().get(), bmqtst::TestHelperUtil::allocator()); @@ -594,11 +597,11 @@ static void test4_subscriptionHandle() bmqa::MessageEvent putMsgEvt = event.messageEvent(); bmqa::MessageIterator mIter = putMsgEvt.messageIterator(); - ASSERT(mIter.nextMessage()); + BMQTST_ASSERT(mIter.nextMessage()); bmqa::Message message = mIter.message(); PVVV("Message: " << message); - ASSERT_OPT_FAIL(message.subscriptionHandle()); + BMQTST_ASSERT_OPT_FAIL(message.subscriptionHandle()); } PV("ACK MESSAGE - FAIL") @@ -613,13 +616,13 @@ static void test4_subscriptionHandle() // Create AckEventBuilder bmqp::AckEventBuilder builder(&blobSpPool, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(0, builder.messageCount()); + BMQTST_ASSERT_EQ(0, builder.messageCount()); bmqt::EventBuilderResult::Enum rc = builder.appendMessage(0, queueId, guid, queueId); - ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); - ASSERT_EQ(1, builder.messageCount()); + BMQTST_ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); + BMQTST_ASSERT_EQ(1, builder.messageCount()); bmqp::Event bmqpEvent(builder.blob().get(), bmqtst::TestHelperUtil::allocator()); @@ -631,11 +634,11 @@ static void test4_subscriptionHandle() bmqa::MessageEvent ackMsgEvt = event.messageEvent(); bmqa::MessageIterator mIter = ackMsgEvt.messageIterator(); - ASSERT(mIter.nextMessage()); + BMQTST_ASSERT(mIter.nextMessage()); bmqa::Message message = mIter.message(); PVVV("Message: " << message); - ASSERT_OPT_FAIL(message.subscriptionHandle()); + BMQTST_ASSERT_OPT_FAIL(message.subscriptionHandle()); } } diff --git a/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp b/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp index 54d29d2a16..17dd6834ca 100644 --- a/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_messageevent.t.cpp @@ -81,7 +81,7 @@ static void appendMessages(bmqp::AckEventBuilder* builder, data.d_corrId, data.d_guid, data.d_queueId); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); vec->push_back(data); } } @@ -205,13 +205,13 @@ static void test2_ackMesageIteratorTest() while (i.nextMessage()) { const bmqa::Message* msg = &(i.message()); - ASSERT_EQ(msg->correlationId(), - bmqt::CorrelationId(messages[offset].d_corrId)); - ASSERT_EQ(msg->messageGUID(), messages[offset].d_guid); + BMQTST_ASSERT_EQ(msg->correlationId(), + bmqt::CorrelationId(messages[offset].d_corrId)); + BMQTST_ASSERT_EQ(msg->messageGUID(), messages[offset].d_guid); ++offset; } - ASSERT_EQ(offset, k_NUM_MSGS); + BMQTST_ASSERT_EQ(offset, k_NUM_MSGS); } } @@ -250,7 +250,7 @@ static void test3_putMessageIteratorTest() &messages, &bufferFactory, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); + BMQTST_ASSERT_EQ(rc, bmqt::EventBuilderResult::e_SUCCESS); } bmqp::Event rawEvent(builder.blob().get(), @@ -281,17 +281,19 @@ static void test3_putMessageIteratorTest() while (i.nextMessage()) { const bmqa::Message* msg = &(i.message()); - ASSERT_EQ(msg->correlationId(), bmqt::CorrelationId(offset)); + BMQTST_ASSERT_EQ(msg->correlationId(), + bmqt::CorrelationId(offset)); bdlbb::Blob payload(&bufferFactory, bmqtst::TestHelperUtil::allocator()); int rc = msg->getData(&payload); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); // Content isn't the same. Length is. Why? - ASSERT(payload.length() == messages[offset].d_payload.length()); + BMQTST_ASSERT(payload.length() == + messages[offset].d_payload.length()); ++offset; } - ASSERT_EQ(offset, k_NUM_MSGS); + BMQTST_ASSERT_EQ(offset, k_NUM_MSGS); } } diff --git a/src/groups/bmq/bmqa/bmqa_messageeventbuilder.t.cpp b/src/groups/bmq/bmqa/bmqa_messageeventbuilder.t.cpp index 659d633b63..a19ff2ca9d 100644 --- a/src/groups/bmq/bmqa/bmqa_messageeventbuilder.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_messageeventbuilder.t.cpp @@ -62,7 +62,7 @@ static void test2_testMessageEventSizeCount() // Start session BMQA_EXPECT_CALL(session, start()).returning(0); const int rc = session.start(); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); } bmqt::Uri uri(bmqtst::TestHelperUtil::allocator()); @@ -73,7 +73,7 @@ static void test2_testMessageEventSizeCount() bsl::string input("bmq://my.domain/queue", bmqtst::TestHelperUtil::allocator()); const int rc = bmqt::UriParser::parse(&uri, &error, input); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); } bmqt::CorrelationId queueCId = bmqt::CorrelationId::autoValue(); @@ -87,7 +87,7 @@ static void test2_testMessageEventSizeCount() const int rc = session.openQueue(&queueId, uri, bmqt::QueueFlags::e_WRITE); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); } // Stage 2: populate MessageEventBuilder @@ -95,8 +95,8 @@ static void test2_testMessageEventSizeCount() session.loadMessageEventBuilder(&builder); // Empty MessageEvent should contain at least its header - ASSERT(builder.messageEventSize() > 0); - ASSERT_EQ(0, builder.messageCount()); + BMQTST_ASSERT(builder.messageEventSize() > 0); + BMQTST_ASSERT_EQ(0, builder.messageCount()); const bsl::string payload("test payload", bmqtst::TestHelperUtil::allocator()); @@ -112,16 +112,16 @@ static void test2_testMessageEventSizeCount() // Make sure that 'messageEventSize' and 'messageCount' remain the same // before packing the message - ASSERT_EQ(messageEventSizeBefore, builder.messageEventSize()); - ASSERT_EQ(messageCountBefore, builder.messageCount()); + BMQTST_ASSERT_EQ(messageEventSizeBefore, builder.messageEventSize()); + BMQTST_ASSERT_EQ(messageCountBefore, builder.messageCount()); builder.packMessage(queueId); // Make sure that 'messageEventSize' and 'messageCount' increase // after packing the message - ASSERT_LT(messageEventSizeBefore, builder.messageEventSize()); - ASSERT_LT(messageCountBefore, builder.messageCount()); - ASSERT_EQ(i, builder.messageCount()); + BMQTST_ASSERT_LT(messageEventSizeBefore, builder.messageEventSize()); + BMQTST_ASSERT_LT(messageCountBefore, builder.messageCount()); + BMQTST_ASSERT_EQ(i, builder.messageCount()); } // Stage 3: start a new message but do not pack @@ -137,8 +137,8 @@ static void test2_testMessageEventSizeCount() // Make sure that 'messageEventSize' and 'messageCount' remain the same // since we do not pack the last started message - ASSERT_EQ(messageEventSizeFinal, builder.messageEventSize()); - ASSERT_EQ(messageCountFinal, builder.messageCount()); + BMQTST_ASSERT_EQ(messageEventSizeFinal, builder.messageEventSize()); + BMQTST_ASSERT_EQ(messageCountFinal, builder.messageCount()); // Stage 4: build MessageEvent // MessageEventBuilder switches from WRITE mode to READ: @@ -148,8 +148,8 @@ static void test2_testMessageEventSizeCount() } // We had non-packed Message before, make sure it was not added to the blob - ASSERT_EQ(messageEventSizeFinal, builder.messageEventSize()); - ASSERT_EQ(messageCountFinal, builder.messageCount()); + BMQTST_ASSERT_EQ(messageEventSizeFinal, builder.messageEventSize()); + BMQTST_ASSERT_EQ(messageCountFinal, builder.messageCount()); // Stage 5: reset MessageEventBuilder // MessageEventBuilder switches from READ mode to WRITE: @@ -157,8 +157,8 @@ static void test2_testMessageEventSizeCount() // Since we resetted the MessageEventBuilder, the currently built message // event is smaller than the populated one from the previous steps - ASSERT_LT(builder.messageEventSize(), messageEventSizeFinal); - ASSERT_EQ(0, builder.messageCount()); + BMQTST_ASSERT_LT(builder.messageEventSize(), messageEventSizeFinal); + BMQTST_ASSERT_EQ(0, builder.messageCount()); } // ============================================================================ diff --git a/src/groups/bmq/bmqa/bmqa_mocksession.h b/src/groups/bmq/bmqa/bmqa_mocksession.h index 04914df336..cd7672f09b 100644 --- a/src/groups/bmq/bmqa/bmqa_mocksession.h +++ b/src/groups/bmq/bmqa/bmqa_mocksession.h @@ -243,19 +243,20 @@ /// /// // Make a call to startAsync and emit the event that is enqueued from /// // that call. -/// ASSERT_EQ(mockSession.startAsync(), 0); +/// BMQTST_ASSERT_EQ(mockSession.startAsync(), 0); /// /// // Emit our enqueued event. This fully sets up the session which is /// // now ready to use. Typically you would have some business logic on /// // 'e_CONNECTED' that makes your application ready to use. -/// ASSERT_EQ(mockSession.emitEvent(), true); +/// BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); /// /// // Our event handler internally just stores the event emitted, so pop /// // it out and examine. /// bmqa::SessionEvent startEvent(eventHandler.popSessionEvent()); /// -/// ASSERT_EQ(startEvent.type(), bmqt::SessionEventType::e_CONNECTED); -/// ASSERT_EQ(startEvent.status Code(), 0); +/// BMQTST_ASSERT_EQ(startEvent.type(), +/// bmqt::SessionEventType::e_CONNECTED); +/// BMQTST_ASSERT_EQ(startEvent.status Code(), 0); /// /// // Create the uri to your queue as you would in your application. /// const bmqt::Uri uri("bmq://my.domain/queue"); @@ -299,11 +300,11 @@ /// /// // We just enqueued a 'bmqa::OpenQueueStatus' to be emitted. We can /// // emit it using 'emitEvent'. -/// ASSERT_EQ(mockSession.emitEvent(), true); +/// BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); /// /// // Pop out this event from the handler and examine it. /// bmqa::OpenQueueStatus result = eventHandler.popOpenQueueStatus(); -/// ASSERT_EQ(result, openQueueResult); +/// BMQTST_ASSERT_EQ(result, openQueueResult); /// /// // On emission of 'bmqa::OpenQueueStatus', the queue is fully open and /// // we can now post to it. @@ -319,7 +320,7 @@ /// // been elided for brevity. /// /// // Now that the event has been built we can 'post' it to BMQ. -/// ASSERT_EQ(mockSession.post(builder.messageEvent()), 0); +/// BMQTST_ASSERT_EQ(mockSession.post(builder.messageEvent()), 0); /// /// // Simply creating a blob buffer factory on the stack to be used by /// // 'createAckEvent'. Typically you would have one for the component. @@ -344,14 +345,15 @@ /// allocator)); /// /// // Emit the enqueued ack event. -/// ASSERT_EQ(mockSession.emitEvent(), true); +/// BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); /// /// // As we did earlier, pop it out and examine. /// bmqa::MessageEvent ackEvent(eventHandler.popMessageEvent()); -/// ASSERT_EQ(ackEvent.type(), bmqt::MessageEventType::e_ACK); +/// BMQTST_ASSERT_EQ(ackEvent.type(), bmqt::MessageEventType::e_ACK); /// bmqa::MessageIterator mIter = ackEvent.messageIterator(); /// mIter.nextMessage(); -/// ASSERT_EQ(mIter.message().ackStatus(), bmqt::AckResult::e_SUCCESS); +/// BMQTST_ASSERT_EQ(mIter.message().ackStatus(), +/// bmqt::AckResult::e_SUCCESS); /// /// // This is a simple test. After posting our message and receiving the /// // ack, we are now shutting down our application. Therefore we expect @@ -367,14 +369,15 @@ /// bmqt::SessionEventType::e_DISCONNECTED, /// 0, // statusCode /// "", // errorDescription -/// allocator)); -/// ASSERT_EQ(mockSession.emitEvent(), true); +/// d_allocator_p)); +/// BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); /// /// // Our event handler internally just stores the event emitted, so pop /// // it out and examine. /// bmqa::SessionEvent stopEvent(eventHandler.popSessionEvent()); -/// ASSERT_EQ(stopEvent.type(), bmqt::SessionEventType::e_DISCONNECTED); -/// ASSERT_EQ(stopEvent.statusCode(), 0); +/// BMQTST_ASSERT_EQ(stopEvent.type(), +/// bmqt::SessionEventType::e_DISCONNECTED); +/// BMQTST_ASSERT_EQ(stopEvent.statusCode(), 0); /// /// // The corresponding pendant operation of the 'initialize' which would /// // need to be called only if 'initialize' was explicitly called. @@ -492,30 +495,31 @@ /// // 'startAsync' is the first call. We expect it to return 0 and we /// // expect 'nextEvent' to return the 'e_CONNECTED' session event. /// int rc = mockSession.startAsync(); -/// ASSERT_EQ(rc, 0); +/// BMQTST_ASSERT_EQ(rc, 0); /// bmqa::SessionEvent startEvent = mockSession.nextEvent( /// bsls::TimeInterval()) /// .sessionEvent(); -/// ASSERT_EQ(startEvent.type(), bmqt::SessionEventType::e_CONNECTED); -/// ASSERT_EQ(startEvent.statusCode(), 0); -/// ASSERT_EQ(startEvent.errorDescription(), ""); +/// BMQTST_ASSERT_EQ(startEvent.type(), +/// bmqt::SessionEventType::e_CONNECTED); +/// BMQTST_ASSERT_EQ(startEvent.statusCode(), 0); +/// BMQTST_ASSERT_EQ(startEvent.errorDescription(), ""); /// /// // Next we expect a call to 'openQueue' to open the queue. /// bmqa::OpenQueueStatus result = mockSession.openQueueSync(&queueId, /// uri, /// flags); -/// ASSERT_EQ(result, expectedResult); +/// BMQTST_ASSERT_EQ(result, expectedResult); /// /// // Now our call to 'nextEvent' will generate a push message from the /// // broker, which we will then go on to confirm. /// bmqa::MessageEvent pushMsgEvt(mockSession.nextEvent( /// bsls::TimeInterval()) /// .messageEvent()); -/// ASSERT_EQ(pushMsgEvt.type(), bmqt::MessageEventType::e_PUSH); +/// BMQTST_ASSERT_EQ(pushMsgEvt.type(), bmqt::MessageEventType::e_PUSH); /// /// // Now that we have received a push message which has yet to be /// // confirmed, we can confirm that 1 unconfirmed message exists. -/// ASSERT_EQ(mockSession.unconfirmedMessages(), 1U); +/// BMQTST_ASSERT_EQ(mockSession.unconfirmedMessages(), 1U); /// /// // Since there is only 1 message in our message event, we dont have to /// // iterate over the event but in reality you will want to iterate over @@ -523,14 +527,14 @@ /// bmqa::MessageIterator mIter = pushMsgEvt.messageIterator(); /// mIter.nextMessage(); /// confirmBuilder.addMessageConfirmation(mIter.message()); -/// ASSERT_EQ(confirmBuilder.messageCount(), 1); +/// BMQTST_ASSERT_EQ(confirmBuilder.messageCount(), 1); /// /// // Confirm the messages using the builder that has been populated. /// rc = mockSession.confirmMessages(&confirmBuilder); -/// ASSERT_EQ(rc, 0); +/// BMQTST_ASSERT_EQ(rc, 0); /// /// // Voila! We now have no unconfirmed messages. -/// ASSERT_EQ(mockSession.unconfirmedMessages(), 0u); +/// BMQTST_ASSERT_EQ(mockSession.unconfirmedMessages(), 0u); /// // 'stop' has been elided for brevity and is analogous to 'start' /// /// // The corresponding pendant operation of the 'initialize' which would diff --git a/src/groups/bmq/bmqa/bmqa_mocksession.t.cpp b/src/groups/bmq/bmqa/bmqa_mocksession.t.cpp index 7e25c03a2b..30472c2b78 100644 --- a/src/groups/bmq/bmqa/bmqa_mocksession.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_mocksession.t.cpp @@ -281,16 +281,17 @@ static void test1_staticMethods() bmqtst::TestHelperUtil::allocator()); bmqa::SessionEvent sessionEvent = event.sessionEvent(); - ASSERT_EQ(sessionEvent.type(), bmqt::SessionEventType::e_CONNECTED); - ASSERT_EQ(sessionEvent.statusCode(), 0); - ASSERT_EQ(sessionEvent.errorDescription(), errorDescription); - ASSERT_EQ(sessionEvent.correlationId(), bmqt::CorrelationId(1)); + BMQTST_ASSERT_EQ(sessionEvent.type(), + bmqt::SessionEventType::e_CONNECTED); + BMQTST_ASSERT_EQ(sessionEvent.statusCode(), 0); + BMQTST_ASSERT_EQ(sessionEvent.errorDescription(), errorDescription); + BMQTST_ASSERT_EQ(sessionEvent.correlationId(), bmqt::CorrelationId(1)); } { PVV("Create Queue Session Event using Session Event Method"); - ASSERT_FAIL(bmqa::MockSessionUtil::createSessionEvent( + BMQTST_ASSERT_FAIL(bmqa::MockSessionUtil::createSessionEvent( bmqt::SessionEventType::e_QUEUE_OPEN_RESULT, bmqt::CorrelationId(1), 0, @@ -319,13 +320,14 @@ static void test1_staticMethods() bmqtst::TestHelperUtil::allocator()); bmqa::MessageEvent ackEvent = event.messageEvent(); - ASSERT_EQ(ackEvent.type(), bmqt::MessageEventType::e_ACK); + BMQTST_ASSERT_EQ(ackEvent.type(), bmqt::MessageEventType::e_ACK); bmqa::MessageIterator mIter = ackEvent.messageIterator(); mIter.nextMessage(); - ASSERT_EQ(mIter.message().ackStatus(), bmqt::AckResult::e_SUCCESS); - ASSERT_EQ(mIter.message().queueId(), queueId); - ASSERT_EQ(mIter.message().correlationId(), corrId); + BMQTST_ASSERT_EQ(mIter.message().ackStatus(), + bmqt::AckResult::e_SUCCESS); + BMQTST_ASSERT_EQ(mIter.message().queueId(), queueId); + BMQTST_ASSERT_EQ(mIter.message().correlationId(), corrId); } { @@ -344,11 +346,11 @@ static void test1_staticMethods() bmqtst::TestHelperUtil::allocator()); bmqa::SessionEvent openQueueEvent = event.sessionEvent(); - ASSERT_EQ(openQueueEvent.type(), - bmqt::SessionEventType::e_QUEUE_OPEN_RESULT); - ASSERT_EQ(openQueueEvent.statusCode(), 0); - ASSERT_EQ(openQueueEvent.errorDescription(), ""); - ASSERT_EQ(openQueueEvent.correlationId(), corrId); + BMQTST_ASSERT_EQ(openQueueEvent.type(), + bmqt::SessionEventType::e_QUEUE_OPEN_RESULT); + BMQTST_ASSERT_EQ(openQueueEvent.statusCode(), 0); + BMQTST_ASSERT_EQ(openQueueEvent.errorDescription(), ""); + BMQTST_ASSERT_EQ(openQueueEvent.correlationId(), corrId); } { @@ -378,20 +380,20 @@ static void test1_staticMethods() bmqa::MessageEvent pushMsgEvt = event.messageEvent(); - ASSERT_EQ(pushMsgEvt.type(), bmqt::MessageEventType::e_PUSH); + BMQTST_ASSERT_EQ(pushMsgEvt.type(), bmqt::MessageEventType::e_PUSH); bmqa::MessageIterator mIter = pushMsgEvt.messageIterator(); mIter.nextMessage(); - ASSERT_EQ(mIter.message().queueId(), queueId); - ASSERT_EQ(mIter.message().messageGUID(), guid); - ASSERT_EQ(mIter.message().dataSize(), 6); + BMQTST_ASSERT_EQ(mIter.message().queueId(), queueId); + BMQTST_ASSERT_EQ(mIter.message().messageGUID(), guid); + BMQTST_ASSERT_EQ(mIter.message().dataSize(), 6); bmqa::MessageProperties out; - ASSERT_EQ(mIter.message().loadProperties(&out), 0); + BMQTST_ASSERT_EQ(mIter.message().loadProperties(&out), 0); - ASSERT_EQ(out.totalSize(), properties.totalSize()); - ASSERT_EQ(out.getPropertyAsInt32("x"), - properties.getPropertyAsInt32("x")); + BMQTST_ASSERT_EQ(out.totalSize(), properties.totalSize()); + BMQTST_ASSERT_EQ(out.getPropertyAsInt32("x"), + properties.getPropertyAsInt32("x")); } bmqp::ProtocolUtil::shutdown(); @@ -413,22 +415,22 @@ static void test2_call() { PVV("Incorrect call"); BMQA_EXPECT_CALL(mockSession, start()).returning(0); - ASSERT_FAIL(mockSession.stop()); - ASSERT_EQ(mockSession.start(), 0); + BMQTST_ASSERT_FAIL(mockSession.stop()); + BMQTST_ASSERT_EQ(mockSession.start(), 0); } { PVV("Empty expected call queue"); - ASSERT_FAIL(mockSession.startAsync()); + BMQTST_ASSERT_FAIL(mockSession.startAsync()); } { PVV("Incorrect arguments"); BMQA_EXPECT_CALL(mockSession, startAsync(bsls::TimeInterval(10))) .returning(0); - ASSERT_FAIL(mockSession.startAsync(bsls::TimeInterval(1))); + BMQTST_ASSERT_FAIL(mockSession.startAsync(bsls::TimeInterval(1))); // To clear the expected queue. - ASSERT_EQ(mockSession.startAsync(bsls::TimeInterval(10)), 0); + BMQTST_ASSERT_EQ(mockSession.startAsync(bsls::TimeInterval(10)), 0); } { @@ -452,7 +454,7 @@ static void test2_call() mockSession_sp.clear(); // Our mockSession reference is also invalid at this point. - ASSERT_EQ(eventHandler.d_assertsInvoked, 1u); + BMQTST_ASSERT_EQ(eventHandler.d_assertsInvoked, 1u); } } @@ -526,21 +528,22 @@ static void test3_queueManagement() typedef bsl::shared_ptr& QueueImplPtr; QueueImplPtr implPtr = reinterpret_cast(queueId1); - ASSERT_EQ(implPtr->uri(), uri1); - ASSERT_EQ(implPtr->correlationId(), corrId1); + BMQTST_ASSERT_EQ(implPtr->uri(), uri1); + BMQTST_ASSERT_EQ(implPtr->correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENING_OPN); + BMQTST_ASSERT_EQ(implPtr->state(), + bmqimp::QueueState::e_OPENING_OPN); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); bmqa::OpenQueueStatus result = eventHandler.popResult(); - ASSERT_EQ(result.queueId(), openQueueResult.queueId()); - ASSERT_EQ(result.result(), openQueueResult.result()); - ASSERT_EQ(result.errorDescription(), - openQueueResult.errorDescription()); + BMQTST_ASSERT_EQ(result.queueId(), openQueueResult.queueId()); + BMQTST_ASSERT_EQ(result.result(), openQueueResult.result()); + BMQTST_ASSERT_EQ(result.errorDescription(), + openQueueResult.errorDescription()); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_CLOSED); + BMQTST_ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_CLOSED); } { @@ -564,21 +567,22 @@ static void test3_queueManagement() typedef bsl::shared_ptr& QueueImplPtr; QueueImplPtr implPtr = reinterpret_cast(queueId1); - ASSERT_EQ(implPtr->uri(), uri1); - ASSERT_EQ(implPtr->correlationId(), corrId1); + BMQTST_ASSERT_EQ(implPtr->uri(), uri1); + BMQTST_ASSERT_EQ(implPtr->correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENING_OPN); + BMQTST_ASSERT_EQ(implPtr->state(), + bmqimp::QueueState::e_OPENING_OPN); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); bmqa::OpenQueueStatus result = eventHandler.popResult(); - ASSERT_EQ(result.result(), 0); - ASSERT_EQ(result.errorDescription(), ""); - ASSERT_EQ(result.queueId().correlationId(), corrId1); + BMQTST_ASSERT_EQ(result.result(), 0); + BMQTST_ASSERT_EQ(result.errorDescription(), ""); + BMQTST_ASSERT_EQ(result.queueId().correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENED); + BMQTST_ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENED); } } @@ -589,22 +593,24 @@ static void test3_queueManagement() { PVVV("Valid queue by uri"); bmqa::QueueId queueIdFound(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), 0); - ASSERT_EQ(queueIdFound, queueId1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), 0); + BMQTST_ASSERT_EQ(queueIdFound, queueId1); } { PVVV("Valid queue by uri"); bmqa::QueueId queueIdFound(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId1), 0); - ASSERT_EQ(queueIdFound, queueId1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId1), + 0); + BMQTST_ASSERT_EQ(queueIdFound, queueId1); } { PVVV("Registered but unused queue"); bmqa::QueueId queueIdFound(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri2), -1); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId2), -1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri2), -1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId2), + -1); } { @@ -620,14 +626,16 @@ static void test3_queueManagement() // Close queue and then attempt to get queue BMQA_EXPECT_CALL(mockSession, closeQueueSync(&queueId1)) .returning(closeResult1); - ASSERT_EQ(mockSession.closeQueueSync(&queueId1), closeResult1); - ASSERT_EQ(closeResult1.queueId(), queueId1); - ASSERT_EQ(closeResult1.result(), - bmqt::CloseQueueResult::e_SUCCESS); + BMQTST_ASSERT_EQ(mockSession.closeQueueSync(&queueId1), + closeResult1); + BMQTST_ASSERT_EQ(closeResult1.queueId(), queueId1); + BMQTST_ASSERT_EQ(closeResult1.result(), + bmqt::CloseQueueResult::e_SUCCESS); bmqa::QueueId queueIdFound(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), -1); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId1), -1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), -1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId1), + -1); // Close queue successfully and then attempt to get queue bmqa::CloseQueueStatus closeResult2 = @@ -639,10 +647,12 @@ static void test3_queueManagement() BMQA_EXPECT_CALL(mockSession, closeQueueSync(&queueId1)) .returning(closeResult2); - ASSERT_EQ(mockSession.closeQueueSync(&queueId1), closeResult2); + BMQTST_ASSERT_EQ(mockSession.closeQueueSync(&queueId1), + closeResult2); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), -1); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId1), -1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), -1); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, corrId1), + -1); } } @@ -672,23 +682,23 @@ static void test3_queueManagement() openQueueSync(&queueId1, uri1, bmqt::QueueFlags::e_READ)) .returning(testOpenQueueResult); - ASSERT_EQ(mockSession.openQueueSync(&queueId1, - uri1, - bmqt::QueueFlags::e_READ), - testOpenQueueResult); + BMQTST_ASSERT_EQ(mockSession.openQueueSync(&queueId1, + uri1, + bmqt::QueueFlags::e_READ), + testOpenQueueResult); typedef bsl::shared_ptr& QueueImplPtr; QueueImplPtr implPtr = reinterpret_cast(queueId1); - ASSERT_EQ(implPtr->uri(), uri1); - ASSERT_EQ(implPtr->correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENED); + BMQTST_ASSERT_EQ(implPtr->uri(), uri1); + BMQTST_ASSERT_EQ(implPtr->correlationId(), corrId1); + BMQTST_ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENED); bmqa::QueueId queueIdFound(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), 0); + BMQTST_ASSERT_EQ(mockSession.getQueueId(&queueIdFound, uri1), 0); - ASSERT(queueId1 == queueIdFound); - ASSERT_NE(queueId1, savedQueueId); + BMQTST_ASSERT(queueId1 == queueIdFound); + BMQTST_ASSERT_NE(queueId1, savedQueueId); bmqa::CloseQueueStatus closeResult1 = bmqa::MockSessionUtil::createCloseQueueStatus( @@ -700,7 +710,7 @@ static void test3_queueManagement() // Close queue and then attempt to get queue BMQA_EXPECT_CALL(mockSession, closeQueueSync(&queueId1)) .returning(closeResult1); - ASSERT_EQ(mockSession.closeQueueSync(&queueId1), closeResult1); + BMQTST_ASSERT_EQ(mockSession.closeQueueSync(&queueId1), closeResult1); } } @@ -742,24 +752,24 @@ static void test4_queueManagementSync() "", bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(mockSession.openQueueAsync(&queueId1, uri1, 10), 0); + BMQTST_ASSERT_EQ(mockSession.openQueueAsync(&queueId1, uri1, 10), 0); typedef bsl::shared_ptr& QueueImplPtr; QueueImplPtr implPtr = reinterpret_cast(queueId1); - ASSERT_EQ(implPtr->uri(), uri1); - ASSERT_EQ(implPtr->correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENING_OPN); + BMQTST_ASSERT_EQ(implPtr->uri(), uri1); + BMQTST_ASSERT_EQ(implPtr->correlationId(), corrId1); + BMQTST_ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENING_OPN); bmqa::SessionEvent openQueueEvent = mockSession.nextEvent().sessionEvent(); - ASSERT_EQ(openQueueEvent.type(), - bmqt::SessionEventType::e_QUEUE_OPEN_RESULT); - ASSERT_EQ(openQueueEvent.statusCode(), 1); - ASSERT_EQ(openQueueEvent.errorDescription(), ""); - ASSERT_EQ(openQueueEvent.correlationId(), corrId1); + BMQTST_ASSERT_EQ(openQueueEvent.type(), + bmqt::SessionEventType::e_QUEUE_OPEN_RESULT); + BMQTST_ASSERT_EQ(openQueueEvent.statusCode(), 1); + BMQTST_ASSERT_EQ(openQueueEvent.errorDescription(), ""); + BMQTST_ASSERT_EQ(openQueueEvent.correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_CLOSED); + BMQTST_ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_CLOSED); } { @@ -775,23 +785,23 @@ static void test4_queueManagementSync() "", bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(mockSession.openQueueAsync(&queueId1, uri1, 10), 0); + BMQTST_ASSERT_EQ(mockSession.openQueueAsync(&queueId1, uri1, 10), 0); typedef bsl::shared_ptr& QueueImplPtr; QueueImplPtr implPtr = reinterpret_cast(queueId1); - ASSERT_EQ(implPtr->uri(), uri1); - ASSERT_EQ(implPtr->correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENING_OPN); + BMQTST_ASSERT_EQ(implPtr->uri(), uri1); + BMQTST_ASSERT_EQ(implPtr->correlationId(), corrId1); + BMQTST_ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENING_OPN); bmqa::SessionEvent openQueueEvent = mockSession.nextEvent().sessionEvent(); - ASSERT_EQ(openQueueEvent.type(), - bmqt::SessionEventType::e_QUEUE_OPEN_RESULT); - ASSERT_EQ(openQueueEvent.statusCode(), 0); - ASSERT_EQ(openQueueEvent.errorDescription(), ""); - ASSERT_EQ(openQueueEvent.correlationId(), corrId1); + BMQTST_ASSERT_EQ(openQueueEvent.type(), + bmqt::SessionEventType::e_QUEUE_OPEN_RESULT); + BMQTST_ASSERT_EQ(openQueueEvent.statusCode(), 0); + BMQTST_ASSERT_EQ(openQueueEvent.errorDescription(), ""); + BMQTST_ASSERT_EQ(openQueueEvent.correlationId(), corrId1); - ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENED); + BMQTST_ASSERT_EQ(implPtr->state(), bmqimp::QueueState::e_OPENED); } } @@ -852,9 +862,9 @@ static void test5_confirmingMessages() &bufferFactory, bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); - ASSERT_EQ(mockSession.unconfirmedMessages(), 3u); + BMQTST_ASSERT_EQ(mockSession.unconfirmedMessages(), 3u); bmqa::MessageEvent messageEvent = eventHandler.popMessageEvent(); { PVV("Confirm push message"); @@ -888,26 +898,26 @@ static void test5_confirmingMessages() mIter.nextMessage(); int rc = confirmBuilder.addMessageConfirmation(mIter.message()); - ASSERT_EQ(rc, 0); - ASSERT_EQ(confirmBuilder.messageCount(), 1); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(confirmBuilder.messageCount(), 1); // we know the guid is invalid so we say the return value is -1. BMQA_EXPECT_CALL(mockSession, confirmMessages(&confirmBuilder)) .returning(bmqt::GenericResult::e_INVALID_ARGUMENT); rc = mockSession.confirmMessages(&confirmBuilder); - ASSERT_EQ(rc, bmqt::GenericResult::e_INVALID_ARGUMENT); + BMQTST_ASSERT_EQ(rc, bmqt::GenericResult::e_INVALID_ARGUMENT); // we know the guid is invalid so we say the return value is -1. BMQA_EXPECT_CALL(mockSession, confirmMessage(mIter.message())) .returning(bmqt::GenericResult::e_INVALID_ARGUMENT); rc = mockSession.confirmMessage(mIter.message()); - ASSERT_EQ(rc, bmqt::GenericResult::e_INVALID_ARGUMENT); + BMQTST_ASSERT_EQ(rc, bmqt::GenericResult::e_INVALID_ARGUMENT); // Finally ensure that no messages were confirmed. (3 messages were // consumed/received from the broker) - ASSERT_EQ(mockSession.unconfirmedMessages(), 3u); + BMQTST_ASSERT_EQ(mockSession.unconfirmedMessages(), 3u); } { @@ -920,13 +930,13 @@ static void test5_confirmingMessages() mIter.nextMessage(); confirmBuilder.addMessageConfirmation(mIter.message()); - ASSERT_EQ(confirmBuilder.messageCount(), 1); + BMQTST_ASSERT_EQ(confirmBuilder.messageCount(), 1); BMQA_EXPECT_CALL(mockSession, confirmMessages(&confirmBuilder)) .returning(0); int rc = mockSession.confirmMessages(&confirmBuilder); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.unconfirmedMessages(), 2u); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.unconfirmedMessages(), 2u); } { @@ -940,14 +950,14 @@ static void test5_confirmingMessages() mIter.nextMessage(); confirmBuilder.addMessageConfirmation(mIter.message()); - ASSERT_EQ(confirmBuilder.messageCount(), 1); + BMQTST_ASSERT_EQ(confirmBuilder.messageCount(), 1); BMQA_EXPECT_CALL(mockSession, confirmMessages(&confirmBuilder)) .returning(0); int rc = mockSession.confirmMessages(&confirmBuilder); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.unconfirmedMessages(), 2u); + BMQTST_ASSERT_EQ(mockSession.unconfirmedMessages(), 2u); } { @@ -964,8 +974,8 @@ static void test5_confirmingMessages() BMQA_EXPECT_CALL(mockSession, confirmMessage(mIter.message())) .returning(0); int rc = mockSession.confirmMessage(mIter.message()); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.unconfirmedMessages(), 1u); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.unconfirmedMessages(), 1u); } } } @@ -1043,74 +1053,74 @@ static void test6_runThrough() .returning(0) .emitting(testEvent); int rc = mockSession.start(); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, startAsync()) .returning(0) .emitting(testEvent); rc = mockSession.startAsync(); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, stop()).emitting(testEvent); mockSession.stop(); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, stopAsync()).emitting(testEvent); mockSession.stopAsync(); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, finalizeStop()).emitting(testEvent); mockSession.finalizeStop(); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, openQueue(&queueId, uri, 0)) .returning(0) .emitting(testEvent); rc = mockSession.openQueue(&queueId, uri, 0); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, closeQueue(&queueId)) .returning(0) .emitting(testEvent); rc = mockSession.closeQueue(&queueId); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, openQueueAsync(&queueId, uri, 0)) .returning(0) .emitting(testEvent); rc = mockSession.openQueueAsync(&queueId, uri, 0); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, closeQueueAsync(&queueId)) .returning(0) .emitting(testEvent); rc = mockSession.closeQueueAsync(&queueId); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, closeQueueAsync(&queueId, closeQueueCallback)) .emitting(testCloseQueueResult); mockSession.closeQueueAsync(&queueId, closeQueueCallback); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, openQueueAsync(&queueId, uri, 0, openQueueCallback)) .emitting(testOpenQueueResult); mockSession.openQueueAsync(&queueId, uri, 0, openQueueCallback); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, configureQueue(&queueId)) .returning(0) .emitting(testEvent); rc = mockSession.configureQueue(&queueId); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, configureQueueSync(&queueId, @@ -1118,18 +1128,18 @@ static void test6_runThrough() bsls::TimeInterval())) .returning(testConfigureQueueResult) .emitting(testEvent); - ASSERT_EQ(mockSession.configureQueueSync(&queueId, - bmqt::QueueOptions(), - bsls::TimeInterval()), - testConfigureQueueResult); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.configureQueueSync(&queueId, + bmqt::QueueOptions(), + bsls::TimeInterval()), + testConfigureQueueResult); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, configureQueueAsync(&queueId)) .returning(0) .emitting(testEvent); rc = mockSession.configureQueueAsync(&queueId); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, configureQueueAsync(&queueId, @@ -1139,14 +1149,14 @@ static void test6_runThrough() mockSession.configureQueueAsync(&queueId, bmqt::QueueOptions(), configureQueueCallback); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); BMQA_EXPECT_CALL(mockSession, post(bmqa::MessageEvent())) .returning(0) .emitting(testEvent); rc = mockSession.post(bmqa::MessageEvent()); - ASSERT_EQ(rc, 0); - ASSERT_EQ(mockSession.emitEvent(), true); + BMQTST_ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(mockSession.emitEvent(), true); } { @@ -1188,23 +1198,23 @@ static void test6_runThrough() BMQA_EXPECT_CALL(mockSession, confirmMessage(mIter.message())) .returning(0); int rc = mockSession.confirmMessage(mIter.message()); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); BMQA_EXPECT_CALL(mockSession, confirmMessage(mIter.message().confirmationCookie())) .returning(0); rc = mockSession.confirmMessage(mIter.message()); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); // Create confirm builder and confirm messages bmqa::ConfirmEventBuilder confirmBuilder; mockSession.loadConfirmEventBuilder(&confirmBuilder); rc = confirmBuilder.addMessageConfirmation(mIter.message()); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); BMQA_EXPECT_CALL(mockSession, confirmMessages(&confirmBuilder)) .returning(0); rc = mockSession.confirmMessages(&confirmBuilder); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); } { @@ -1220,10 +1230,10 @@ static void test6_runThrough() // removed from the two key hash map yet and can still be looked up. bmqa::QueueId foundId; int rc = mockSession.getQueueId(&foundId, uri); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); rc = mockSession.getQueueId(&foundId, corrId); - ASSERT_EQ(rc, 0); + BMQTST_ASSERT_EQ(rc, 0); } // Clear the handler since we dont care about the events emitted @@ -1274,77 +1284,81 @@ static void test7_postAndAccess() bmqa::Message& bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload1); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload2); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload3); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); bmqa::MessageEvent retrievedPostedEvent; - ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), false); + BMQTST_ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), false); bmqa::MessageEvent postedEvent(builder.messageEvent()); BMQA_EXPECT_CALL(mockSession, post(builder.messageEvent())).returning(0); - ASSERT_EQ(mockSession.post(postedEvent), 0); + BMQTST_ASSERT_EQ(mockSession.post(postedEvent), 0); - ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), true); + BMQTST_ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), true); // Please see description of 'compareEvents' for additional details on // messageEvent comparison. // NOTE: Comparison is implementation specific. - ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent, postedEvent), - true); + BMQTST_ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent, + postedEvent), + true); - ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), false); + BMQTST_ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), false); // Append another 2 events builder.reset(); bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload1); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload2); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload3); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload4); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); bmqa::MessageEvent postedEvent2(builder.messageEvent()); bmqa::MessageEvent postedEvent3(builder.messageEvent()); BMQA_EXPECT_CALL(mockSession, post(postedEvent2)).returning(0); - ASSERT_EQ(mockSession.post(postedEvent2), 0); + BMQTST_ASSERT_EQ(mockSession.post(postedEvent2), 0); BMQA_EXPECT_CALL(mockSession, post(postedEvent3)).returning(0); - ASSERT_EQ(mockSession.post(postedEvent3), 0); + BMQTST_ASSERT_EQ(mockSession.post(postedEvent3), 0); bmqa::MessageEvent retrievedPostedEvent2; bmqa::MessageEvent retrievedPostedEvent3; // ASSERT that the compare fails for different events - ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent2, postedEvent), - false); + BMQTST_ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent2, + postedEvent), + false); - ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent2), true); - ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent2, postedEvent2), - true); + BMQTST_ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent2), true); + BMQTST_ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent2, + postedEvent2), + true); - ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent3), true); - ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent3, postedEvent3), - true); + BMQTST_ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent3), true); + BMQTST_ASSERT_EQ(EventHandler::compareEvents(retrievedPostedEvent3, + postedEvent3), + true); // We are out of posted messages again. - ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), false); + BMQTST_ASSERT_EQ(mockSession.popPostedEvent(&retrievedPostedEvent), false); eventHandler.clearEvents(); @@ -1396,12 +1410,12 @@ static void test8_postBlockedToSuspendedQueue() // Ensure that the message cannot be packed. bmqa::Message& bmqMessage = builder.startMessage(); bmqMessage.setDataRef(&payload); - ASSERT_EQ(builder.packMessage(queueId), - bmqt::EventBuilderResult::e_QUEUE_SUSPENDED); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), + bmqt::EventBuilderResult::e_QUEUE_SUSPENDED); // Unsuspend the queue, and try again. implPtr->setIsSuspended(false); - ASSERT_EQ(builder.packMessage(queueId), 0); + BMQTST_ASSERT_EQ(builder.packMessage(queueId), 0); eventHandler.clearEvents(); // Ensure that the builder is clear to ensure that the blob held by the diff --git a/src/groups/bmq/bmqa/bmqa_openqueuestatus.t.cpp b/src/groups/bmq/bmqa/bmqa_openqueuestatus.t.cpp index beefb5cc1a..81e1c5163c 100644 --- a/src/groups/bmq/bmqa/bmqa_openqueuestatus.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_openqueuestatus.t.cpp @@ -57,10 +57,10 @@ static void test1_breathingTest() PV("Default Constructor"); { bmqa::OpenQueueStatus obj(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj), true); - ASSERT_EQ(obj.result(), bmqt::OpenQueueResult::e_SUCCESS); - ASSERT_EQ(obj.errorDescription(), - bsl::string("", bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(bool(obj), true); + BMQTST_ASSERT_EQ(obj.result(), bmqt::OpenQueueResult::e_SUCCESS); + BMQTST_ASSERT_EQ(obj.errorDescription(), + bsl::string("", bmqtst::TestHelperUtil::allocator())); } PV("Valued Constructor"); @@ -79,10 +79,10 @@ static void test1_breathingTest() errorDescription, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj), false); - ASSERT_EQ(obj.queueId(), queueId); - ASSERT_EQ(obj.result(), result); - ASSERT_EQ(obj.errorDescription(), errorDescription); + BMQTST_ASSERT_EQ(bool(obj), false); + BMQTST_ASSERT_EQ(obj.queueId(), queueId); + BMQTST_ASSERT_EQ(obj.result(), result); + BMQTST_ASSERT_EQ(obj.errorDescription(), errorDescription); } PV("Copy Constructor"); @@ -102,10 +102,10 @@ static void test1_breathingTest() bmqtst::TestHelperUtil::allocator()); bmqa::OpenQueueStatus obj2(obj1, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(bool(obj2), bool(obj1)); - ASSERT_EQ(obj1.queueId(), obj2.queueId()); - ASSERT_EQ(obj1.result(), obj2.result()); - ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); + BMQTST_ASSERT_EQ(bool(obj2), bool(obj1)); + BMQTST_ASSERT_EQ(obj1.queueId(), obj2.queueId()); + BMQTST_ASSERT_EQ(obj1.result(), obj2.result()); + BMQTST_ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); } PV("Assignment Operator"); @@ -126,10 +126,10 @@ static void test1_breathingTest() bmqa::OpenQueueStatus obj2(bmqtst::TestHelperUtil::allocator()); obj2 = obj1; - ASSERT_EQ(bool(obj1), bool(obj2)); - ASSERT_EQ(obj1.queueId(), obj2.queueId()); - ASSERT_EQ(obj1.result(), obj2.result()); - ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); + BMQTST_ASSERT_EQ(bool(obj1), bool(obj2)); + BMQTST_ASSERT_EQ(obj1.queueId(), obj2.queueId()); + BMQTST_ASSERT_EQ(obj1.result(), obj2.result()); + BMQTST_ASSERT_EQ(obj1.errorDescription(), obj2.errorDescription()); } } @@ -172,7 +172,7 @@ static void test2_comparison() bmqtst::TestHelperUtil::allocator()); bmqa::OpenQueueStatus obj2(obj1, bmqtst::TestHelperUtil::allocator()); - ASSERT(obj1 == obj2); + BMQTST_ASSERT(obj1 == obj2); } PV("Inequality"); @@ -197,7 +197,7 @@ static void test2_comparison() errorDescription, bmqtst::TestHelperUtil::allocator()); - ASSERT(obj1 != obj2); + BMQTST_ASSERT(obj1 != obj2); } } @@ -253,13 +253,13 @@ static void test3_print() // operator<< out << obj; - ASSERT_EQ(out.str(), expected); + BMQTST_ASSERT_EQ(out.str(), expected); // Print out.reset(); obj.print(out, 0, -1); - ASSERT_EQ(out.str(), expected); + BMQTST_ASSERT_EQ(out.str(), expected); } // ============================================================================ diff --git a/src/groups/bmq/bmqa/bmqa_queueid.t.cpp b/src/groups/bmq/bmqa/bmqa_queueid.t.cpp index fdfc9cf595..d92f5f3e09 100644 --- a/src/groups/bmq/bmqa/bmqa_queueid.t.cpp +++ b/src/groups/bmq/bmqa/bmqa_queueid.t.cpp @@ -64,7 +64,7 @@ static void test1_breathingTest() PV("Default Constructor"); { bmqa::QueueId obj(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(obj.isValid(), false); + BMQTST_ASSERT_EQ(obj.isValid(), false); } PV("Valued Constructor - correlationId"); @@ -73,11 +73,12 @@ static void test1_breathingTest() const bmqt::CorrelationId corrId(id); bmqa::QueueId obj(corrId, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(obj.correlationId(), corrId); - ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); - ASSERT_EQ(obj.uri(), bmqt::Uri(bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.options(), k_NULL_OPTIONS); - ASSERT_EQ(obj.isValid(), false); + BMQTST_ASSERT_EQ(obj.correlationId(), corrId); + BMQTST_ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); + BMQTST_ASSERT_EQ(obj.uri(), + bmqt::Uri(bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(obj.options(), k_NULL_OPTIONS); + BMQTST_ASSERT_EQ(obj.isValid(), false); } PV("Valued Constructor - numeric"); @@ -85,11 +86,12 @@ static void test1_breathingTest() const bsls::Types::Int64 id = 5; bmqa::QueueId obj(id, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(id)); - ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); - ASSERT_EQ(obj.uri(), bmqt::Uri(bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.options(), k_NULL_OPTIONS); - ASSERT_EQ(obj.isValid(), false); + BMQTST_ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(id)); + BMQTST_ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); + BMQTST_ASSERT_EQ(obj.uri(), + bmqt::Uri(bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(obj.options(), k_NULL_OPTIONS); + BMQTST_ASSERT_EQ(obj.isValid(), false); } PV("Valued Constructor - void ptr"); @@ -98,11 +100,12 @@ static void test1_breathingTest() void* ptr = static_cast(const_cast(buffer)); bmqa::QueueId obj(ptr, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(ptr)); - ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); - ASSERT_EQ(obj.uri(), bmqt::Uri(bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.options(), k_NULL_OPTIONS); - ASSERT_EQ(obj.isValid(), false); + BMQTST_ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(ptr)); + BMQTST_ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); + BMQTST_ASSERT_EQ(obj.uri(), + bmqt::Uri(bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(obj.options(), k_NULL_OPTIONS); + BMQTST_ASSERT_EQ(obj.isValid(), false); } PV("Valued Constructor - shared ptr to void"); @@ -113,11 +116,12 @@ static void test1_breathingTest() sptr.createInplace(bmqtst::TestHelperUtil::allocator(), k_VALUE); bmqa::QueueId obj(sptr, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(sptr)); - ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); - ASSERT_EQ(obj.uri(), bmqt::Uri(bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.options(), k_NULL_OPTIONS); - ASSERT_EQ(obj.isValid(), false); + BMQTST_ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(sptr)); + BMQTST_ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); + BMQTST_ASSERT_EQ(obj.uri(), + bmqt::Uri(bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(obj.options(), k_NULL_OPTIONS); + BMQTST_ASSERT_EQ(obj.isValid(), false); } PV("Copy Constructor"); @@ -126,11 +130,11 @@ static void test1_breathingTest() bmqa::QueueId obj1(id, bmqtst::TestHelperUtil::allocator()); bmqa::QueueId obj2(obj1, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(obj1.correlationId(), obj2.correlationId()); - ASSERT_EQ(obj1.flags(), obj2.flags()); - ASSERT_EQ(obj1.uri(), obj2.uri()); - ASSERT_EQ(obj1.options(), obj2.options()); - ASSERT_EQ(obj1.isValid(), obj2.isValid()); + BMQTST_ASSERT_EQ(obj1.correlationId(), obj2.correlationId()); + BMQTST_ASSERT_EQ(obj1.flags(), obj2.flags()); + BMQTST_ASSERT_EQ(obj1.uri(), obj2.uri()); + BMQTST_ASSERT_EQ(obj1.options(), obj2.options()); + BMQTST_ASSERT_EQ(obj1.isValid(), obj2.isValid()); } PV("Assignment Operator"); @@ -140,11 +144,11 @@ static void test1_breathingTest() bmqa::QueueId obj1(id, bmqtst::TestHelperUtil::allocator()); bmqa::QueueId obj2(bmqtst::TestHelperUtil::allocator()); obj2 = obj1; - ASSERT_EQ(obj1.correlationId(), obj2.correlationId()); - ASSERT_EQ(obj1.flags(), obj2.flags()); - ASSERT_EQ(obj1.uri(), obj2.uri()); - ASSERT_EQ(obj1.options(), obj2.options()); - ASSERT_EQ(obj1.isValid(), obj2.isValid()); + BMQTST_ASSERT_EQ(obj1.correlationId(), obj2.correlationId()); + BMQTST_ASSERT_EQ(obj1.flags(), obj2.flags()); + BMQTST_ASSERT_EQ(obj1.uri(), obj2.uri()); + BMQTST_ASSERT_EQ(obj1.options(), obj2.options()); + BMQTST_ASSERT_EQ(obj1.isValid(), obj2.isValid()); } PV("Uri Method"); @@ -153,11 +157,12 @@ static void test1_breathingTest() const char k_QUEUE_URL[] = "bmq://ts.trades.myapp.~bt/my.queue?id=foo"; bmqa::QueueId obj(id, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(id)); - ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); - ASSERT_EQ(obj.uri(), bmqt::Uri(bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.options(), k_NULL_OPTIONS); - ASSERT_EQ(obj.isValid(), false); + BMQTST_ASSERT_EQ(obj.correlationId(), bmqt::CorrelationId(id)); + BMQTST_ASSERT_EQ(obj.flags(), bmqt::QueueFlagsUtil::empty()); + BMQTST_ASSERT_EQ(obj.uri(), + bmqt::Uri(bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_EQ(obj.options(), k_NULL_OPTIONS); + BMQTST_ASSERT_EQ(obj.isValid(), false); // Convert to bmqimp::Queue bsl::shared_ptr& queue = @@ -165,11 +170,11 @@ static void test1_breathingTest() // Set uri to impl object const bmqt::Uri uri(k_QUEUE_URL, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(uri.isValid(), true); + BMQTST_ASSERT_EQ(uri.isValid(), true); queue->setUri(uri); - ASSERT_EQ(obj.uri().asString(), k_QUEUE_URL); + BMQTST_ASSERT_EQ(obj.uri().asString(), k_QUEUE_URL); } } @@ -200,14 +205,14 @@ static void test2_comparison() bmqa::QueueId obj1(k_ID, bmqtst::TestHelperUtil::allocator()); bmqa::QueueId obj2(k_ID, bmqtst::TestHelperUtil::allocator()); - ASSERT_NE(obj1, obj2); + BMQTST_ASSERT_NE(obj1, obj2); } PV("Equality"); { // Different defaults are never equal - ASSERT_NE(bmqa::QueueId(bmqtst::TestHelperUtil::allocator()), - bmqa::QueueId(bmqtst::TestHelperUtil::allocator())); + BMQTST_ASSERT_NE(bmqa::QueueId(bmqtst::TestHelperUtil::allocator()), + bmqa::QueueId(bmqtst::TestHelperUtil::allocator())); // Assignment makes equal const bsls::Types::Int64 k_ID1 = 5; @@ -218,7 +223,7 @@ static void test2_comparison() BSLS_ASSERT_OPT(obj1 != obj2); obj1 = obj2; - ASSERT_EQ(obj1, obj2); + BMQTST_ASSERT_EQ(obj1, obj2); } } diff --git a/src/groups/bmq/bmqc/bmqc_array.t.cpp b/src/groups/bmq/bmqc/bmqc_array.t.cpp index 00b91d679a..c788d96902 100644 --- a/src/groups/bmq/bmqc/bmqc_array.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_array.t.cpp @@ -143,12 +143,12 @@ static void test1_breathingTest() ObjType obj(bmqtst::TestHelperUtil::allocator()); const ObjType& constObj = obj; - ASSERT_EQ(true, obj.empty()); - ASSERT_EQ(0UL, obj.size()); - ASSERT_EQ(bmqtst::TestHelperUtil::allocator(), - obj.get_allocator().mechanism()); - ASSERT_EQ(true, obj.begin() == obj.end()); - ASSERT_EQ(true, constObj.begin() == constObj.end()); + BMQTST_ASSERT_EQ(true, obj.empty()); + BMQTST_ASSERT_EQ(0UL, obj.size()); + BMQTST_ASSERT_EQ(bmqtst::TestHelperUtil::allocator(), + obj.get_allocator().mechanism()); + BMQTST_ASSERT_EQ(true, obj.begin() == obj.end()); + BMQTST_ASSERT_EQ(true, constObj.begin() == constObj.end()); } { @@ -162,26 +162,26 @@ static void test1_breathingTest() obj.push_back(TestType(i, bmqtst::TestHelperUtil::allocator())); } - ASSERT_EQ(false, obj.empty()); - ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); - ASSERT_EQ(true, obj.begin() != obj.end()); + BMQTST_ASSERT_EQ(false, obj.empty()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); + BMQTST_ASSERT_EQ(true, obj.begin() != obj.end()); for (int idx = 0, i = 1; idx < k_NB_ITEMS; ++idx, ++i) { - ASSERT_EQ_D(idx, i, obj[idx].valueAsInt()); - ASSERT_EQ_D(idx, i, constObj[idx].valueAsInt()); + BMQTST_ASSERT_EQ_D(idx, i, obj[idx].valueAsInt()); + BMQTST_ASSERT_EQ_D(idx, i, constObj[idx].valueAsInt()); } int i = 1; for (ObjType::iterator it = obj.begin(); it != obj.end(); ++it, ++i) { - ASSERT_EQ_D(i, it->valueAsInt(), i); - ASSERT_EQ_D(i, (*it).valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, it->valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, (*it).valueAsInt(), i); } i = 1; for (ObjType::const_iterator it = constObj.begin(); it != constObj.end(); ++it, ++i) { - ASSERT_EQ_D(i, it->valueAsInt(), i); - ASSERT_EQ_D(i, (*it).valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, it->valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, (*it).valueAsInt(), i); } } @@ -199,69 +199,69 @@ static void test1_breathingTest() int i = 1; for (ObjType::iterator it = obj.begin(); it != obj.end(); it += 1, ++i) { - ASSERT_EQ_D(i, it->valueAsInt(), i); - ASSERT_EQ_D(i, (*it).valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, it->valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, (*it).valueAsInt(), i); } // Iterator operator-= i = k_NB_ITEMS; for (ObjType::iterator it = obj.end(); i > 0; --i) { it -= 1; - ASSERT_EQ_D(i, it->valueAsInt(), i); - ASSERT_EQ_D(i, (*it).valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, it->valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, (*it).valueAsInt(), i); } { // Misc. iterator expressions ObjType::iterator it = obj.begin(); - ASSERT_EQ(it->valueAsInt(), 1); - ASSERT_EQ((++it)->valueAsInt(), 2); - ASSERT_EQ((--it)->valueAsInt(), 1); - ASSERT_EQ(it[0].valueAsInt(), 1); + BMQTST_ASSERT_EQ(it->valueAsInt(), 1); + BMQTST_ASSERT_EQ((++it)->valueAsInt(), 2); + BMQTST_ASSERT_EQ((--it)->valueAsInt(), 1); + BMQTST_ASSERT_EQ(it[0].valueAsInt(), 1); ObjType::iterator it2 = it++; - ASSERT_EQ(it2->valueAsInt(), 1); - ASSERT_EQ(it->valueAsInt(), 2); - ASSERT(it != it2); - ASSERT(it > it2); - ASSERT(it >= it2); - ASSERT(it2 <= it); - ASSERT(it2 < it); - ASSERT(it == it2 + 1); - ASSERT(it == 1 + it2); - ASSERT(it - 1 == it2); - ASSERT(it - it2 == 1); - ASSERT(it[0] == it2[1]); + BMQTST_ASSERT_EQ(it2->valueAsInt(), 1); + BMQTST_ASSERT_EQ(it->valueAsInt(), 2); + BMQTST_ASSERT(it != it2); + BMQTST_ASSERT(it > it2); + BMQTST_ASSERT(it >= it2); + BMQTST_ASSERT(it2 <= it); + BMQTST_ASSERT(it2 < it); + BMQTST_ASSERT(it == it2 + 1); + BMQTST_ASSERT(it == 1 + it2); + BMQTST_ASSERT(it - 1 == it2); + BMQTST_ASSERT(it - it2 == 1); + BMQTST_ASSERT(it[0] == it2[1]); ObjType::iterator it3 = --it; - ASSERT_EQ(it3->valueAsInt(), 1); - ASSERT_EQ(it2->valueAsInt(), 1); - ASSERT(it == it3); - ASSERT(it >= it3); - ASSERT(it <= it3); - ASSERT(it + 1 == 1 + it); - ASSERT(it3 + 1 == 1 + it3); - ASSERT(it + 1 == it3 + 1); - ASSERT(it - it3 == 0); - ASSERT(it3 - it == 0); - ASSERT(it[2] == it3[2]); - ASSERT(*it++ == *it3); + BMQTST_ASSERT_EQ(it3->valueAsInt(), 1); + BMQTST_ASSERT_EQ(it2->valueAsInt(), 1); + BMQTST_ASSERT(it == it3); + BMQTST_ASSERT(it >= it3); + BMQTST_ASSERT(it <= it3); + BMQTST_ASSERT(it + 1 == 1 + it); + BMQTST_ASSERT(it3 + 1 == 1 + it3); + BMQTST_ASSERT(it + 1 == it3 + 1); + BMQTST_ASSERT(it - it3 == 0); + BMQTST_ASSERT(it3 - it == 0); + BMQTST_ASSERT(it[2] == it3[2]); + BMQTST_ASSERT(*it++ == *it3); } { // const-iterator ObjType::const_iterator it = obj.begin(); - ASSERT_EQ(it->valueAsInt(), 1); - ASSERT_EQ((++it)->valueAsInt(), 2); - ASSERT_EQ((--it)->valueAsInt(), 1); + BMQTST_ASSERT_EQ(it->valueAsInt(), 1); + BMQTST_ASSERT_EQ((++it)->valueAsInt(), 2); + BMQTST_ASSERT_EQ((--it)->valueAsInt(), 1); ObjType::const_iterator it2 = it++; - ASSERT_EQ(it2->valueAsInt(), 1); - ASSERT_EQ(it->valueAsInt(), 2); + BMQTST_ASSERT_EQ(it2->valueAsInt(), 1); + BMQTST_ASSERT_EQ(it->valueAsInt(), 2); ObjType::const_iterator it3 = --it; - ASSERT_EQ(it3->valueAsInt(), 1); - ASSERT_EQ(it2->valueAsInt(), 1); + BMQTST_ASSERT_EQ(it3->valueAsInt(), 1); + BMQTST_ASSERT_EQ(it2->valueAsInt(), 1); } } @@ -273,9 +273,9 @@ static void test1_breathingTest() ObjType obj(k_NB_ITEMS, TestType(1, bmqtst::TestHelperUtil::allocator()), bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(false, obj.empty()); - ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); - ASSERT_EQ( + BMQTST_ASSERT_EQ(false, obj.empty()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); + BMQTST_ASSERT_EQ( k_NB_ITEMS, bsl::count(obj.begin(), obj.end(), @@ -292,9 +292,9 @@ static void test1_breathingTest() bmqtst::TestHelperUtil::allocator()); ObjType obj(v.begin(), v.end(), bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(false, obj.empty()); - ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); - ASSERT_EQ( + BMQTST_ASSERT_EQ(false, obj.empty()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); + BMQTST_ASSERT_EQ( k_NB_ITEMS, bsl::count(obj.begin(), obj.end(), @@ -313,23 +313,23 @@ static void test1_breathingTest() } ObjType objCopy(obj, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(false, objCopy.empty()); - ASSERT_EQ(static_cast(k_NB_ITEMS), objCopy.size()); - ASSERT_EQ(true, objCopy.begin() != objCopy.end()); + BMQTST_ASSERT_EQ(false, objCopy.empty()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS), objCopy.size()); + BMQTST_ASSERT_EQ(true, objCopy.begin() != objCopy.end()); int i = 1; for (ObjType::iterator it = objCopy.begin(); it != objCopy.end(); ++it) { - ASSERT_EQ_D(i, it->valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, it->valueAsInt(), i); ++i; } objCopy.clear(); - ASSERT_EQ(true, objCopy.empty()); - ASSERT_EQ(0UL, objCopy.size()); - ASSERT_EQ(true, objCopy.begin() == objCopy.end()); + BMQTST_ASSERT_EQ(true, objCopy.empty()); + BMQTST_ASSERT_EQ(0UL, objCopy.size()); + BMQTST_ASSERT_EQ(true, objCopy.begin() == objCopy.end()); - ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS), obj.size()); } { @@ -349,21 +349,21 @@ static void test1_breathingTest() obj2.push_back(TestType(i, bmqtst::TestHelperUtil::allocator())); } - ASSERT_EQ(false, obj2.empty()); - ASSERT_EQ(static_cast(k_NB_ITEMS_2), obj2.size()); - ASSERT_EQ(true, obj2.begin() != obj2.end()); + BMQTST_ASSERT_EQ(false, obj2.empty()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS_2), obj2.size()); + BMQTST_ASSERT_EQ(true, obj2.begin() != obj2.end()); // Self assignment obj1 = obj1; - ASSERT_EQ(false, obj1.empty()); - ASSERT_EQ(static_cast(k_NB_ITEMS_1), obj1.size()); - ASSERT_EQ(true, obj1.begin() != obj1.end()); + BMQTST_ASSERT_EQ(false, obj1.empty()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS_1), obj1.size()); + BMQTST_ASSERT_EQ(true, obj1.begin() != obj1.end()); obj2 = obj1; - ASSERT_EQ(false, obj2.empty()); - ASSERT_EQ(static_cast(k_NB_ITEMS_1), obj2.size()); - ASSERT_EQ(true, obj2.begin() != obj2.end()); + BMQTST_ASSERT_EQ(false, obj2.empty()); + BMQTST_ASSERT_EQ(static_cast(k_NB_ITEMS_1), obj2.size()); + BMQTST_ASSERT_EQ(true, obj2.begin() != obj2.end()); } { @@ -374,11 +374,11 @@ static void test1_breathingTest() for (int i = 1; i <= 2 * k_STATIC_LEN; ++i) { obj.push_back(TestType(i, bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(1, obj.front().valueAsInt()); - ASSERT_EQ(i, obj.back().valueAsInt()); + BMQTST_ASSERT_EQ(1, obj.front().valueAsInt()); + BMQTST_ASSERT_EQ(i, obj.back().valueAsInt()); - ASSERT_EQ(1, constObj.front().valueAsInt()); - ASSERT_EQ(i, constObj.back().valueAsInt()); + BMQTST_ASSERT_EQ(1, constObj.front().valueAsInt()); + BMQTST_ASSERT_EQ(i, constObj.back().valueAsInt()); } } @@ -395,11 +395,11 @@ static void test1_breathingTest() TestType("a", bmqtst::TestHelperUtil::allocator())); } - ASSERT_EQ(k_NB_ITEMS, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(k_NB_ITEMS, TestType::s_numAliveInstances); obj.clear(); - ASSERT_EQ(0, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(0, TestType::s_numAliveInstances); } { @@ -416,11 +416,11 @@ static void test1_breathingTest() TestType("b", bmqtst::TestHelperUtil::allocator())); } - ASSERT_EQ(150, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(150, TestType::s_numAliveInstances); obj2 = obj1; - ASSERT_EQ(100, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(100, TestType::s_numAliveInstances); } { @@ -437,11 +437,11 @@ static void test1_breathingTest() TestType("b", bmqtst::TestHelperUtil::allocator())); } - ASSERT_EQ(150, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(150, TestType::s_numAliveInstances); obj1 = obj2; - ASSERT_EQ(200, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(200, TestType::s_numAliveInstances); } { @@ -453,11 +453,11 @@ static void test1_breathingTest() TestType("a", bmqtst::TestHelperUtil::allocator())); } - ASSERT_EQ(50, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(50, TestType::s_numAliveInstances); bmqtst::TestHelperUtil::allocator()->deleteObject(obj); - ASSERT_EQ(0, TestType::s_numAliveInstances); + BMQTST_ASSERT_EQ(0, TestType::s_numAliveInstances); } } } @@ -481,14 +481,14 @@ static void test2_outOfBoundValidation() const ObjType& constObj = obj; // non-const - ASSERT_SAFE_FAIL(obj.front()); - ASSERT_SAFE_FAIL(obj.back()); - ASSERT_SAFE_FAIL(obj[0]); + BMQTST_ASSERT_SAFE_FAIL(obj.front()); + BMQTST_ASSERT_SAFE_FAIL(obj.back()); + BMQTST_ASSERT_SAFE_FAIL(obj[0]); // const - ASSERT_SAFE_FAIL(constObj.front()); - ASSERT_SAFE_FAIL(constObj.back()); - ASSERT_SAFE_FAIL(constObj[0]); + BMQTST_ASSERT_SAFE_FAIL(constObj.front()); + BMQTST_ASSERT_SAFE_FAIL(constObj.back()); + BMQTST_ASSERT_SAFE_FAIL(constObj[0]); // insert some items const int k_NB_ITEMS = 5; @@ -496,7 +496,7 @@ static void test2_outOfBoundValidation() obj.push_back(TestType(i, bmqtst::TestHelperUtil::allocator())); } - ASSERT_SAFE_FAIL(constObj[k_NB_ITEMS + 1]); + BMQTST_ASSERT_SAFE_FAIL(constObj[k_NB_ITEMS + 1]); static_cast(constObj); } @@ -518,17 +518,17 @@ static void test3_noMemoryAllocation() ObjType obj(&ta); - ASSERT_EQ(ta.numBlocksInUse(), 0); + BMQTST_ASSERT_EQ(ta.numBlocksInUse(), 0); // Add up to k_STATIC_LEN, no allocations for (int i = 1; i <= k_STATIC_LEN; ++i) { obj.push_back(TestType(i, bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(ta.numBlocksInUse(), 0); + BMQTST_ASSERT_EQ(ta.numBlocksInUse(), 0); } // Adding one more, allocation" obj.push_back(TestType(0, bmqtst::TestHelperUtil::allocator())); - ASSERT_NE(ta.numBlocksInUse(), 0); + BMQTST_ASSERT_NE(ta.numBlocksInUse(), 0); } static void test4_reserve() @@ -556,7 +556,7 @@ static void test4_reserve() for (int i = 1; i <= k_CAPACITY; ++i) { obj.push_back(TestType(i, bmqtst::TestHelperUtil::allocator())); } - ASSERT_EQ(ta.numAllocations(), numAllocations); + BMQTST_ASSERT_EQ(ta.numAllocations(), numAllocations); } static void test5_resize() @@ -579,20 +579,20 @@ static void test5_resize() // 1) Resize to static length obj.resize(k_STATIC_LEN, TestType(1, bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.size(), static_cast(k_STATIC_LEN)); - ASSERT_EQ(TestType::s_numAliveInstances, k_STATIC_LEN); - ASSERT_EQ(ta.numAllocations(), numAllocations); + BMQTST_ASSERT_EQ(obj.size(), static_cast(k_STATIC_LEN)); + BMQTST_ASSERT_EQ(TestType::s_numAliveInstances, k_STATIC_LEN); + BMQTST_ASSERT_EQ(ta.numAllocations(), numAllocations); // 2) Resize to half the static length obj.resize(k_STATIC_LEN / 2, TestType(2, bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.size(), static_cast(k_STATIC_LEN / 2)); - ASSERT_EQ(TestType::s_numAliveInstances, k_STATIC_LEN / 2); - ASSERT_EQ(ta.numAllocations(), numAllocations); + BMQTST_ASSERT_EQ(obj.size(), static_cast(k_STATIC_LEN / 2)); + BMQTST_ASSERT_EQ(TestType::s_numAliveInstances, k_STATIC_LEN / 2); + BMQTST_ASSERT_EQ(ta.numAllocations(), numAllocations); for (size_t i = 0; i < obj.size(); ++i) { - ASSERT_EQ_D(i, obj[i].valueAsInt(), 1); + BMQTST_ASSERT_EQ_D(i, obj[i].valueAsInt(), 1); } // k_FULL_LENGTH exercises both static and dynamic parts of 'bmqc_array'. @@ -602,34 +602,34 @@ static void test5_resize() obj.resize(2 * k_STATIC_LEN, TestType(3, bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.size(), static_cast(k_FULL_LEN)); - ASSERT_EQ(TestType::s_numAliveInstances, 2 * k_STATIC_LEN); - ASSERT_EQ(ta.numAllocations(), numAllocations + 1); + BMQTST_ASSERT_EQ(obj.size(), static_cast(k_FULL_LEN)); + BMQTST_ASSERT_EQ(TestType::s_numAliveInstances, 2 * k_STATIC_LEN); + BMQTST_ASSERT_EQ(ta.numAllocations(), numAllocations + 1); for (size_t i = 0; i < k_FULL_LEN; ++i) { const int expected = (i < (k_STATIC_LEN / 2)) ? 1 : 3; - ASSERT_EQ_D(i, obj[i].valueAsInt(), expected); + BMQTST_ASSERT_EQ_D(i, obj[i].valueAsInt(), expected); } // 4) Again resize to twice the static length (i.e. same size) obj.resize(k_FULL_LEN, TestType(4, bmqtst::TestHelperUtil::allocator())); - ASSERT_EQ(obj.size(), static_cast(k_FULL_LEN)); - ASSERT_EQ(TestType::s_numAliveInstances, 2 * k_STATIC_LEN); - ASSERT_EQ(ta.numAllocations(), numAllocations + 1); + BMQTST_ASSERT_EQ(obj.size(), static_cast(k_FULL_LEN)); + BMQTST_ASSERT_EQ(TestType::s_numAliveInstances, 2 * k_STATIC_LEN); + BMQTST_ASSERT_EQ(ta.numAllocations(), numAllocations + 1); for (size_t i = 0; i < k_FULL_LEN; ++i) { const int expected = (i < (k_STATIC_LEN / 2)) ? 1 : 3; - ASSERT_EQ_D(i, obj[i].valueAsInt(), expected); + BMQTST_ASSERT_EQ_D(i, obj[i].valueAsInt(), expected); } // 5) Resize to zero obj.resize(0, TestType(5, bmqtst::TestHelperUtil::allocator())); - ASSERT(obj.empty()); - ASSERT_EQ(obj.size(), 0UL); - ASSERT_EQ(TestType::s_numAliveInstances, 0); - ASSERT_EQ(ta.numAllocations(), numAllocations + 1); + BMQTST_ASSERT(obj.empty()); + BMQTST_ASSERT_EQ(obj.size(), 0UL); + BMQTST_ASSERT_EQ(TestType::s_numAliveInstances, 0); + BMQTST_ASSERT_EQ(ta.numAllocations(), numAllocations + 1); } static void test6_assign() @@ -660,9 +660,9 @@ static void test6_assign() obj.assign(srcVec.begin(), srcVec.end()); // Verify - ASSERT_EQ(obj.size(), srcVec.size()); + BMQTST_ASSERT_EQ(obj.size(), srcVec.size()); for (size_t i = 0; i < obj.size(); ++i) { - ASSERT_EQ_D(i, obj[i].valueAsInt(), srcVec[i].valueAsInt()); + BMQTST_ASSERT_EQ_D(i, obj[i].valueAsInt(), srcVec[i].valueAsInt()); } } @@ -692,7 +692,7 @@ static void test7_algorithms() // Verify: {1, 2, ..., 30} for (int i = 0; i <= 30; ++i) { - ASSERT_EQ_D(i, obj[i].valueAsInt(), i); + BMQTST_ASSERT_EQ_D(i, obj[i].valueAsInt(), i); } } } @@ -716,7 +716,7 @@ static void test8_allocatorProp() ObjType obj(&ta); obj.push_back(TestType(0, &ta)); - ASSERT_EQ(true, obj.back().d_allocator_p != &ta); + BMQTST_ASSERT_EQ(true, obj.back().d_allocator_p != &ta); } { @@ -727,7 +727,7 @@ static void test8_allocatorProp() bmqc::Array obj(&ta); obj.push_back("foo"); - ASSERT_EQ(true, obj.back().get_allocator().mechanism() == &ta); + BMQTST_ASSERT_EQ(true, obj.back().get_allocator().mechanism() == &ta); } } @@ -751,18 +751,20 @@ static void test9_copyAssignDifferentStaticLength() { ObjType obj(rhs, &ta); - ASSERT_EQ(obj.size(), 2u); - ASSERT_EQ(obj.capacity(), 10u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 2u); + BMQTST_ASSERT_EQ(obj.capacity(), 10u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } rhs.resize(42, TestType(2)); { ObjType obj(rhs, &ta); - ASSERT_EQ(obj.size(), 42u); - ASSERT_EQ(obj.capacity(), 42u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 42u); + BMQTST_ASSERT_EQ(obj.capacity(), 42u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } } @@ -776,9 +778,10 @@ static void test9_copyAssignDifferentStaticLength() { ObjType obj(&ta); obj = rhs; - ASSERT_EQ(obj.size(), 2u); - ASSERT_EQ(obj.capacity(), 10u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 2u); + BMQTST_ASSERT_EQ(obj.capacity(), 10u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } rhs.resize(42, TestType(2)); @@ -786,9 +789,10 @@ static void test9_copyAssignDifferentStaticLength() { ObjType obj(&ta); obj = rhs; - ASSERT_EQ(obj.size(), 42u); - ASSERT_EQ(obj.capacity(), 42u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 42u); + BMQTST_ASSERT_EQ(obj.capacity(), 42u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } } @@ -801,18 +805,20 @@ static void test9_copyAssignDifferentStaticLength() { ObjType obj(rhs, &ta); - ASSERT_EQ(obj.size(), 2u); - ASSERT_EQ(obj.capacity(), 10u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 2u); + BMQTST_ASSERT_EQ(obj.capacity(), 10u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } rhs.resize(42, TestType(2)); { ObjType obj(rhs, &ta); - ASSERT_EQ(obj.size(), 42u); - ASSERT_EQ(obj.capacity(), 42u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 42u); + BMQTST_ASSERT_EQ(obj.capacity(), 42u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } } @@ -826,9 +832,10 @@ static void test9_copyAssignDifferentStaticLength() { ObjType obj(&ta); obj = rhs; - ASSERT_EQ(obj.size(), 2u); - ASSERT_EQ(obj.capacity(), 10u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 2u); + BMQTST_ASSERT_EQ(obj.capacity(), 10u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } rhs.resize(42, TestType(2)); @@ -836,9 +843,10 @@ static void test9_copyAssignDifferentStaticLength() { ObjType obj(&ta); obj = rhs; - ASSERT_EQ(obj.size(), 42u); - ASSERT_EQ(obj.capacity(), 42u); - ASSERT_EQ(true, bsl::equal(obj.begin(), obj.end(), rhs.begin())); + BMQTST_ASSERT_EQ(obj.size(), 42u); + BMQTST_ASSERT_EQ(obj.capacity(), 42u); + BMQTST_ASSERT_EQ(true, + bsl::equal(obj.begin(), obj.end(), rhs.begin())); } } } @@ -863,9 +871,9 @@ static void test10_pushBackSelfRef() for (int i = 0; i < k_SIZE; ++i) { obj.push_back(TestType(i, bmqtst::TestHelperUtil::allocator())); } - ASSERT_PASS(obj.push_back(obj[k_STATIC_LEN])); - ASSERT_EQ(k_STATIC_LEN, obj[k_STATIC_LEN].valueAsInt()); - ASSERT_EQ(k_STATIC_LEN, obj[k_SIZE].valueAsInt()); + BMQTST_ASSERT_PASS(obj.push_back(obj[k_STATIC_LEN])); + BMQTST_ASSERT_EQ(k_STATIC_LEN, obj[k_STATIC_LEN].valueAsInt()); + BMQTST_ASSERT_EQ(k_STATIC_LEN, obj[k_SIZE].valueAsInt()); } } diff --git a/src/groups/bmq/bmqc/bmqc_monitoredqueue.t.cpp b/src/groups/bmq/bmqc/bmqc_monitoredqueue.t.cpp index eb61862bb3..8d7efd7865 100644 --- a/src/groups/bmq/bmqc/bmqc_monitoredqueue.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_monitoredqueue.t.cpp @@ -87,7 +87,7 @@ static void test1_MonitoredQueueState_toAscii() ascii = bmqc::MonitoredQueueState::toAscii( bmqc::MonitoredQueueState::Enum(test.d_value)); - ASSERT_EQ_D(test.d_line, ascii, test.d_expected); + BMQTST_ASSERT_EQ_D(test.d_line, ascii, test.d_expected); } } @@ -145,20 +145,20 @@ static void test2_MonitoredQueueState_print() bsl::string expected(bmqtst::TestHelperUtil::allocator()); expected.assign(test.d_expected); expected.append("\n"); - ASSERT_EQ_D(test.d_line, out.str(), expected); + BMQTST_ASSERT_EQ_D(test.d_line, out.str(), expected); // operator<< out.reset(); out << obj; - ASSERT_EQ_D(test.d_line, out.str(), test.d_expected); + BMQTST_ASSERT_EQ_D(test.d_line, out.str(), test.d_expected); // 2. 'badbit' set out.reset(); out.setstate(bsl::ios_base::badbit); bmqc::MonitoredQueueState::print(out, obj, 0, -1); - ASSERT_EQ_D(test.d_line, out.str(), ""); + BMQTST_ASSERT_EQ_D(test.d_line, out.str(), ""); } } diff --git a/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccfixedqueue.t.cpp b/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccfixedqueue.t.cpp index 74cfd3d490..89b2ae39a0 100644 --- a/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccfixedqueue.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccfixedqueue.t.cpp @@ -167,34 +167,34 @@ static void test1_MonitoredQueue_breathingTest() k_QUEUE_SIZE, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); queue.setWatermarks(k_LOW_WATERMARK, k_HIGH_WATERMARK, k_HIGH_WATERMARK2); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); - ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); - ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); - ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); + BMQTST_ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); // pushBack two items - ASSERT_EQ(queue.pushBack(1), 0); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.pushBack(1), 0); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); - ASSERT_EQ(queue.tryPushBack(2), 0); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 2); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.tryPushBack(2), 0); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 2); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); int item = -1; @@ -206,23 +206,23 @@ static void test1_MonitoredQueue_breathingTest() // // int item = -1; // const bsls::TimeInterval timeout = bsls::TimeInterval( // 0, 5 * bdlt::TimeUnitRatio::k_NANOSECONDS_PER_MILLISECOND); - // ASSERT_SAFE_FAIL(queue.timedPopFront(&item, timeout)); + // BMQTST_ASSERT_SAFE_FAIL(queue.timedPopFront(&item, timeout)); // (void)timeout; // prod-build compiler happiness // popfront two items item = -1; - ASSERT_EQ(queue.tryPopFront(&item), 0); - ASSERT_EQ(item, 1); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.tryPopFront(&item), 0); + BMQTST_ASSERT_EQ(item, 1); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); item = -1; queue.popFront(&item); - ASSERT_EQ(item, 2); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(item, 2); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); } { @@ -233,34 +233,34 @@ static void test1_MonitoredQueue_breathingTest() true, // supportTimedOperations bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); queue.setWatermarks(k_LOW_WATERMARK, k_HIGH_WATERMARK, k_HIGH_WATERMARK2); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); - ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); - ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); - ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); + BMQTST_ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); // pushBack two items - ASSERT_EQ(queue.pushBack(1), 0); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.pushBack(1), 0); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); - ASSERT_EQ(queue.pushBack(2), 0); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 2); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.pushBack(2), 0); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 2); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); // popFront two items // 1. timedPopFront @@ -268,19 +268,19 @@ static void test1_MonitoredQueue_breathingTest() const bsls::TimeInterval timeout = bsls::TimeInterval( 0, 5 * bdlt::TimeUnitRatio::k_NANOSECONDS_PER_MILLISECOND); - ASSERT_EQ(queue.timedPopFront(&item, timeout), 0); - ASSERT_EQ(item, 1) - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.timedPopFront(&item, timeout), 0); + BMQTST_ASSERT_EQ(item, 1) + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); // 2. popFront item = -1; queue.popFront(&item); - ASSERT_EQ(item, 2); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(item, 2); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); } } @@ -326,21 +326,21 @@ static void test2_MonitoredQueue_reset() queue.tryPushBack(8); queue.tryPushBack(9); - ASSERT_EQ(queue.tryPushBack(10), -1); + BMQTST_ASSERT_EQ(queue.tryPushBack(10), -1); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), k_QUEUE_SIZE); - ASSERT_EQ(queue.isEmpty(), false); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_QUEUE_FILLED); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_QUEUE_FILLED); // 2. Reset the queue and verify that items were removed and state is reset // to an empty queue. queue.reset(); - ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.capacity(), k_QUEUE_SIZE); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); } BSLA_MAYBE_UNUSED diff --git a/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccsingleconsumerqueue.t.cpp b/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccsingleconsumerqueue.t.cpp index 5187413e31..10dc5a5905 100644 --- a/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccsingleconsumerqueue.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_monitoredqueue_bdlccsingleconsumerqueue.t.cpp @@ -170,46 +170,46 @@ static void test1_MonitoredSingleConsumerQueue_breathingTest() k_QUEUE_SIZE, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); queue.setWatermarks(k_LOW_WATERMARK, k_HIGH_WATERMARK, k_HIGH_WATERMARK2); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); - ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); - ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); - ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); + BMQTST_ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); // pushBack two items - ASSERT_EQ(queue.pushBack(1), 0); - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.pushBack(1), 0); + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); - ASSERT_EQ(queue.tryPushBack(2), 0); - ASSERT_EQ(queue.numElements(), 2); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.tryPushBack(2), 0); + BMQTST_ASSERT_EQ(queue.numElements(), 2); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); // Verify timed popFront is undefined int item = -1; // popFront two items item = -1; - ASSERT_EQ(queue.tryPopFront(&item), 0); - ASSERT_EQ(item, 1); - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.tryPopFront(&item), 0); + BMQTST_ASSERT_EQ(item, 1); + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); item = -1; queue.popFront(&item); - ASSERT_EQ(item, 2); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(item, 2); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); } { @@ -221,30 +221,30 @@ static void test1_MonitoredSingleConsumerQueue_breathingTest() // supportTimedOperations bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); queue.setWatermarks(k_LOW_WATERMARK, k_HIGH_WATERMARK, k_HIGH_WATERMARK2); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); - ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); - ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); - ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); + BMQTST_ASSERT_EQ(queue.lowWatermark(), k_LOW_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark(), k_HIGH_WATERMARK); + BMQTST_ASSERT_EQ(queue.highWatermark2(), k_HIGH_WATERMARK2); // pushBack two items - ASSERT_EQ(queue.pushBack(1), 0); - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.pushBack(1), 0); + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); - ASSERT_EQ(queue.pushBack(2), 0); - ASSERT_EQ(queue.numElements(), 2); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.pushBack(2), 0); + BMQTST_ASSERT_EQ(queue.numElements(), 2); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); // popFront two items // 1. timedPopFront @@ -252,17 +252,17 @@ static void test1_MonitoredSingleConsumerQueue_breathingTest() const bsls::TimeInterval timeout = bsls::TimeInterval( 0, 5 * bdlt::TimeUnitRatio::k_NANOSECONDS_PER_MILLISECOND); - ASSERT_EQ(queue.timedPopFront(&item, timeout), 0); - ASSERT_EQ(item, 1) - ASSERT_EQ(queue.numElements(), 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.timedPopFront(&item, timeout), 0); + BMQTST_ASSERT_EQ(item, 1) + BMQTST_ASSERT_EQ(queue.numElements(), 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); // 2. popFront item = -1; queue.popFront(&item); - ASSERT_EQ(item, 2); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(item, 2); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); } } @@ -309,18 +309,18 @@ static void test2_MonitoredSingleConsumerQueue_exceed_reset() queue.tryPushBack(8); queue.tryPushBack(9); - ASSERT_EQ(queue.tryPushBack(10), 0); + BMQTST_ASSERT_EQ(queue.tryPushBack(10), 0); - ASSERT_EQ(queue.numElements(), k_QUEUE_SIZE + 1); - ASSERT_EQ(queue.isEmpty(), false); + BMQTST_ASSERT_EQ(queue.numElements(), k_QUEUE_SIZE + 1); + BMQTST_ASSERT_EQ(queue.isEmpty(), false); // 2. Reset the queue and verify that items were removed and state is reset // to an empty queue. queue.reset(); - ASSERT_EQ(queue.numElements(), 0); - ASSERT_EQ(queue.isEmpty(), true); - ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); + BMQTST_ASSERT_EQ(queue.numElements(), 0); + BMQTST_ASSERT_EQ(queue.isEmpty(), true); + BMQTST_ASSERT_EQ(queue.state(), bmqc::MonitoredQueueState::e_NORMAL); } BSLA_MAYBE_UNUSED diff --git a/src/groups/bmq/bmqc/bmqc_multiqueuethreadpool.t.cpp b/src/groups/bmq/bmqc/bmqc_multiqueuethreadpool.t.cpp index 33af002bbc..cf37370083 100644 --- a/src/groups/bmq/bmqc/bmqc_multiqueuethreadpool.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_multiqueuethreadpool.t.cpp @@ -187,12 +187,12 @@ static void test1_breathingTest() bmqtst::TestHelperUtil::allocator()); MQTP mfqtp(config, bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(mfqtp.isStarted(), false); - ASSERT_EQ(mfqtp.numQueues(), k_NUM_QUEUES); - ASSERT_EQ(mfqtp.isSingleThreaded(), false); - ASSERT_EQ(mfqtp.start(), 0); - ASSERT_NE(mfqtp.start(), 0); // MQTP has already been started - ASSERT_EQ(mfqtp.isStarted(), true); + BMQTST_ASSERT_EQ(mfqtp.isStarted(), false); + BMQTST_ASSERT_EQ(mfqtp.numQueues(), k_NUM_QUEUES); + BMQTST_ASSERT_EQ(mfqtp.isSingleThreaded(), false); + BMQTST_ASSERT_EQ(mfqtp.start(), 0); + BMQTST_ASSERT_NE(mfqtp.start(), 0); // MQTP has already been started + BMQTST_ASSERT_EQ(mfqtp.isStarted(), true); MQTP::Event* event = mfqtp.getUnmanagedEvent(); event->object() = 0; @@ -211,19 +211,19 @@ static void test1_breathingTest() mfqtp.enqueueEventOnAllQueues(event); mfqtp.stop(); - ASSERT_EQ(mfqtp.isStarted(), false); + BMQTST_ASSERT_EQ(mfqtp.isStarted(), false); - ASSERT_EQ(queueContextMap[0].size(), 2U); - ASSERT_EQ(queueContextMap[0][0], 0); - ASSERT_EQ(queueContextMap[0][1], 3); + BMQTST_ASSERT_EQ(queueContextMap[0].size(), 2U); + BMQTST_ASSERT_EQ(queueContextMap[0][0], 0); + BMQTST_ASSERT_EQ(queueContextMap[0][1], 3); - ASSERT_EQ(queueContextMap[0].size(), 2U); - ASSERT_EQ(queueContextMap[1][0], 1); - ASSERT_EQ(queueContextMap[1][1], 3); + BMQTST_ASSERT_EQ(queueContextMap[0].size(), 2U); + BMQTST_ASSERT_EQ(queueContextMap[1][0], 1); + BMQTST_ASSERT_EQ(queueContextMap[1][1], 3); - ASSERT_EQ(queueContextMap[0].size(), 2U); - ASSERT_EQ(queueContextMap[2][0], 2); - ASSERT_EQ(queueContextMap[2][1], 3); + BMQTST_ASSERT_EQ(queueContextMap[0].size(), 2U); + BMQTST_ASSERT_EQ(queueContextMap[2][0], 2); + BMQTST_ASSERT_EQ(queueContextMap[2][1], 3); threadPool.stop(); } @@ -543,4 +543,4 @@ int main(int argc, char* argv[]) } // ---------------------------------------------------------------------------- -// NOTICE: \ No newline at end of file +// NOTICE: diff --git a/src/groups/bmq/bmqc/bmqc_orderedhashmap.t.cpp b/src/groups/bmq/bmqc/bmqc_orderedhashmap.t.cpp index 26adbfa8fc..6fb9c2de88 100644 --- a/src/groups/bmq/bmqc/bmqc_orderedhashmap.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_orderedhashmap.t.cpp @@ -129,34 +129,34 @@ static void test1_breathingTest() MyMapType map(bmqtst::TestHelperUtil::allocator()); const MyMapType& cmap = map; - ASSERT_EQ(true, map.begin() == map.end()); - ASSERT_EQ(true, cmap.begin() == cmap.end()); + BMQTST_ASSERT_EQ(true, map.begin() == map.end()); + BMQTST_ASSERT_EQ(true, cmap.begin() == cmap.end()); map.clear(); - ASSERT_EQ(0U, map.count(1)); - ASSERT_EQ(0U, map.erase(1)); - ASSERT_EQ(true, map.end() == map.find(1)); - ASSERT_EQ(true, cmap.empty()); - ASSERT_EQ(true, cmap.end() == cmap.find(1)); - ASSERT_EQ(0U, cmap.count(1)); - ASSERT_EQ(0U, cmap.size()); + BMQTST_ASSERT_EQ(0U, map.count(1)); + BMQTST_ASSERT_EQ(0U, map.erase(1)); + BMQTST_ASSERT_EQ(true, map.end() == map.find(1)); + BMQTST_ASSERT_EQ(true, cmap.empty()); + BMQTST_ASSERT_EQ(true, cmap.end() == cmap.find(1)); + BMQTST_ASSERT_EQ(0U, cmap.count(1)); + BMQTST_ASSERT_EQ(0U, cmap.size()); bsl::pair rc = map.insert(bsl::make_pair(1, s)); - ASSERT_EQ(true, rc.first != map.end()); - ASSERT_EQ(rc.second, true); - ASSERT_EQ(1U, rc.first->first); - ASSERT_EQ(s, rc.first->second); - ASSERT_EQ(1U, cmap.count(1)); + BMQTST_ASSERT_EQ(true, rc.first != map.end()); + BMQTST_ASSERT_EQ(rc.second, true); + BMQTST_ASSERT_EQ(1U, rc.first->first); + BMQTST_ASSERT_EQ(s, rc.first->second); + BMQTST_ASSERT_EQ(1U, cmap.count(1)); ConstIterType cit = cmap.find(1); - ASSERT_EQ(true, cmap.end() != cit); - ASSERT_EQ(1U, cmap.size()); - ASSERT_EQ(false, cmap.empty()); - ASSERT_EQ(1U, map.erase(1)); - ASSERT_EQ(true, map.begin() == map.end()); - ASSERT_EQ(true, cmap.begin() == cmap.end()); - ASSERT_EQ(true, cmap.end() == cmap.find(1)); + BMQTST_ASSERT_EQ(true, cmap.end() != cit); + BMQTST_ASSERT_EQ(1U, cmap.size()); + BMQTST_ASSERT_EQ(false, cmap.empty()); + BMQTST_ASSERT_EQ(1U, map.erase(1)); + BMQTST_ASSERT_EQ(true, map.begin() == map.end()); + BMQTST_ASSERT_EQ(true, cmap.begin() == cmap.end()); + BMQTST_ASSERT_EQ(true, cmap.end() == cmap.find(1)); } static void test2_impDetails_nextPrime() @@ -190,11 +190,11 @@ static void test2_impDetails_nextPrime() break; // RETURN } - ASSERT_EQ(isPrime(currPrime), true); - ASSERT_GT(currPrime, prevPrime); + BMQTST_ASSERT_EQ(isPrime(currPrime), true); + BMQTST_ASSERT_GT(currPrime, prevPrime); } - ASSERT_EQ(lastPrime, 0U); + BMQTST_ASSERT_EQ(lastPrime, 0U); } static void test3_insert() @@ -229,23 +229,23 @@ static void test3_insert() // Insert 1M elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i + 1)); - ASSERT_EQ_D(i, true, rc.second); - ASSERT_EQ_D(i, true, rc.first != map.end()); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, (i + 1), rc.first->second); - ASSERT_EQ_D(i, true, 1.5 >= map.load_factor()); + BMQTST_ASSERT_EQ_D(i, true, rc.second); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), rc.first->second); + BMQTST_ASSERT_EQ_D(i, true, 1.5 >= map.load_factor()); } - ASSERT_EQ(map.size(), k_NUM_ELEMENTS); + BMQTST_ASSERT_EQ(map.size(), k_NUM_ELEMENTS); // Iterate and confirm { const MyMapType& cmap = map; size_t i = 0; for (ConstIterType cit = cmap.begin(); cit != cmap.end(); ++cit) { - ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); - ASSERT_EQ_D(i, i, cit->first); - ASSERT_EQ_D(i, (i + 1), cit->second); + BMQTST_ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); + BMQTST_ASSERT_EQ_D(i, i, cit->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), cit->second); ++i; } } @@ -256,14 +256,14 @@ static void test3_insert() size_t i = k_NUM_ELEMENTS - 1; ConstIterType cit = --(cmap.end()); // last element for (; cit != cmap.begin(); --cit) { - ASSERT_EQ_D(i, true, i > 0); - ASSERT_EQ_D(i, i, cit->first); - ASSERT_EQ_D(i, (i + 1), cit->second); + BMQTST_ASSERT_EQ_D(i, true, i > 0); + BMQTST_ASSERT_EQ_D(i, i, cit->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), cit->second); --i; } - ASSERT_EQ(true, cit == cmap.begin()); - ASSERT_EQ(cit->first, i); - ASSERT_EQ(cit->second, (i + 1)); + BMQTST_ASSERT_EQ(true, cit == cmap.begin()); + BMQTST_ASSERT_EQ(cit->first, i); + BMQTST_ASSERT_EQ(cit->second, (i + 1)); } } @@ -300,22 +300,22 @@ static void test4_rinsert() // Insert 1M elements for (int i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.rinsert(bsl::make_pair(i, i + 1)); - ASSERT_EQ_D(i, true, rc.second); - ASSERT_EQ_D(i, true, rc.first != map.end()); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, (i + 1), rc.first->second); - ASSERT_EQ_D(i, true, 1.5 >= map.load_factor()); + BMQTST_ASSERT_EQ_D(i, true, rc.second); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), rc.first->second); + BMQTST_ASSERT_EQ_D(i, true, 1.5 >= map.load_factor()); } - ASSERT_EQ(map.size(), static_cast(k_NUM_ELEMENTS)); + BMQTST_ASSERT_EQ(map.size(), static_cast(k_NUM_ELEMENTS)); // Iterate and confirm { const MyMapType& cmap = map; int i = k_NUM_ELEMENTS - 1; for (ConstIterType cit = cmap.begin(); cit != cmap.end(); ++cit) { - ASSERT_EQ_D(i, i, cit->first); - ASSERT_EQ_D(i, (i + 1), cit->second); + BMQTST_ASSERT_EQ_D(i, i, cit->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), cit->second); --i; } } @@ -326,14 +326,14 @@ static void test4_rinsert() int i = 0; ConstIterType cit = --(cmap.end()); // last element for (; cit != cmap.begin(); --cit) { - ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); - ASSERT_EQ_D(i, i, cit->first); - ASSERT_EQ_D(i, (i + 1), cit->second); + BMQTST_ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); + BMQTST_ASSERT_EQ_D(i, i, cit->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), cit->second); ++i; } - ASSERT_EQ(true, cit == cmap.begin()); - ASSERT_EQ(i, cit->first); - ASSERT_EQ(cit->second, (i + 1)); + BMQTST_ASSERT_EQ(true, cit == cmap.begin()); + BMQTST_ASSERT_EQ(i, cit->first); + BMQTST_ASSERT_EQ(cit->second, (i + 1)); } } @@ -358,10 +358,10 @@ static void test5_insertEraseInsert() // Insert elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i + 1)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != map.end()); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, (i + 1), rc.first->second); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), rc.first->second); } // Iterate and confirm @@ -369,21 +369,21 @@ static void test5_insertEraseInsert() const MyMapType& cmap = map; size_t i = 0; for (ConstIterType cit = cmap.begin(); cit != cmap.end(); ++cit) { - ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); - ASSERT_EQ_D(i, i, cit->first); - ASSERT_EQ_D(i, (i + 1), cit->second); + BMQTST_ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); + BMQTST_ASSERT_EQ_D(i, i, cit->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), cit->second); ++i; } } // Erase few elements for (size_t i = 0; i < k_NUM_ELEMENTS; i += k_STEP) { - ASSERT_EQ_D(i, 1U, map.erase(i)); + BMQTST_ASSERT_EQ_D(i, 1U, map.erase(i)); } // Find erased elements for (size_t i = 0; i < k_NUM_ELEMENTS; i += k_STEP) { - ASSERT_EQ_D(i, true, map.end() == map.find(i)); + BMQTST_ASSERT_EQ_D(i, true, map.end() == map.find(i)); } // Iterate and confirm @@ -391,9 +391,9 @@ static void test5_insertEraseInsert() const MyMapType& cmap = map; size_t i = 1; for (ConstIterType cit = cmap.begin(); cit != cmap.end(); ++cit) { - ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); - ASSERT_EQ_D(i, i, cit->first); - ASSERT_EQ_D(i, (i + 1), cit->second); + BMQTST_ASSERT_EQ_D(i, true, i < k_NUM_ELEMENTS); + BMQTST_ASSERT_EQ_D(i, i, cit->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), cit->second); ++i; if (i % k_STEP == 0) { ++i; @@ -404,10 +404,10 @@ static void test5_insertEraseInsert() // Insert elements which were erased earlier for (size_t i = 0; i < k_NUM_ELEMENTS; i += k_STEP) { RcType rc = map.insert(bsl::make_pair(i, i + 1)); - ASSERT_EQ_D(i, true, rc.second); - ASSERT_EQ_D(i, true, rc.first != map.end()); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, (i + 1), rc.first->second); + BMQTST_ASSERT_EQ_D(i, true, rc.second); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), rc.first->second); } // Iterate and confirm @@ -417,9 +417,9 @@ static void test5_insertEraseInsert() // Iterate over original elements for (; it != map.end(); ++it) { - ASSERT_EQ_D(i, true, it != map.end()); - ASSERT_EQ_D(i, i, it->first); - ASSERT_EQ_D(i, (i + 1), it->second); + BMQTST_ASSERT_EQ_D(i, true, it != map.end()); + BMQTST_ASSERT_EQ_D(i, i, it->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), it->second); if (it->first == (k_NUM_ELEMENTS - 1)) { ++it; break; @@ -432,13 +432,13 @@ static void test5_insertEraseInsert() // Iterate ove elements inserted after erase operation for (i = 0; i < k_NUM_ELEMENTS; i += k_STEP) { - ASSERT_EQ_D(i, true, it != map.end()); - ASSERT_EQ_D(i, i, it->first); - ASSERT_EQ_D(i, (i + 1), it->second); + BMQTST_ASSERT_EQ_D(i, true, it != map.end()); + BMQTST_ASSERT_EQ_D(i, i, it->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), it->second); ++it; } - ASSERT_EQ(true, it == map.end()); + BMQTST_ASSERT_EQ(true, it == map.end()); } } @@ -455,37 +455,37 @@ static void test6_clear() typedef bsl::pair RcType; MyMapType map(bmqtst::TestHelperUtil::allocator()); - ASSERT_EQ(true, map.empty()); - ASSERT_EQ(true, map.begin() == map.end()); - ASSERT_EQ(0U, map.size()); - ASSERT_EQ(true, map.load_factor() == 0.0); + BMQTST_ASSERT_EQ(true, map.empty()); + BMQTST_ASSERT_EQ(true, map.begin() == map.end()); + BMQTST_ASSERT_EQ(0U, map.size()); + BMQTST_ASSERT_EQ(true, map.load_factor() == 0.0); map.clear(); - ASSERT_EQ(true, map.empty()); - ASSERT_EQ(true, map.begin() == map.end()); - ASSERT_EQ(0U, map.size()); - ASSERT_EQ(true, map.load_factor() == 0.0); + BMQTST_ASSERT_EQ(true, map.empty()); + BMQTST_ASSERT_EQ(true, map.begin() == map.end()); + BMQTST_ASSERT_EQ(0U, map.size()); + BMQTST_ASSERT_EQ(true, map.load_factor() == 0.0); const int k_NUM_ELEMENTS = 100; // Insert elements for (int i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i + 1)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != map.end()); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, (i + 1), rc.first->second); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, (i + 1), rc.first->second); } - ASSERT_EQ(false, map.empty()); - ASSERT_EQ(true, map.begin() != map.end()); - ASSERT_EQ(static_cast(k_NUM_ELEMENTS), map.size()); + BMQTST_ASSERT_EQ(false, map.empty()); + BMQTST_ASSERT_EQ(true, map.begin() != map.end()); + BMQTST_ASSERT_EQ(static_cast(k_NUM_ELEMENTS), map.size()); map.clear(); - ASSERT_EQ(true, map.empty()); - ASSERT_EQ(true, map.begin() == map.end()); - ASSERT_EQ(0U, map.size()); - ASSERT_EQ(true, map.load_factor() == 0.0); + BMQTST_ASSERT_EQ(true, map.empty()); + BMQTST_ASSERT_EQ(true, map.begin() == map.end()); + BMQTST_ASSERT_EQ(0U, map.size()); + BMQTST_ASSERT_EQ(true, map.load_factor() == 0.0); } static void test7_erase() @@ -507,10 +507,10 @@ static void test7_erase() // Insert elements for (int i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != map.end()); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, i, rc.first->second); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, i, rc.first->second); } const MyMapType& cmap = map; @@ -519,8 +519,8 @@ static void test7_erase() map.erase(cit++); } - ASSERT_EQ(0U, map.size()); - ASSERT_EQ(true, map.empty()); + BMQTST_ASSERT_EQ(0U, map.size()); + BMQTST_ASSERT_EQ(true, map.empty()); } static void test8_eraseClear() @@ -545,11 +545,11 @@ static void test8_eraseClear() for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert( bsl::make_pair(TestKeyType(i), TestValueType(i))); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); } - ASSERT_EQ(k_NUM_ELEMENTS, map.size()); + BMQTST_ASSERT_EQ(k_NUM_ELEMENTS, map.size()); // Reset static counters TestKeyType::s_numDeletions = 0; @@ -560,8 +560,8 @@ static void test8_eraseClear() map.erase(it++); } - ASSERT_EQ(TestKeyType::s_numDeletions, k_NUM_ELEMENTS); - ASSERT_EQ(TestValueType::s_numDeletions, k_NUM_ELEMENTS); + BMQTST_ASSERT_EQ(TestKeyType::s_numDeletions, k_NUM_ELEMENTS); + BMQTST_ASSERT_EQ(TestValueType::s_numDeletions, k_NUM_ELEMENTS); } static void test9_insertFailure() @@ -586,15 +586,15 @@ static void test9_insertFailure() // Insert elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, true, rc.second); - ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, true, rc.second); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); } // insert same keys again for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, rc.second, false); - ASSERT_EQ_D(i, true, rc.first == map.find(i)); + BMQTST_ASSERT_EQ_D(i, rc.second, false); + BMQTST_ASSERT_EQ_D(i, true, rc.first == map.find(i)); } } @@ -619,23 +619,23 @@ static void test10_erasureIterator() // Insert elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); } // Find IterType iter = map.find(9000); - ASSERT_EQ(true, iter != map.end()); - ASSERT_EQ(iter->first, 9000U); + BMQTST_ASSERT_EQ(true, iter != map.end()); + BMQTST_ASSERT_EQ(iter->first, 9000U); // erase IterType it = map.erase(iter); - ASSERT_EQ(true, it != map.end()); - ASSERT_EQ(true, it == map.find(9001)); + BMQTST_ASSERT_EQ(true, it != map.end()); + BMQTST_ASSERT_EQ(true, it == map.find(9001)); size_t i = 9001; for (; it != map.end(); ++it) { - ASSERT_EQ_D(i, i, it->first); + BMQTST_ASSERT_EQ_D(i, i, it->first); ++i; } } @@ -668,8 +668,8 @@ static void test11_copyConstructor() // Insert elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = m1p->insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != m1p->end()); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != m1p->end()); } MyMapType m2(*m1p, bmqtst::TestHelperUtil::allocator()); @@ -677,8 +677,8 @@ static void test11_copyConstructor() // Iterate and confirm size_t i = 0; for (ConstIterType cit = m2.begin(); cit != m2.end(); ++cit) { - ASSERT_EQ_D(i, cit->first, i); - ASSERT_EQ_D(i, cit->second, i); + BMQTST_ASSERT_EQ_D(i, cit->first, i); + BMQTST_ASSERT_EQ_D(i, cit->second, i); ++i; } @@ -687,8 +687,8 @@ static void test11_copyConstructor() i = 0; for (ConstIterType cit = m2.begin(); cit != m2.end(); ++cit) { - ASSERT_EQ_D(i, cit->first, i); - ASSERT_EQ_D(i, cit->second, i); + BMQTST_ASSERT_EQ_D(i, cit->first, i); + BMQTST_ASSERT_EQ_D(i, cit->second, i); ++i; } } @@ -722,8 +722,8 @@ static void test12_assignmentOperator() // Insert elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = m1p->insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != m1p->end()); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != m1p->end()); } MyMapType m2(bmqtst::TestHelperUtil::allocator()); @@ -731,8 +731,8 @@ static void test12_assignmentOperator() // Insert elements for (size_t i = k_NUM_ELEMENTS; i > 0; --i) { RcType rc = m2.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != m2.end()); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != m2.end()); } m2 = *m1p; @@ -740,8 +740,8 @@ static void test12_assignmentOperator() // Iterate and confirm size_t i = 0; for (ConstIterType cit = m2.begin(); cit != m2.end(); ++cit) { - ASSERT_EQ_D(i, cit->first, i); - ASSERT_EQ_D(i, cit->second, i); + BMQTST_ASSERT_EQ_D(i, cit->first, i); + BMQTST_ASSERT_EQ_D(i, cit->second, i); ++i; } @@ -749,8 +749,8 @@ static void test12_assignmentOperator() bmqtst::TestHelperUtil::allocator()->deleteObject(m1p); i = 0; for (ConstIterType cit = m2.begin(); cit != m2.end(); ++cit) { - ASSERT_EQ_D(i, cit->first, i); - ASSERT_EQ_D(i, cit->second, i); + BMQTST_ASSERT_EQ_D(i, cit->first, i); + BMQTST_ASSERT_EQ_D(i, cit->second, i); ++i; } } @@ -773,9 +773,9 @@ static void test13_previousEndIterator() MyMapType map(bmqtst::TestHelperUtil::allocator()); const MyMapType& cmap = map; - ASSERT_EQ(true, map.begin() == map.end()); - ASSERT_EQ(true, cmap.begin() == cmap.end()); - ASSERT_EQ(true, cmap.empty()); + BMQTST_ASSERT_EQ(true, map.begin() == map.end()); + BMQTST_ASSERT_EQ(true, cmap.begin() == cmap.end()); + BMQTST_ASSERT_EQ(true, cmap.empty()); IterType endIt = map.end(); ConstIterType endCit = cmap.end(); @@ -783,41 +783,41 @@ static void test13_previousEndIterator() int i = 0; bsl::pair rc = map.insert(bsl::make_pair(i, i * i)); - ASSERT_EQ(true, rc.first == endIt); - ASSERT_EQ(true, rc.first == endCit); + BMQTST_ASSERT_EQ(true, rc.first == endIt); + BMQTST_ASSERT_EQ(true, rc.first == endCit); - ASSERT_EQ(i, endIt->first); - ASSERT_EQ((i * i), endIt->second); + BMQTST_ASSERT_EQ(i, endIt->first); + BMQTST_ASSERT_EQ((i * i), endIt->second); ++i; for (; i < 10000; ++i) { endIt = map.end(); rc = map.insert(bsl::make_pair(i, i * i)); - ASSERT_EQ_D(i, true, rc.first == endIt); - ASSERT_EQ_D(i, i, endIt->first); - ASSERT_EQ_D(i, (i * i), endIt->second); + BMQTST_ASSERT_EQ_D(i, true, rc.first == endIt); + BMQTST_ASSERT_EQ_D(i, i, endIt->first); + BMQTST_ASSERT_EQ_D(i, (i * i), endIt->second); } // Erase last element map.erase(i - 1); - ASSERT_EQ((i - 2), (--map.end())->first); + BMQTST_ASSERT_EQ((i - 2), (--map.end())->first); endIt = map.end(); ++i; rc = map.insert(bsl::make_pair(i, i * i)); - ASSERT_EQ(true, rc.first == endIt); - ASSERT_EQ(i, endIt->first); - ASSERT_EQ((i * i), endIt->second); + BMQTST_ASSERT_EQ(true, rc.first == endIt); + BMQTST_ASSERT_EQ(i, endIt->first); + BMQTST_ASSERT_EQ((i * i), endIt->second); // rinsert an element, which doesn't affect end(). ++i; endIt = map.end(); rc = map.rinsert(bsl::make_pair(i, i * i)); - ASSERT_EQ(true, endIt == map.end()); + BMQTST_ASSERT_EQ(true, endIt == map.end()); ++i; rc = map.insert(bsl::make_pair(i, i * i)); - ASSERT_EQ(true, endIt == rc.first); - ASSERT_EQ(i, endIt->first); - ASSERT_EQ((i * i), endIt->second); + BMQTST_ASSERT_EQ(true, endIt == rc.first); + BMQTST_ASSERT_EQ(i, endIt->first); + BMQTST_ASSERT_EQ((i * i), endIt->second); } static void test14_localIterator() @@ -853,20 +853,20 @@ static void test14_localIterator() LocalIterType localIt = map.begin(bucket); LocalIterType localEndIt = map.end(bucket); - ASSERT_EQ(false, localIt == localEndIt); - ASSERT_EQ(localIt->first, key); - ASSERT_EQ(localIt->second, key * key); + BMQTST_ASSERT_EQ(false, localIt == localEndIt); + BMQTST_ASSERT_EQ(localIt->first, key); + BMQTST_ASSERT_EQ(localIt->second, key * key); ++localIt; - ASSERT_EQ(true, localIt == localEndIt); + BMQTST_ASSERT_EQ(true, localIt == localEndIt); ConstLocalIterType cLocalIt = cmap.begin(bucket); ConstLocalIterType cLocalEndIt = cmap.end(bucket); - ASSERT_EQ(false, cLocalIt == cLocalEndIt); - ASSERT_EQ(cLocalIt->first, key); - ASSERT_EQ(cLocalIt->second, key * key); + BMQTST_ASSERT_EQ(false, cLocalIt == cLocalEndIt); + BMQTST_ASSERT_EQ(cLocalIt->first, key); + BMQTST_ASSERT_EQ(cLocalIt->second, key * key); ++cLocalIt; - ASSERT_EQ(true, cLocalIt == cLocalEndIt); + BMQTST_ASSERT_EQ(true, cLocalIt == cLocalEndIt); // Add keys such that they all map to same bucket in the table, while // ensuring that table is not rehashed. @@ -880,8 +880,8 @@ static void test14_localIterator() key = originalKey; for (; localIt != localEndIt; ++localIt, key += bucketCount) { - ASSERT_EQ(localIt->first, key); - ASSERT_EQ(localIt->second, key * key); + BMQTST_ASSERT_EQ(localIt->first, key); + BMQTST_ASSERT_EQ(localIt->second, key * key); } } @@ -917,37 +917,41 @@ static void test15_eraseRange() // Insert elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, rc.second, true); - ASSERT_EQ_D(i, true, rc.first != map.end()); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, i, rc.first->second); + BMQTST_ASSERT_EQ_D(i, rc.second, true); + BMQTST_ASSERT_EQ_D(i, true, rc.first != map.end()); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, i, rc.first->second); } - ASSERT_EQ(k_NUM_ELEMENTS, map.size()); + BMQTST_ASSERT_EQ(k_NUM_ELEMENTS, map.size()); - ASSERT(map.erase(map.begin(), map.begin()) == map.begin()); - ASSERT_EQ(k_NUM_ELEMENTS, map.size()); + BMQTST_ASSERT(map.erase(map.begin(), map.begin()) == map.begin()); + BMQTST_ASSERT_EQ(k_NUM_ELEMENTS, map.size()); - ASSERT(map.erase(map.end(), map.end()) == map.end()); - ASSERT_EQ(k_NUM_ELEMENTS, map.size()); + BMQTST_ASSERT(map.erase(map.end(), map.end()) == map.end()); + BMQTST_ASSERT_EQ(k_NUM_ELEMENTS, map.size()); ConstIterType second = ++map.begin(); - ASSERT(map.erase(map.begin(), second) == second); - ASSERT(map.begin() == second); - ASSERT_EQ(k_NUM_ELEMENTS - 1, map.size()); - ASSERT_EQ_D(1, 1U, map.begin()->first); - ASSERT_EQ_D(1, 1U, map.begin()->second); - - ASSERT(map.erase(--map.end(), map.end()) == map.end()); - ASSERT_EQ(k_NUM_ELEMENTS - 2, map.size()); - ASSERT_EQ_D(k_NUM_ELEMENTS - 2, k_NUM_ELEMENTS - 2, (--map.end())->first); - ASSERT_EQ_D(k_NUM_ELEMENTS - 2, k_NUM_ELEMENTS - 2, (--map.end())->second); - - ASSERT(map.erase(map.begin(), map.end()) == map.end()); - - ASSERT_EQ(0U, map.size()); - - ASSERT_EQ(true, map.empty()); + BMQTST_ASSERT(map.erase(map.begin(), second) == second); + BMQTST_ASSERT(map.begin() == second); + BMQTST_ASSERT_EQ(k_NUM_ELEMENTS - 1, map.size()); + BMQTST_ASSERT_EQ_D(1, 1U, map.begin()->first); + BMQTST_ASSERT_EQ_D(1, 1U, map.begin()->second); + + BMQTST_ASSERT(map.erase(--map.end(), map.end()) == map.end()); + BMQTST_ASSERT_EQ(k_NUM_ELEMENTS - 2, map.size()); + BMQTST_ASSERT_EQ_D(k_NUM_ELEMENTS - 2, + k_NUM_ELEMENTS - 2, + (--map.end())->first); + BMQTST_ASSERT_EQ_D(k_NUM_ELEMENTS - 2, + k_NUM_ELEMENTS - 2, + (--map.end())->second); + + BMQTST_ASSERT(map.erase(map.begin(), map.end()) == map.end()); + + BMQTST_ASSERT_EQ(0U, map.size()); + + BMQTST_ASSERT_EQ(true, map.empty()); } BSLA_MAYBE_UNUSED @@ -1028,8 +1032,8 @@ BSLA_MAYBE_UNUSED static void testN2_erasePerformanceOrdered() // Insert 1M elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, i, rc.first->second); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, i, rc.first->second); } // Iterate and erase @@ -1066,8 +1070,8 @@ BSLA_MAYBE_UNUSED static void testN2_erasePerformanceUnordered() // Insert 1M elements for (size_t i = 0; i < k_NUM_ELEMENTS; ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, i, rc.first->second); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, i, rc.first->second); } // Iterate and erase @@ -1156,8 +1160,8 @@ testN2_erasePerformanceUnordered_GoogleBenchmark(benchmark::State& state) state.PauseTiming(); for (size_t i = 0; i < static_cast(state.range(0)); ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, i, rc.first->second); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, i, rc.first->second); } // Iterate and erase IterType it = map.begin(); @@ -1186,8 +1190,8 @@ testN2_erasePerformanceOrdered_GoogleBenchmark(benchmark::State& state) state.PauseTiming(); for (size_t i = 0; i < static_cast(state.range(0)); ++i) { RcType rc = map.insert(bsl::make_pair(i, i)); - ASSERT_EQ_D(i, i, rc.first->first); - ASSERT_EQ_D(i, i, rc.first->second); + BMQTST_ASSERT_EQ_D(i, i, rc.first->first); + BMQTST_ASSERT_EQ_D(i, i, rc.first->second); } // Iterate and erase IterType it = map.begin(); diff --git a/src/groups/bmq/bmqc/bmqc_orderedhashmapwithhistory.t.cpp b/src/groups/bmq/bmqc/bmqc_orderedhashmapwithhistory.t.cpp index d034bd8137..443e9e60a9 100644 --- a/src/groups/bmq/bmqc/bmqc_orderedhashmapwithhistory.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_orderedhashmapwithhistory.t.cpp @@ -33,17 +33,17 @@ static void setup(ObjectUnderTest& obj, size_t total, int timeout) for (size_t key = 0; key < total; ++key) { bsl::pair rc = obj.insert(bsl::make_pair(key, key + 1), now); - ASSERT_EQ(true, rc.second); - ASSERT_EQ(true, rc.first != obj.end()); - ASSERT_EQ(true, rc.first == obj.begin() || key); - ASSERT_EQ(key, rc.first->first); - ASSERT_EQ(key + 1, rc.first->second); + BMQTST_ASSERT_EQ(true, rc.second); + BMQTST_ASSERT_EQ(true, rc.first != obj.end()); + BMQTST_ASSERT_EQ(true, rc.first == obj.begin() || key); + BMQTST_ASSERT_EQ(key, rc.first->first); + BMQTST_ASSERT_EQ(key + 1, rc.first->second); - ASSERT_EQ(key + 1, obj.size()); + BMQTST_ASSERT_EQ(key + 1, obj.size()); for (size_t i = 0; i <= key; ++i) { - ASSERT_EQ(true, obj.isInHistory(i)); - ASSERT_EQ(true, obj.find(i) != obj.end()); + BMQTST_ASSERT_EQ(true, obj.isInHistory(i)); + BMQTST_ASSERT_EQ(true, obj.find(i) != obj.end()); } now += timeout; } @@ -98,20 +98,20 @@ static void test2_eraseMiddleToEnd() // erase middle to end for (size_t key = HALF; key < TOTAL; ++key) { - ASSERT_EQ(true, obj.isInHistory(key)); + BMQTST_ASSERT_EQ(true, obj.isInHistory(key)); Iterator it = obj.find(key); - ASSERT_EQ(true, it != obj.end()); + BMQTST_ASSERT_EQ(true, it != obj.end()); obj.erase(it); // should be down by 1 - ASSERT_EQ(TOTAL + HALF - key - 1, obj.size()); + BMQTST_ASSERT_EQ(TOTAL + HALF - key - 1, obj.size()); for (size_t i = HALF; i <= key; ++i) { - ASSERT_EQ(true, obj.isInHistory(i)); - ASSERT_EQ(false, obj.find(i) != obj.end()); + BMQTST_ASSERT_EQ(true, obj.isInHistory(i)); + BMQTST_ASSERT_EQ(false, obj.find(i) != obj.end()); } } @@ -119,8 +119,8 @@ static void test2_eraseMiddleToEnd() bsls::Types::Int64 now = (HALF + 2) * timeout; for (size_t key = HALF; key < TOTAL; ++key, now += timeout) { obj.gc(now); - ASSERT_EQ(false, obj.isInHistory(key)); - ASSERT_EQ(false, obj.find(key) != obj.end()); + BMQTST_ASSERT_EQ(false, obj.isInHistory(key)); + BMQTST_ASSERT_EQ(false, obj.find(key) != obj.end()); } } @@ -152,21 +152,21 @@ static void test3_eraseMiddleToBegin() // erase end to middle for (size_t key = HALF; key-- > 0;) { - ASSERT_EQ(true, obj.isInHistory(key)); - ASSERT_EQ(true, obj.find(key) != obj.end()); + BMQTST_ASSERT_EQ(true, obj.isInHistory(key)); + BMQTST_ASSERT_EQ(true, obj.find(key) != obj.end()); Iterator it = obj.find(key); - ASSERT_EQ(true, it != obj.end()); + BMQTST_ASSERT_EQ(true, it != obj.end()); obj.erase(it); // should be down by 1 - ASSERT_EQ(key + HALF, obj.size()); + BMQTST_ASSERT_EQ(key + HALF, obj.size()); for (size_t i = HALF; i-- > key;) { - ASSERT_EQ(true, obj.isInHistory(i)); - ASSERT_EQ(false, obj.find(i) != obj.end()); + BMQTST_ASSERT_EQ(true, obj.isInHistory(i)); + BMQTST_ASSERT_EQ(false, obj.find(i) != obj.end()); } } @@ -174,8 +174,8 @@ static void test3_eraseMiddleToBegin() bsls::Types::Int64 now = 2 * timeout; for (size_t key = 0; key < HALF; ++key, now += timeout) { obj.gc(now); - ASSERT_EQ(false, obj.isInHistory(key)); - ASSERT_EQ(false, obj.find(key) != obj.end()); + BMQTST_ASSERT_EQ(false, obj.isInHistory(key)); + BMQTST_ASSERT_EQ(false, obj.find(key) != obj.end()); } } @@ -207,45 +207,45 @@ static void test4_gc() // erase end to middle for (size_t key = TOTAL; key-- > HALF;) { - ASSERT_EQ(true, obj.isInHistory(key)); - ASSERT_EQ(true, obj.find(key) != obj.end()); + BMQTST_ASSERT_EQ(true, obj.isInHistory(key)); + BMQTST_ASSERT_EQ(true, obj.find(key) != obj.end()); Iterator it = obj.find(key); - ASSERT_EQ(true, it != obj.end()); + BMQTST_ASSERT_EQ(true, it != obj.end()); obj.erase(it, 1 * timeout); // 'it' is not expired yet // should be down by 1 - ASSERT_EQ(key, obj.size()); + BMQTST_ASSERT_EQ(key, obj.size()); for (size_t i = TOTAL; i-- > key;) { - ASSERT_EQ(true, obj.isInHistory(i)); - ASSERT_EQ(false, obj.find(i) != obj.end()); + BMQTST_ASSERT_EQ(true, obj.isInHistory(i)); + BMQTST_ASSERT_EQ(false, obj.find(i) != obj.end()); } } // erase middle to begin for (size_t key = HALF; key-- > 0;) { - ASSERT_EQ(true, obj.isInHistory(key)); - ASSERT_EQ(true, obj.find(key) != obj.end()); + BMQTST_ASSERT_EQ(true, obj.isInHistory(key)); + BMQTST_ASSERT_EQ(true, obj.find(key) != obj.end()); Iterator it = obj.find(key); - ASSERT_EQ(true, it != obj.end()); + BMQTST_ASSERT_EQ(true, it != obj.end()); obj.erase(it, (TOTAL + 1) * timeout); // 'it' is expired // should be down by 1 - ASSERT_EQ(key, obj.size()); + BMQTST_ASSERT_EQ(key, obj.size()); for (size_t i = HALF; i-- > key;) { - ASSERT_EQ(false, obj.isInHistory(i)); - ASSERT_EQ(false, obj.find(i) != obj.end()); + BMQTST_ASSERT_EQ(false, obj.isInHistory(i)); + BMQTST_ASSERT_EQ(false, obj.find(i) != obj.end()); } } - ASSERT_EQ(0U, obj.size()); + BMQTST_ASSERT_EQ(0U, obj.size()); } static void test5_insertAfterEnd() @@ -273,14 +273,14 @@ static void test5_insertAfterEnd() Iterator begin = obj.begin(); Iterator end = obj.end(); - ASSERT(begin == end); + BMQTST_ASSERT(begin == end); setup(obj, 1, timeout); - ASSERT(begin == end); - ASSERT(end != obj.end()); - ASSERT_EQ(0U, end->first); // key - ASSERT_EQ(1U, end->second); // value + BMQTST_ASSERT(begin == end); + BMQTST_ASSERT(end != obj.end()); + BMQTST_ASSERT_EQ(0U, end->first); // key + BMQTST_ASSERT_EQ(1U, end->second); // value } static void test6_eraseThenGc() diff --git a/src/groups/bmq/bmqc/bmqc_twokeyhashmap.t.cpp b/src/groups/bmq/bmqc/bmqc_twokeyhashmap.t.cpp index 04b440d2b5..6c1e7cc1cc 100644 --- a/src/groups/bmq/bmqc/bmqc_twokeyhashmap.t.cpp +++ b/src/groups/bmq/bmqc/bmqc_twokeyhashmap.t.cpp @@ -198,7 +198,7 @@ static void test0_usageExample() map.insert("first", 1, "Hello"); // size - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.size(), 1u); bsl::pair p = map.insert("second", 2, "World"); @@ -206,7 +206,7 @@ static void test0_usageExample() BSLS_ASSERT(p.first != map.end()); // size - ASSERT_EQ(map.size(), 2u); + BMQTST_ASSERT_EQ(map.size(), 2u); // find elements using 'findByKey()' methods { @@ -250,9 +250,9 @@ static void test0_usageExample() // clearing the map { map.clear(); - ASSERT_EQ(map.size(), 0u); - ASSERT(map.begin() == map.end()); - ASSERT(map.begin() == map.end()); + BMQTST_ASSERT_EQ(map.size(), 0u); + BMQTST_ASSERT(map.begin() == map.end()); + BMQTST_ASSERT(map.begin() == map.end()); } } @@ -295,12 +295,12 @@ static void test1_basicCreators() bmqc::TwoKeyHashMap, TestHasher > map(&alloc); - ASSERT_EQ(map.empty(), true); - ASSERT_EQ(map.size(), 0u); - ASSERT_EQ(map.begin() == map.end(), true); - ASSERT_EQ(map.hash1().id(), 0); - ASSERT_EQ(map.hash2().id(), 0); - ASSERT_EQ(map.allocator() == &alloc, true); + BMQTST_ASSERT_EQ(map.empty(), true); + BMQTST_ASSERT_EQ(map.size(), 0u); + BMQTST_ASSERT_EQ(map.begin() == map.end(), true); + BMQTST_ASSERT_EQ(map.hash1().id(), 0); + BMQTST_ASSERT_EQ(map.hash2().id(), 0); + BMQTST_ASSERT_EQ(map.allocator() == &alloc, true); } // 3. one-hasher constructor @@ -308,12 +308,12 @@ static void test1_basicCreators() bmqc::TwoKeyHashMap, TestHasher > map(TestHasher(1), &alloc); - ASSERT_EQ(map.empty(), true); - ASSERT_EQ(map.size(), 0u); - ASSERT_EQ(map.begin() == map.end(), true); - ASSERT_EQ(map.hash1().id(), 1); - ASSERT_EQ(map.hash2().id(), 0); - ASSERT_EQ(map.allocator() == &alloc, true); + BMQTST_ASSERT_EQ(map.empty(), true); + BMQTST_ASSERT_EQ(map.size(), 0u); + BMQTST_ASSERT_EQ(map.begin() == map.end(), true); + BMQTST_ASSERT_EQ(map.hash1().id(), 1); + BMQTST_ASSERT_EQ(map.hash2().id(), 0); + BMQTST_ASSERT_EQ(map.allocator() == &alloc, true); } // 4. two-hasher constructor @@ -321,12 +321,12 @@ static void test1_basicCreators() bmqc::TwoKeyHashMap, TestHasher > map(TestHasher(1), TestHasher(2), &alloc); - ASSERT_EQ(map.empty(), true); - ASSERT_EQ(map.size(), 0u); - ASSERT_EQ(map.begin() == map.end(), true); - ASSERT_EQ(map.hash1().id(), 1); - ASSERT_EQ(map.hash2().id(), 2); - ASSERT_EQ(map.allocator() == &alloc, true); + BMQTST_ASSERT_EQ(map.empty(), true); + BMQTST_ASSERT_EQ(map.size(), 0u); + BMQTST_ASSERT_EQ(map.begin() == map.end(), true); + BMQTST_ASSERT_EQ(map.hash1().id(), 1); + BMQTST_ASSERT_EQ(map.hash2().id(), 2); + BMQTST_ASSERT_EQ(map.allocator() == &alloc, true); } } @@ -374,13 +374,13 @@ static void test2_copyAndMove() original.insert(4, "forth", "value4"); original.insert(5, "fifth", "value5"); - ASSERT_EQ(original.size(), 5u); - ASSERT_EQ(original.findByKey1(1) != original.end() && - original.findByKey1(2) != original.end() && - original.findByKey1(3) != original.end() && - original.findByKey1(4) != original.end() && - original.findByKey1(5) != original.end(), - true); + BMQTST_ASSERT_EQ(original.size(), 5u); + BMQTST_ASSERT_EQ(original.findByKey1(1) != original.end() && + original.findByKey1(2) != original.end() && + original.findByKey1(3) != original.end() && + original.findByKey1(4) != original.end() && + original.findByKey1(5) != original.end(), + true); // 1. copy construction { @@ -388,27 +388,27 @@ static void test2_copyAndMove() Map copy(original, &alloc); // the copy's contents is identical to original's - ASSERT_EQ(copy.size(), 5u); + BMQTST_ASSERT_EQ(copy.size(), 5u); - ASSERT_EQ(copy.findByKey1(1) != copy.end() && - *original.findByKey1(1) == *copy.findByKey1(1), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(1) != copy.end() && + *original.findByKey1(1) == *copy.findByKey1(1), + true); - ASSERT_EQ(copy.findByKey1(2) != copy.end() && - *original.findByKey1(2) == *copy.findByKey1(2), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(2) != copy.end() && + *original.findByKey1(2) == *copy.findByKey1(2), + true); - ASSERT_EQ(copy.findByKey1(3) != copy.end() && - *original.findByKey1(3) == *copy.findByKey1(3), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(3) != copy.end() && + *original.findByKey1(3) == *copy.findByKey1(3), + true); - ASSERT_EQ(copy.findByKey1(4) != copy.end() && - *original.findByKey1(4) == *copy.findByKey1(4), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(4) != copy.end() && + *original.findByKey1(4) == *copy.findByKey1(4), + true); - ASSERT_EQ(copy.findByKey1(5) != copy.end() && - *original.findByKey1(5) == *copy.findByKey1(5), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(5) != copy.end() && + *original.findByKey1(5) == *copy.findByKey1(5), + true); } // 2. move construction @@ -420,27 +420,27 @@ static void test2_copyAndMove() Map movedTo(bslmf::MovableRefUtil::move(movedFrom), &alloc); // the moved-to object contents is identical to original's - ASSERT_EQ(movedTo.size(), 5u); + BMQTST_ASSERT_EQ(movedTo.size(), 5u); - ASSERT_EQ(movedTo.findByKey1(1) != movedTo.end() && - *original.findByKey1(1) == *movedTo.findByKey1(1), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(1) != movedTo.end() && + *original.findByKey1(1) == *movedTo.findByKey1(1), + true); - ASSERT_EQ(movedTo.findByKey1(2) != movedTo.end() && - *original.findByKey1(2) == *movedTo.findByKey1(2), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(2) != movedTo.end() && + *original.findByKey1(2) == *movedTo.findByKey1(2), + true); - ASSERT_EQ(movedTo.findByKey1(3) != movedTo.end() && - *original.findByKey1(3) == *movedTo.findByKey1(3), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(3) != movedTo.end() && + *original.findByKey1(3) == *movedTo.findByKey1(3), + true); - ASSERT_EQ(movedTo.findByKey1(4) != movedTo.end() && - *original.findByKey1(4) == *movedTo.findByKey1(4), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(4) != movedTo.end() && + *original.findByKey1(4) == *movedTo.findByKey1(4), + true); - ASSERT_EQ(movedTo.findByKey1(5) != movedTo.end() && - *original.findByKey1(5) == *movedTo.findByKey1(5), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(5) != movedTo.end() && + *original.findByKey1(5) == *movedTo.findByKey1(5), + true); } // 3. copy assignment @@ -450,33 +450,33 @@ static void test2_copyAndMove() // insert elements into copy copy.insert(1, "first", "value1"); copy.insert(999, "999-th", "value999"); - ASSERT_EQ(copy.size(), 2u); + BMQTST_ASSERT_EQ(copy.size(), 2u); // do copy copy = original; // the copy's contents is identical to original's - ASSERT_EQ(copy.size(), 5u); + BMQTST_ASSERT_EQ(copy.size(), 5u); - ASSERT_EQ(copy.findByKey1(1) != copy.end() && - *original.findByKey1(1) == *copy.findByKey1(1), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(1) != copy.end() && + *original.findByKey1(1) == *copy.findByKey1(1), + true); - ASSERT_EQ(copy.findByKey1(2) != copy.end() && - *original.findByKey1(2) == *copy.findByKey1(2), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(2) != copy.end() && + *original.findByKey1(2) == *copy.findByKey1(2), + true); - ASSERT_EQ(copy.findByKey1(3) != copy.end() && - *original.findByKey1(3) == *copy.findByKey1(3), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(3) != copy.end() && + *original.findByKey1(3) == *copy.findByKey1(3), + true); - ASSERT_EQ(copy.findByKey1(4) != copy.end() && - *original.findByKey1(4) == *copy.findByKey1(4), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(4) != copy.end() && + *original.findByKey1(4) == *copy.findByKey1(4), + true); - ASSERT_EQ(copy.findByKey1(5) != copy.end() && - *original.findByKey1(5) == *copy.findByKey1(5), - true); + BMQTST_ASSERT_EQ(copy.findByKey1(5) != copy.end() && + *original.findByKey1(5) == *copy.findByKey1(5), + true); } // 4. move assignment @@ -489,33 +489,33 @@ static void test2_copyAndMove() // insert elements into 'movedTo' movedTo.insert(1, "first", "value1"); movedTo.insert(999, "999-th", "value999"); - ASSERT_EQ(movedTo.size(), 2u); + BMQTST_ASSERT_EQ(movedTo.size(), 2u); // do move movedTo = bslmf::MovableRefUtil::move(movedFrom); // the moved-to object contents is identical to original's - ASSERT_EQ(movedTo.size(), 5u); + BMQTST_ASSERT_EQ(movedTo.size(), 5u); - ASSERT_EQ(movedTo.findByKey1(1) != movedTo.end() && - *original.findByKey1(1) == *movedTo.findByKey1(1), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(1) != movedTo.end() && + *original.findByKey1(1) == *movedTo.findByKey1(1), + true); - ASSERT_EQ(movedTo.findByKey1(2) != movedTo.end() && - *original.findByKey1(2) == *movedTo.findByKey1(2), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(2) != movedTo.end() && + *original.findByKey1(2) == *movedTo.findByKey1(2), + true); - ASSERT_EQ(movedTo.findByKey1(3) != movedTo.end() && - *original.findByKey1(3) == *movedTo.findByKey1(3), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(3) != movedTo.end() && + *original.findByKey1(3) == *movedTo.findByKey1(3), + true); - ASSERT_EQ(movedTo.findByKey1(4) != movedTo.end() && - *original.findByKey1(4) == *movedTo.findByKey1(4), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(4) != movedTo.end() && + *original.findByKey1(4) == *movedTo.findByKey1(4), + true); - ASSERT_EQ(movedTo.findByKey1(5) != movedTo.end() && - *original.findByKey1(5) == *movedTo.findByKey1(5), - true); + BMQTST_ASSERT_EQ(movedTo.findByKey1(5) != movedTo.end() && + *original.findByKey1(5) == *movedTo.findByKey1(5), + true); } } @@ -585,16 +585,16 @@ static void test3_insert() Map::iterator iterator1 = pair1.first; // element inserted - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(result1, Map::e_INSERTED); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(result1, Map::e_INSERTED); // returned iterator refers to the inserted element and is bound to the // first key - ASSERT_EQ(iterator1 == map.end(), false); - ASSERT_EQ(iterator1.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(iterator1->key1(), 1); - ASSERT_EQ(iterator1->key2(), "first"); - ASSERT_EQ(iterator1->value(), "value1"); + BMQTST_ASSERT_EQ(iterator1 == map.end(), false); + BMQTST_ASSERT_EQ(iterator1.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(iterator1->key1(), 1); + BMQTST_ASSERT_EQ(iterator1->key2(), "first"); + BMQTST_ASSERT_EQ(iterator1->value(), "value1"); // insert second element InsertPair pair2 = @@ -604,22 +604,22 @@ static void test3_insert() Map::iterator iterator2 = pair2.first; // element inserted - ASSERT_EQ(map.size(), 2u); - ASSERT_EQ(result2, Map::e_INSERTED); + BMQTST_ASSERT_EQ(map.size(), 2u); + BMQTST_ASSERT_EQ(result2, Map::e_INSERTED); // returned iterator refers to the inserted element and is bound to the // second key - ASSERT_EQ(iterator2 == map.end(), false); - ASSERT_EQ(iterator2.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(iterator2->key1(), 2); - ASSERT_EQ(iterator2->key2(), "second"); - ASSERT_EQ(iterator2->value(), "value2"); + BMQTST_ASSERT_EQ(iterator2 == map.end(), false); + BMQTST_ASSERT_EQ(iterator2.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(iterator2->key1(), 2); + BMQTST_ASSERT_EQ(iterator2->key2(), "second"); + BMQTST_ASSERT_EQ(iterator2->value(), "value2"); // the first element is intact - ASSERT_EQ(map.size(), 2u); - ASSERT_EQ(iterator1->key1(), 1); - ASSERT_EQ(iterator1->key2(), "first"); - ASSERT_EQ(iterator1->value(), "value1"); + BMQTST_ASSERT_EQ(map.size(), 2u); + BMQTST_ASSERT_EQ(iterator1->key1(), 1); + BMQTST_ASSERT_EQ(iterator1->key2(), "first"); + BMQTST_ASSERT_EQ(iterator1->value(), "value1"); } // 2. first key already exists @@ -636,19 +636,19 @@ static void test3_insert() map.insert(1, "second", "value2", Map::e_SECOND_KEY); // nothing inserted - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.size(), 1u); // check returned values and that the map contents hasn't changed Map::InsertResult result = pair.second; Map::iterator iterator = pair.first; - ASSERT_EQ(result, Map::e_FIRST_KEY_EXISTS); + BMQTST_ASSERT_EQ(result, Map::e_FIRST_KEY_EXISTS); - ASSERT_EQ(iterator == map.end(), false); - ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(iterator->key1(), 1); - ASSERT_EQ(iterator->key2(), "first"); - ASSERT_EQ(iterator->value(), "value1"); + BMQTST_ASSERT_EQ(iterator == map.end(), false); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(iterator->key1(), 1); + BMQTST_ASSERT_EQ(iterator->key2(), "first"); + BMQTST_ASSERT_EQ(iterator->value(), "value1"); } // 3. second key already exists @@ -668,13 +668,13 @@ static void test3_insert() Map::InsertResult result = pair.second; Map::iterator iterator = pair.first; - ASSERT_EQ(result, Map::e_SECOND_KEY_EXISTS); + BMQTST_ASSERT_EQ(result, Map::e_SECOND_KEY_EXISTS); - ASSERT_EQ(iterator == map.end(), false); - ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(iterator->key1(), 1); - ASSERT_EQ(iterator->key2(), "first"); - ASSERT_EQ(iterator->value(), "value1"); + BMQTST_ASSERT_EQ(iterator == map.end(), false); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(iterator->key1(), 1); + BMQTST_ASSERT_EQ(iterator->key2(), "first"); + BMQTST_ASSERT_EQ(iterator->value(), "value1"); } // 4. check exception safety @@ -703,13 +703,13 @@ static void test3_insert() } // an exception was thrown - ASSERT_EQ(exceptionThrown, true); + BMQTST_ASSERT_EQ(exceptionThrown, true); // the map state hasn't changed - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(map.begin()->key1().value(), 0); - ASSERT_EQ(map.begin()->key2().value(), 0); - ASSERT_EQ(map.begin()->value().value(), 0); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.begin()->key1().value(), 0); + BMQTST_ASSERT_EQ(map.begin()->key2().value(), 0); + BMQTST_ASSERT_EQ(map.begin()->value().value(), 0); // try inserting another element, given that the second key copy // constructor throws @@ -724,13 +724,13 @@ static void test3_insert() } // an exception was thrown - ASSERT_EQ(exceptionThrown, true); + BMQTST_ASSERT_EQ(exceptionThrown, true); // the map state hasn't changed - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(map.begin()->key1().value(), 0); - ASSERT_EQ(map.begin()->key2().value(), 0); - ASSERT_EQ(map.begin()->value().value(), 0); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.begin()->key1().value(), 0); + BMQTST_ASSERT_EQ(map.begin()->key2().value(), 0); + BMQTST_ASSERT_EQ(map.begin()->value().value(), 0); // try inserting another element, given that the value copy // constructor throws @@ -745,13 +745,13 @@ static void test3_insert() } // an exception was thrown - ASSERT_EQ(exceptionThrown, true); + BMQTST_ASSERT_EQ(exceptionThrown, true); // the map state hasn't changed - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(map.begin()->key1().value(), 0); - ASSERT_EQ(map.begin()->key2().value(), 0); - ASSERT_EQ(map.begin()->value().value(), 0); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.begin()->key1().value(), 0); + BMQTST_ASSERT_EQ(map.begin()->key2().value(), 0); + BMQTST_ASSERT_EQ(map.begin()->value().value(), 0); } } @@ -812,7 +812,7 @@ static void test4_erase() map.insert(3, "third", "value3"); map.insert(4, "forth", "value4"); map.insert(5, "fifth", "value5"); - ASSERT_EQ(map.size(), 5u); + BMQTST_ASSERT_EQ(map.size(), 5u); // make a list of elements ordered according to the first key it = map.begin(Map::e_FIRST_KEY); @@ -834,9 +834,9 @@ static void test4_erase() // find element with first key equal to 3 Map::iterator erased = map.findByKey1(3); - ASSERT_EQ(erased == map.end(), false) - ASSERT_EQ(erased->key1(), 3); - ASSERT_EQ(erased.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(erased == map.end(), false) + BMQTST_ASSERT_EQ(erased->key1(), 3); + BMQTST_ASSERT_EQ(erased.keyIndex(), Map::e_FIRST_KEY); const Map::value_type* erased_p = &*erased; @@ -844,42 +844,52 @@ static void test4_erase() map.erase(erased); // element removed - ASSERT_EQ(map.size(), 4u); - ASSERT_EQ(map.findByKey1(3) == map.end(), true); + BMQTST_ASSERT_EQ(map.size(), 4u); + BMQTST_ASSERT_EQ(map.findByKey1(3) == map.end(), true); // order of remaining elements indexed by the first key hasn't changed it = map.begin(Map::e_FIRST_KEY); - ASSERT_EQ(elementsByKey1[0] == erased_p || elementsByKey1[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[0] == erased_p || + elementsByKey1[0] == &*it++, + true); - ASSERT_EQ(elementsByKey1[1] == erased_p || elementsByKey1[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[1] == erased_p || + elementsByKey1[1] == &*it++, + true); - ASSERT_EQ(elementsByKey1[2] == erased_p || elementsByKey1[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[2] == erased_p || + elementsByKey1[2] == &*it++, + true); - ASSERT_EQ(elementsByKey1[3] == erased_p || elementsByKey1[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[3] == erased_p || + elementsByKey1[3] == &*it++, + true); - ASSERT_EQ(elementsByKey1[4] == erased_p || elementsByKey1[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[4] == erased_p || + elementsByKey1[4] == &*it++, + true); // order of remaining elements indexed by the second key hasn't changed it = map.begin(Map::e_SECOND_KEY); - ASSERT_EQ(elementsByKey2[0] == erased_p || elementsByKey2[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[0] == erased_p || + elementsByKey2[0] == &*it++, + true); - ASSERT_EQ(elementsByKey2[1] == erased_p || elementsByKey2[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[1] == erased_p || + elementsByKey2[1] == &*it++, + true); - ASSERT_EQ(elementsByKey2[2] == erased_p || elementsByKey2[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[2] == erased_p || + elementsByKey2[2] == &*it++, + true); - ASSERT_EQ(elementsByKey2[3] == erased_p || elementsByKey2[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[3] == erased_p || + elementsByKey2[3] == &*it++, + true); - ASSERT_EQ(elementsByKey2[4] == erased_p || elementsByKey2[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[4] == erased_p || + elementsByKey2[4] == &*it++, + true); } // 2. erase by iterator bound to second key @@ -893,7 +903,7 @@ static void test4_erase() map.insert(3, "third", "value3"); map.insert(4, "forth", "value4"); map.insert(5, "fifth", "value5"); - ASSERT_EQ(map.size(), 5u); + BMQTST_ASSERT_EQ(map.size(), 5u); // make a list of elements ordered according to the first key it = map.begin(Map::e_FIRST_KEY); @@ -915,9 +925,9 @@ static void test4_erase() // find element with second key equal to "third" Map::iterator erased = map.findByKey2("third"); - ASSERT_EQ(erased == map.end(), false) - ASSERT_EQ(erased->key2(), "third"); - ASSERT_EQ(erased.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(erased == map.end(), false) + BMQTST_ASSERT_EQ(erased->key2(), "third"); + BMQTST_ASSERT_EQ(erased.keyIndex(), Map::e_SECOND_KEY); const Map::value_type* erased_p = &*erased; @@ -925,42 +935,52 @@ static void test4_erase() map.erase(erased); // element removed - ASSERT_EQ(map.size(), 4u); - ASSERT_EQ(map.findByKey2("third") == map.end(), true); + BMQTST_ASSERT_EQ(map.size(), 4u); + BMQTST_ASSERT_EQ(map.findByKey2("third") == map.end(), true); // order of remaining elements indexed by the first key hasn't changed it = map.begin(Map::e_FIRST_KEY); - ASSERT_EQ(elementsByKey1[0] == erased_p || elementsByKey1[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[0] == erased_p || + elementsByKey1[0] == &*it++, + true); - ASSERT_EQ(elementsByKey1[1] == erased_p || elementsByKey1[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[1] == erased_p || + elementsByKey1[1] == &*it++, + true); - ASSERT_EQ(elementsByKey1[2] == erased_p || elementsByKey1[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[2] == erased_p || + elementsByKey1[2] == &*it++, + true); - ASSERT_EQ(elementsByKey1[3] == erased_p || elementsByKey1[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[3] == erased_p || + elementsByKey1[3] == &*it++, + true); - ASSERT_EQ(elementsByKey1[4] == erased_p || elementsByKey1[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[4] == erased_p || + elementsByKey1[4] == &*it++, + true); // order of remaining elements indexed by the second key hasn't changed it = map.begin(Map::e_SECOND_KEY); - ASSERT_EQ(elementsByKey2[0] == erased_p || elementsByKey2[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[0] == erased_p || + elementsByKey2[0] == &*it++, + true); - ASSERT_EQ(elementsByKey2[1] == erased_p || elementsByKey2[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[1] == erased_p || + elementsByKey2[1] == &*it++, + true); - ASSERT_EQ(elementsByKey2[2] == erased_p || elementsByKey2[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[2] == erased_p || + elementsByKey2[2] == &*it++, + true); - ASSERT_EQ(elementsByKey2[3] == erased_p || elementsByKey2[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[3] == erased_p || + elementsByKey2[3] == &*it++, + true); - ASSERT_EQ(elementsByKey2[4] == erased_p || elementsByKey2[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[4] == erased_p || + elementsByKey2[4] == &*it++, + true); } // 3. check return value when erasing by an iterator bound to the first key @@ -974,7 +994,7 @@ static void test4_erase() map.insert(3, "third", "value3"); map.insert(4, "forth", "value4"); map.insert(5, "fifth", "value5"); - ASSERT_EQ(map.size(), 5u); + BMQTST_ASSERT_EQ(map.size(), 5u); while (!map.empty()) { // erase first element, as ordered by the first key @@ -982,8 +1002,9 @@ static void test4_erase() map.begin(Map::e_FIRST_KEY)); // 'erase()' returned an iterator to the next element - ASSERT_EQ(nextAfterErased == map.begin(Map::e_FIRST_KEY), true); - ASSERT_EQ(nextAfterErased.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(nextAfterErased == map.begin(Map::e_FIRST_KEY), + true); + BMQTST_ASSERT_EQ(nextAfterErased.keyIndex(), Map::e_FIRST_KEY); } } @@ -999,7 +1020,7 @@ static void test4_erase() map.insert(3, "third", "value3"); map.insert(4, "forth", "value4"); map.insert(5, "fifth", "value5"); - ASSERT_EQ(map.size(), 5u); + BMQTST_ASSERT_EQ(map.size(), 5u); while (!map.empty()) { // erase first element, as ordered by the second key @@ -1007,8 +1028,9 @@ static void test4_erase() map.begin(Map::e_SECOND_KEY)); // 'erase()' returned an iterator to the next element - ASSERT_EQ(nextAfterErased == map.begin(Map::e_SECOND_KEY), true); - ASSERT_EQ(nextAfterErased.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(nextAfterErased == map.begin(Map::e_SECOND_KEY), + true); + BMQTST_ASSERT_EQ(nextAfterErased.keyIndex(), Map::e_SECOND_KEY); } } } @@ -1056,7 +1078,7 @@ static void test5_eraseByKey1() map.insert(3, "third", "value3"); map.insert(4, "forth", "value4"); map.insert(5, "fifth", "value5"); - ASSERT_EQ(map.size(), 5u); + BMQTST_ASSERT_EQ(map.size(), 5u); // make a list of elements ordered according to the first key it = map.begin(Map::e_FIRST_KEY); @@ -1078,8 +1100,8 @@ static void test5_eraseByKey1() // find element with first key equal to 3 Map::iterator erased = map.findByKey1(3); - ASSERT_EQ(erased == map.end(), false) - ASSERT_EQ(erased->key1(), 3); + BMQTST_ASSERT_EQ(erased == map.end(), false) + BMQTST_ASSERT_EQ(erased->key1(), 3); const Map::value_type* erased_p = &*erased; @@ -1087,45 +1109,55 @@ static void test5_eraseByKey1() int eraseRc = map.eraseByKey1(3); // return value is 0 - ASSERT_EQ(eraseRc, 0); + BMQTST_ASSERT_EQ(eraseRc, 0); // element removed - ASSERT_EQ(map.size(), 4u); - ASSERT_EQ(map.findByKey1(3) == map.end(), true); + BMQTST_ASSERT_EQ(map.size(), 4u); + BMQTST_ASSERT_EQ(map.findByKey1(3) == map.end(), true); // order of remaining elements indexed by the first key hasn't changed it = map.begin(Map::e_FIRST_KEY); - ASSERT_EQ(elementsByKey1[0] == erased_p || elementsByKey1[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[0] == erased_p || + elementsByKey1[0] == &*it++, + true); - ASSERT_EQ(elementsByKey1[1] == erased_p || elementsByKey1[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[1] == erased_p || + elementsByKey1[1] == &*it++, + true); - ASSERT_EQ(elementsByKey1[2] == erased_p || elementsByKey1[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[2] == erased_p || + elementsByKey1[2] == &*it++, + true); - ASSERT_EQ(elementsByKey1[3] == erased_p || elementsByKey1[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[3] == erased_p || + elementsByKey1[3] == &*it++, + true); - ASSERT_EQ(elementsByKey1[4] == erased_p || elementsByKey1[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[4] == erased_p || + elementsByKey1[4] == &*it++, + true); // order of remaining elements indexed by the second key hasn't changed it = map.begin(Map::e_SECOND_KEY); - ASSERT_EQ(elementsByKey2[0] == erased_p || elementsByKey2[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[0] == erased_p || + elementsByKey2[0] == &*it++, + true); - ASSERT_EQ(elementsByKey2[1] == erased_p || elementsByKey2[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[1] == erased_p || + elementsByKey2[1] == &*it++, + true); - ASSERT_EQ(elementsByKey2[2] == erased_p || elementsByKey2[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[2] == erased_p || + elementsByKey2[2] == &*it++, + true); - ASSERT_EQ(elementsByKey2[3] == erased_p || elementsByKey2[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[3] == erased_p || + elementsByKey2[3] == &*it++, + true); - ASSERT_EQ(elementsByKey2[4] == erased_p || elementsByKey2[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[4] == erased_p || + elementsByKey2[4] == &*it++, + true); } // 2. erase by first key, which doesn't exist @@ -1136,19 +1168,19 @@ static void test5_eraseByKey1() // insert elements map.insert(1, "first", "value1"); - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.size(), 1u); // try erasing by key that doesn't exist int eraseRc = map.eraseByKey1(2); // returned value is non-zero - ASSERT_NE(eraseRc, 0); + BMQTST_ASSERT_NE(eraseRc, 0); // the map is intact - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(map.begin()->key1(), 1); - ASSERT_EQ(map.begin()->key2(), "first"); - ASSERT_EQ(map.begin()->value(), "value1"); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.begin()->key1(), 1); + BMQTST_ASSERT_EQ(map.begin()->key2(), "first"); + BMQTST_ASSERT_EQ(map.begin()->value(), "value1"); } // 3. erase by first key, which exists, but throws on comparison @@ -1160,7 +1192,7 @@ static void test5_eraseByKey1() // insert elements map.insert(1, "first", "value1"); - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.size(), 1u); bool exceptionThrown = false; @@ -1173,13 +1205,13 @@ static void test5_eraseByKey1() } // exception was thrown - ASSERT_EQ(exceptionThrown, true); + BMQTST_ASSERT_EQ(exceptionThrown, true); // the map is intact - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(map.begin()->key1().value(), 1); - ASSERT_EQ(map.begin()->key2(), "first"); - ASSERT_EQ(map.begin()->value(), "value1"); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.begin()->key1().value(), 1); + BMQTST_ASSERT_EQ(map.begin()->key2(), "first"); + BMQTST_ASSERT_EQ(map.begin()->value(), "value1"); } } @@ -1226,7 +1258,7 @@ static void test6_eraseByKey2() map.insert(3, "third", "value3"); map.insert(4, "forth", "value4"); map.insert(5, "fifth", "value5"); - ASSERT_EQ(map.size(), 5u); + BMQTST_ASSERT_EQ(map.size(), 5u); // make a list of elements ordered according to the first key it = map.begin(Map::e_FIRST_KEY); @@ -1248,8 +1280,8 @@ static void test6_eraseByKey2() // find element with second key equal to "third" Map::iterator erased = map.findByKey2("third"); - ASSERT_EQ(erased == map.end(), false) - ASSERT_EQ(erased->key2(), "third"); + BMQTST_ASSERT_EQ(erased == map.end(), false) + BMQTST_ASSERT_EQ(erased->key2(), "third"); const Map::value_type* erased_p = &*erased; @@ -1257,45 +1289,55 @@ static void test6_eraseByKey2() int eraseRc = map.eraseByKey2("third"); // return value is 0 - ASSERT_EQ(eraseRc, 0); + BMQTST_ASSERT_EQ(eraseRc, 0); // element removed - ASSERT_EQ(map.size(), 4u); - ASSERT_EQ(map.findByKey2("third") == map.end(), true); + BMQTST_ASSERT_EQ(map.size(), 4u); + BMQTST_ASSERT_EQ(map.findByKey2("third") == map.end(), true); // order of remaining elements indexed by the first key hasn't changed it = map.begin(Map::e_FIRST_KEY); - ASSERT_EQ(elementsByKey1[0] == erased_p || elementsByKey1[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[0] == erased_p || + elementsByKey1[0] == &*it++, + true); - ASSERT_EQ(elementsByKey1[1] == erased_p || elementsByKey1[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[1] == erased_p || + elementsByKey1[1] == &*it++, + true); - ASSERT_EQ(elementsByKey1[2] == erased_p || elementsByKey1[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[2] == erased_p || + elementsByKey1[2] == &*it++, + true); - ASSERT_EQ(elementsByKey1[3] == erased_p || elementsByKey1[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[3] == erased_p || + elementsByKey1[3] == &*it++, + true); - ASSERT_EQ(elementsByKey1[4] == erased_p || elementsByKey1[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey1[4] == erased_p || + elementsByKey1[4] == &*it++, + true); // order of remaining elements indexed by the second key hasn't changed it = map.begin(Map::e_SECOND_KEY); - ASSERT_EQ(elementsByKey2[0] == erased_p || elementsByKey2[0] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[0] == erased_p || + elementsByKey2[0] == &*it++, + true); - ASSERT_EQ(elementsByKey2[1] == erased_p || elementsByKey2[1] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[1] == erased_p || + elementsByKey2[1] == &*it++, + true); - ASSERT_EQ(elementsByKey2[2] == erased_p || elementsByKey2[2] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[2] == erased_p || + elementsByKey2[2] == &*it++, + true); - ASSERT_EQ(elementsByKey2[3] == erased_p || elementsByKey2[3] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[3] == erased_p || + elementsByKey2[3] == &*it++, + true); - ASSERT_EQ(elementsByKey2[4] == erased_p || elementsByKey2[4] == &*it++, - true); + BMQTST_ASSERT_EQ(elementsByKey2[4] == erased_p || + elementsByKey2[4] == &*it++, + true); } // 2. erase by second key, which doesn't exist @@ -1306,19 +1348,19 @@ static void test6_eraseByKey2() // insert elements map.insert(1, "first", "value1"); - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.size(), 1u); // try erasing by key that doesn't exist int eraseRc = map.eraseByKey2("second"); // returned value is non-zero - ASSERT_NE(eraseRc, 0); + BMQTST_ASSERT_NE(eraseRc, 0); // the map is intact - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(map.begin()->key1(), 1); - ASSERT_EQ(map.begin()->key2(), "first"); - ASSERT_EQ(map.begin()->value(), "value1"); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.begin()->key1(), 1); + BMQTST_ASSERT_EQ(map.begin()->key2(), "first"); + BMQTST_ASSERT_EQ(map.begin()->value(), "value1"); } // 3. erase by second key, which exists, but throws on comparison @@ -1330,7 +1372,7 @@ static void test6_eraseByKey2() // insert elements map.insert("first", 1, "value1"); - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.size(), 1u); bool exceptionThrown = false; @@ -1343,13 +1385,13 @@ static void test6_eraseByKey2() } // exception was thrown - ASSERT_EQ(exceptionThrown, true); + BMQTST_ASSERT_EQ(exceptionThrown, true); // the map is intact - ASSERT_EQ(map.size(), 1u); - ASSERT_EQ(map.begin()->key1(), "first"); - ASSERT_EQ(map.begin()->key2().value(), 1); - ASSERT_EQ(map.begin()->value(), "value1"); + BMQTST_ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.begin()->key1(), "first"); + BMQTST_ASSERT_EQ(map.begin()->key2().value(), 1); + BMQTST_ASSERT_EQ(map.begin()->value(), "value1"); } } @@ -1378,19 +1420,19 @@ static void test7_clear() map.insert(1, "first", "value1"); map.insert(2, "second", "value2"); map.insert(3, "third", "value3"); - ASSERT_EQ(map.size(), 3u); + BMQTST_ASSERT_EQ(map.size(), 3u); // do clear map.clear(); // the map is now empty - ASSERT_EQ(map.empty(), true); + BMQTST_ASSERT_EQ(map.empty(), true); // clear again map.clear(); // the map is still empty - ASSERT_EQ(map.empty(), true); + BMQTST_ASSERT_EQ(map.empty(), true); } static void test8_swap() @@ -1417,36 +1459,36 @@ static void test8_swap() // insert 1 element to map1 map1.insert(1, "first", "value1"); - ASSERT_EQ(map1.size(), 1u); + BMQTST_ASSERT_EQ(map1.size(), 1u); // insert 2 elements to map2 map2.insert(2, "second", "value2"); map2.insert(3, "third", "value3"); - ASSERT_EQ(map2.size(), 2u); + BMQTST_ASSERT_EQ(map2.size(), 2u); // swap maps swap(map1, map2); // map1 now have the contents of map2 - ASSERT_EQ(map1.size(), 2u); + BMQTST_ASSERT_EQ(map1.size(), 2u); - ASSERT_EQ((it = map1.findByKey1(2)) == map1.end(), false); - ASSERT_EQ(it->key1(), 2); - ASSERT_EQ(it->key2(), "second"); - ASSERT_EQ(it->value(), "value2"); + BMQTST_ASSERT_EQ((it = map1.findByKey1(2)) == map1.end(), false); + BMQTST_ASSERT_EQ(it->key1(), 2); + BMQTST_ASSERT_EQ(it->key2(), "second"); + BMQTST_ASSERT_EQ(it->value(), "value2"); - ASSERT_EQ((it = map1.findByKey1(3)) == map1.end(), false); - ASSERT_EQ(it->key1(), 3); - ASSERT_EQ(it->key2(), "third"); - ASSERT_EQ(it->value(), "value3"); + BMQTST_ASSERT_EQ((it = map1.findByKey1(3)) == map1.end(), false); + BMQTST_ASSERT_EQ(it->key1(), 3); + BMQTST_ASSERT_EQ(it->key2(), "third"); + BMQTST_ASSERT_EQ(it->value(), "value3"); // map2 now have the contents of map1 - ASSERT_EQ(map2.size(), 1u); + BMQTST_ASSERT_EQ(map2.size(), 1u); - ASSERT_EQ((it = map2.findByKey1(1)) == map2.end(), false); - ASSERT_EQ(it->key1(), 1); - ASSERT_EQ(it->key2(), "first"); - ASSERT_EQ(it->value(), "value1"); + BMQTST_ASSERT_EQ((it = map2.findByKey1(1)) == map2.end(), false); + BMQTST_ASSERT_EQ(it->key1(), 1); + BMQTST_ASSERT_EQ(it->key2(), "first"); + BMQTST_ASSERT_EQ(it->value(), "value1"); } static void test9_rangeObservers() @@ -1478,7 +1520,7 @@ static void test9_rangeObservers() // insert 1 element to nonEmptyMap nonEmptyMap.insert(1, "first", "value1"); - ASSERT_EQ(nonEmptyMap.size(), 1u); + BMQTST_ASSERT_EQ(nonEmptyMap.size(), 1u); const Map::value_type* element_p = &*nonEmptyMap.begin(); @@ -1486,164 +1528,164 @@ static void test9_rangeObservers() { // begin(), first key iterator = emptyMap.begin(Map::e_FIRST_KEY); - ASSERT_EQ(iterator == emptyMap.end(), true); - ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(iterator == emptyMap.end(), true); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); // begin(), second key iterator = emptyMap.begin(Map::e_SECOND_KEY); - ASSERT_EQ(iterator == emptyMap.end(), true); - ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(iterator == emptyMap.end(), true); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); // cbegin(), first key constIterator = emptyMap.cbegin(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator == emptyMap.cend(), true); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator == emptyMap.cend(), true); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // cbegin(), second key constIterator = emptyMap.cbegin(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator == emptyMap.cend(), true); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator == emptyMap.cend(), true); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); // end(), first key iterator = emptyMap.end(Map::e_FIRST_KEY); - ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); // end(), second key iterator = emptyMap.end(Map::e_SECOND_KEY); - ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); // cend(), first key constIterator = emptyMap.cend(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // cend(), second key constIterator = emptyMap.cend(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); } // non-const non-empty map { // begin(), first key iterator = nonEmptyMap.begin(Map::e_FIRST_KEY); - ASSERT_EQ(iterator == nonEmptyMap.end(), false); - ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(*iterator == *element_p, true); + BMQTST_ASSERT_EQ(iterator == nonEmptyMap.end(), false); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(*iterator == *element_p, true); // begin(), second key iterator = nonEmptyMap.begin(Map::e_SECOND_KEY); - ASSERT_EQ(iterator == nonEmptyMap.end(), false); - ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(*iterator == *element_p, true); + BMQTST_ASSERT_EQ(iterator == nonEmptyMap.end(), false); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(*iterator == *element_p, true); // cbegin(), first key constIterator = nonEmptyMap.cbegin(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(*constIterator == *element_p, true); + BMQTST_ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(*constIterator == *element_p, true); // cbegin(), second key constIterator = nonEmptyMap.cbegin(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(*constIterator == *element_p, true); + BMQTST_ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(*constIterator == *element_p, true); // end(), first key iterator = nonEmptyMap.end(Map::e_FIRST_KEY); - ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_FIRST_KEY); // end(), second key iterator = nonEmptyMap.end(Map::e_SECOND_KEY); - ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(iterator.keyIndex(), Map::e_SECOND_KEY); // cend(), first key constIterator = nonEmptyMap.cend(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // cend(), second key constIterator = nonEmptyMap.cend(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); } // const empty map { // begin(), first key constIterator = bsl::cref(emptyMap).get().begin(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator == emptyMap.end(), true); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator == emptyMap.end(), true); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // begin(), second key constIterator = bsl::cref(emptyMap).get().begin(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator == emptyMap.end(), true); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator == emptyMap.end(), true); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); // cbegin(), first key constIterator = bsl::cref(emptyMap).get().cbegin(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator == emptyMap.cend(), true); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator == emptyMap.cend(), true); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // cbegin(), second key constIterator = bsl::cref(emptyMap).get().cbegin(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator == emptyMap.cend(), true); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator == emptyMap.cend(), true); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); // end(), first key constIterator = bsl::cref(emptyMap).get().end(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // end(), second key constIterator = bsl::cref(emptyMap).get().end(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); // cend(), first key constIterator = bsl::cref(emptyMap).get().cend(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // cend(), second key constIterator = bsl::cref(emptyMap).get().cend(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); } // const non-empty map { // begin(), first key constIterator = bsl::cref(nonEmptyMap).get().begin(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator == nonEmptyMap.end(), false); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(*constIterator == *element_p, true); + BMQTST_ASSERT_EQ(constIterator == nonEmptyMap.end(), false); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(*constIterator == *element_p, true); // begin(), second key constIterator = bsl::cref(nonEmptyMap).get().begin(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator == nonEmptyMap.end(), false); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(*constIterator == *element_p, true); + BMQTST_ASSERT_EQ(constIterator == nonEmptyMap.end(), false); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(*constIterator == *element_p, true); // cbegin(), first key constIterator = bsl::cref(nonEmptyMap).get().cbegin(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(*constIterator == *element_p, true); + BMQTST_ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(*constIterator == *element_p, true); // cbegin(), second key constIterator = bsl::cref(nonEmptyMap).get().cbegin(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(*constIterator == *element_p, true); + BMQTST_ASSERT_EQ(constIterator == nonEmptyMap.cend(), false); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(*constIterator == *element_p, true); // end(), first key constIterator = bsl::cref(nonEmptyMap).get().end(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // end(), second key constIterator = bsl::cref(nonEmptyMap).get().end(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); // cend(), first key constIterator = bsl::cref(nonEmptyMap).get().cend(Map::e_FIRST_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_FIRST_KEY); // cend(), second key constIterator = bsl::cref(nonEmptyMap).get().cend(Map::e_SECOND_KEY); - ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(constIterator.keyIndex(), Map::e_SECOND_KEY); } } @@ -1689,40 +1731,40 @@ static void test10_findByKey1() // insert elements map.insert(1, "first", "value1"); map.insert(2, "second", "value2"); - ASSERT_EQ(map.size(), 2u); + BMQTST_ASSERT_EQ(map.size(), 2u); // 1. non-const contained, key exists { Map::iterator it = map.findByKey1(1); - ASSERT_EQ(it == map.end(), false); - ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(it->key1(), 1); - ASSERT_EQ(it->key2(), "first"); - ASSERT_EQ(it->value(), "value1"); + BMQTST_ASSERT_EQ(it == map.end(), false); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(it->key1(), 1); + BMQTST_ASSERT_EQ(it->key2(), "first"); + BMQTST_ASSERT_EQ(it->value(), "value1"); } // 2. const contained, key exists { Map::const_iterator it = bsl::cref(map).get().findByKey1(2); - ASSERT_EQ(it == map.end(), false); - ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); - ASSERT_EQ(it->key1(), 2); - ASSERT_EQ(it->key2(), "second"); - ASSERT_EQ(it->value(), "value2"); + BMQTST_ASSERT_EQ(it == map.end(), false); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(it->key1(), 2); + BMQTST_ASSERT_EQ(it->key2(), "second"); + BMQTST_ASSERT_EQ(it->value(), "value2"); } // 3. non-const contained, key doesn't exist { Map::iterator it = map.findByKey1(3); - ASSERT_EQ(it == map.end(), true); - ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(it == map.end(), true); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); } // 4. const contained, key doesn't exist { Map::const_iterator it = bsl::cref(map).get().findByKey1(3); - ASSERT_EQ(it == map.end(), true); - ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); + BMQTST_ASSERT_EQ(it == map.end(), true); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_FIRST_KEY); } } @@ -1768,40 +1810,40 @@ static void test11_findByKey2() // insert elements map.insert(1, "first", "value1"); map.insert(2, "second", "value2"); - ASSERT_EQ(map.size(), 2u); + BMQTST_ASSERT_EQ(map.size(), 2u); // 1. non-const contained, key exists { Map::iterator it = map.findByKey2("first"); - ASSERT_EQ(it == map.end(), false); - ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(it->key1(), 1); - ASSERT_EQ(it->key2(), "first"); - ASSERT_EQ(it->value(), "value1"); + BMQTST_ASSERT_EQ(it == map.end(), false); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(it->key1(), 1); + BMQTST_ASSERT_EQ(it->key2(), "first"); + BMQTST_ASSERT_EQ(it->value(), "value1"); } // 2. const contained, key exists { Map::const_iterator it = bsl::cref(map).get().findByKey2("second"); - ASSERT_EQ(it == map.end(), false); - ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); - ASSERT_EQ(it->key1(), 2); - ASSERT_EQ(it->key2(), "second"); - ASSERT_EQ(it->value(), "value2"); + BMQTST_ASSERT_EQ(it == map.end(), false); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(it->key1(), 2); + BMQTST_ASSERT_EQ(it->key2(), "second"); + BMQTST_ASSERT_EQ(it->value(), "value2"); } // 3. non-const contained, key doesn't exist { Map::iterator it = map.findByKey2("third"); - ASSERT_EQ(it == map.end(), true); - ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(it == map.end(), true); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); } // 4. const contained, key doesn't exist { Map::const_iterator it = bsl::cref(map).get().findByKey2("third"); - ASSERT_EQ(it == map.end(), true); - ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); + BMQTST_ASSERT_EQ(it == map.end(), true); + BMQTST_ASSERT_EQ(it.keyIndex(), Map::e_SECOND_KEY); } } @@ -1826,38 +1868,38 @@ static void test12_sizeObservers() bslma::TestAllocator alloc; Map map(&alloc); - ASSERT_EQ(map.empty(), true); - ASSERT_EQ(map.size(), 0u); + BMQTST_ASSERT_EQ(map.empty(), true); + BMQTST_ASSERT_EQ(map.size(), 0u); map.insert(1, "first", "value1"); - ASSERT_EQ(map.empty(), false); - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.empty(), false); + BMQTST_ASSERT_EQ(map.size(), 1u); map.insert(2, "second", "value2"); - ASSERT_EQ(map.empty(), false); - ASSERT_EQ(map.size(), 2u); + BMQTST_ASSERT_EQ(map.empty(), false); + BMQTST_ASSERT_EQ(map.size(), 2u); map.insert(3, "third", "value2"); - ASSERT_EQ(map.empty(), false); - ASSERT_EQ(map.size(), 3u); + BMQTST_ASSERT_EQ(map.empty(), false); + BMQTST_ASSERT_EQ(map.size(), 3u); map.erase(map.begin()); - ASSERT_EQ(map.empty(), false); - ASSERT_EQ(map.size(), 2u); + BMQTST_ASSERT_EQ(map.empty(), false); + BMQTST_ASSERT_EQ(map.size(), 2u); map.erase(map.begin()); - ASSERT_EQ(map.empty(), false); - ASSERT_EQ(map.size(), 1u); + BMQTST_ASSERT_EQ(map.empty(), false); + BMQTST_ASSERT_EQ(map.size(), 1u); map.erase(map.begin()); - ASSERT_EQ(map.empty(), true); - ASSERT_EQ(map.size(), 0u); + BMQTST_ASSERT_EQ(map.empty(), true); + BMQTST_ASSERT_EQ(map.size(), 0u); } static void test13_equality() @@ -1886,19 +1928,19 @@ static void test13_equality() map1.insert(3, "third", "value3"); for (Map::const_iterator it = map1.cbegin(); it != map1.cend(); ++it) { - ASSERT(map1 != map2); + BMQTST_ASSERT(map1 != map2); map2.insert(it->key1(), it->key2(), it->value()); } - ASSERT(map1 == map2); + BMQTST_ASSERT(map1 == map2); while (!map1.empty()) { map1.erase(map1.begin()); - ASSERT(map1 != map2); + BMQTST_ASSERT(map1 != map2); } while (!map2.empty()) { - ASSERT(map1 != map2); + BMQTST_ASSERT(map1 != map2); map2.erase(map2.begin()); } - ASSERT(map1 == map2); + BMQTST_ASSERT(map1 == map2); } //============================================================================= diff --git a/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.t.cpp b/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.t.cpp index a2f97a630b..de3fd963fc 100644 --- a/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.t.cpp +++ b/src/groups/bmq/bmqeval/bmqeval_simpleevaluator.t.cpp @@ -88,10 +88,10 @@ static void testN1_SimpleEvaluator_GoogleBenchmark(benchmark::State& state) CompilationContext compilationContext(&localAllocator); SimpleEvaluator evaluator; - ASSERT(evaluator.compile("false || (i64_42==42 && s_foo==\"foo\")", - compilationContext) == 0); + BMQTST_ASSERT(evaluator.compile("false || (i64_42==42 && s_foo==\"foo\")", + compilationContext) == 0); - ASSERT_EQ(evaluator.evaluate(evaluationContext), true); + BMQTST_ASSERT_EQ(evaluator.evaluate(evaluationContext), true); //