MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / testBTreeDatabase

Function testBTreeDatabase

source/test/btree_database_test.cpp:81–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79 }
80
81 void testBTreeDatabase(size_t testCount, size_t writeRepeat, size_t randCount, size_t rollbackCount, size_t blockSize) {
82 auto tmpFile = File::temporaryFile();
83 auto finallyGuard = finally([&tmpFile]() { tmpFile->remove(); });
84
85 Set<uint32_t> keySet;
86 BTreeDatabase db("TestDB", 4);
87 db.setAutoCommit(false);
88
89 while (keySet.size() < testCount)
90 keySet.add(Random::randUInt(0, MaxKey));
91
92 List<uint32_t> keys;
93 for (uint32_t k : keySet) {
94 for (uint32_t j = 0; j < writeRepeat; ++j)
95 keys.append(k);
96 }
97
98 db.setIndexCacheSize(0);
99 db.setBlockSize(blockSize);
100 db.setIODevice(tmpFile);
101 db.open();
102
103 // record writes/reads repeated writeRepeat times randomly each cycle
104 Random::shuffle(keys);
105 putAll(db, keys);
106
107 EXPECT_EQ(db.recordCount(), testCount);
108
109 Random::shuffle(keys);
110 checkAll(db, keys);
111
112 // Random reads/writes with randCount cycles...
113 for (uint32_t i = 0; i < randCount; ++i) {
114 List<uint32_t> keysTemp(keys.begin(), keys.begin() + keys.size() / 2);
115
116 Random::shuffle(keysTemp);
117 removeAll(db, keysTemp);
118
119 Random::shuffle(keysTemp);
120 putAll(db, keysTemp);
121
122 Random::shuffle(keys);
123 checkAll(db, keys);
124 }
125
126 db.commit();
127
128 // Random reads/writes/rollbacks with rollbackCount cycles...
129 for (uint32_t i = 0; i < rollbackCount ; ++i) {
130 List<uint32_t> keysTemp(keys.begin(), keys.begin() + keys.size() / 2);
131 Random::shuffle(keysTemp);
132
133 removeAll(db, keysTemp);
134 db.rollback();
135
136 checkAll(db, keys);
137 }
138

Callers 1

TESTFunction · 0.85

Calls 15

finallyFunction · 0.85
randUIntFunction · 0.85
setAutoCommitMethod · 0.80
setIndexCacheSizeMethod · 0.80
setBlockSizeMethod · 0.80
setIODeviceMethod · 0.80
commitMethod · 0.80
rollbackMethod · 0.80
totalBlockCountMethod · 0.80
freeBlockCountMethod · 0.80
indexBlockCountMethod · 0.80
leafBlockCountMethod · 0.80

Tested by

no test coverage detected