Commit 8743e25c authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[2378] Check attempt to load past the end

parent c2d2a53b
......@@ -161,6 +161,12 @@ TEST_F(ZoneLoaderTest, copyUnsigned) {
destination_client_.rrsets_.front());
EXPECT_EQ("m.root-servers.net. 3600000 IN AAAA 2001:dc3::35\n",
destination_client_.rrsets_.back());
// It isn't possible to try again now
EXPECT_THROW(loader.load(), isc::InvalidOperation);
EXPECT_THROW(loader.loadIncremental(1), isc::InvalidOperation);
// Even 0, which should load nothing, returns the error
EXPECT_THROW(loader.loadIncremental(0), isc::InvalidOperation);
}
}
......@@ -32,7 +32,8 @@ ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
// Separate the RRsets as that is possibly faster (the data source doesn't
// have to aggregate them) and also because our limit semantics.
iterator_(source.getIterator(zone_name, true)),
updater_(destination.getUpdater(zone_name, true, false))
updater_(destination.getUpdater(zone_name, true, false)),
complete_(false)
{
// The getIterator should never return NULL. So we check it.
// Or should we throw instead?
......@@ -69,9 +70,15 @@ copyRRsets(const ZoneUpdaterPtr& destination, const ZoneIteratorPtr& source,
bool
ZoneLoader::loadIncremental(size_t limit) {
if (complete_) {
isc_throw(isc::InvalidOperation,
"Loading has been completed previously");
}
if (iterator_ != ZoneIteratorPtr()) {
if (copyRRsets(updater_, iterator_, limit)) {
updater_->commit();
complete_ = true;
return (true);
} else {
return (false);
......
......@@ -119,6 +119,8 @@ private:
const ZoneIteratorPtr iterator_;
/// \brief The destination zone updater
const ZoneUpdaterPtr updater_;
/// \brief Indicator if loading was completed
bool complete_;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment