mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 06:25:34 +00:00
[2207] Throw better exception
This commit is contained in:
@@ -47,7 +47,7 @@ public:
|
|||||||
/// discard it.
|
/// discard it.
|
||||||
/// \note After successful load(), you have to call cleanup() some time
|
/// \note After successful load(), you have to call cleanup() some time
|
||||||
/// later.
|
/// later.
|
||||||
/// \throw isc::Unexpected if called second time.
|
/// \throw isc::InvalidOperation if called second time.
|
||||||
virtual void load() = 0;
|
virtual void load() = 0;
|
||||||
|
|
||||||
/// \brief Put the changes to effect.
|
/// \brief Put the changes to effect.
|
||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
/// This may throw in rare cases, depending on the concrete implementation.
|
/// This may throw in rare cases, depending on the concrete implementation.
|
||||||
/// If it throws, you still need to call cleanup().
|
/// If it throws, you still need to call cleanup().
|
||||||
///
|
///
|
||||||
/// \throw isc::Unexpected if called without previous load() or for the
|
/// \throw isc::InvalidOperation if called without previous load() or for the
|
||||||
/// second time or cleanup() was called already.
|
/// second time or cleanup() was called already.
|
||||||
virtual void install() = 0;
|
virtual void install() = 0;
|
||||||
|
|
||||||
|
@@ -46,14 +46,14 @@ ZoneWriterLocal::~ZoneWriterLocal() {
|
|||||||
void
|
void
|
||||||
ZoneWriterLocal::load() {
|
ZoneWriterLocal::load() {
|
||||||
if (loaded_) {
|
if (loaded_) {
|
||||||
isc_throw(isc::Unexpected, "Trying to load twice");
|
isc_throw(isc::InvalidOperation, "Trying to load twice");
|
||||||
}
|
}
|
||||||
|
|
||||||
zone_data_ = load_action_(segment_->getMemorySegment());
|
zone_data_ = load_action_(segment_->getMemorySegment());
|
||||||
|
|
||||||
if (zone_data_ == NULL) {
|
if (zone_data_ == NULL) {
|
||||||
// Bug inside load_action_.
|
// Bug inside load_action_.
|
||||||
isc_throw(isc::Unexpected, "No data returned from load action");
|
isc_throw(isc::InvalidOperation, "No data returned from load action");
|
||||||
}
|
}
|
||||||
|
|
||||||
loaded_ = true;
|
loaded_ = true;
|
||||||
@@ -63,13 +63,13 @@ ZoneWriterLocal::load() {
|
|||||||
void
|
void
|
||||||
ZoneWriterLocal::install() {
|
ZoneWriterLocal::install() {
|
||||||
if (!data_ready_) {
|
if (!data_ready_) {
|
||||||
isc_throw(isc::Unexpected, "No data to install");
|
isc_throw(isc::InvalidOperation, "No data to install");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ZoneTable* table(segment_->getHeader().getTable());
|
ZoneTable* table(segment_->getHeader().getTable());
|
||||||
if (table == NULL) {
|
if (table == NULL) {
|
||||||
isc_throw(isc::Unexpected, "No zone table present");
|
isc_throw(isc::InvalidOperation, "No zone table present");
|
||||||
}
|
}
|
||||||
ZoneTable::AddResult result(table->addZone(segment_->getMemorySegment(),
|
ZoneTable::AddResult result(table->addZone(segment_->getMemorySegment(),
|
||||||
rrclass_, origin_, zone_data_));
|
rrclass_, origin_, zone_data_));
|
||||||
|
@@ -53,7 +53,7 @@ public:
|
|||||||
/// This calls the load_action (passed to constructor) and stores the
|
/// This calls the load_action (passed to constructor) and stores the
|
||||||
/// data for future use.
|
/// data for future use.
|
||||||
///
|
///
|
||||||
/// \throw isc::Unexpected if it is called the second time in lifetime
|
/// \throw isc::InvalidOperation if it is called the second time in lifetime
|
||||||
/// of the object.
|
/// of the object.
|
||||||
/// \throw Whatever the load_action throws, it is propagated up.
|
/// \throw Whatever the load_action throws, it is propagated up.
|
||||||
virtual void load();
|
virtual void load();
|
||||||
@@ -63,7 +63,7 @@ public:
|
|||||||
/// It modifies the zone table accessible through the segment (passed to
|
/// It modifies the zone table accessible through the segment (passed to
|
||||||
/// constructor).
|
/// constructor).
|
||||||
///
|
///
|
||||||
/// \throw isc::Unexpected if it is called the second time in lifetime
|
/// \throw isc::InvalidOperation if it is called the second time in lifetime
|
||||||
/// of the object or if load() was not called previously or if
|
/// of the object or if load() was not called previously or if
|
||||||
/// cleanup() was already called.
|
/// cleanup() was already called.
|
||||||
virtual void install();
|
virtual void install();
|
||||||
|
@@ -118,7 +118,7 @@ TEST_F(ZoneWriterLocalTest, loadTwice) {
|
|||||||
load_called_ = false;
|
load_called_ = false;
|
||||||
|
|
||||||
// The second time, it should not be possible
|
// The second time, it should not be possible
|
||||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
EXPECT_THROW(writer_->load(), isc::InvalidOperation);
|
||||||
EXPECT_FALSE(load_called_);
|
EXPECT_FALSE(load_called_);
|
||||||
|
|
||||||
// The object should not be damaged, try installing and clearing now
|
// The object should not be damaged, try installing and clearing now
|
||||||
@@ -139,20 +139,20 @@ TEST_F(ZoneWriterLocalTest, loadLater) {
|
|||||||
// Reset so we see nothing is called now
|
// Reset so we see nothing is called now
|
||||||
load_called_ = false;
|
load_called_ = false;
|
||||||
|
|
||||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
EXPECT_THROW(writer_->load(), isc::InvalidOperation);
|
||||||
EXPECT_FALSE(load_called_);
|
EXPECT_FALSE(load_called_);
|
||||||
|
|
||||||
// Cleanup and try loading again. Still shouldn't work.
|
// Cleanup and try loading again. Still shouldn't work.
|
||||||
EXPECT_NO_THROW(writer_->cleanup());
|
EXPECT_NO_THROW(writer_->cleanup());
|
||||||
|
|
||||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
EXPECT_THROW(writer_->load(), isc::InvalidOperation);
|
||||||
EXPECT_FALSE(load_called_);
|
EXPECT_FALSE(load_called_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try calling install at various bad times
|
// Try calling install at various bad times
|
||||||
TEST_F(ZoneWriterLocalTest, invalidInstall) {
|
TEST_F(ZoneWriterLocalTest, invalidInstall) {
|
||||||
// Nothing loaded yet
|
// Nothing loaded yet
|
||||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
EXPECT_THROW(writer_->install(), isc::InvalidOperation);
|
||||||
EXPECT_FALSE(load_called_);
|
EXPECT_FALSE(load_called_);
|
||||||
|
|
||||||
EXPECT_NO_THROW(writer_->load());
|
EXPECT_NO_THROW(writer_->load());
|
||||||
@@ -160,7 +160,7 @@ TEST_F(ZoneWriterLocalTest, invalidInstall) {
|
|||||||
// This install is OK
|
// This install is OK
|
||||||
EXPECT_NO_THROW(writer_->install());
|
EXPECT_NO_THROW(writer_->install());
|
||||||
// But we can't call it second time now
|
// But we can't call it second time now
|
||||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
EXPECT_THROW(writer_->install(), isc::InvalidOperation);
|
||||||
EXPECT_FALSE(load_called_);
|
EXPECT_FALSE(load_called_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ TEST_F(ZoneWriterLocalTest, cleanWithoutInstall) {
|
|||||||
EXPECT_TRUE(load_called_);
|
EXPECT_TRUE(load_called_);
|
||||||
|
|
||||||
// We cleaned up, no way to install now
|
// We cleaned up, no way to install now
|
||||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
EXPECT_THROW(writer_->install(), isc::InvalidOperation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the case when load callback throws
|
// Test the case when load callback throws
|
||||||
@@ -183,7 +183,7 @@ TEST_F(ZoneWriterLocalTest, loadThrows) {
|
|||||||
EXPECT_THROW(writer_->load(), TestException);
|
EXPECT_THROW(writer_->load(), TestException);
|
||||||
|
|
||||||
// We can't install now
|
// We can't install now
|
||||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
EXPECT_THROW(writer_->install(), isc::InvalidOperation);
|
||||||
EXPECT_TRUE(load_called_);
|
EXPECT_TRUE(load_called_);
|
||||||
|
|
||||||
// But we can cleanup
|
// But we can cleanup
|
||||||
@@ -208,10 +208,10 @@ TEST_F(ZoneWriterLocalTest, retry) {
|
|||||||
// Check the writer defends itsefl when load action returns NULL
|
// Check the writer defends itsefl when load action returns NULL
|
||||||
TEST_F(ZoneWriterLocalTest, loadNull) {
|
TEST_F(ZoneWriterLocalTest, loadNull) {
|
||||||
load_null_ = true;
|
load_null_ = true;
|
||||||
EXPECT_THROW(writer_->load(), isc::Unexpected);
|
EXPECT_THROW(writer_->load(), isc::InvalidOperation);
|
||||||
|
|
||||||
// We can't install that
|
// We can't install that
|
||||||
EXPECT_THROW(writer_->install(), isc::Unexpected);
|
EXPECT_THROW(writer_->install(), isc::InvalidOperation);
|
||||||
|
|
||||||
// It should be possible to clean up safely
|
// It should be possible to clean up safely
|
||||||
EXPECT_NO_THROW(writer_->cleanup());
|
EXPECT_NO_THROW(writer_->cleanup());
|
||||||
|
Reference in New Issue
Block a user