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 static const char *fname = TOKU_TEST_FILENAME;
41 
42 static TOKUTXN const null_txn = 0;
43 CACHETABLE ct;
44 FT_HANDLE ft;
45 FT_CURSOR cursor;
46 
test_ft_cursor_keycompare(DB * db,const DBT * a,const DBT * b)47 static int test_ft_cursor_keycompare(DB *db __attribute__((unused)), const DBT *a, const DBT *b) {
48     return toku_keycompare(a->data, a->size, b->data, b->size);
49 }
50 int
test_main(int argc,const char * argv[])51 test_main (int argc __attribute__((__unused__)), const char *argv[]  __attribute__((__unused__))) {
52     int r;
53 
54     unlink(fname);
55 
56     toku_cachetable_create(&ct, 0, ZERO_LSN, nullptr);
57     r = toku_open_ft_handle(fname, 1, &ft, 1<<12, 1<<9, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, test_ft_cursor_keycompare);   assert(r==0);
58     r = toku_ft_cursor(ft, &cursor, NULL, false, false);               assert(r==0);
59 
60     int i;
61     for (i=0; i<1000; i++) {
62 	char string[100];
63 	snprintf(string, sizeof(string), "%04d", i);
64 	DBT key,val;
65 	toku_ft_insert(ft, toku_fill_dbt(&key, string, 5), toku_fill_dbt(&val, string, 5), 0);
66     }
67 
68     {
69 	struct check_pair pair = {5, "0000", 5, "0000", 0};
70 	r = toku_ft_cursor_get(cursor, NULL, lookup_checkf, &pair, DB_NEXT);    assert(r==0); assert(pair.call_count==1);
71     }
72     {
73 	struct check_pair pair = {5, "0001", 5, "0001", 0};
74 	r = toku_ft_cursor_get(cursor, NULL, lookup_checkf, &pair, DB_NEXT);    assert(r==0); assert(pair.call_count==1);
75     }
76 
77     // This will invalidate due to the root counter bumping, but the OMT itself will still be valid.
78     {
79 	DBT key, val;
80 	toku_ft_insert(ft, toku_fill_dbt(&key, "d", 2), toku_fill_dbt(&val, "w", 2), 0);
81     }
82 
83     {
84 	struct check_pair pair = {5, "0002", 5, "0002", 0};
85 	r = toku_ft_cursor_get(cursor, NULL, lookup_checkf, &pair, DB_NEXT);    assert(r==0); assert(pair.call_count==1);
86     }
87 
88     toku_ft_cursor_close(cursor);
89     r = toku_close_ft_handle_nolsn(ft, 0);                                                               assert(r==0);
90     toku_cachetable_close(&ct);
91     return 0;
92 }
93