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 "test.h"
40 #include <toku_time.h>
41 
42 static const char *fname = TOKU_TEST_FILENAME;
43 
44 static TOKUTXN const null_txn = 0;
45 
test4(int nodesize,int count)46 static void test4 (int nodesize, int count) {
47     FT_HANDLE t;
48     int r;
49     struct timeval t0,t1;
50     int i;
51     CACHETABLE ct;
52     gettimeofday(&t0, 0);
53     unlink(fname);
54 
55     toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr);
56     r = toku_open_ft_handle(fname, 1, &t, nodesize, nodesize / 8, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun); assert(r==0);
57     for (i=0; i<count; i++) {
58 	char key[100],val[100];
59 	int rv = random();
60 	DBT k,v;
61 	snprintf(key,100,"hello%d",rv);
62 	snprintf(val,100,"there%d",i);
63 	toku_ft_insert(t, toku_fill_dbt(&k, key, 1+strlen(key)), toku_fill_dbt(&v, val, 1+strlen(val)), null_txn);
64     }
65     r = toku_verify_ft(t); assert(r==0);
66     r = toku_close_ft_handle_nolsn(t, 0);        assert(r==0);
67     toku_cachetable_close(&ct);
68 
69     gettimeofday(&t1, 0);
70     {
71 	double diff = toku_tdiff(&t1, &t0);
72 	if (verbose) printf("random insertions: blocksize=%d %d insertions in %.3f seconds, %.2f insertions/second\n", nodesize, count, diff, count/diff);
73     }
74 }
75 
ft_blackbox_test(void)76 static void ft_blackbox_test (void) {
77     test4(2048, 1<<14);
78 
79     if (0) {
80 
81 	if (verbose) printf("test4 slow\n");
82 	test4(2048, 1<<15);
83 
84 	//if (verbose) toku_pma_show_stats();
85 
86 	test4(1<<15, 1024);
87 
88 	test4(1<<18, 1<<20);
89 
90 	// Once upon a time srandom(8) caused this test to fail.
91 	srandom(8); test4(2048, 1<<15);
92     }
93 }
94 
95 int
test_main(int argc,const char * argv[])96 test_main (int argc , const char *argv[]) {
97     default_parse_args(argc, argv);
98 
99     ft_blackbox_test();
100 
101     if (verbose) printf("test ok\n");
102     return 0;
103 }
104