MCPcopy Create free account
hub / github.com/ElementsProject/elements / TEST

Function TEST

src/leveldb/issues/issue320_test.cc:42–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40class Issue320 {};
41
42TEST(Issue320, Test) {
43 std::srand(0);
44
45 bool delete_before_put = false;
46 bool keep_snapshots = true;
47
48 std::vector<std::unique_ptr<std::pair<std::string, std::string>>> test_map(
49 10000);
50 std::vector<Snapshot const*> snapshots(100, nullptr);
51
52 DB* db;
53 Options options;
54 options.create_if_missing = true;
55
56 std::string dbpath = test::TmpDir() + "/leveldb_issue320_test";
57 ASSERT_OK(DB::Open(options, dbpath, &db));
58
59 uint32_t target_size = 10000;
60 uint32_t num_items = 0;
61 uint32_t count = 0;
62 std::string key;
63 std::string value, old_value;
64
65 WriteOptions writeOptions;
66 ReadOptions readOptions;
67 while (count < 200000) {
68 if ((++count % 1000) == 0) {
69 std::cout << "count: " << count << std::endl;
70 }
71
72 int index = GenerateRandomNumber(test_map.size());
73 WriteBatch batch;
74
75 if (test_map[index] == nullptr) {
76 num_items++;
77 test_map[index].reset(new std::pair<std::string, std::string>(
78 CreateRandomString(index), CreateRandomString(index)));
79 batch.Put(test_map[index]->first, test_map[index]->second);
80 } else {
81 ASSERT_OK(db->Get(readOptions, test_map[index]->first, &old_value));
82 if (old_value != test_map[index]->second) {
83 std::cout << "ERROR incorrect value returned by Get" << std::endl;
84 std::cout << " count=" << count << std::endl;
85 std::cout << " old value=" << old_value << std::endl;
86 std::cout << " test_map[index]->second=" << test_map[index]->second
87 << std::endl;
88 std::cout << " test_map[index]->first=" << test_map[index]->first
89 << std::endl;
90 std::cout << " index=" << index << std::endl;
91 ASSERT_EQ(old_value, test_map[index]->second);
92 }
93
94 if (num_items >= target_size && GenerateRandomNumber(100) > 30) {
95 batch.Delete(test_map[index]->first);
96 test_map[index] = nullptr;
97 --num_items;
98 } else {
99 test_map[index]->second = CreateRandomString(index);

Callers

nothing calls this directly

Calls 12

TmpDirFunction · 0.85
GenerateRandomNumberFunction · 0.85
CreateRandomStringFunction · 0.85
DestroyDBFunction · 0.85
sizeMethod · 0.45
resetMethod · 0.45
PutMethod · 0.45
GetMethod · 0.45
DeleteMethod · 0.45
WriteMethod · 0.45
ReleaseSnapshotMethod · 0.45
GetSnapshotMethod · 0.45

Tested by

no test coverage detected