MCPcopy Create free account
hub / github.com/couchbase/forestdb / custom_compare_variable_test

Function custom_compare_variable_test

tests/functional/fdb_functional_test.cc:2361–2548  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2359}
2360
2361void custom_compare_variable_test()
2362{
2363 TEST_INIT();
2364
2365 memleak_start();
2366
2367 int i, j, r;
2368 int n = 1000;
2369 int count;
2370 fdb_file_handle *dbfile;
2371 fdb_kvs_handle *db, *db2;
2372 fdb_doc **doc = alca(fdb_doc*, n);
2373 fdb_doc *rdoc = NULL;
2374 fdb_status status;
2375 fdb_iterator *iterator;
2376
2377 size_t keylen = 16;
2378 size_t prev_keylen;
2379 char keybuf[256], bodybuf[256];
2380 char prev_key[256];
2381
2382 // remove previous dummy files
2383 r = system(SHELL_DEL" dummy* > errorlog.txt");
2384 (void)r;
2385
2386 fdb_config fconfig = fdb_get_default_config();
2387 fdb_kvs_config kvs_config = fdb_get_default_kvs_config();
2388 fconfig.seqtree_opt = FDB_SEQTREE_USE;
2389 fconfig.buffercache_size = 0;
2390 fconfig.wal_threshold = 1024;
2391 fconfig.flags = FDB_OPEN_FLAG_CREATE;
2392 fconfig.compaction_threshold = 0;
2393 fconfig.multi_kv_instances = true;
2394
2395 kvs_config.custom_cmp = _cmp_variable;
2396
2397 // open db with custom compare function for variable length key type
2398 //fdb_open_cmp_variable(&dbfile, "./dummy1", &fconfig);
2399 fdb_open(&dbfile, "./dummy1", &fconfig);
2400 fdb_kvs_open_default(dbfile, &db, &kvs_config);
2401 status = fdb_set_log_callback(db, logCallbackFunc,
2402 (void *) "custom_compare_variable_test");
2403 TEST_CHK(status == FDB_RESULT_SUCCESS);
2404
2405 for (i=0;i<n;++i){
2406 for (j=0;j<2;++j){
2407 keybuf[j] = 'a' + rand()%('z'-'a');
2408 }
2409 sprintf(keybuf+2, "%06d", i);
2410 for (j=8;(size_t)j<keylen-1;++j){
2411 keybuf[j] = 'a' + rand()%('z'-'a');
2412 }
2413 keybuf[keylen-1] = 0;
2414 sprintf(bodybuf, "value: %d", i);
2415 fdb_doc_create(&doc[i], (void*)keybuf, keylen, NULL, 0,
2416 (void*)bodybuf, strlen(bodybuf)+1);
2417 fdb_set(db, doc[i]);
2418 }

Callers 1

mainFunction · 0.85

Calls 3

memleak_startFunction · 0.85
_cmp_variableFunction · 0.85
memleak_endFunction · 0.85

Tested by

no test coverage detected