Skip to content

Commit

Permalink
fix: do not use defaultSubQueueInfoArray() (bloomberg#230)
Browse files Browse the repository at this point in the history
Signed-off-by: dorjesinpo <[email protected]>
  • Loading branch information
dorjesinpo authored and syuzvinsky committed Apr 4, 2024
1 parent 8ca79b2 commit 0d441ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 89 deletions.
25 changes: 0 additions & 25 deletions src/groups/bmq/bmqp/bmqp_protocolutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ bsls::ObjectBuffer<bdlbb::Blob> g_heartbeatRspBlob;
/// heartbeat response and an empty blob.
bsls::ObjectBuffer<bdlbb::Blob> g_emptyBlob;

/// A static SubQueueInfoArray prefilled with the default subQueueId and an
/// unlimited RDA counter.
bsls::ObjectBuffer<Protocol::SubQueueInfosArray> g_defaultSubQueueInfoArray;

/// 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`
Expand Down Expand Up @@ -168,13 +164,6 @@ void ProtocolUtil::initialize(bslma::Allocator* allocator)

// Create empty blob
new (g_emptyBlob.buffer()) bdlbb::Blob(alloc);

// Populate the default subQueueInfo array with the default subQueueId and
// an unlimited RDA counter
new (g_defaultSubQueueInfoArray.buffer()) Protocol::SubQueueInfosArray(
1,
SubQueueInfo(Protocol::k_DEFAULT_SUBSCRIPTION_ID),
alloc);
}

void ProtocolUtil::shutdown()
Expand All @@ -188,12 +177,6 @@ void ProtocolUtil::shutdown()
return; // RETURN
}

g_defaultSubQueueInfoArray.object()
.mwcc::Array<SubQueueInfo, 16>::Array::~Array();
// Above expression, particularly the 'Array::' before '~Array()' is
// required if passing '-Wpedantic' flag in our build, which is what we
// are doing when building with clang.

g_heartbeatRspBlob.object().bdlbb::Blob::~Blob();
g_heartbeatReqBlob.object().bdlbb::Blob::~Blob();
g_emptyBlob.object().bdlbb::Blob::~Blob();
Expand Down Expand Up @@ -339,14 +322,6 @@ void ProtocolUtil::binaryToHex(char* buffer,
}
}

const Protocol::SubQueueInfosArray& ProtocolUtil::defaultSubQueueInfoArray()
{
// PRECONDITIONS
BSLS_ASSERT_SAFE(g_initialized && "Not initialized");

return g_defaultSubQueueInfoArray.object();
}

int ProtocolUtil::ackResultToCode(bmqt::AckResult::Enum value)
{
switch (value) {
Expand Down
7 changes: 0 additions & 7 deletions src/groups/bmq/bmqp/bmqp_protocolutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,6 @@ struct ProtocolUtil {

/// Protocol miscellaneous
///----------------------

/// Return a reference not offering modifiable access to the statically
/// created default SubQueueInfoArray (a SubQueueInfosArray containing
/// the default subQueueId and an unlimited RDA counter). The behavior
/// is undefined unless `initialize` has been called.
static const Protocol::SubQueueInfosArray& defaultSubQueueInfoArray();

static int ackResultToCode(bmqt::AckResult::Enum value);

/// Convert the specified `value` between an `AckResult` enum value
Expand Down
66 changes: 10 additions & 56 deletions src/groups/bmq/bmqp/bmqp_protocolutil.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,52 +528,7 @@ static void test6_heartbeatAndEmptyBlobs()
bmqp::ProtocolUtil::shutdown();
}

static void test7_defaultSubQueueInfoArray()
// ------------------------------------------------------------------------
// DEFAULT SUBQUEUEINFO ARRAY
//
// Concerns:
// 1. If 'initialize' has not been called, unable to obtain the default
// SubQueueInfoArray.
// 2. After 'initialize' has been called, should be able to obtain a
// reference not offering modifiable access to the statically created
// default SubQueueInfoArray containing one element: The default
// subQueueId with an unlimited RDA counter.
//
// Plan:
// 1. Assert failure of calling 'defaultSubQueueInfoArray' without prior
// call to 'initialize'.
// 2. Initialize the 'ProtocolUtil' and verify obtaining the default
// SubQueueInfoArray.
//
// Testing:
// defaultSubQueueInfoArray
// ----------------------------------------------------------------------
{
mwctst::TestHelper::printTestName("DEFAULT SUBQUEUEINFOARRAY");

// 1. If 'initialize' has not been called, unable to obtain the default
// SubQueueInfoArray.
ASSERT_SAFE_FAIL(bmqp::ProtocolUtil::defaultSubQueueInfoArray());

// 2. After 'initialize' has been called, should be able to obtain a
// reference not offering modifiable access to the statically created
// default SubQueueInfoArray containing one element: The default
// subQueueId with an unlimited RDA counter.
bmqp::ProtocolUtil::initialize(s_allocator_p);

ASSERT_SAFE_PASS(bmqp::ProtocolUtil::defaultSubQueueInfoArray());

const bmqp::Protocol::SubQueueInfosArray& subQueueInfoArray =
bmqp::ProtocolUtil::defaultSubQueueInfoArray();
ASSERT_EQ(subQueueInfoArray.size(), 1U);
ASSERT_EQ(subQueueInfoArray[0].id(), bmqp::QueueId::k_DEFAULT_SUBQUEUE_ID);
ASSERT_EQ(subQueueInfoArray[0].rdaInfo().isUnlimited(), true);

bmqp::ProtocolUtil::shutdown();
}

static void test8_ackResultToCode()
static void test7_ackResultToCode()
// ------------------------------------------------------------------------
// ACK RESULT TO CODE
//
Expand Down Expand Up @@ -621,7 +576,7 @@ static void test8_ackResultToCode()
}
}

static void test9_ackResultFromCode()
static void test8_ackResultFromCode()
// ------------------------------------------------------------------------
// ACK RESULT FROM CODE
//
Expand Down Expand Up @@ -665,7 +620,7 @@ static void test9_ackResultFromCode()
}
}

static void test10_loadFieldValues()
static void test9_loadFieldValues()
// ------------------------------------------------------------------------
// LOAD FIELD VALUES
//
Expand Down Expand Up @@ -802,7 +757,7 @@ static void encodeDecodeHelper(E encodingType)
ASSERT_EQ(decodedClusterMessage, clusterMessage);
}

static void test11_encodeDecodeMessage()
static void test10_encodeDecodeMessage()
// ------------------------------------------------------------------------
// ENCODE DECODE MESSAGE
//
Expand Down Expand Up @@ -868,7 +823,7 @@ static void populateBlob(bdlbb::Blob* blob, int atLeastLen)
}
}

static void test12_parseMessageProperties()
static void test11_parseMessageProperties()
// ------------------------------------------------------------------------
// TESTS PARSING AS IT IS USED IN QueueEngineUtil::logRejectMessage
//
Expand Down Expand Up @@ -953,12 +908,11 @@ int main(int argc, char* argv[])

switch (_testCase) {
case 0:
case 12: test12_parseMessageProperties(); break;
case 11: test11_encodeDecodeMessage(); break;
case 10: test10_loadFieldValues(); break;
case 9: test9_ackResultFromCode(); break;
case 8: test8_ackResultToCode(); break;
case 7: test7_defaultSubQueueInfoArray(); break;
case 11: test11_parseMessageProperties(); break;
case 10: test10_encodeDecodeMessage(); break;
case 9: test9_loadFieldValues(); break;
case 8: test8_ackResultFromCode(); break;
case 7: test7_ackResultToCode(); break;
case 6: test6_heartbeatAndEmptyBlobs(); break;
case 5: test5_paddingBlob(); break;
case 4: test4_paddingChar(); break;
Expand Down
5 changes: 4 additions & 1 deletion src/groups/mqb/mqbblp/mqbblp_queueengineutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,10 @@ bool QueueEngineUtil_AppState::visitBroadcast(
message->guid(),
message->attributes(),
"", // msgGroupId
bmqp::ProtocolUtil::defaultSubQueueInfoArray());
bmqp::Protocol::SubQueueInfosArray(
1,
bmqp::SubQueueInfo(subscription->d_downstreamSubscriptionId)));

return false;
}

Expand Down

0 comments on commit 0d441ee

Please sign in to comment.