leveldb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +95 -0
  4. data/ext/Rakefile +11 -0
  5. data/ext/leveldb/LICENSE +27 -0
  6. data/ext/leveldb/Makefile +206 -0
  7. data/ext/leveldb/build_config.mk +13 -0
  8. data/ext/leveldb/db/builder.cc +88 -0
  9. data/ext/leveldb/db/builder.h +34 -0
  10. data/ext/leveldb/db/c.cc +595 -0
  11. data/ext/leveldb/db/c_test.c +390 -0
  12. data/ext/leveldb/db/corruption_test.cc +359 -0
  13. data/ext/leveldb/db/db_bench.cc +979 -0
  14. data/ext/leveldb/db/db_impl.cc +1485 -0
  15. data/ext/leveldb/db/db_impl.h +203 -0
  16. data/ext/leveldb/db/db_iter.cc +299 -0
  17. data/ext/leveldb/db/db_iter.h +26 -0
  18. data/ext/leveldb/db/db_test.cc +2092 -0
  19. data/ext/leveldb/db/dbformat.cc +140 -0
  20. data/ext/leveldb/db/dbformat.h +227 -0
  21. data/ext/leveldb/db/dbformat_test.cc +112 -0
  22. data/ext/leveldb/db/filename.cc +139 -0
  23. data/ext/leveldb/db/filename.h +80 -0
  24. data/ext/leveldb/db/filename_test.cc +122 -0
  25. data/ext/leveldb/db/leveldb_main.cc +238 -0
  26. data/ext/leveldb/db/log_format.h +35 -0
  27. data/ext/leveldb/db/log_reader.cc +259 -0
  28. data/ext/leveldb/db/log_reader.h +108 -0
  29. data/ext/leveldb/db/log_test.cc +500 -0
  30. data/ext/leveldb/db/log_writer.cc +103 -0
  31. data/ext/leveldb/db/log_writer.h +48 -0
  32. data/ext/leveldb/db/memtable.cc +145 -0
  33. data/ext/leveldb/db/memtable.h +91 -0
  34. data/ext/leveldb/db/repair.cc +389 -0
  35. data/ext/leveldb/db/skiplist.h +379 -0
  36. data/ext/leveldb/db/skiplist_test.cc +378 -0
  37. data/ext/leveldb/db/snapshot.h +66 -0
  38. data/ext/leveldb/db/table_cache.cc +121 -0
  39. data/ext/leveldb/db/table_cache.h +61 -0
  40. data/ext/leveldb/db/version_edit.cc +266 -0
  41. data/ext/leveldb/db/version_edit.h +107 -0
  42. data/ext/leveldb/db/version_edit_test.cc +46 -0
  43. data/ext/leveldb/db/version_set.cc +1443 -0
  44. data/ext/leveldb/db/version_set.h +383 -0
  45. data/ext/leveldb/db/version_set_test.cc +179 -0
  46. data/ext/leveldb/db/write_batch.cc +147 -0
  47. data/ext/leveldb/db/write_batch_internal.h +49 -0
  48. data/ext/leveldb/db/write_batch_test.cc +120 -0
  49. data/ext/leveldb/doc/bench/db_bench_sqlite3.cc +718 -0
  50. data/ext/leveldb/doc/bench/db_bench_tree_db.cc +528 -0
  51. data/ext/leveldb/helpers/memenv/memenv.cc +384 -0
  52. data/ext/leveldb/helpers/memenv/memenv.h +20 -0
  53. data/ext/leveldb/helpers/memenv/memenv_test.cc +232 -0
  54. data/ext/leveldb/include/leveldb/c.h +291 -0
  55. data/ext/leveldb/include/leveldb/cache.h +99 -0
  56. data/ext/leveldb/include/leveldb/comparator.h +63 -0
  57. data/ext/leveldb/include/leveldb/db.h +161 -0
  58. data/ext/leveldb/include/leveldb/env.h +333 -0
  59. data/ext/leveldb/include/leveldb/filter_policy.h +70 -0
  60. data/ext/leveldb/include/leveldb/iterator.h +100 -0
  61. data/ext/leveldb/include/leveldb/options.h +195 -0
  62. data/ext/leveldb/include/leveldb/slice.h +109 -0
  63. data/ext/leveldb/include/leveldb/status.h +106 -0
  64. data/ext/leveldb/include/leveldb/table.h +85 -0
  65. data/ext/leveldb/include/leveldb/table_builder.h +92 -0
  66. data/ext/leveldb/include/leveldb/write_batch.h +64 -0
  67. data/ext/leveldb/issues/issue178_test.cc +92 -0
  68. data/ext/leveldb/port/atomic_pointer.h +224 -0
  69. data/ext/leveldb/port/port.h +19 -0
  70. data/ext/leveldb/port/port_example.h +135 -0
  71. data/ext/leveldb/port/port_posix.cc +54 -0
  72. data/ext/leveldb/port/port_posix.h +157 -0
  73. data/ext/leveldb/port/thread_annotations.h +59 -0
  74. data/ext/leveldb/port/win/stdint.h +24 -0
  75. data/ext/leveldb/table/block.cc +268 -0
  76. data/ext/leveldb/table/block.h +44 -0
  77. data/ext/leveldb/table/block_builder.cc +109 -0
  78. data/ext/leveldb/table/block_builder.h +57 -0
  79. data/ext/leveldb/table/filter_block.cc +111 -0
  80. data/ext/leveldb/table/filter_block.h +68 -0
  81. data/ext/leveldb/table/filter_block_test.cc +128 -0
  82. data/ext/leveldb/table/format.cc +145 -0
  83. data/ext/leveldb/table/format.h +108 -0
  84. data/ext/leveldb/table/iterator.cc +67 -0
  85. data/ext/leveldb/table/iterator_wrapper.h +63 -0
  86. data/ext/leveldb/table/merger.cc +197 -0
  87. data/ext/leveldb/table/merger.h +26 -0
  88. data/ext/leveldb/table/table.cc +275 -0
  89. data/ext/leveldb/table/table_builder.cc +270 -0
  90. data/ext/leveldb/table/table_test.cc +868 -0
  91. data/ext/leveldb/table/two_level_iterator.cc +182 -0
  92. data/ext/leveldb/table/two_level_iterator.h +34 -0
  93. data/ext/leveldb/util/arena.cc +68 -0
  94. data/ext/leveldb/util/arena.h +68 -0
  95. data/ext/leveldb/util/arena_test.cc +68 -0
  96. data/ext/leveldb/util/bloom.cc +95 -0
  97. data/ext/leveldb/util/bloom_test.cc +160 -0
  98. data/ext/leveldb/util/cache.cc +325 -0
  99. data/ext/leveldb/util/cache_test.cc +186 -0
  100. data/ext/leveldb/util/coding.cc +194 -0
  101. data/ext/leveldb/util/coding.h +104 -0
  102. data/ext/leveldb/util/coding_test.cc +196 -0
  103. data/ext/leveldb/util/comparator.cc +81 -0
  104. data/ext/leveldb/util/crc32c.cc +332 -0
  105. data/ext/leveldb/util/crc32c.h +45 -0
  106. data/ext/leveldb/util/crc32c_test.cc +72 -0
  107. data/ext/leveldb/util/env.cc +96 -0
  108. data/ext/leveldb/util/env_posix.cc +698 -0
  109. data/ext/leveldb/util/env_test.cc +104 -0
  110. data/ext/leveldb/util/filter_policy.cc +11 -0
  111. data/ext/leveldb/util/hash.cc +52 -0
  112. data/ext/leveldb/util/hash.h +19 -0
  113. data/ext/leveldb/util/histogram.cc +139 -0
  114. data/ext/leveldb/util/histogram.h +42 -0
  115. data/ext/leveldb/util/logging.cc +81 -0
  116. data/ext/leveldb/util/logging.h +47 -0
  117. data/ext/leveldb/util/mutexlock.h +41 -0
  118. data/ext/leveldb/util/options.cc +29 -0
  119. data/ext/leveldb/util/posix_logger.h +98 -0
  120. data/ext/leveldb/util/random.h +59 -0
  121. data/ext/leveldb/util/status.cc +75 -0
  122. data/ext/leveldb/util/testharness.cc +77 -0
  123. data/ext/leveldb/util/testharness.h +138 -0
  124. data/ext/leveldb/util/testutil.cc +51 -0
  125. data/ext/leveldb/util/testutil.h +53 -0
  126. data/lib/leveldb/version.rb +3 -0
  127. data/lib/leveldb.rb +1006 -0
  128. metadata +228 -0
@@ -0,0 +1,59 @@
1
+ // Copyright (c) 2011 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
+
5
+ #ifndef STORAGE_LEVELDB_UTIL_RANDOM_H_
6
+ #define STORAGE_LEVELDB_UTIL_RANDOM_H_
7
+
8
+ #include <stdint.h>
9
+
10
+ namespace leveldb {
11
+
12
+ // A very simple random number generator. Not especially good at
13
+ // generating truly random bits, but good enough for our needs in this
14
+ // package.
15
+ class Random {
16
+ private:
17
+ uint32_t seed_;
18
+ public:
19
+ explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { }
20
+ uint32_t Next() {
21
+ static const uint32_t M = 2147483647L; // 2^31-1
22
+ static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0
23
+ // We are computing
24
+ // seed_ = (seed_ * A) % M, where M = 2^31-1
25
+ //
26
+ // seed_ must not be zero or M, or else all subsequent computed values
27
+ // will be zero or M respectively. For all other values, seed_ will end
28
+ // up cycling through every number in [1,M-1]
29
+ uint64_t product = seed_ * A;
30
+
31
+ // Compute (product % M) using the fact that ((x << 31) % M) == x.
32
+ seed_ = static_cast<uint32_t>((product >> 31) + (product & M));
33
+ // The first reduction may overflow by 1 bit, so we may need to
34
+ // repeat. mod == M is not possible; using > allows the faster
35
+ // sign-bit-based test.
36
+ if (seed_ > M) {
37
+ seed_ -= M;
38
+ }
39
+ return seed_;
40
+ }
41
+ // Returns a uniformly distributed value in the range [0..n-1]
42
+ // REQUIRES: n > 0
43
+ uint32_t Uniform(int n) { return Next() % n; }
44
+
45
+ // Randomly returns true ~"1/n" of the time, and false otherwise.
46
+ // REQUIRES: n > 0
47
+ bool OneIn(int n) { return (Next() % n) == 0; }
48
+
49
+ // Skewed: pick "base" uniformly from range [0,max_log] and then
50
+ // return "base" random bits. The effect is to pick a number in the
51
+ // range [0,2^max_log-1] with exponential bias towards smaller numbers.
52
+ uint32_t Skewed(int max_log) {
53
+ return Uniform(1 << Uniform(max_log + 1));
54
+ }
55
+ };
56
+
57
+ } // namespace leveldb
58
+
59
+ #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_
@@ -0,0 +1,75 @@
1
+ // Copyright (c) 2011 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
+
5
+ #include <stdio.h>
6
+ #include "port/port.h"
7
+ #include "leveldb/status.h"
8
+
9
+ namespace leveldb {
10
+
11
+ const char* Status::CopyState(const char* state) {
12
+ uint32_t size;
13
+ memcpy(&size, state, sizeof(size));
14
+ char* result = new char[size + 5];
15
+ memcpy(result, state, size + 5);
16
+ return result;
17
+ }
18
+
19
+ Status::Status(Code code, const Slice& msg, const Slice& msg2) {
20
+ assert(code != kOk);
21
+ const uint32_t len1 = msg.size();
22
+ const uint32_t len2 = msg2.size();
23
+ const uint32_t size = len1 + (len2 ? (2 + len2) : 0);
24
+ char* result = new char[size + 5];
25
+ memcpy(result, &size, sizeof(size));
26
+ result[4] = static_cast<char>(code);
27
+ memcpy(result + 5, msg.data(), len1);
28
+ if (len2) {
29
+ result[5 + len1] = ':';
30
+ result[6 + len1] = ' ';
31
+ memcpy(result + 7 + len1, msg2.data(), len2);
32
+ }
33
+ state_ = result;
34
+ }
35
+
36
+ std::string Status::ToString() const {
37
+ if (state_ == NULL) {
38
+ return "OK";
39
+ } else {
40
+ char tmp[30];
41
+ const char* type;
42
+ switch (code()) {
43
+ case kOk:
44
+ type = "OK";
45
+ break;
46
+ case kNotFound:
47
+ type = "NotFound: ";
48
+ break;
49
+ case kCorruption:
50
+ type = "Corruption: ";
51
+ break;
52
+ case kNotSupported:
53
+ type = "Not implemented: ";
54
+ break;
55
+ case kInvalidArgument:
56
+ type = "Invalid argument: ";
57
+ break;
58
+ case kIOError:
59
+ type = "IO error: ";
60
+ break;
61
+ default:
62
+ snprintf(tmp, sizeof(tmp), "Unknown code(%d): ",
63
+ static_cast<int>(code()));
64
+ type = tmp;
65
+ break;
66
+ }
67
+ std::string result(type);
68
+ uint32_t length;
69
+ memcpy(&length, state_, sizeof(length));
70
+ result.append(state_ + 5, length);
71
+ return result;
72
+ }
73
+ }
74
+
75
+ } // namespace leveldb
@@ -0,0 +1,77 @@
1
+ // Copyright (c) 2011 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
+
5
+ #include "util/testharness.h"
6
+
7
+ #include <string>
8
+ #include <stdlib.h>
9
+ #include <sys/stat.h>
10
+ #include <sys/types.h>
11
+
12
+ namespace leveldb {
13
+ namespace test {
14
+
15
+ namespace {
16
+ struct Test {
17
+ const char* base;
18
+ const char* name;
19
+ void (*func)();
20
+ };
21
+ std::vector<Test>* tests;
22
+ }
23
+
24
+ bool RegisterTest(const char* base, const char* name, void (*func)()) {
25
+ if (tests == NULL) {
26
+ tests = new std::vector<Test>;
27
+ }
28
+ Test t;
29
+ t.base = base;
30
+ t.name = name;
31
+ t.func = func;
32
+ tests->push_back(t);
33
+ return true;
34
+ }
35
+
36
+ int RunAllTests() {
37
+ const char* matcher = getenv("LEVELDB_TESTS");
38
+
39
+ int num = 0;
40
+ if (tests != NULL) {
41
+ for (int i = 0; i < tests->size(); i++) {
42
+ const Test& t = (*tests)[i];
43
+ if (matcher != NULL) {
44
+ std::string name = t.base;
45
+ name.push_back('.');
46
+ name.append(t.name);
47
+ if (strstr(name.c_str(), matcher) == NULL) {
48
+ continue;
49
+ }
50
+ }
51
+ fprintf(stderr, "==== Test %s.%s\n", t.base, t.name);
52
+ (*t.func)();
53
+ ++num;
54
+ }
55
+ }
56
+ fprintf(stderr, "==== PASSED %d tests\n", num);
57
+ return 0;
58
+ }
59
+
60
+ std::string TmpDir() {
61
+ std::string dir;
62
+ Status s = Env::Default()->GetTestDirectory(&dir);
63
+ ASSERT_TRUE(s.ok()) << s.ToString();
64
+ return dir;
65
+ }
66
+
67
+ int RandomSeed() {
68
+ const char* env = getenv("TEST_RANDOM_SEED");
69
+ int result = (env != NULL ? atoi(env) : 301);
70
+ if (result <= 0) {
71
+ result = 301;
72
+ }
73
+ return result;
74
+ }
75
+
76
+ } // namespace test
77
+ } // namespace leveldb
@@ -0,0 +1,138 @@
1
+ // Copyright (c) 2011 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
+
5
+ #ifndef STORAGE_LEVELDB_UTIL_TESTHARNESS_H_
6
+ #define STORAGE_LEVELDB_UTIL_TESTHARNESS_H_
7
+
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+ #include <sstream>
11
+ #include "leveldb/env.h"
12
+ #include "leveldb/slice.h"
13
+ #include "util/random.h"
14
+
15
+ namespace leveldb {
16
+ namespace test {
17
+
18
+ // Run some of the tests registered by the TEST() macro. If the
19
+ // environment variable "LEVELDB_TESTS" is not set, runs all tests.
20
+ // Otherwise, runs only the tests whose name contains the value of
21
+ // "LEVELDB_TESTS" as a substring. E.g., suppose the tests are:
22
+ // TEST(Foo, Hello) { ... }
23
+ // TEST(Foo, World) { ... }
24
+ // LEVELDB_TESTS=Hello will run the first test
25
+ // LEVELDB_TESTS=o will run both tests
26
+ // LEVELDB_TESTS=Junk will run no tests
27
+ //
28
+ // Returns 0 if all tests pass.
29
+ // Dies or returns a non-zero value if some test fails.
30
+ extern int RunAllTests();
31
+
32
+ // Return the directory to use for temporary storage.
33
+ extern std::string TmpDir();
34
+
35
+ // Return a randomization seed for this run. Typically returns the
36
+ // same number on repeated invocations of this binary, but automated
37
+ // runs may be able to vary the seed.
38
+ extern int RandomSeed();
39
+
40
+ // An instance of Tester is allocated to hold temporary state during
41
+ // the execution of an assertion.
42
+ class Tester {
43
+ private:
44
+ bool ok_;
45
+ const char* fname_;
46
+ int line_;
47
+ std::stringstream ss_;
48
+
49
+ public:
50
+ Tester(const char* f, int l)
51
+ : ok_(true), fname_(f), line_(l) {
52
+ }
53
+
54
+ ~Tester() {
55
+ if (!ok_) {
56
+ fprintf(stderr, "%s:%d:%s\n", fname_, line_, ss_.str().c_str());
57
+ exit(1);
58
+ }
59
+ }
60
+
61
+ Tester& Is(bool b, const char* msg) {
62
+ if (!b) {
63
+ ss_ << " Assertion failure " << msg;
64
+ ok_ = false;
65
+ }
66
+ return *this;
67
+ }
68
+
69
+ Tester& IsOk(const Status& s) {
70
+ if (!s.ok()) {
71
+ ss_ << " " << s.ToString();
72
+ ok_ = false;
73
+ }
74
+ return *this;
75
+ }
76
+
77
+ #define BINARY_OP(name,op) \
78
+ template <class X, class Y> \
79
+ Tester& name(const X& x, const Y& y) { \
80
+ if (! (x op y)) { \
81
+ ss_ << " failed: " << x << (" " #op " ") << y; \
82
+ ok_ = false; \
83
+ } \
84
+ return *this; \
85
+ }
86
+
87
+ BINARY_OP(IsEq, ==)
88
+ BINARY_OP(IsNe, !=)
89
+ BINARY_OP(IsGe, >=)
90
+ BINARY_OP(IsGt, >)
91
+ BINARY_OP(IsLe, <=)
92
+ BINARY_OP(IsLt, <)
93
+ #undef BINARY_OP
94
+
95
+ // Attach the specified value to the error message if an error has occurred
96
+ template <class V>
97
+ Tester& operator<<(const V& value) {
98
+ if (!ok_) {
99
+ ss_ << " " << value;
100
+ }
101
+ return *this;
102
+ }
103
+ };
104
+
105
+ #define ASSERT_TRUE(c) ::leveldb::test::Tester(__FILE__, __LINE__).Is((c), #c)
106
+ #define ASSERT_OK(s) ::leveldb::test::Tester(__FILE__, __LINE__).IsOk((s))
107
+ #define ASSERT_EQ(a,b) ::leveldb::test::Tester(__FILE__, __LINE__).IsEq((a),(b))
108
+ #define ASSERT_NE(a,b) ::leveldb::test::Tester(__FILE__, __LINE__).IsNe((a),(b))
109
+ #define ASSERT_GE(a,b) ::leveldb::test::Tester(__FILE__, __LINE__).IsGe((a),(b))
110
+ #define ASSERT_GT(a,b) ::leveldb::test::Tester(__FILE__, __LINE__).IsGt((a),(b))
111
+ #define ASSERT_LE(a,b) ::leveldb::test::Tester(__FILE__, __LINE__).IsLe((a),(b))
112
+ #define ASSERT_LT(a,b) ::leveldb::test::Tester(__FILE__, __LINE__).IsLt((a),(b))
113
+
114
+ #define TCONCAT(a,b) TCONCAT1(a,b)
115
+ #define TCONCAT1(a,b) a##b
116
+
117
+ #define TEST(base,name) \
118
+ class TCONCAT(_Test_,name) : public base { \
119
+ public: \
120
+ void _Run(); \
121
+ static void _RunIt() { \
122
+ TCONCAT(_Test_,name) t; \
123
+ t._Run(); \
124
+ } \
125
+ }; \
126
+ bool TCONCAT(_Test_ignored_,name) = \
127
+ ::leveldb::test::RegisterTest(#base, #name, &TCONCAT(_Test_,name)::_RunIt); \
128
+ void TCONCAT(_Test_,name)::_Run()
129
+
130
+ // Register the specified test. Typically not used directly, but
131
+ // invoked via the macro expansion of TEST.
132
+ extern bool RegisterTest(const char* base, const char* name, void (*func)());
133
+
134
+
135
+ } // namespace test
136
+ } // namespace leveldb
137
+
138
+ #endif // STORAGE_LEVELDB_UTIL_TESTHARNESS_H_
@@ -0,0 +1,51 @@
1
+ // Copyright (c) 2011 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
+
5
+ #include "util/testutil.h"
6
+
7
+ #include "util/random.h"
8
+
9
+ namespace leveldb {
10
+ namespace test {
11
+
12
+ Slice RandomString(Random* rnd, int len, std::string* dst) {
13
+ dst->resize(len);
14
+ for (int i = 0; i < len; i++) {
15
+ (*dst)[i] = static_cast<char>(' ' + rnd->Uniform(95)); // ' ' .. '~'
16
+ }
17
+ return Slice(*dst);
18
+ }
19
+
20
+ std::string RandomKey(Random* rnd, int len) {
21
+ // Make sure to generate a wide variety of characters so we
22
+ // test the boundary conditions for short-key optimizations.
23
+ static const char kTestChars[] = {
24
+ '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff'
25
+ };
26
+ std::string result;
27
+ for (int i = 0; i < len; i++) {
28
+ result += kTestChars[rnd->Uniform(sizeof(kTestChars))];
29
+ }
30
+ return result;
31
+ }
32
+
33
+
34
+ extern Slice CompressibleString(Random* rnd, double compressed_fraction,
35
+ int len, std::string* dst) {
36
+ int raw = static_cast<int>(len * compressed_fraction);
37
+ if (raw < 1) raw = 1;
38
+ std::string raw_data;
39
+ RandomString(rnd, raw, &raw_data);
40
+
41
+ // Duplicate the random data until we have filled "len" bytes
42
+ dst->clear();
43
+ while (dst->size() < len) {
44
+ dst->append(raw_data);
45
+ }
46
+ dst->resize(len);
47
+ return Slice(*dst);
48
+ }
49
+
50
+ } // namespace test
51
+ } // namespace leveldb
@@ -0,0 +1,53 @@
1
+ // Copyright (c) 2011 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
+
5
+ #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_
6
+ #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_
7
+
8
+ #include "leveldb/env.h"
9
+ #include "leveldb/slice.h"
10
+ #include "util/random.h"
11
+
12
+ namespace leveldb {
13
+ namespace test {
14
+
15
+ // Store in *dst a random string of length "len" and return a Slice that
16
+ // references the generated data.
17
+ extern Slice RandomString(Random* rnd, int len, std::string* dst);
18
+
19
+ // Return a random key with the specified length that may contain interesting
20
+ // characters (e.g. \x00, \xff, etc.).
21
+ extern std::string RandomKey(Random* rnd, int len);
22
+
23
+ // Store in *dst a string of length "len" that will compress to
24
+ // "N*compressed_fraction" bytes and return a Slice that references
25
+ // the generated data.
26
+ extern Slice CompressibleString(Random* rnd, double compressed_fraction,
27
+ int len, std::string* dst);
28
+
29
+ // A wrapper that allows injection of errors.
30
+ class ErrorEnv : public EnvWrapper {
31
+ public:
32
+ bool writable_file_error_;
33
+ int num_writable_file_errors_;
34
+
35
+ ErrorEnv() : EnvWrapper(Env::Default()),
36
+ writable_file_error_(false),
37
+ num_writable_file_errors_(0) { }
38
+
39
+ virtual Status NewWritableFile(const std::string& fname,
40
+ WritableFile** result) {
41
+ if (writable_file_error_) {
42
+ ++num_writable_file_errors_;
43
+ *result = NULL;
44
+ return Status::IOError(fname, "fake error");
45
+ }
46
+ return target()->NewWritableFile(fname, result);
47
+ }
48
+ };
49
+
50
+ } // namespace test
51
+ } // namespace leveldb
52
+
53
+ #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_
@@ -0,0 +1,3 @@
1
+ module Leveldb
2
+ VERSION = "0.0.1"
3
+ end