1 #include <gtest/gtest.h>
2 #include "include/Context.h"
3 #include "rocksdb/db.h"
4 #include "rocksdb/env.h"
5 #include "rocksdb/thread_status.h"
6 #include "kv/RocksDBStore.h"
11 const string dir("rocksdb.test_temp_dir");
13 TEST(RocksDBOption, simple) {
14 rocksdb::Options options;
15 rocksdb::Status status;
16 RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, NULL);
17 string options_string = ""
18 "write_buffer_size=536870912;"
19 "create_if_missing=true;"
20 "max_write_buffer_number=4;"
21 "max_background_compactions=4;"
22 "stats_dump_period_sec = 5;"
23 "min_write_buffer_number_to_merge = 2;"
24 "level0_file_num_compaction_trigger = 4;"
25 "max_bytes_for_level_base = 104857600;"
26 "target_file_size_base = 10485760;"
28 "compression = kNoCompression;";
29 int r = db->ParseOptionsFromString(options_string, options);
31 ASSERT_EQ(536870912u, options.write_buffer_size);
32 ASSERT_EQ(4, options.max_write_buffer_number);
33 ASSERT_EQ(4, options.max_background_compactions);
34 ASSERT_EQ(5u, options.stats_dump_period_sec);
35 ASSERT_EQ(2, options.min_write_buffer_number_to_merge);
36 ASSERT_EQ(4, options.level0_file_num_compaction_trigger);
37 ASSERT_EQ(104857600u, options.max_bytes_for_level_base);
38 ASSERT_EQ(10485760u, options.target_file_size_base);
39 ASSERT_EQ(3, options.num_levels);
40 ASSERT_EQ(rocksdb::kNoCompression, options.compression);
42 TEST(RocksDBOption, interpret) {
43 rocksdb::Options options;
44 rocksdb::Status status;
45 RocksDBStore *db = new RocksDBStore(g_ceph_context, dir, NULL);
46 string options_string = "compact_on_mount = true; compaction_threads=10;flusher_threads=5;";
48 int r = db->ParseOptionsFromString(options_string, options);
50 ASSERT_TRUE(db->compact_on_mount);
51 //check thread pool setting
52 options.env->SleepForMicroseconds(100000);
53 std::vector<rocksdb::ThreadStatus> thread_list;
54 status = options.env->GetThreadList(&thread_list);
55 ASSERT_TRUE(status.ok());
57 int num_high_pri_threads = 0;
58 int num_low_pri_threads = 0;
59 for (vector<rocksdb::ThreadStatus>::iterator it = thread_list.begin();
60 it!= thread_list.end();
62 if (it->thread_type == rocksdb::ThreadStatus::HIGH_PRIORITY)
63 num_high_pri_threads++;
64 if (it->thread_type == rocksdb::ThreadStatus::LOW_PRIORITY)
65 num_low_pri_threads++;
67 ASSERT_EQ(15u, thread_list.size());
68 //low pri threads is compaction_threads
69 ASSERT_EQ(10, num_low_pri_threads);
70 //high pri threads is flusher_threads
71 ASSERT_EQ(5, num_high_pri_threads);