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
41 static int
put_callback(DB * dest_db,DB * src_db,DBT_ARRAY * dest_keys,DBT_ARRAY * dest_vals,const DBT * src_key,const DBT * src_val)42 put_callback(DB *dest_db, DB *src_db, DBT_ARRAY *dest_keys, DBT_ARRAY *dest_vals, const DBT *src_key, const DBT *src_val) {
43 toku_dbt_array_resize(dest_keys, 1);
44 toku_dbt_array_resize(dest_vals, 1);
45 DBT *dest_key = &dest_keys->dbts[0];
46 DBT *dest_val = &dest_vals->dbts[0];
47
48 (void) dest_db; (void) src_db; (void) dest_key; (void) dest_val; (void) src_key; (void) src_val;
49 lazy_assert(src_db != NULL && dest_db != NULL);
50
51 toku_free(dest_key->data);
52 dest_key->data = toku_xmemdup(src_val->data, src_val->size);
53 dest_key->ulen = dest_key->size = src_val->size;
54 dest_val->size = 0;
55
56 return 0;
57 }
58
59 static void
run_test(void)60 run_test(void) {
61 int r;
62 DB_ENV *env = NULL;
63 r = db_env_create(&env, 0); assert_zero(r);
64
65 r = env->set_generate_row_callback_for_put(env, put_callback); assert_zero(r);
66
67 r = env->open(env, TOKU_TEST_FILENAME, DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); assert_zero(r);
68
69 DB *src_db = NULL;
70 r = db_create(&src_db, env, 0); assert_zero(r);
71 r = src_db->open(src_db, NULL, "0.tdb", NULL, DB_BTREE, DB_AUTO_COMMIT+DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); assert_zero(r);
72
73 DB *dest_db = NULL;
74 r = db_create(&dest_db, env, 0); assert_zero(r);
75 r = dest_db->open(dest_db, NULL, "1.tdb", NULL, DB_BTREE, DB_AUTO_COMMIT+DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); assert_zero(r);
76
77 DB_TXN* index_txn = NULL;
78 r = env->txn_begin(env, NULL, &index_txn , 0); assert_zero(r);
79 DB_TXN* put_txn = NULL;
80 r = env->txn_begin(env, NULL, &put_txn , 0); assert_zero(r);
81
82 DBT key,data;
83 r = src_db->put(
84 src_db,
85 put_txn,
86 dbt_init(&key, "hello", 6),
87 dbt_init(&data, "there", 6),
88 0
89 );
90
91 DB_INDEXER *indexer = NULL;
92 r = env->create_indexer(env, index_txn, &indexer, src_db, 1, &dest_db, NULL, 0); assert_zero(r);
93 r = indexer->build(indexer); assert_zero(r);
94 r = indexer->close(indexer); assert_zero(r);
95 r = index_txn->abort(index_txn); assert_zero(r);
96
97 r = put_txn->abort(put_txn); assert_zero(r);
98
99
100 r = src_db->close(src_db, 0); assert_zero(r);
101 r = dest_db->close(dest_db, 0); assert_zero(r);
102
103 r = env->close(env, 0); assert_zero(r);
104 }
105
106 int
test_main(int argc,char * const argv[])107 test_main(int argc, char * const argv[]) {
108 int r;
109
110 // parse_args(argc, argv);
111 for (int i = 1; i < argc; i++) {
112 char * const arg = argv[i];
113 if (strcmp(arg, "-v") == 0) {
114 verbose++;
115 continue;
116 }
117 if (strcmp(arg, "-q") == 0) {
118 verbose = 0;
119 continue;
120 }
121 }
122
123 toku_os_recursive_delete(TOKU_TEST_FILENAME);
124 r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO); assert_zero(r);
125
126 run_test();
127
128 return 0;
129 }
130
131