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 dest_key->flags = 0;
48 dest_val->flags = 0;
49 (void) dest_db; (void) src_db; (void) dest_key; (void) dest_val; (void) src_key; (void) src_val;
50
51 lazy_assert(src_db != NULL && dest_db != NULL);
52
53 dest_key->data = src_val->data;
54 dest_key->size = src_val->size;
55 dest_val->size = 0;
56
57 return 0;
58 }
59
60 static void
run_test(void)61 run_test(void) {
62 int r;
63 DB_ENV *env = NULL;
64 r = db_env_create(&env, 0); assert_zero(r);
65
66 r = env->set_generate_row_callback_for_put(env, put_callback); assert_zero(r);
67
68 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);
69
70 DB *src_db = NULL;
71 r = db_create(&src_db, env, 0); assert_zero(r);
72 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);
73
74 DB *dest_db = NULL;
75 r = db_create(&dest_db, env, 0); assert_zero(r);
76 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);
77
78 DB_TXN *txn = NULL;
79 r = env->txn_begin(env, NULL, &txn, 0); assert_zero(r);
80
81 DB_INDEXER *indexer = NULL;
82 r = env->create_indexer(env, txn, &indexer, src_db, 1, &dest_db, NULL, 0); assert_zero(r);
83
84 r = indexer->abort(indexer); assert_zero(r);
85
86 r = txn->abort(txn); assert_zero(r);
87
88 r = src_db->close(src_db, 0); assert_zero(r);
89 r = dest_db->close(dest_db, 0); assert_zero(r);
90
91 r = env->close(env, 0); assert_zero(r);
92 }
93
94 int
test_main(int argc,char * const argv[])95 test_main(int argc, char * const argv[]) {
96 int r;
97
98 // parse_args(argc, argv);
99 for (int i = 1; i < argc; i++) {
100 char * const arg = argv[i];
101 if (strcmp(arg, "-v") == 0) {
102 verbose++;
103 continue;
104 }
105 if (strcmp(arg, "-q") == 0) {
106 verbose = 0;
107 continue;
108 }
109 }
110
111 toku_os_recursive_delete(TOKU_TEST_FILENAME);
112 r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO); assert_zero(r);
113
114 run_test();
115
116 return 0;
117 }
118
119