Skip to content

Commit 512d195

Browse files
authored
Feat[bmqstoragetool]: Add unit tests for m_bmqstoragetool::Printer implementations (#621)
Signed-off-by: Anton Pryakhin <[email protected]>
1 parent b4e345e commit 512d195

11 files changed

+2709
-170
lines changed

src/applications/bmqstoragetool/m_bmqstoragetool_journalfile.cpp

+58-63
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,57 @@ JournalFile::~JournalFile()
8080
// NOTHING
8181
}
8282

83+
JournalFile::RecordBufferType
84+
JournalFile::makeQueueOpRecord(unsigned int primaryLeaseId,
85+
bsls::Types::Uint64 sequenceNumber)
86+
{
87+
// QueueOpRec
88+
OffsetPtr<QueueOpRecord> rec(d_block, d_currPos);
89+
new (rec.get()) QueueOpRecord();
90+
rec->header()
91+
.setPrimaryLeaseId(primaryLeaseId)
92+
.setSequenceNumber(sequenceNumber)
93+
.setTimestamp(sequenceNumber * d_timestampIncrement);
94+
rec->setFlags(3)
95+
.setQueueKey(mqbu::StorageKey(mqbu::StorageKey::BinaryRepresentation(),
96+
"abcde"))
97+
.setAppKey(mqbu::StorageKey(mqbu::StorageKey::BinaryRepresentation(),
98+
"appid"))
99+
.setType(QueueOpType::e_PURGE)
100+
.setMagic(RecordHeader::k_MAGIC);
101+
102+
RecordBufferType buf;
103+
bsl::memcpy(buf.buffer(),
104+
rec.get(),
105+
FileStoreProtocol::k_JOURNAL_RECORD_SIZE);
106+
return buf;
107+
}
108+
109+
JournalFile::RecordBufferType
110+
JournalFile::makeJournalOpRecord(unsigned int primaryLeaseId,
111+
bsls::Types::Uint64 sequenceNumber)
112+
{
113+
OffsetPtr<JournalOpRecord> rec(d_block, d_currPos);
114+
new (rec.get()) JournalOpRecord(JournalOpType::e_SYNCPOINT,
115+
SyncPointType::e_REGULAR,
116+
1234567, // seqNum
117+
25, // leaderTerm
118+
121, // leaderNodeId
119+
8800, // dataFilePosition
120+
100, // qlistFilePosition
121+
RecordHeader::k_MAGIC);
122+
123+
rec->header()
124+
.setPrimaryLeaseId(primaryLeaseId)
125+
.setSequenceNumber(sequenceNumber)
126+
.setTimestamp(sequenceNumber * d_timestampIncrement);
127+
RecordBufferType buf;
128+
bsl::memcpy(buf.buffer(),
129+
rec.get(),
130+
FileStoreProtocol::k_JOURNAL_RECORD_SIZE);
131+
return buf;
132+
}
133+
83134
void JournalFile::addAllTypesRecords(RecordsListType* records)
84135
{
85136
// PRECONDITIONS
@@ -166,49 +217,12 @@ void JournalFile::addAllTypesRecords(RecordsListType* records)
166217
records->push_back(bsl::make_pair(RecordType::e_DELETION, buf));
167218
}
168219
else if (3 == remainder) {
169-
// QueueOpRec
170-
OffsetPtr<QueueOpRecord> rec(d_block, d_currPos);
171-
new (rec.get()) QueueOpRecord();
172-
rec->header()
173-
.setPrimaryLeaseId(100)
174-
.setSequenceNumber(i)
175-
.setTimestamp(i * d_timestampIncrement);
176-
rec->setFlags(3)
177-
.setQueueKey(
178-
mqbu::StorageKey(mqbu::StorageKey::BinaryRepresentation(),
179-
"abcde"))
180-
.setAppKey(
181-
mqbu::StorageKey(mqbu::StorageKey::BinaryRepresentation(),
182-
"appid"))
183-
.setType(QueueOpType::e_PURGE)
184-
.setMagic(RecordHeader::k_MAGIC);
185-
186-
RecordBufferType buf;
187-
bsl::memcpy(buf.buffer(),
188-
rec.get(),
189-
FileStoreProtocol::k_JOURNAL_RECORD_SIZE);
190-
records->push_back(bsl::make_pair(RecordType::e_QUEUE_OP, buf));
220+
records->push_back(bsl::make_pair(RecordType::e_QUEUE_OP,
221+
makeQueueOpRecord(100, i)));
191222
}
192223
else {
193-
OffsetPtr<JournalOpRecord> rec(d_block, d_currPos);
194-
new (rec.get()) JournalOpRecord(JournalOpType::e_SYNCPOINT,
195-
SyncPointType::e_REGULAR,
196-
1234567, // seqNum
197-
25, // leaderTerm
198-
121, // leaderNodeId
199-
8800, // dataFilePosition
200-
100, // qlistFilePosition
201-
RecordHeader::k_MAGIC);
202-
203-
rec->header()
204-
.setPrimaryLeaseId(100)
205-
.setSequenceNumber(i)
206-
.setTimestamp(i * d_timestampIncrement);
207-
RecordBufferType buf;
208-
bsl::memcpy(buf.buffer(),
209-
rec.get(),
210-
FileStoreProtocol::k_JOURNAL_RECORD_SIZE);
211-
records->push_back(bsl::make_pair(RecordType::e_JOURNAL_OP, buf));
224+
records->push_back(bsl::make_pair(RecordType::e_JOURNAL_OP,
225+
makeJournalOpRecord(100, i)));
212226
}
213227

214228
d_currPos += FileStoreProtocol::k_JOURNAL_RECORD_SIZE;
@@ -335,7 +349,6 @@ void JournalFile::addJournalRecordsWithPartiallyConfirmedMessages(
335349
unsigned int remainder = i % 3;
336350

337351
if (1 == remainder) {
338-
// bmqt::MessageGUID g;
339352
mqbu::MessageGUIDUtil::generateGUID(&lastMessageGUID);
340353
OffsetPtr<MessageRecord> rec(d_block, d_currPos);
341354
new (rec.get()) MessageRecord();
@@ -698,27 +711,9 @@ void JournalFile::addMultipleTypesRecordsWithMultipleLeaseId(
698711
}
699712
else {
700713
// QueueOpRec
701-
OffsetPtr<QueueOpRecord> rec(d_block, d_currPos);
702-
new (rec.get()) QueueOpRecord();
703-
rec->header()
704-
.setPrimaryLeaseId(leaseId)
705-
.setSequenceNumber(seqNumber++)
706-
.setTimestamp(i * d_timestampIncrement);
707-
rec->setFlags(3)
708-
.setQueueKey(
709-
mqbu::StorageKey(mqbu::StorageKey::BinaryRepresentation(),
710-
"abcde"))
711-
.setAppKey(
712-
mqbu::StorageKey(mqbu::StorageKey::BinaryRepresentation(),
713-
"appid"))
714-
.setType(QueueOpType::e_PURGE)
715-
.setMagic(RecordHeader::k_MAGIC);
716-
717-
RecordBufferType buf;
718-
bsl::memcpy(buf.buffer(),
719-
rec.get(),
720-
FileStoreProtocol::k_JOURNAL_RECORD_SIZE);
721-
records->push_back(bsl::make_pair(RecordType::e_QUEUE_OP, buf));
714+
records->push_back(
715+
bsl::make_pair(RecordType::e_QUEUE_OP,
716+
makeQueueOpRecord(leaseId, seqNumber++)));
722717
}
723718

724719
d_currPos += FileStoreProtocol::k_JOURNAL_RECORD_SIZE;

src/applications/bmqstoragetool/m_bmqstoragetool_journalfile.h

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ class JournalFile {
108108

109109
// MANIPULATORS
110110

111+
/// Generate a record of QueueOp type with the specified `primaryLeaseId`
112+
/// and the specified `sequenceNumber`. Push it to the specified `records`.
113+
RecordBufferType makeQueueOpRecord(unsigned int primaryLeaseId,
114+
bsls::Types::Uint64 sequenceNumber);
115+
116+
/// Generate a record of JournalOp type with the specified `primaryLeaseId`
117+
/// and the specified `sequenceNumber`. Push it to the specified `records`.
118+
RecordBufferType makeJournalOpRecord(unsigned int primaryLeaseId,
119+
bsls::Types::Uint64 sequenceNumber);
120+
111121
/// Generate sequence of all types of records. Store list of created
112122
/// records in the specified `records`.
113123
void addAllTypesRecords(RecordsListType* records);

src/applications/bmqstoragetool/m_bmqstoragetool_journalfileprocessor.t.cpp

+9-37
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ MATCHER_P(OffsetMatcher, expectedOffset, "")
280280
return arg.d_recordOffset == expectedOffset;
281281
}
282282

283+
/// Calculate record offset
283284
template <typename RECORD_TYPE>
284285
bsls::Types::Uint64 recordOffset(const RECORD_TYPE& record)
285286
{
@@ -288,33 +289,6 @@ bsls::Types::Uint64 recordOffset(const RECORD_TYPE& record)
288289
mqbs::FileStoreProtocol::k_JOURNAL_RECORD_SIZE;
289290
}
290291

291-
class RecordSequenceNumbersChecker {
292-
public:
293-
typedef bsl::vector<CompositeSequenceNumber> CompositesVec;
294-
295-
private:
296-
const CompositesVec& d_composites;
297-
CompositesVec::const_iterator d_it;
298-
299-
public:
300-
explicit RecordSequenceNumbersChecker(const CompositesVec& composites)
301-
: d_composites(composites)
302-
, d_it(d_composites.cbegin())
303-
{
304-
}
305-
306-
template <typename RECORD_TYPE>
307-
void checkDetails(const RecordDetails<RECORD_TYPE>& details)
308-
{
309-
BMQTST_ASSERT_D("TOO MANY CALLS", (d_it != d_composites.cend()));
310-
BMQTST_ASSERT_EQ(CompositeSequenceNumber(
311-
details.d_record.header().primaryLeaseId(),
312-
details.d_record.header().sequenceNumber()),
313-
*d_it);
314-
++d_it;
315-
}
316-
};
317-
318292
/// Helper matcher to check the offset of the record. Return 'true' if the
319293
/// specified 'expectedOffset' is equal to the offset of the RecordDetails
320294
/// 'arg'.
@@ -1895,9 +1869,7 @@ static void test18_searchMessagesByOffsetsRange()
18951869
if (rtype == RecordType::e_MESSAGE) {
18961870
const MessageRecord& msg = *reinterpret_cast<const MessageRecord*>(
18971871
recordIter->second.buffer());
1898-
const bsls::Types::Uint64& offset =
1899-
msg.header().sequenceNumber() *
1900-
mqbs::FileStoreProtocol::k_JOURNAL_RECORD_SIZE;
1872+
const bsls::Types::Uint64 offset = recordOffset(msg);
19011873
if (offset > offsetGt && offset < offsetLt) {
19021874
EXPECT_CALL(*printer, printGuid(msg.messageGUID()))
19031875
.InSequence(s);
@@ -1961,7 +1933,7 @@ static void test19_searchQueueOpRecords()
19611933
createCommandProcessor(&params,
19621934
printer,
19631935
fileManager,
1964-
bsl::cout,
1936+
resultStream,
19651937
bmqtst::TestHelperUtil::allocator());
19661938

19671939
// Get queueOp records content within offsets range and prepare
@@ -1976,7 +1948,7 @@ static void test19_searchQueueOpRecords()
19761948
const QueueOpRecord& queueOp =
19771949
*reinterpret_cast<const QueueOpRecord*>(
19781950
recordIter->second.buffer());
1979-
const bsls::Types::Uint64& offset = recordOffset(queueOp);
1951+
const bsls::Types::Uint64 offset = recordOffset(queueOp);
19801952
if (offset > offsetGt && offset < offsetLt) {
19811953
++queueOpCount;
19821954
EXPECT_CALL(*printer,
@@ -2056,7 +2028,7 @@ static void test20_searchJournalOpRecords()
20562028
const JournalOpRecord& journalOp =
20572029
*reinterpret_cast<const JournalOpRecord*>(
20582030
recordIter->second.buffer());
2059-
const bsls::Types::Uint64& offset = recordOffset(journalOp);
2031+
const bsls::Types::Uint64 offset = recordOffset(journalOp);
20602032
if (offset > offsetGt && offset < offsetLt) {
20612033
++journalOpCount;
20622034
EXPECT_CALL(*printer,
@@ -2140,7 +2112,7 @@ static void test21_searchAllTypesRecords()
21402112
if (rtype == RecordType::e_MESSAGE) {
21412113
const MessageRecord& msg = *reinterpret_cast<const MessageRecord*>(
21422114
recordIter->second.buffer());
2143-
const bsls::Types::Uint64& offset = recordOffset(msg);
2115+
const bsls::Types::Uint64 offset = recordOffset(msg);
21442116
if (offset > offsetGt && offset < offsetLt) {
21452117
msgCnt++;
21462118
EXPECT_CALL(*printer, printGuid(msg.messageGUID()))
@@ -2151,7 +2123,7 @@ static void test21_searchAllTypesRecords()
21512123
const QueueOpRecord& queueOp =
21522124
*reinterpret_cast<const QueueOpRecord*>(
21532125
recordIter->second.buffer());
2154-
const bsls::Types::Uint64& offset = recordOffset(queueOp);
2126+
const bsls::Types::Uint64 offset = recordOffset(queueOp);
21552127
if (offset > offsetGt && offset < offsetLt) {
21562128
queueOpCnt++;
21572129
EXPECT_CALL(*printer,
@@ -2163,7 +2135,7 @@ static void test21_searchAllTypesRecords()
21632135
const JournalOpRecord& journalOp =
21642136
*reinterpret_cast<const JournalOpRecord*>(
21652137
recordIter->second.buffer());
2166-
const bsls::Types::Uint64& offset = recordOffset(journalOp);
2138+
const bsls::Types::Uint64 offset = recordOffset(journalOp);
21672139
if (offset > offsetGt && offset < offsetLt) {
21682140
journalOpCnt++;
21692141
EXPECT_CALL(*printer,
@@ -2233,7 +2205,7 @@ static void test22_searchQueueOpRecordsByOffset()
22332205
const QueueOpRecord& queueOp =
22342206
*reinterpret_cast<const QueueOpRecord*>(
22352207
recordIter->second.buffer());
2236-
const bsls::Types::Uint64& offset = recordOffset(queueOp);
2208+
const bsls::Types::Uint64 offset = recordOffset(queueOp);
22372209
if (queueOpCnt++ % 3 == 0) {
22382210
params.d_offset.push_back(offset);
22392211
EXPECT_CALL(*printer,

src/applications/bmqstoragetool/m_bmqstoragetool_messagedetails.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct QueueDetails {
6868
}
6969
};
7070
typedef bsl::unordered_map<mqbu::StorageKey, AppDetails> AppDetailsMap;
71-
// Map of records deteils per App
71+
// Map of records details per App
7272

7373
// PUBLIC DATA
7474

src/applications/bmqstoragetool/m_bmqstoragetool_parameters.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ void Parameters::validateQueueNames(bslma::Allocator* allocator) const
474474
{
475475
// Validate given queue names agains existing in csl file
476476
bmqu::MemOutStream ss(allocator);
477-
mqbu::StorageKey key;
478477
bsl::vector<bsl::string>::const_iterator it = d_queueName.cbegin();
479478
for (; it != d_queueName.cend(); ++it) {
480479
if (!d_queueMap.findKeyByUri(*it).has_value()) {

0 commit comments

Comments
 (0)