Skip to content

Commit 6a36263

Browse files
authored
Refactor[mqbblp]: simplify RootQueueEngine (#1637)
- Remove useless `RootQueueEngine::create` - `QueueEngineTester`: use `allocateManaged` - `src/groups/mqb/mqbblp/mqbblp_rootqueueengine.t.cpp`: simplify test cases, remove useless includes, add missing `broadcast` test case Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
1 parent 378b54b commit 6a36263

7 files changed

Lines changed: 68 additions & 175 deletions

src/groups/mqb/mqbblp/mqbblp_localqueue.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,11 @@ int LocalQueue::configure(bsl::ostream& errorDescription, bool isReconfigure)
158158
// during update of a domain's configuration, this object already exists,
159159
// and should not be re-created.
160160
if (!d_queueEngine_mp) {
161-
RootQueueEngine::create(&d_queueEngine_mp,
162-
d_state_p,
163-
*domainCfg,
164-
d_allocator_p);
161+
d_queueEngine_mp =
162+
bslma::ManagedPtrUtil::allocateManaged<RootQueueEngine>(
163+
d_allocator_p,
164+
d_state_p,
165+
*domainCfg);
165166
}
166167

167168
// Inform the storage about the queue.

src/groups/mqb/mqbblp/mqbblp_queueenginetester.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include <bmqt_uri.h>
3737

3838
#include <bmqu_memoutstream.h>
39-
#include <bmqu_time.h>
4039

4140
// BDE
4241
#include <bdlb_string.h>
@@ -49,7 +48,6 @@
4948
#include <bsl_memory.h>
5049
#include <bsl_utility.h>
5150
#include <bsl_vector.h>
52-
#include <bslmt_once.h>
5351
#include <bsls_types.h>
5452
#include <bslstl_stringref.h>
5553

@@ -395,8 +393,6 @@ QueueEngineTester::QueueEngineTester(const mqbconfm::Domain& domainConfig,
395393
, d_messageCount(0)
396394
, d_allocator_p(allocator)
397395
{
398-
oneTimeInit();
399-
400396
mqbconfm::Domain config = domainConfig;
401397

402398
config.deduplicationTimeMs() = 0; // No history
@@ -421,18 +417,9 @@ QueueEngineTester::~QueueEngineTester()
421417
d_mockDomain_mp->unregisterQueue(queue);
422418

423419
d_mockCluster_mp->stop();
424-
oneTimeShutdown();
425420
}
426421

427422
// PRIVATE MANIPULATORS
428-
void QueueEngineTester::oneTimeInit()
429-
{
430-
BSLMT_ONCE_DO
431-
{
432-
bmqu::Time::initialize();
433-
}
434-
}
435-
436423
void QueueEngineTester::init(const mqbconfm::Domain& domainConfig,
437424
bool startScheduler)
438425
{
@@ -627,14 +614,6 @@ void QueueEngineTester::init(const mqbconfm::Domain& domainConfig,
627614
.setHandleFactory(handleFactory_mp);
628615
}
629616

630-
void QueueEngineTester::oneTimeShutdown()
631-
{
632-
BSLMT_ONCE_DO
633-
{
634-
bmqu::Time::shutdown();
635-
}
636-
}
637-
638617
void QueueEngineTester::handleReleasedCallback(
639618
int* rc,
640619
bool* isDeletedOutput,

src/groups/mqb/mqbblp/mqbblp_queueenginetester.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,10 @@ class QueueEngineTester {
257257
private:
258258
// PRIVATE MANIPULATORS
259259

260-
/// Perform any initialization that needs to be done one time only in
261-
/// the course of a program's execution (to enable thread-safety of some
262-
/// component, etc.).
263-
void oneTimeInit();
264-
265260
/// Reset and recreate all objects using the currently set options and
266261
/// the specific `domainConfig`.
267262
void init(const mqbconfm::Domain& domainConfig, bool startScheduler);
268263

269-
/// Pendant operation of the `oneTimeInit` one.
270-
void oneTimeShutdown();
271-
272264
void
273265
handleReleasedCallback(int* rc,
274266
bool* isDeletedOutput,
@@ -642,12 +634,14 @@ inline T* QueueEngineTester::createQueueEngine()
642634
{
643635
// PRECONDITIONS
644636
BSLS_ASSERT_OPT(!d_queueEngine_mp && "'createQueueEngine()' was called");
645-
T* result = new (*d_allocator_p)
646-
T(d_queueState_mp.get(),
647-
*d_queueState_mp->queue()->domain()->config(),
648-
d_allocator_p);
637+
649638
// Create and configure Queue Engine
650-
d_queueEngine_mp.load(result, d_allocator_p);
639+
d_queueEngine_mp = bslma::ManagedPtrUtil::allocateManaged<T>(
640+
d_allocator_p,
641+
d_queueState_mp.get(),
642+
*d_queueState_mp->queue()->domain()->config());
643+
644+
T* result = static_cast<T*>(d_queueEngine_mp.get());
651645

652646
createQueueEngineHelper(d_queueEngine_mp.get());
653647

src/groups/mqb/mqbblp/mqbblp_relayqueueengine.t.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <mqbstat_brokerstats.h>
2626

2727
#include <bmqu_memoutstream.h>
28+
#include <bmqu_time.h>
2829

2930
// BMQ
3031
#include <bmqp_protocol.h>
@@ -2028,6 +2029,8 @@ int main(int argc, char* argv[])
20282029
{
20292030
TEST_PROLOG(bmqtst::TestHelper::e_DEFAULT);
20302031

2032+
bmqu::Time::initialize(bmqtst::TestHelperUtil::allocator());
2033+
20312034
{
20322035
mqbcfg::AppConfig brokerConfig(bmqtst::TestHelperUtil::allocator());
20332036
mqbcfg::BrokerConfig::set(brokerConfig);
@@ -2068,6 +2071,8 @@ int main(int argc, char* argv[])
20682071
}
20692072
}
20702073

2074+
bmqu::Time::shutdown();
2075+
20712076
// Default allocator check is disabled for all UTs:
20722077
// `mqbblp::QueueEngine` and mocks from `mqbi` methods use ball logging
20732078
// that allocates using default allocator.

src/groups/mqb/mqbblp/mqbblp_rootqueueengine.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,6 @@ void RootQueueEngine::onHandleCreation(void* ptr, void* cookie)
300300
hndlCreated);
301301
}
302302

303-
void RootQueueEngine::create(bslma::ManagedPtr<mqbi::QueueEngine>* queueEngine,
304-
QueueState* queueState,
305-
const mqbconfm::Domain& domainConfig,
306-
bslma::Allocator* allocator)
307-
{
308-
// PRECONDITIONS
309-
BSLS_ASSERT_SAFE(queueEngine);
310-
311-
queueEngine->load(new (*allocator)
312-
RootQueueEngine(queueState, domainConfig, allocator),
313-
allocator);
314-
}
315-
316303
void RootQueueEngine::FanoutConfiguration::loadRoutingConfiguration(
317304
bmqp_ctrlmsg::RoutingConfiguration* config)
318305
{

src/groups/mqb/mqbblp/mqbblp_rootqueueengine.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,6 @@ class RootQueueEngine BSLS_KEYWORD_FINAL : public mqbi::QueueEngine {
220220
/// to a boolean flag indicating whether the handle was created or not.
221221
static void onHandleCreation(void* ptr, void* cookie);
222222

223-
/// Loads the specified `queueEngine` with a new `RootQueueEngine`
224-
/// initialized using the specified `queueState`, `domainConfig`,
225-
/// `scheduler` and `allocator`.
226-
static void create(bslma::ManagedPtr<mqbi::QueueEngine>* queueEngine,
227-
QueueState* queueState,
228-
const mqbconfm::Domain& domainConfig,
229-
bslma::Allocator* allocator);
230-
231223
/// Loads the specified `config` with the appropriate values for
232224
/// fanout delivery mode.
233225
struct FanoutConfiguration {

0 commit comments

Comments
 (0)