Skip to content

Commit

Permalink
Merge branch 'main' into unit-test-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbeard authored Oct 4, 2024
2 parents 3bcb657 + 4ab89d1 commit d3aa2a0
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 48 deletions.
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,6 @@ else()
endif()
endif()

# TBD: TEMPORARY >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if (NOT installBMQ)
# Enable MSG GroupId public APIs ONLY if not doing a DPKG build (i.e., a
# release) of libbmq; until the feature is fully implemented.
add_definitions("-DBMQ_ENABLE_MSG_GROUPID")
else()
message(STATUS "Message GroupId APIs *NOT* exposed!")
endif()
# TBD: TEMPORARY <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

# -----------------------------------------------------------------------------
# PROJECTS
# -----------------------------------------------------------------------------
Expand Down
12 changes: 10 additions & 2 deletions src/groups/bmq/bmqimp/bmqimp_event.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,9 @@ static void test8_putEventBuilder()
bmqp::Crc32c::initialize();

bdlbb::PooledBlobBufferFactory bufferFactory(1024, s_allocator_p);
#ifdef BMQ_ENABLE_MSG_GROUPID
const bmqp::Protocol::MsgGroupId k_MSG_GROUP_ID("gid:0", s_allocator_p);
#endif
const int k_PROPERTY_VAL_ENCODING = 3;
const bsl::string k_PROPERTY_VAL_ID = "myCoolId";
const unsigned int k_CRC32 = 123;
Expand Down Expand Up @@ -1106,8 +1108,10 @@ static void test8_putEventBuilder()

builder.startMessage();
builder.setMessagePayload(k_PAYLOAD, k_PAYLOAD_LEN)
.setMessageProperties(&msgProps)
.setMsgGroupId(k_MSG_GROUP_ID);
.setMessageProperties(&msgProps);
#ifdef BMQ_ENABLE_MSG_GROUPID
builder.setMsgGroupId(k_MSG_GROUP_ID);
#endif

struct Test {
int d_line;
Expand Down Expand Up @@ -1149,8 +1153,10 @@ static void test8_putEventBuilder()
s_allocator_p,
bmqt::CompressionAlgorithmType::e_NONE);

#ifdef BMQ_ENABLE_MSG_GROUPID
ASSERT_EQ(builder.msgGroupId().isNull(), false);
ASSERT_EQ(builder.msgGroupId().value(), k_MSG_GROUP_ID);
#endif

ASSERT_EQ(builder.unpackedMessageSize(), k_PAYLOAD_LEN);

Expand Down Expand Up @@ -1232,11 +1238,13 @@ static void test8_putEventBuilder()
ASSERT_EQ(prop.getPropertyAsInt64("timestamp"), test.d_timeStamp);
}

#ifdef BMQ_ENABLE_MSG_GROUPID
bmqp::Protocol::MsgGroupId msgGroupId(s_allocator_p);
ASSERT_EQ(putIter.hasMsgGroupId(), true);
ASSERT_EQ(putIter.extractMsgGroupId(&msgGroupId), true);
ASSERT_EQ(msgGroupId, k_MSG_GROUP_ID);
ASSERT_EQ(putIter.isValid(), true);
#endif
}

ASSERT_EQ(true, putIter.isValid());
Expand Down
32 changes: 32 additions & 0 deletions src/groups/bmq/bmqimp/bmqimp_messagedumper.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,14 @@ struct Tester BSLS_CPP11_FINAL {
/// is undefined unless a queue with the `uri` was created and inserted
/// using a call to `insertQueue`, or if packing the message is
/// unsuccessful.
#ifdef BMQ_ENABLE_MSG_GROUPID
void packPutMessage(const bslstl::StringRef& uri,
const bslstl::StringRef& payload,
const bslstl::StringRef& msgGroupId = "");
#else
void packPutMessage(const bslstl::StringRef& uri,
const bslstl::StringRef& payload);
#endif

/// Append to the CONFIRM event being built a CONFIRM message associated
/// with the queue corresponding to the specified `uri`. The behavior
Expand Down Expand Up @@ -460,9 +465,14 @@ void Tester::appendAckMessage(const bslstl::StringRef& uri,
BSLS_ASSERT_OPT(rc == 0);
}

#ifdef BMQ_ENABLE_MSG_GROUPID
void Tester::packPutMessage(const bslstl::StringRef& uri,
const bslstl::StringRef& payload,
const bslstl::StringRef& msgGroupId)
#else
void Tester::packPutMessage(const bslstl::StringRef& uri,
const bslstl::StringRef& payload)
#endif
{
// PRECONDITIONS
BSLS_ASSERT_OPT(d_queueIdsByUri.find(uri) != d_queueIdsByUri.end() &&
Expand All @@ -481,10 +491,12 @@ void Tester::packPutMessage(const bslstl::StringRef& uri,

d_putEventBuilder.startMessage();
d_putEventBuilder.setMessageGUID(guid).setMessagePayload(&msgPayload);
#ifdef BMQ_ENABLE_MSG_GROUPID
if (!msgGroupId.empty()) {
bmqp::Protocol::MsgGroupId groupId(msgGroupId, d_allocator_p);
d_putEventBuilder.setMsgGroupId(msgGroupId);
}
#endif

int rc = d_putEventBuilder.packMessage(queueId.id());
BSLS_ASSERT_OPT(rc == 0);
Expand Down Expand Up @@ -1659,8 +1671,13 @@ static void test8_dumpPutEvent()
// messages.
tester.processDumpCommand("PUT ON");

#ifdef BMQ_ENABLE_MSG_GROUPID
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd", "Group 1");
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd", "Group 2");
#else
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd");
tester.packPutMessage("bmq://bmq.test.mmap.fanout/q1", "abcd");
#endif
tester.packPutMessage("bmq://bmq.test.mmap.priority/q1", "efgh");
tester.packPutMessage("bmq://bmq.test.mmap.priority/q2", "ijkl");

Expand All @@ -1674,6 +1691,7 @@ static void test8_dumpPutEvent()

PVV(L_ << ": PUT event dump: " << out.str());

#ifdef BMQ_ENABLE_MSG_GROUPID
ASSERT_EQ(regexMatch(out.str(),
"PUT Message #1:.*"
"queue: bmq://bmq.test.mmap.fanout/q1.*"
Expand All @@ -1688,6 +1706,20 @@ static void test8_dumpPutEvent()
"abcd.*",
s_allocator_p),
true);
#else
ASSERT_EQ(regexMatch(out.str(),
"PUT Message #1:.*"
"queue: bmq://bmq.test.mmap.fanout/q1.*"
"abcd.*",
s_allocator_p),
true);
ASSERT_EQ(regexMatch(out.str(),
"PUT Message #2:.*"
"queue: bmq://bmq.test.mmap.fanout/q1.*"
"abcd.*",
s_allocator_p),
true);
#endif
ASSERT_EQ(regexMatch(out.str(),
"PUT Message #3:.*"
"queue: bmq://bmq.test.mmap.priority/q1.*"
Expand Down
4 changes: 4 additions & 0 deletions src/groups/bmq/bmqp/bmqp_optionutil.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ static void test3_checkOptionsBlobSegment()
}
}

#ifdef BMQ_ENABLE_MSG_GROUPID
static void test4_isValidMsgGroupId()
// ------------------------------------------------------------------------
// VALIDATE GROUPID LENGTH
Expand Down Expand Up @@ -426,6 +427,7 @@ static void test4_isValidMsgGroupId()
ASSERT_EQ(Result::e_SUCCESS,
bmqp::OptionUtil::isValidMsgGroupId(maxLength));
}
#endif

// ============================================================================
// MAIN PROGRAM
Expand All @@ -439,7 +441,9 @@ int main(int argc, char* argv[])

switch (_testCase) {
case 0:
#ifdef BMQ_ENABLE_MSG_GROUPID
case 4: test4_isValidMsgGroupId(); break;
#endif
case 3: test3_checkOptionsBlobSegment(); break;
case 2: test2_basicOptionsBoxCanAdd(); break;
case 1: test1_basicOptionMetaProperties(); break;
Expand Down
18 changes: 17 additions & 1 deletion src/groups/bmq/bmqp/bmqp_pusheventbuilder.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ using namespace bsl;
// ----------------------------------------------------------------------------
namespace {

#ifdef BMQ_ENABLE_MSG_GROUPID
typedef bdlb::NullableValue<bmqp::Protocol::MsgGroupId> NullableMsgGroupId;
#endif

struct Data {
bmqt::MessageGUID d_guid;
int d_qid;
bmqp::Protocol::SubQueueInfosArray d_subQueueInfos;
#ifdef BMQ_ENABLE_MSG_GROUPID
NullableMsgGroupId d_msgGroupId;
#endif
bdlbb::Blob d_payload;
int d_flags;
bmqt::CompressionAlgorithmType::Enum d_compressionAlgorithmType;
Expand All @@ -82,7 +86,9 @@ Data::Data(bdlbb::BlobBufferFactory* bufferFactory,
bslma::Allocator* allocator)
: d_qid(-1)
, d_subQueueInfos(allocator)
#ifdef BMQ_ENABLE_MSG_GROUPID
, d_msgGroupId(allocator)
#endif
, d_payload(bufferFactory, allocator)
, d_flags(0)
, d_compressionAlgorithmType(bmqt::CompressionAlgorithmType::e_NONE)
Expand All @@ -94,7 +100,9 @@ Data::Data(const Data& other, bslma::Allocator* allocator)
: d_guid(other.d_guid)
, d_qid(other.d_qid)
, d_subQueueInfos(other.d_subQueueInfos, allocator)
#ifdef BMQ_ENABLE_MSG_GROUPID
, d_msgGroupId(other.d_msgGroupId, allocator)
#endif
, d_payload(other.d_payload, allocator)
, d_flags(other.d_flags)
, d_compressionAlgorithmType(other.d_compressionAlgorithmType)
Expand Down Expand Up @@ -142,6 +150,7 @@ void generateSubQueueInfos(bmqp::Protocol::SubQueueInfosArray* subQueueInfos,
static_cast<unsigned int>(numSubQueueInfos));
}

#ifdef BMQ_ENABLE_MSG_GROUPID
/// Populate the specified `msgGroupId` with a random Group Id.
static void generateMsgGroupId(bmqp::Protocol::MsgGroupId* msgGroupId)
{
Expand All @@ -152,6 +161,7 @@ static void generateMsgGroupId(bmqp::Protocol::MsgGroupId* msgGroupId)
oss << "gid:" << generateRandomInteger(0, 120);
*msgGroupId = oss.str();
}
#endif

/// Append at least `atLeastLen` bytes to the specified `blob` and populate
/// the specified `payloadLen` with the number of bytes appended.
Expand Down Expand Up @@ -200,6 +210,7 @@ appendMessage(size_t iteration,
return rc; // RETURN
}

#ifdef BMQ_ENABLE_MSG_GROUPID
// Every 3rd iteration we don't add a Group Id.
if (iteration % 3) {
generateMsgGroupId(&data.d_msgGroupId.makeValue());
Expand All @@ -208,11 +219,14 @@ appendMessage(size_t iteration,
return rc; // RETURN
}
}
#endif

bdlbb::Blob payload(bufferFactory, allocator);
const int blobSize = generateRandomInteger(0, 1024);
#ifdef BMQ_ENABLE_MSG_GROUPID
const bmqp::Protocol::MsgGroupId str(blobSize, 'x', allocator);
bdlbb::BlobUtil::append(&payload, str.c_str(), blobSize);
#endif

data.d_payload = payload;

Expand Down Expand Up @@ -651,6 +665,7 @@ static void test4_buildEventWithMultipleMessages()
ASSERT_EQ_D(i, D.d_subQueueInfos[i], retrievedSQInfos[i]);
}
}
#ifdef BMQ_ENABLE_MSG_GROUPID
const bool hasMsgGroupId = !D.d_msgGroupId.isNull();
ASSERT_EQ(hasMsgGroupId,
optionsView.find(bmqp::OptionType::e_MSG_GROUP_ID) !=
Expand All @@ -661,6 +676,7 @@ static void test4_buildEventWithMultipleMessages()
optionsView.loadMsgGroupIdOption(&retrievedMsgGroupId));
ASSERT_EQ(D.d_msgGroupId.value(), retrievedMsgGroupId);
}
#endif
++dataIndex;
}

Expand Down Expand Up @@ -900,6 +916,7 @@ static void test7_buildEventOptionTooBig()

ASSERT_EQ(rc, bmqt::EventBuilderResult::e_OPTION_TOO_BIG);

#ifdef BMQ_ENABLE_MSG_GROUPID
// Add another option larger than maximum allowed
bmqp::Protocol::MsgGroupId msgGrIdBig1(bmqp::OptionHeader::k_MAX_SIZE + 1,
'x',
Expand All @@ -916,7 +933,6 @@ static void test7_buildEventOptionTooBig()

rc = peb.addMsgGroupIdOption(msgGrIdBig2);

#ifdef BMQ_ENABLE_MSG_GROUPID
ASSERT_EQ(rc, bmqt::EventBuilderResult::e_INVALID_MSG_GROUP_ID);
#endif

Expand Down
Loading

0 comments on commit d3aa2a0

Please sign in to comment.