1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6 
7 
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9 
10     PerconaFT is free software: you can redistribute it and/or modify
11     it under the terms of the GNU General Public License, version 2,
12     as published by the Free Software Foundation.
13 
14     PerconaFT is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
21 
22 ----------------------------------------
23 
24     PerconaFT is free software: you can redistribute it and/or modify
25     it under the terms of the GNU Affero General Public License, version 3,
26     as published by the Free Software Foundation.
27 
28     PerconaFT is distributed in the hope that it will be useful,
29     but WITHOUT ANY WARRANTY; without even the implied warranty of
30     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31     GNU Affero General Public License for more details.
32 
33     You should have received a copy of the GNU Affero General Public License
34     along with PerconaFT.  If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36 
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38 
39 #pragma once
40 
41 #include "test.h"
42 
43 #include <concurrent_tree.h>
44 
45 namespace toku {
46 
47 class concurrent_tree_unit_test {
48 public:
49     // creating a concurrent tree should initialize it to a valid,
50     // empty state. the root node should be properly marked, have
51     // no children, and the correct comparator.
52     void test_create_destroy(void);
53 
54     // acquiring a locked keyrange should lock and "root" itself at
55     // the proper subtree node. releasing it should unlock that node.
56     void test_lkr_acquire_release(void);
57 
58     // remove_all on a locked keyrange should properly remove everything
59     // from the tree and account correctly for the amount of memory released.
60     void test_lkr_remove_all(void);
61 
62     // test that insert/remove work properly together, confirming
63     // whether keys exist using iterate()
64     void test_lkr_insert_remove(void);
65 
66     // test that the concurrent tree can survive many serial inserts
67     // this is a blackbox test for tree rotations.
68     void test_lkr_insert_serial_large(void);
69 
70 private:
71 
72     // populate the given concurrent tree with elements from min..max but
73     // starting with a certain element. this allows the caller to modestly
74     // control the way the tree is built/rotated, for test variability.
populate_tree(concurrent_tree * tree,uint64_t start,uint64_t min,uint64_t max)75     static void populate_tree(concurrent_tree *tree, uint64_t start, uint64_t min, uint64_t max) {
76         concurrent_tree::locked_keyrange lkr;
77         lkr.prepare(tree);
78         lkr.acquire(keyrange::get_infinite_range());
79 
80         for (uint64_t i = start; i <= max; i++) {
81             keyrange range;
82             range.create(get_dbt(i), get_dbt(i));
83             lkr.insert(range, i);
84         }
85         for (uint64_t i = min; i < start; i++) {
86             keyrange range;
87             range.create(get_dbt(i), get_dbt(i));
88             lkr.insert(range, i);
89         }
90 
91         lkr.release();
92     }
93 };
94 
95 } /* namespace toku */
96