| 40 | class Issue320 {}; |
| 41 | |
| 42 | TEST(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); |
nothing calls this directly
no test coverage detected