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 #include <portability/toku_pthread.h>
40 
41 #include "concurrent_tree_unit_test.h"
42 
43 namespace toku {
44 
45 // This is intended to be a black-box test for the concurrent_tree's
46 // ability to rebalance in the face of many serial insertions.
47 // If the code survives many inserts, it is considered successful.
test_lkr_insert_serial_large(void)48 void concurrent_tree_unit_test::test_lkr_insert_serial_large(void) {
49     comparator cmp;
50     cmp.create(compare_dbts, nullptr);
51 
52     concurrent_tree tree;
53     tree.create(&cmp);
54 
55     // prepare and acquire the infinte range
56     concurrent_tree::locked_keyrange lkr;
57     lkr.prepare(&tree);
58     lkr.acquire(keyrange::get_infinite_range());
59 
60     // 128k keys should be fairly stressful.
61     // a bad tree will flatten and die way earlier than 128k inserts.
62     // a good tree will rebalance and reach height logn(128k) ~= 17,
63     // survival the onslaught of inserts.
64     const uint64_t num_keys = 128 * 1024;
65 
66     // populate the tree with all the keys
67     for (uint64_t i = 0; i < num_keys; i++) {
68         DBT k;
69         toku_fill_dbt(&k, &i, sizeof(i));
70         keyrange range;
71         range.create(&k, &k);
72         lkr.insert(range, i);
73     }
74 
75     // remove all of the keys
76     for (uint64_t i = 0; i < num_keys; i++) {
77         DBT k;
78         toku_fill_dbt(&k, &i, sizeof(i));
79         keyrange range;
80         range.create(&k, &k);
81         lkr.remove(range);
82     }
83 
84     lkr.release();
85     tree.destroy();
86     cmp.destroy();
87 }
88 
89 } /* namespace toku */
90 
main(void)91 int main(void) {
92     toku::concurrent_tree_unit_test test;
93     test.test_lkr_insert_serial_large();
94     return 0;
95 }
96