|
@@ -180,17 +180,16 @@ protected:
|
|
|
};
|
|
|
|
|
|
// Use the loader to load an unsigned zone.
|
|
|
-TEST_F(ZoneLoaderTest, copyUnsigned) {
|
|
|
+TEST_F(ZoneLoaderTest , copyUnsigned) {
|
|
|
prepareSource(Name::ROOT_NAME(), "root.zone");
|
|
|
ZoneLoader loader(destination_client_, Name::ROOT_NAME(), source_client_);
|
|
|
// It gets the updater directly in the constructor
|
|
|
ASSERT_EQ(1, destination_client_.provided_updaters_.size());
|
|
|
EXPECT_EQ(Name::ROOT_NAME(), destination_client_.provided_updaters_[0]);
|
|
|
|
|
|
- // Counters are initialized to 0.
|
|
|
+ // Counter is initialized to 0, progress is "unknown" in case of copy.
|
|
|
EXPECT_EQ(0, loader.getRRCount());
|
|
|
- EXPECT_EQ(0, loader.getSize());
|
|
|
- EXPECT_EQ(0, loader.getPosition());
|
|
|
+ EXPECT_EQ(ZoneLoader::PROGRESS_UNKNOWN, loader.getProgress());
|
|
|
|
|
|
// Now load the whole zone
|
|
|
loader.load();
|
|
@@ -202,10 +201,9 @@ TEST_F(ZoneLoaderTest, copyUnsigned) {
|
|
|
EXPECT_EQ(34, destination_client_.rrsets_.size());
|
|
|
|
|
|
// Check various counters. getRRCount should be identical of the RRs
|
|
|
- // we've seen. size and position should be still 0 in the copy operation.
|
|
|
+ // we've seen. progress is still "unknown" in the copy operation.
|
|
|
EXPECT_EQ(destination_client_.rrsets_.size(), loader.getRRCount());
|
|
|
- EXPECT_EQ(0, loader.getSize());
|
|
|
- EXPECT_EQ(0, loader.getPosition());
|
|
|
+ EXPECT_EQ(ZoneLoader::PROGRESS_UNKNOWN, loader.getProgress());
|
|
|
|
|
|
// Ensure known order.
|
|
|
std::sort(destination_client_.rrsets_.begin(),
|
|
@@ -234,11 +232,10 @@ TEST_F(ZoneLoaderTest, copyUnsignedIncremental) {
|
|
|
// Not committed yet, we didn't complete the loading
|
|
|
EXPECT_FALSE(destination_client_.commit_called_);
|
|
|
|
|
|
- // Check we can get intermediate counters. size/position are always 0
|
|
|
+ // Check we can get intermediate counters. progress is always "unknown"
|
|
|
// in case of copy.
|
|
|
EXPECT_EQ(destination_client_.rrsets_.size(), loader.getRRCount());
|
|
|
- EXPECT_EQ(0, loader.getSize());
|
|
|
- EXPECT_EQ(0, loader.getPosition());
|
|
|
+ EXPECT_EQ(ZoneLoader::PROGRESS_UNKNOWN, loader.getProgress());
|
|
|
|
|
|
// This is unusual, but allowed. Check it doesn't do anything
|
|
|
loader.loadIncremental(0);
|
|
@@ -309,10 +306,9 @@ TEST_F(ZoneLoaderTest, loadUnsigned) {
|
|
|
ZoneLoader loader(destination_client_, Name::ROOT_NAME(),
|
|
|
TEST_DATA_DIR "/root.zone");
|
|
|
|
|
|
- // Counters are initialized to 0.
|
|
|
+ // Counter and progress are initialized to 0.
|
|
|
EXPECT_EQ(0, loader.getRRCount());
|
|
|
- EXPECT_EQ(0, loader.getSize());
|
|
|
- EXPECT_EQ(0, loader.getPosition());
|
|
|
+ EXPECT_EQ(0, loader.getProgress());
|
|
|
|
|
|
// It gets the updater directly in the constructor
|
|
|
ASSERT_EQ(1, destination_client_.provided_updaters_.size());
|
|
@@ -326,12 +322,10 @@ TEST_F(ZoneLoaderTest, loadUnsigned) {
|
|
|
// The count is 34 because we expect the RRs to be separated.
|
|
|
EXPECT_EQ(34, destination_client_.rrsets_.size());
|
|
|
|
|
|
- // Check various counters. getRRCount should be identical of the RRs
|
|
|
- // we've seen. size and position should be identical of the RRs
|
|
|
- // file (hardcoded, assuming we won't change it so often).
|
|
|
+ // getRRCount should be identical of the RRs we've seen. progress
|
|
|
+ // should reach 100%.
|
|
|
EXPECT_EQ(destination_client_.rrsets_.size(), loader.getRRCount());
|
|
|
- EXPECT_EQ(1541, loader.getSize());
|
|
|
- EXPECT_EQ(1541, loader.getPosition());
|
|
|
+ EXPECT_EQ(100, loader.getProgress());
|
|
|
|
|
|
// Ensure known order.
|
|
|
std::sort(destination_client_.rrsets_.begin(),
|
|
@@ -341,13 +335,6 @@ TEST_F(ZoneLoaderTest, loadUnsigned) {
|
|
|
EXPECT_EQ("m.root-servers.net. 3600000 IN AAAA 2001:dc3::35\n",
|
|
|
destination_client_.rrsets_.back());
|
|
|
|
|
|
- // Check various counters. getRRCount should be identical of the RRs
|
|
|
- // we've seen. size and position should be equal to the size of the zone
|
|
|
- // file (hardcoded assuming we won't change it so often).
|
|
|
- EXPECT_EQ(destination_client_.rrsets_.size(), loader.getRRCount());
|
|
|
- EXPECT_EQ(1541, loader.getSize());
|
|
|
- EXPECT_EQ(1541, loader.getPosition());
|
|
|
-
|
|
|
// It isn't possible to try again now
|
|
|
EXPECT_THROW(loader.load(), isc::InvalidOperation);
|
|
|
EXPECT_THROW(loader.loadIncremental(1), isc::InvalidOperation);
|
|
@@ -362,8 +349,7 @@ TEST_F(ZoneLoaderTest, loadUnsignedIncremental) {
|
|
|
|
|
|
// Counters are initialized to 0.
|
|
|
EXPECT_EQ(0, loader.getRRCount());
|
|
|
- EXPECT_EQ(0, loader.getSize());
|
|
|
- EXPECT_EQ(0, loader.getPosition());
|
|
|
+ EXPECT_EQ(0, loader.getProgress());
|
|
|
|
|
|
// Try loading few RRs first.
|
|
|
loader.loadIncremental(10);
|
|
@@ -375,22 +361,23 @@ TEST_F(ZoneLoaderTest, loadUnsignedIncremental) {
|
|
|
EXPECT_EQ(10, destination_client_.rrsets_.size());
|
|
|
EXPECT_FALSE(destination_client_.commit_called_);
|
|
|
|
|
|
- // Check we can get intermediate counters. size is the size of the
|
|
|
- // zone file; position is the offset to the end of 10th RR (both
|
|
|
- // hardcoded).
|
|
|
+ // Check we can get intermediate counters. expected progress is calculated
|
|
|
+ // based on the size of the zone file and the offset to the end of 10th RR
|
|
|
+ // (subject to future changes to the file, but we assume it's a rare
|
|
|
+ // event.). This also involves floating point operation, which may
|
|
|
+ // cause a margin error depending on environments. If it happens we
|
|
|
+ // should loosen the test condition to accept some margin.
|
|
|
EXPECT_EQ(destination_client_.rrsets_.size(), loader.getRRCount());
|
|
|
- EXPECT_EQ(1541, loader.getSize());
|
|
|
- EXPECT_EQ(428, loader.getPosition());
|
|
|
+ EXPECT_EQ(27, loader.getProgress()); // file size = 1541, offset = 428
|
|
|
|
|
|
// We can finish the rest
|
|
|
loader.loadIncremental(30);
|
|
|
EXPECT_EQ(34, destination_client_.rrsets_.size());
|
|
|
EXPECT_TRUE(destination_client_.commit_called_);
|
|
|
|
|
|
- // Counters are updated accordingly. size and position are now identical.
|
|
|
+ // Counters are updated accordingly. progress should reach 100%.
|
|
|
EXPECT_EQ(destination_client_.rrsets_.size(), loader.getRRCount());
|
|
|
- EXPECT_EQ(1541, loader.getSize());
|
|
|
- EXPECT_EQ(1541, loader.getPosition());
|
|
|
+ EXPECT_EQ(100, loader.getProgress());
|
|
|
|
|
|
// No more loading now
|
|
|
EXPECT_THROW(loader.load(), isc::InvalidOperation);
|