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 "lock_request_unit_test.h"
40 
41 namespace toku {
42 
43 static const uint64_t my_lock_wait_time = 10 * 1000; // 10 sec
44 
45 // make sure deadlocks are detected when a lock request starts
test_wait_time_callback(void)46 void lock_request_unit_test::test_wait_time_callback(void) {
47     int r;
48     locktree lt;
49 
50     DICTIONARY_ID dict_id = { 1 };
51     lt.create(nullptr, dict_id, dbt_comparator);
52 
53     TXNID txnid_a = 1001;
54     lock_request request_a;
55     request_a.create();
56 
57     TXNID txnid_b = 2001;
58     lock_request request_b;
59     request_b.create();
60 
61     const DBT *one = get_dbt(1);
62     const DBT *two = get_dbt(2);
63 
64     // a locks 'one'
65     request_a.set(&lt, txnid_a, one, one, lock_request::type::WRITE, false);
66     r = request_a.start();
67     assert_zero(r);
68 
69     // b tries to lock 'one'
70     request_b.set(&lt, txnid_b, one, two, lock_request::type::WRITE, false);
71     r = request_b.start();
72     assert(r == DB_LOCK_NOTGRANTED);
73     uint64_t t_start = toku_current_time_microsec();
74     r = request_b.wait(my_lock_wait_time);
75     uint64_t t_end = toku_current_time_microsec();
76     assert(r == DB_LOCK_NOTGRANTED);
77     assert(t_end > t_start);
78     uint64_t t_delta = t_end - t_start;
79     assert(t_delta >= my_lock_wait_time);
80     request_b.destroy();
81 
82     release_lock_and_retry_requests(&lt, txnid_a, one, one);
83     request_a.destroy();
84 
85     lt.release_reference();
86     lt.destroy();
87 }
88 
89 } /* namespace toku */
90 
main(void)91 int main(void) {
92     toku::lock_request_unit_test test;
93     test.test_wait_time_callback();
94     return 0;
95 }
96 
97