11 #include "./test_key.h"
13 using namespace mabain;
15 static const char *mbdir = "/var/tmp/mabain_test/";
16 static pthread_t wid = 0;
17 static MBConfig mbconf;
18 static bool stop_processing = false;
19 static uint32_t run_time = 3600;
21 static void* run_mb_test(void *arg);
23 static void* TestThread(void *arg)
26 mbconf.options = CONSTS::ReaderOptions();
29 std::cerr << "failed tp open db\n";
32 assert(db.SetAsyncWriterPtr(dbw) == MBError::SUCCESS);
33 assert(db.AsyncWriterEnabled());
38 TestKey tkey_int(MABAIN_TEST_KEY_TYPE_INT);
39 TestKey tkey_sha1(MABAIN_TEST_KEY_TYPE_SHA_128);
40 TestKey tkey_sha2(MABAIN_TEST_KEY_TYPE_SHA_256);
44 while(!stop_processing) {
45 keystr = tkey_int.get_key(ikey);
46 rval = db.Find(keystr, mbd);
47 if(rval != MBError::SUCCESS) {
48 db.Add(keystr, keystr);
50 keystr = tkey_sha1.get_key(ikey);
51 rval = db.Find(keystr, mbd);
52 if(rval != MBError::SUCCESS) {
53 db.Add(keystr, keystr);
55 keystr = tkey_sha2.get_key(ikey);
56 rval = db.Find(keystr, mbd);
57 if(rval != MBError::SUCCESS) {
58 db.Add(keystr, keystr);
65 assert(db.UnsetAsyncWriterPtr(dbw) == MBError::SUCCESS);
73 if(pthread_join(wid, NULL) != 0) {
74 std::cout << "cannot join mbtest thread\n";
81 if(pthread_create(&wid, NULL, run_mb_test, NULL) != 0) {
82 std::cout << "failed to create test thread" << std::endl;
86 static void* run_mb_test(void *arg)
88 int64_t run_stop_time = time(NULL) + run_time;
92 DB::SetLogFile("/var/tmp/mabain_test/mabain.log");
93 memset(&mbconf, 0, sizeof(mbconf));
95 mbconf.block_size_index = 32*1024*1024;
96 mbconf.block_size_data = 32*1024*1024;
97 mbconf.memcap_index = 128LL*1024*1024;
98 mbconf.memcap_data = 128LL*1024*1024;
100 int options = CONSTS::WriterOptions() | CONSTS::ASYNC_WRITER_MODE;
101 mbconf.options = options;
102 DB *db = new DB(mbconf);
104 std::cerr << "failed to open writer db" << std::endl;
110 assert(nreaders < 256);
111 for(int i = 0; i < nreaders; i++) {
112 if(pthread_create(&tid[i], NULL, TestThread, db) != 0) {
113 std::cout << "failed to create reader thread" << std::endl;
119 while(!stop_processing) {
120 std::cout << "Running rc... " << db->Count() <<"\n";
121 db->CollectResource(8*1024*1024LL, 8*1024*1024LL, 1000000000000, 3000000);
123 sleep_time = (rand() % 10) + 1;
126 if(time(NULL) >= run_stop_time) {
127 stop_processing = true;
131 for(int i = 0; i < nreaders; i++) {
132 pthread_join(tid[i], NULL);
140 static void SetTestStatus(bool success)
144 cmd = std::string("touch ") + mbdir + "/_success";
146 cmd = std::string("rm ") + mbdir + "/_success >" + mbdir + "/out 2>" + mbdir + "/err";
148 if(system(cmd.c_str()) != 0) {
152 int main(int argc, char *argv[])
156 std::cout << "Test db directory is " << mbdir << "\n";
159 run_time = atoi(argv[2]);
160 std::cout << "running " << argv[0] << " for " << run_time << " seconds...\n";
163 DB::SetLogFile(std::string(mbdir) + "/mabain.log");
164 SetTestStatus(false);