|
|
@ -80,18 +80,22 @@ TEST_F(WritableFileWriterTest, RangeSync) { |
|
|
|
new WritableFileWriter(NewLegacyWritableFileWrapper(std::move(wf)), |
|
|
|
new WritableFileWriter(NewLegacyWritableFileWrapper(std::move(wf)), |
|
|
|
"" /* don't care */, env_options)); |
|
|
|
"" /* don't care */, env_options)); |
|
|
|
Random r(301); |
|
|
|
Random r(301); |
|
|
|
|
|
|
|
Status s; |
|
|
|
std::unique_ptr<char[]> large_buf(new char[10 * kMb]); |
|
|
|
std::unique_ptr<char[]> large_buf(new char[10 * kMb]); |
|
|
|
for (int i = 0; i < 1000; i++) { |
|
|
|
for (int i = 0; i < 1000; i++) { |
|
|
|
int skew_limit = (i < 700) ? 10 : 15; |
|
|
|
int skew_limit = (i < 700) ? 10 : 15; |
|
|
|
uint32_t num = r.Skewed(skew_limit) * 100 + r.Uniform(100); |
|
|
|
uint32_t num = r.Skewed(skew_limit) * 100 + r.Uniform(100); |
|
|
|
writer->Append(Slice(large_buf.get(), num)); |
|
|
|
s = writer->Append(Slice(large_buf.get(), num)); |
|
|
|
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
|
|
|
// Flush in a chance of 1/10.
|
|
|
|
// Flush in a chance of 1/10.
|
|
|
|
if (r.Uniform(10) == 0) { |
|
|
|
if (r.Uniform(10) == 0) { |
|
|
|
writer->Flush(); |
|
|
|
s = writer->Flush(); |
|
|
|
|
|
|
|
ASSERT_OK(s); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
writer->Close(); |
|
|
|
s = writer->Close(); |
|
|
|
|
|
|
|
ASSERT_OK(s); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_F(WritableFileWriterTest, IncrementalBuffer) { |
|
|
|
TEST_F(WritableFileWriterTest, IncrementalBuffer) { |
|
|
@ -242,15 +246,18 @@ class ReadaheadRandomAccessFileTest |
|
|
|
ReadaheadRandomAccessFileTest() : control_contents_() {} |
|
|
|
ReadaheadRandomAccessFileTest() : control_contents_() {} |
|
|
|
std::string Read(uint64_t offset, size_t n) { |
|
|
|
std::string Read(uint64_t offset, size_t n) { |
|
|
|
Slice result; |
|
|
|
Slice result; |
|
|
|
test_read_holder_->Read(offset, n, &result, scratch_.get()); |
|
|
|
Status s = test_read_holder_->Read(offset, n, &result, scratch_.get()); |
|
|
|
|
|
|
|
EXPECT_TRUE(s.ok() || s.IsInvalidArgument()); |
|
|
|
return std::string(result.data(), result.size()); |
|
|
|
return std::string(result.data(), result.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
void ResetSourceStr(const std::string& str = "") { |
|
|
|
void ResetSourceStr(const std::string& str = "") { |
|
|
|
auto write_holder = |
|
|
|
auto write_holder = |
|
|
|
std::unique_ptr<WritableFileWriter>(test::GetWritableFileWriter( |
|
|
|
std::unique_ptr<WritableFileWriter>(test::GetWritableFileWriter( |
|
|
|
new test::StringSink(&control_contents_), "" /* don't care */)); |
|
|
|
new test::StringSink(&control_contents_), "" /* don't care */)); |
|
|
|
write_holder->Append(Slice(str)); |
|
|
|
Status s = write_holder->Append(Slice(str)); |
|
|
|
write_holder->Flush(); |
|
|
|
EXPECT_OK(s); |
|
|
|
|
|
|
|
s = write_holder->Flush(); |
|
|
|
|
|
|
|
EXPECT_OK(s); |
|
|
|
auto read_holder = std::unique_ptr<RandomAccessFile>( |
|
|
|
auto read_holder = std::unique_ptr<RandomAccessFile>( |
|
|
|
new test::StringSource(control_contents_)); |
|
|
|
new test::StringSource(control_contents_)); |
|
|
|
test_read_holder_ = |
|
|
|
test_read_holder_ = |
|
|
@ -340,7 +347,8 @@ class ReadaheadSequentialFileTest : public testing::Test, |
|
|
|
ReadaheadSequentialFileTest() {} |
|
|
|
ReadaheadSequentialFileTest() {} |
|
|
|
std::string Read(size_t n) { |
|
|
|
std::string Read(size_t n) { |
|
|
|
Slice result; |
|
|
|
Slice result; |
|
|
|
test_read_holder_->Read(n, &result, scratch_.get()); |
|
|
|
Status s = test_read_holder_->Read(n, &result, scratch_.get()); |
|
|
|
|
|
|
|
EXPECT_TRUE(s.ok() || s.IsInvalidArgument()); |
|
|
|
return std::string(result.data(), result.size()); |
|
|
|
return std::string(result.data(), result.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
void Skip(size_t n) { test_read_holder_->Skip(n); } |
|
|
|
void Skip(size_t n) { test_read_holder_->Skip(n); } |
|
|
|