|
|
@ -172,154 +172,160 @@ TEST(FindFileTest, OverlappingFiles) { |
|
|
|
ASSERT_TRUE(Overlaps("600", "700")); |
|
|
|
} |
|
|
|
|
|
|
|
void AddBoundaryInputs(const InternalKeyComparator &icmp, |
|
|
|
const std::vector<FileMetaData *> &levelFiles, |
|
|
|
std::vector<FileMetaData *> *compactionFiles); |
|
|
|
void AddBoundaryInputs(const InternalKeyComparator& icmp, |
|
|
|
const std::vector<FileMetaData*>& level_files, |
|
|
|
std::vector<FileMetaData*>* compaction_files); |
|
|
|
|
|
|
|
class AddBoundaryInputsTest { |
|
|
|
public: |
|
|
|
std::vector<FileMetaData *> levelFiles_; |
|
|
|
std::vector<FileMetaData *> compactionFiles_; |
|
|
|
std::vector<FileMetaData *> allFiles_; |
|
|
|
std::vector<FileMetaData*> level_files_; |
|
|
|
std::vector<FileMetaData*> compaction_files_; |
|
|
|
std::vector<FileMetaData*> all_files_; |
|
|
|
InternalKeyComparator icmp_; |
|
|
|
|
|
|
|
AddBoundaryInputsTest() : icmp_(BytewiseComparator()){}; |
|
|
|
|
|
|
|
~AddBoundaryInputsTest() { |
|
|
|
for (size_t i = 0; i < allFiles_.size(); ++i) { |
|
|
|
delete allFiles_[i]; |
|
|
|
for (size_t i = 0; i < all_files_.size(); ++i) { |
|
|
|
delete all_files_[i]; |
|
|
|
} |
|
|
|
allFiles_.clear(); |
|
|
|
all_files_.clear(); |
|
|
|
}; |
|
|
|
|
|
|
|
FileMetaData *CreateFileMetaData(uint64_t number, InternalKey smallest, |
|
|
|
FileMetaData* CreateFileMetaData(uint64_t number, InternalKey smallest, |
|
|
|
InternalKey largest) { |
|
|
|
FileMetaData *f = new FileMetaData(); |
|
|
|
FileMetaData* f = new FileMetaData(); |
|
|
|
f->number = number; |
|
|
|
f->smallest = smallest; |
|
|
|
f->largest = largest; |
|
|
|
allFiles_.push_back(f); |
|
|
|
all_files_.push_back(f); |
|
|
|
return f; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
TEST(AddBoundaryInputsTest, TestEmptyFileSets) { |
|
|
|
AddBoundaryInputs(icmp_, levelFiles_, &compactionFiles_); |
|
|
|
ASSERT_TRUE(compactionFiles_.empty()); |
|
|
|
ASSERT_TRUE(levelFiles_.empty()); |
|
|
|
AddBoundaryInputs(icmp_, level_files_, &compaction_files_); |
|
|
|
ASSERT_TRUE(compaction_files_.empty()); |
|
|
|
ASSERT_TRUE(level_files_.empty()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AddBoundaryInputsTest, TestEmptyLevelFiles) { |
|
|
|
FileMetaData *f1 = |
|
|
|
FileMetaData* f1 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 1, kTypeValue))); |
|
|
|
compactionFiles_.push_back(f1); |
|
|
|
compaction_files_.push_back(f1); |
|
|
|
|
|
|
|
AddBoundaryInputs(icmp_, levelFiles_, &compactionFiles_); |
|
|
|
ASSERT_EQ(1, compactionFiles_.size()); |
|
|
|
ASSERT_EQ(f1, compactionFiles_[0]); |
|
|
|
ASSERT_TRUE(levelFiles_.empty()); |
|
|
|
AddBoundaryInputs(icmp_, level_files_, &compaction_files_); |
|
|
|
ASSERT_EQ(1, compaction_files_.size()); |
|
|
|
ASSERT_EQ(f1, compaction_files_[0]); |
|
|
|
ASSERT_TRUE(level_files_.empty()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AddBoundaryInputsTest, TestEmptyCompactionFiles) { |
|
|
|
FileMetaData *f1 = |
|
|
|
FileMetaData* f1 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 1, kTypeValue))); |
|
|
|
levelFiles_.push_back(f1); |
|
|
|
level_files_.push_back(f1); |
|
|
|
|
|
|
|
AddBoundaryInputs(icmp_, levelFiles_, &compactionFiles_); |
|
|
|
ASSERT_TRUE(compactionFiles_.empty()); |
|
|
|
ASSERT_EQ(1, levelFiles_.size()); |
|
|
|
ASSERT_EQ(f1, levelFiles_[0]); |
|
|
|
AddBoundaryInputs(icmp_, level_files_, &compaction_files_); |
|
|
|
ASSERT_TRUE(compaction_files_.empty()); |
|
|
|
ASSERT_EQ(1, level_files_.size()); |
|
|
|
ASSERT_EQ(f1, level_files_[0]); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AddBoundaryInputsTest, TestNoBoundaryFiles) { |
|
|
|
FileMetaData *f1 = |
|
|
|
FileMetaData* f1 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 1, kTypeValue))); |
|
|
|
FileMetaData *f2 = |
|
|
|
FileMetaData* f2 = |
|
|
|
CreateFileMetaData(1, InternalKey("200", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("200", 1, kTypeValue))); |
|
|
|
FileMetaData *f3 = |
|
|
|
FileMetaData* f3 = |
|
|
|
CreateFileMetaData(1, InternalKey("300", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("300", 1, kTypeValue))); |
|
|
|
|
|
|
|
levelFiles_.push_back(f3); |
|
|
|
levelFiles_.push_back(f2); |
|
|
|
levelFiles_.push_back(f1); |
|
|
|
compactionFiles_.push_back(f2); |
|
|
|
compactionFiles_.push_back(f3); |
|
|
|
level_files_.push_back(f3); |
|
|
|
level_files_.push_back(f2); |
|
|
|
level_files_.push_back(f1); |
|
|
|
compaction_files_.push_back(f2); |
|
|
|
compaction_files_.push_back(f3); |
|
|
|
|
|
|
|
AddBoundaryInputs(icmp_, levelFiles_, &compactionFiles_); |
|
|
|
ASSERT_EQ(2, compactionFiles_.size()); |
|
|
|
AddBoundaryInputs(icmp_, level_files_, &compaction_files_); |
|
|
|
ASSERT_EQ(2, compaction_files_.size()); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AddBoundaryInputsTest, TestOneBoundaryFiles) { |
|
|
|
FileMetaData *f1 = |
|
|
|
FileMetaData* f1 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 3, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 2, kTypeValue))); |
|
|
|
FileMetaData *f2 = |
|
|
|
FileMetaData* f2 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 1, kTypeValue), |
|
|
|
InternalKey(InternalKey("200", 3, kTypeValue))); |
|
|
|
FileMetaData *f3 = |
|
|
|
FileMetaData* f3 = |
|
|
|
CreateFileMetaData(1, InternalKey("300", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("300", 1, kTypeValue))); |
|
|
|
|
|
|
|
levelFiles_.push_back(f3); |
|
|
|
levelFiles_.push_back(f2); |
|
|
|
levelFiles_.push_back(f1); |
|
|
|
compactionFiles_.push_back(f1); |
|
|
|
level_files_.push_back(f3); |
|
|
|
level_files_.push_back(f2); |
|
|
|
level_files_.push_back(f1); |
|
|
|
compaction_files_.push_back(f1); |
|
|
|
|
|
|
|
AddBoundaryInputs(icmp_, levelFiles_, &compactionFiles_); |
|
|
|
ASSERT_EQ(2, compactionFiles_.size()); |
|
|
|
ASSERT_EQ(f1, compactionFiles_[0]); |
|
|
|
ASSERT_EQ(f2, compactionFiles_[1]); |
|
|
|
AddBoundaryInputs(icmp_, level_files_, &compaction_files_); |
|
|
|
ASSERT_EQ(2, compaction_files_.size()); |
|
|
|
ASSERT_EQ(f1, compaction_files_[0]); |
|
|
|
ASSERT_EQ(f2, compaction_files_[1]); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AddBoundaryInputsTest, TestTwoBoundaryFiles) { |
|
|
|
FileMetaData *f1 = |
|
|
|
FileMetaData* f1 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 6, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 5, kTypeValue))); |
|
|
|
FileMetaData *f2 = |
|
|
|
FileMetaData* f2 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("300", 1, kTypeValue))); |
|
|
|
FileMetaData *f3 = |
|
|
|
FileMetaData* f3 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 4, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 3, kTypeValue))); |
|
|
|
|
|
|
|
levelFiles_.push_back(f2); |
|
|
|
levelFiles_.push_back(f3); |
|
|
|
levelFiles_.push_back(f1); |
|
|
|
compactionFiles_.push_back(f1); |
|
|
|
level_files_.push_back(f2); |
|
|
|
level_files_.push_back(f3); |
|
|
|
level_files_.push_back(f1); |
|
|
|
compaction_files_.push_back(f1); |
|
|
|
|
|
|
|
AddBoundaryInputs(icmp_, levelFiles_, &compactionFiles_); |
|
|
|
ASSERT_EQ(3, compactionFiles_.size()); |
|
|
|
ASSERT_EQ(f1, compactionFiles_[0]); |
|
|
|
ASSERT_EQ(f3, compactionFiles_[1]); |
|
|
|
ASSERT_EQ(f2, compactionFiles_[2]); |
|
|
|
AddBoundaryInputs(icmp_, level_files_, &compaction_files_); |
|
|
|
ASSERT_EQ(3, compaction_files_.size()); |
|
|
|
ASSERT_EQ(f1, compaction_files_[0]); |
|
|
|
ASSERT_EQ(f3, compaction_files_[1]); |
|
|
|
ASSERT_EQ(f2, compaction_files_[2]); |
|
|
|
} |
|
|
|
|
|
|
|
TEST(AddBoundaryInputsTest, TestDisjoinFilePointers) { |
|
|
|
FileMetaData *f1 = CreateFileMetaData(1, InternalKey("100", 6, kTypeValue), InternalKey(InternalKey("100", 5, kTypeValue))); |
|
|
|
FileMetaData *f2 = CreateFileMetaData(1, InternalKey("100", 6, kTypeValue), InternalKey(InternalKey("100", 5, kTypeValue))); |
|
|
|
FileMetaData *f3 = CreateFileMetaData(1, InternalKey("100", 2, kTypeValue), InternalKey(InternalKey("300", 1, kTypeValue))); |
|
|
|
FileMetaData *f4 = CreateFileMetaData(1, InternalKey("100", 4, kTypeValue), InternalKey(InternalKey("100", 3, kTypeValue))); |
|
|
|
|
|
|
|
levelFiles_.push_back(f2); |
|
|
|
levelFiles_.push_back(f3); |
|
|
|
levelFiles_.push_back(f4); |
|
|
|
|
|
|
|
compactionFiles_.push_back(f1); |
|
|
|
|
|
|
|
AddBoundaryInputs(icmp_, levelFiles_, &compactionFiles_); |
|
|
|
ASSERT_EQ(3, compactionFiles_.size()); |
|
|
|
ASSERT_EQ(f1, compactionFiles_[0]); |
|
|
|
ASSERT_EQ(f4, compactionFiles_[1]); |
|
|
|
ASSERT_EQ(f3, compactionFiles_[2]); |
|
|
|
} |
|
|
|
FileMetaData* f1 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 6, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 5, kTypeValue))); |
|
|
|
FileMetaData* f2 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 6, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 5, kTypeValue))); |
|
|
|
FileMetaData* f3 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 2, kTypeValue), |
|
|
|
InternalKey(InternalKey("300", 1, kTypeValue))); |
|
|
|
FileMetaData* f4 = |
|
|
|
CreateFileMetaData(1, InternalKey("100", 4, kTypeValue), |
|
|
|
InternalKey(InternalKey("100", 3, kTypeValue))); |
|
|
|
|
|
|
|
} // namespace leveldb
|
|
|
|
level_files_.push_back(f2); |
|
|
|
level_files_.push_back(f3); |
|
|
|
level_files_.push_back(f4); |
|
|
|
|
|
|
|
int main(int argc, char** argv) { |
|
|
|
return leveldb::test::RunAllTests(); |
|
|
|
compaction_files_.push_back(f1); |
|
|
|
|
|
|
|
AddBoundaryInputs(icmp_, level_files_, &compaction_files_); |
|
|
|
ASSERT_EQ(3, compaction_files_.size()); |
|
|
|
ASSERT_EQ(f1, compaction_files_[0]); |
|
|
|
ASSERT_EQ(f4, compaction_files_[1]); |
|
|
|
ASSERT_EQ(f3, compaction_files_[2]); |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace leveldb
|
|
|
|
|
|
|
|
int main(int argc, char** argv) { return leveldb::test::RunAllTests(); } |