/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/filelock_test.cc
Line | Count | Source |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under the BSD-style license found in the |
3 | | // LICENSE file in the root directory of this source tree. An additional grant |
4 | | // of patent rights can be found in the PATENTS file in the same directory. |
5 | | // |
6 | | // The following only applies to changes made to this file as part of YugaByte development. |
7 | | // |
8 | | // Portions Copyright (c) YugaByte, Inc. |
9 | | // |
10 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
11 | | // in compliance with the License. You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
16 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
17 | | // or implied. See the License for the specific language governing permissions and limitations |
18 | | // under the License. |
19 | | // |
20 | | |
21 | | #include <string> |
22 | | #include <vector> |
23 | | |
24 | | #include <gtest/gtest.h> |
25 | | |
26 | | #include "yb/rocksdb/env.h" |
27 | | #include "yb/rocksdb/util/testharness.h" |
28 | | |
29 | | #include "yb/util/status.h" |
30 | | #include "yb/util/test_macros.h" |
31 | | #include "yb/rocksdb/util/testutil.h" |
32 | | |
33 | | namespace rocksdb { |
34 | | |
35 | | class LockTest : public RocksDBTest { |
36 | | public: |
37 | | static LockTest* current_; |
38 | | std::string file_; |
39 | | rocksdb::Env* env_; |
40 | | |
41 | | LockTest() : file_(test::TmpDir() + "/db_testlock_file"), |
42 | 1 | env_(rocksdb::Env::Default()) { |
43 | 1 | current_ = this; |
44 | 1 | } |
45 | | |
46 | 1 | ~LockTest() { |
47 | 1 | } |
48 | | |
49 | 2 | Status LockFile(FileLock** db_lock) { |
50 | 2 | return env_->LockFile(file_, db_lock); |
51 | 2 | } |
52 | | |
53 | 1 | Status UnlockFile(FileLock* db_lock) { |
54 | 1 | return env_->UnlockFile(db_lock); |
55 | 1 | } |
56 | | }; |
57 | | LockTest* LockTest::current_; |
58 | | |
59 | 1 | TEST_F(LockTest, LockBySameThread) { |
60 | 1 | FileLock* lock1; |
61 | 1 | FileLock* lock2; |
62 | | |
63 | | // acquire a lock on a file |
64 | 1 | ASSERT_OK(LockFile(&lock1)); |
65 | | |
66 | | // re-acquire the lock on the same file. This should fail. |
67 | 1 | ASSERT_TRUE(LockFile(&lock2).IsIOError()); |
68 | | |
69 | | // release the lock |
70 | 1 | ASSERT_OK(UnlockFile(lock1)); |
71 | | |
72 | 1 | } |
73 | | |
74 | | } // namespace rocksdb |
75 | | |
76 | 13.2k | int main(int argc, char** argv) { |
77 | 13.2k | ::testing::InitGoogleTest(&argc, argv); |
78 | 13.2k | return RUN_ALL_TESTS(); |
79 | 13.2k | } |