提供基本的ttl测试用例
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

64 righe
1.9 KiB

  1. // Copyright (c) 2018 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. #include "leveldb/env.h"
  5. #include "port/port.h"
  6. #include "util/env_windows_test_helper.h"
  7. #include "util/testharness.h"
  8. namespace leveldb {
  9. static const int kMMapLimit = 4;
  10. class EnvWindowsTest {
  11. public:
  12. static void SetFileLimits(int mmap_limit) {
  13. EnvWindowsTestHelper::SetReadOnlyMMapLimit(mmap_limit);
  14. }
  15. EnvWindowsTest() : env_(Env::Default()) {}
  16. Env* env_;
  17. };
  18. TEST(EnvWindowsTest, TestOpenOnRead) {
  19. // Write some test data to a single file that will be opened |n| times.
  20. std::string test_dir;
  21. ASSERT_OK(env_->GetTestDirectory(&test_dir));
  22. std::string test_file = test_dir + "/open_on_read.txt";
  23. FILE* f = fopen(test_file.c_str(), "w");
  24. ASSERT_TRUE(f != nullptr);
  25. const char kFileData[] = "abcdefghijklmnopqrstuvwxyz";
  26. fputs(kFileData, f);
  27. fclose(f);
  28. // Open test file some number above the sum of the two limits to force
  29. // leveldb::WindowsEnv to switch from mapping the file into memory
  30. // to basic file reading.
  31. const int kNumFiles = kMMapLimit + 5;
  32. leveldb::RandomAccessFile* files[kNumFiles] = {0};
  33. for (int i = 0; i < kNumFiles; i++) {
  34. ASSERT_OK(env_->NewRandomAccessFile(test_file, &files[i]));
  35. }
  36. char scratch;
  37. Slice read_result;
  38. for (int i = 0; i < kNumFiles; i++) {
  39. ASSERT_OK(files[i]->Read(i, 1, &read_result, &scratch));
  40. ASSERT_EQ(kFileData[i], read_result[0]);
  41. }
  42. for (int i = 0; i < kNumFiles; i++) {
  43. delete files[i];
  44. }
  45. ASSERT_OK(env_->DeleteFile(test_file));
  46. }
  47. } // namespace leveldb
  48. int main(int argc, char** argv) {
  49. // All tests currently run with the same read-only file limits.
  50. leveldb::EnvWindowsTest::SetFileLimits(leveldb::kMMapLimit);
  51. return leveldb::test::RunAllTests();
  52. }