CLI option & Rename() allow overwrite

Summary: this test support CLI option to select HdfsEnv/NativeHdfsEnv now. The latter one is default. add test about when Rename(src, target) should overwrite target

Test Plan: existing test

Reviewers: sdong, andrewkr

Reviewed By: andrewkr

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D60399
main
Wanning Jiang 9 years ago
parent 7c190070b4
commit 0f691c4b5b
  1. 22
      util/env_basic_test.cc

@ -153,25 +153,37 @@ TEST_P(EnvBasicTestWithParam, Basics) {
ASSERT_OK(env_->GetChildren(test_dir_, &children));
ASSERT_EQ(1U, children.size());
ASSERT_EQ("f", children[0]);
ASSERT_OK(env_->DeleteFile(test_dir_ + "/f"));
// Write to the file.
ASSERT_OK(env_->NewWritableFile(test_dir_ + "/f", &writable_file, soptions_));
ASSERT_OK(
env_->NewWritableFile(test_dir_ + "/f1", &writable_file, soptions_));
ASSERT_OK(writable_file->Append("abc"));
ASSERT_OK(writable_file->Close());
writable_file.reset();
ASSERT_OK(
env_->NewWritableFile(test_dir_ + "/f2", &writable_file, soptions_));
ASSERT_OK(writable_file->Close());
writable_file.reset();
// Check for expected size.
ASSERT_OK(env_->GetFileSize(test_dir_ + "/f", &file_size));
ASSERT_OK(env_->GetFileSize(test_dir_ + "/f1", &file_size));
ASSERT_EQ(3U, file_size);
// Check that renaming works.
ASSERT_TRUE(!env_->RenameFile(test_dir_ + "/non_existent", "/g").ok());
ASSERT_OK(env_->RenameFile(test_dir_ + "/f", test_dir_ + "/g"));
ASSERT_EQ(Status::NotFound(), env_->FileExists(test_dir_ + "/f"));
ASSERT_TRUE(
!env_->RenameFile(test_dir_ + "/non_existent", test_dir_ + "/g").ok());
ASSERT_OK(env_->RenameFile(test_dir_ + "/f1", test_dir_ + "/g"));
ASSERT_EQ(Status::NotFound(), env_->FileExists(test_dir_ + "/f1"));
ASSERT_OK(env_->FileExists(test_dir_ + "/g"));
ASSERT_OK(env_->GetFileSize(test_dir_ + "/g", &file_size));
ASSERT_EQ(3U, file_size);
// Check that renaming overwriting works
ASSERT_OK(env_->RenameFile(test_dir_ + "/f2", test_dir_ + "/g"));
ASSERT_OK(env_->GetFileSize(test_dir_ + "/g", &file_size));
ASSERT_EQ(0U, file_size);
// Check that opening non-existent file fails.
unique_ptr<SequentialFile> seq_file;
unique_ptr<RandomAccessFile> rand_file;

Loading…
Cancel
Save