Skip to content

Commit 7d8db39

Browse files
authored
Feat[BMQT]: better verbosity for bmqt::QueueId::isValid [180624984] (#913)
Signed-off-by: Evgeny Malygin <[email protected]> Signed-off-by: Evgenii Malygin <[email protected]>
1 parent 6ccf7d3 commit 7d8db39

File tree

5 files changed

+38
-20
lines changed

5 files changed

+38
-20
lines changed

src/groups/bmq/bmqa/bmqa_queueid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ const bmqt::QueueOptions& QueueId::options() const
126126
return d_impl_sp->options();
127127
}
128128

129-
bool QueueId::isValid() const
129+
bool QueueId::isValid(bsl::ostream* reason_p) const
130130
{
131131
// PRECONDITIONS
132132
BSLS_ASSERT_SAFE(d_impl_sp);
133133

134-
return d_impl_sp->isValid();
134+
return d_impl_sp->isValid(reason_p);
135135
}
136136

137137
bsl::ostream&

src/groups/bmq/bmqa/bmqa_queueid.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ class QueueId {
128128
/// Return the options used when opening this queue.
129129
const bmqt::QueueOptions& options() const;
130130

131-
/// Return whether this QueueId is valid, i.e., is associated to an
132-
/// opened queue.
133-
bool isValid() const;
131+
/// @brief Return whether this QueueId is valid, i.e., is associated to an
132+
/// opened queue.
133+
/// @param reason_p The optionally specified stream that is used to report
134+
/// the reason why this QueueId is not valid.
135+
/// @return bool True if this QueueId is valid, false otherwise.
136+
bool isValid(bsl::ostream* reason_p = 0) const;
134137

135138
/// Format this object to the specified output `stream` at the (absolute
136139
/// value of) the optionally specified indentation `level` and return a

src/groups/bmq/bmqa/bmqa_queueid.t.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <bmqt_queueoptions.h>
2525
#include <bmqt_resultcode.h>
2626
#include <bmqt_uri.h>
27+
#include <bmqu_memoutstream.h>
2728

2829
// BDE
2930
#include <bsl_memory.h>
@@ -64,7 +65,9 @@ static void test1_breathingTest()
6465
PV("Default Constructor");
6566
{
6667
bmqa::QueueId obj(bmqtst::TestHelperUtil::allocator());
67-
BMQTST_ASSERT_EQ(obj.isValid(), false);
68+
bmqu::MemOutStream reason(bmqtst::TestHelperUtil::allocator());
69+
BMQTST_ASSERT_EQ(obj.isValid(&reason), false);
70+
BMQTST_ASSERT_EQ(reason.str(), "Invalid QueueId: 4294967295");
6871
}
6972

7073
PV("Valued Constructor - correlationId");

src/groups/bmq/bmqa/bmqa_session.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,7 @@ SessionUtil::validateAndSetConfigureQueueParameters(
582582
}
583583

584584
// Make sure the provided QueueId is valid
585-
if (!queueId->isValid()) {
586-
(*errorDescription) << "Invalid QueueId";
585+
if (!queueId->isValid(errorDescription)) {
587586
return bmqt::ConfigureQueueResult::e_INVALID_QUEUE; // RETURN
588587
}
589588

@@ -618,8 +617,7 @@ bmqt::CloseQueueResult::Enum SessionUtil::validateAndSetCloseQueueParameters(
618617
}
619618

620619
// Make sure the provided QueueId is valid
621-
if (!queueId->isValid()) {
622-
(*errorDescription) << "Invalid QueueId";
620+
if (!queueId->isValid(errorDescription)) {
623621
return bmqt::CloseQueueResult::e_INVALID_QUEUE; // RETURN
624622
}
625623

src/groups/bmq/bmqimp/bmqimp_queue.h

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,12 @@ class Queue {
381381

382382
bmqp::SchemaGenerator& schemaGenerator();
383383

384-
/// Return whether this Queue is valid, i.e., is associated to an
385-
/// initialized queue.
386-
bool isValid() const;
384+
/// @brief Return whether this Queue is valid, i.e., is associated to an
385+
/// opened queue.
386+
/// @param reason_p The optionally specified stream that is used to report
387+
/// the reason why this Queue is not valid.
388+
/// @return bool True if this Queue is valid, false otherwise.
389+
bool isValid(bsl::ostream* reason_p = 0) const;
387390

388391
/// Return whether this Queue is valid, i.e., is associated to an opened
389392
/// queue.
@@ -677,15 +680,26 @@ inline bmqp::SchemaGenerator& Queue::schemaGenerator()
677680
return d_schemaGenerator;
678681
}
679682

680-
inline bool Queue::isValid() const
683+
inline bool Queue::isValid(bsl::ostream* reason_p) const
681684
{
682685
const QueueState::Enum queueState = state();
683-
return ((d_handleParameters.qId() !=
684-
static_cast<unsigned int>(k_INVALID_QUEUE_ID)) &&
685-
(queueState == QueueState::e_OPENED ||
686-
queueState == QueueState::e_PENDING ||
687-
queueState == QueueState::e_REOPENING_OPN ||
688-
queueState == QueueState::e_REOPENING_CFG));
686+
if (d_handleParameters.qId() ==
687+
static_cast<unsigned int>(k_INVALID_QUEUE_ID)) {
688+
if (reason_p) {
689+
(*reason_p) << "Invalid QueueId: " << d_handleParameters.qId();
690+
}
691+
return false; // RETURN
692+
}
693+
const bool queueStateIsValid = (queueState == QueueState::e_OPENED ||
694+
queueState == QueueState::e_PENDING ||
695+
queueState ==
696+
QueueState::e_REOPENING_OPN ||
697+
queueState == QueueState::e_REOPENING_CFG);
698+
699+
if (!queueStateIsValid && reason_p) {
700+
(*reason_p) << "Invalid queue state: " << queueState;
701+
}
702+
return queueStateIsValid;
689703
}
690704

691705
inline bool Queue::isOpened() const

0 commit comments

Comments
 (0)