manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 1 | #include "ibm/locks.hpp" |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 2 | |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 3 | #include <cstdint> |
| 4 | #include <memory> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 5 | #include <string> |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 6 | #include <tuple> |
| 7 | #include <utility> |
| 8 | #include <variant> |
| 9 | #include <vector> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 10 | |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 11 | #include <gmock/gmock.h> // IWYU pragma: keep |
| 12 | #include <gtest/gtest.h> // IWYU pragma: keep |
| 13 | |
| 14 | // IWYU pragma: no_include <gtest/gtest-message.h> |
| 15 | // IWYU pragma: no_include <gtest/gtest-test-part.h> |
| 16 | // IWYU pragma: no_include "gtest/gtest_pred_impl.h" |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 17 | |
Nan Zhou | 38ead5e | 2022-07-03 23:07:27 +0000 | [diff] [blame] | 18 | namespace crow::ibm_mc_lock |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 19 | { |
Nan Zhou | 38ead5e | 2022-07-03 23:07:27 +0000 | [diff] [blame] | 20 | namespace |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 21 | { |
Nan Zhou | 38ead5e | 2022-07-03 23:07:27 +0000 | [diff] [blame] | 22 | |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 23 | using SType = std::string; |
| 24 | using LockRequest = std::tuple<SType, SType, SType, uint64_t, SegmentFlags>; |
| 25 | using LockRequests = std::vector<LockRequest>; |
| 26 | using Rc = |
| 27 | std::pair<bool, std::variant<uint32_t, std::pair<uint32_t, LockRequest>>>; |
| 28 | using RcRelaseLock = std::pair<bool, std::pair<uint32_t, LockRequest>>; |
| 29 | using RcGetLockList = |
| 30 | std::variant<std::string, std::vector<std::pair<uint32_t, LockRequests>>>; |
| 31 | using ListOfTransactionIds = std::vector<uint32_t>; |
| 32 | using RcAcquireLock = std::pair<bool, std::variant<Rc, std::pair<bool, int>>>; |
| 33 | using RcReleaseLockApi = std::pair<bool, std::variant<bool, RcRelaseLock>>; |
| 34 | using SessionFlags = std::pair<SType, SType>; |
| 35 | using ListOfSessionIds = std::vector<std::string>; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 36 | using ::testing::IsEmpty; |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 37 | |
| 38 | class LockTest : public ::testing::Test |
| 39 | { |
| 40 | protected: |
| 41 | LockRequests request; |
| 42 | LockRequests request1, request2; |
| 43 | LockRequest record; |
| 44 | |
| 45 | public: |
Ed Tanous | b31cef6 | 2022-06-30 17:51:46 -0700 | [diff] [blame] | 46 | LockTest() : |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 47 | // lockrequest with multiple lockrequests |
Ed Tanous | b31cef6 | 2022-06-30 17:51:46 -0700 | [diff] [blame] | 48 | request{{"xxxxx", |
| 49 | "hmc-id", |
| 50 | "Read", |
| 51 | 234, |
| 52 | {{"DontLock", 2}, {"DontLock", 4}}}, |
| 53 | {"xxxxx", |
| 54 | "hmc-id", |
| 55 | "Read", |
| 56 | 234, |
| 57 | {{"DontLock", 2}, {"DontLock", 4}}}}, |
| 58 | request1{{"xxxxx", |
| 59 | "hmc-id", |
| 60 | "Read", |
| 61 | 234, |
| 62 | {{"DontLock", 2}, {"DontLock", 4}}}}, |
| 63 | request2{{"xxxxx", |
| 64 | "hmc-id", |
| 65 | "Write", |
| 66 | 234, |
| 67 | {{"LockAll", 2}, {"DontLock", 4}}}}, |
| 68 | record{ |
| 69 | "xxxxx", "hmc-id", "Read", 234, {{"DontLock", 2}, {"DontLock", 4}}} |
| 70 | {} |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 71 | |
| 72 | ~LockTest() override = default; |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 73 | |
| 74 | LockTest(const LockTest&) = delete; |
| 75 | LockTest(LockTest&&) = delete; |
| 76 | LockTest& operator=(const LockTest&) = delete; |
| 77 | LockTest& operator=(const LockTest&&) = delete; |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | class MockLock : public crow::ibm_mc_lock::Lock |
| 81 | { |
| 82 | public: |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 83 | bool isValidLockRequest(const LockRequest& record1) override |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 84 | { |
| 85 | bool status = Lock::isValidLockRequest(record1); |
| 86 | return status; |
| 87 | } |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 88 | bool isConflictRequest(const LockRequests& request) override |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 89 | { |
| 90 | bool status = Lock::isConflictRequest(request); |
| 91 | return status; |
| 92 | } |
Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 93 | Rc isConflictWithTable(const LockRequests& request) override |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 94 | { |
| 95 | auto conflict = Lock::isConflictWithTable(request); |
| 96 | return conflict; |
| 97 | } |
| 98 | uint32_t generateTransactionId() override |
| 99 | { |
| 100 | uint32_t tid = Lock::generateTransactionId(); |
| 101 | return tid; |
| 102 | } |
| 103 | |
| 104 | bool validateRids(const ListOfTransactionIds& tids) override |
| 105 | { |
| 106 | bool status = Lock::validateRids(tids); |
| 107 | return status; |
| 108 | } |
| 109 | RcRelaseLock isItMyLock(const ListOfTransactionIds& tids, |
| 110 | const SessionFlags& ids) override |
| 111 | { |
| 112 | auto status = Lock::isItMyLock(tids, ids); |
| 113 | return status; |
| 114 | } |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 115 | friend class LockTest; |
| 116 | }; |
| 117 | |
| 118 | TEST_F(LockTest, ValidationGoodTestCase) |
| 119 | { |
| 120 | MockLock lockManager; |
| 121 | const LockRequest& t = record; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 122 | EXPECT_TRUE(lockManager.isValidLockRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | TEST_F(LockTest, ValidationBadTestWithLocktype) |
| 126 | { |
| 127 | MockLock lockManager; |
| 128 | // Corrupt the lock type |
| 129 | std::get<2>(record) = "rwrite"; |
| 130 | const LockRequest& t = record; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 131 | EXPECT_FALSE(lockManager.isValidLockRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | TEST_F(LockTest, ValidationBadTestWithlockFlags) |
| 135 | { |
| 136 | MockLock lockManager; |
| 137 | // Corrupt the lockflag |
| 138 | std::get<4>(record)[0].first = "lock"; |
| 139 | const LockRequest& t = record; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 140 | EXPECT_FALSE(lockManager.isValidLockRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | TEST_F(LockTest, ValidationBadTestWithSegmentlength) |
| 144 | { |
| 145 | MockLock lockManager; |
| 146 | // Corrupt the Segment length |
| 147 | std::get<4>(record)[0].second = 7; |
| 148 | const LockRequest& t = record; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 149 | EXPECT_FALSE(lockManager.isValidLockRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | TEST_F(LockTest, MultiRequestWithoutConflict) |
| 153 | { |
| 154 | MockLock lockManager; |
| 155 | const LockRequests& t = request; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 156 | EXPECT_FALSE(lockManager.isConflictRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | TEST_F(LockTest, MultiRequestWithConflictduetoSameSegmentLength) |
| 160 | { |
| 161 | MockLock lockManager; |
| 162 | // Corrupt the locktype |
| 163 | std::get<2>(request[0]) = "Write"; |
| 164 | // Match the segment lengths to points them to lock similar kind of |
| 165 | // resource |
| 166 | std::get<4>(request[0])[0].first = "LockAll"; |
| 167 | const LockRequests& t = request; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 168 | EXPECT_TRUE(lockManager.isConflictRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 169 | } |
Patrick Williams | 26b3630 | 2023-05-10 17:29:00 -0500 | [diff] [blame] | 170 | #if 0 // Comment out due to bad code in include/ibm/locks.hpp |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 171 | TEST_F(LockTest, MultiRequestWithoutConflictduetoDifferentSegmentData) |
| 172 | { |
| 173 | MockLock lockManager; |
| 174 | // Corrupt the locktype |
| 175 | std::get<2>(request[0]) = "Write"; |
| 176 | // Match the segment lengths to points them to lock similar kind of |
| 177 | // resource |
| 178 | std::get<4>(request[0])[0].first = "DontLock"; |
| 179 | std::get<4>(request[0])[1].first = "LockAll"; |
| 180 | |
| 181 | // Change the resource id(2nd byte) of first record, so the locks are |
| 182 | // different so no conflict |
| 183 | std::get<3>(request[0]) = 216179379183550464; // HEX 03 00 06 00 00 00 00 00 |
| 184 | std::get<3>(request[1]) = 288236973221478400; // HEX 04 00 06 00 00 00 00 00 |
| 185 | const LockRequests& t = request; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 186 | EXPECT_FALSE(lockManager.isConflictRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | TEST_F(LockTest, MultiRequestWithConflictduetoSameSegmentData) |
| 190 | { |
| 191 | MockLock lockManager; |
| 192 | // Corrupt the locktype |
| 193 | std::get<2>(request[0]) = "Write"; |
| 194 | // Match the segment lengths to points them to lock similar kind of |
| 195 | // resource |
| 196 | std::get<4>(request[0])[0].first = "DontLock"; |
| 197 | std::get<4>(request[0])[1].first = "LockAll"; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 198 | // Dont Change the resource id(1st & 2nd byte) at all, so that the |
| 199 | // conflict occurs from the second segment which is trying to lock all |
| 200 | // the resources. |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 201 | std::get<3>(request[0]) = 216173882346831872; // 03 00 01 00 2B 00 00 00 |
| 202 | std::get<3>(request[1]) = 216173882346831872; // 03 00 01 00 2B 00 00 00 |
| 203 | const LockRequests& t = request; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 204 | EXPECT_TRUE(lockManager.isConflictRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 205 | } |
Patrick Williams | 26b3630 | 2023-05-10 17:29:00 -0500 | [diff] [blame] | 206 | #endif |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 207 | |
| 208 | TEST_F(LockTest, MultiRequestWithoutConflictduetoDifferentSegmentLength) |
| 209 | { |
| 210 | MockLock lockManager; |
| 211 | // Corrupt the locktype |
| 212 | std::get<2>(request[0]) = "Write"; |
| 213 | // Match the segment lengths to points them to lock similar kind of |
| 214 | // resource |
| 215 | std::get<4>(request[0])[0].first = "LockSame"; |
| 216 | // Change the segment length , so that the requests are trying to lock |
| 217 | // two different kind of resources |
| 218 | std::get<4>(request[0])[0].second = 3; |
| 219 | const LockRequests& t = request; |
| 220 | // Return No Conflict |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 221 | EXPECT_FALSE(lockManager.isConflictRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | TEST_F(LockTest, MultiRequestWithoutConflictduetoReadLocktype) |
| 225 | { |
| 226 | MockLock lockManager; |
| 227 | // Match the segment lengths to points them to lock similar kind of |
| 228 | // resource |
| 229 | std::get<4>(request[0])[0].first = "LockAll"; |
| 230 | const LockRequests& t = request; |
| 231 | // Return No Conflict |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 232 | EXPECT_FALSE(lockManager.isConflictRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | TEST_F(LockTest, MultiRequestWithoutConflictduetoReadLocktypeAndLockall) |
| 236 | { |
| 237 | MockLock lockManager; |
| 238 | // Match the segment lengths to points them to lock similar kind of |
| 239 | // resource |
| 240 | std::get<4>(request[0])[0].first = "LockAll"; |
| 241 | std::get<4>(request[0])[1].first = "LockAll"; |
| 242 | const LockRequests& t = request; |
| 243 | // Return No Conflict |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 244 | EXPECT_FALSE(lockManager.isConflictRequest(t)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 245 | } |
| 246 | |
Patrick Williams | 26b3630 | 2023-05-10 17:29:00 -0500 | [diff] [blame] | 247 | #if 0 // Comment out due to bad code in include/ibm/locks.hpp |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 248 | TEST_F(LockTest, RequestConflictedWithLockTableEntries) |
| 249 | { |
| 250 | MockLock lockManager; |
| 251 | const LockRequests& t = request1; |
| 252 | auto rc1 = lockManager.isConflictWithTable(t); |
| 253 | // Corrupt the lock type |
| 254 | std::get<2>(request[0]) = "Write"; |
| 255 | // Corrupt the lockflag |
| 256 | std::get<4>(request[0])[1].first = "LockAll"; |
| 257 | const LockRequests& p = request; |
| 258 | auto rc2 = lockManager.isConflictWithTable(p); |
| 259 | // Return a Conflict |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 260 | EXPECT_TRUE(rc2.first); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 261 | } |
Patrick Williams | 26b3630 | 2023-05-10 17:29:00 -0500 | [diff] [blame] | 262 | #endif |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 263 | |
| 264 | TEST_F(LockTest, RequestNotConflictedWithLockTableEntries) |
| 265 | { |
| 266 | MockLock lockManager; |
| 267 | const LockRequests& t = request1; |
| 268 | // Insert the request1 into the lock table |
| 269 | auto rc1 = lockManager.isConflictWithTable(t); |
| 270 | // Corrupt the lock type |
| 271 | std::get<2>(request[0]) = "Read"; |
| 272 | // Corrupt the lockflag |
| 273 | std::get<4>(request[0])[1].first = "LockAll"; |
| 274 | const LockRequests& p = request; |
| 275 | auto rc2 = lockManager.isConflictWithTable(p); |
| 276 | // Return No Conflict |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 277 | EXPECT_FALSE(rc2.first); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | TEST_F(LockTest, TestGenerateTransactionIDFunction) |
| 281 | { |
| 282 | MockLock lockManager; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 283 | uint32_t transactionId1 = lockManager.generateTransactionId(); |
| 284 | uint32_t transactionId2 = lockManager.generateTransactionId(); |
| 285 | EXPECT_EQ(transactionId2, ++transactionId1); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | TEST_F(LockTest, ValidateTransactionIDsGoodTestCase) |
| 289 | { |
| 290 | MockLock lockManager; |
| 291 | const LockRequests& t = request1; |
| 292 | // Insert the request1 into the lock table |
| 293 | auto rc1 = lockManager.isConflictWithTable(t); |
| 294 | std::vector<uint32_t> tids = {1}; |
| 295 | const std::vector<uint32_t>& p = tids; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 296 | EXPECT_TRUE(lockManager.validateRids(p)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | TEST_F(LockTest, ValidateTransactionIDsBadTestCase) |
| 300 | { |
| 301 | MockLock lockManager; |
| 302 | // Insert the request1 into the lock table |
| 303 | const LockRequests& t = request1; |
| 304 | auto rc1 = lockManager.isConflictWithTable(t); |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 305 | std::vector<uint32_t> tids = {10}; |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 306 | const std::vector<uint32_t>& p = tids; |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 307 | EXPECT_FALSE(lockManager.validateRids(p)); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | TEST_F(LockTest, ValidateisItMyLockGoodTestCase) |
| 311 | { |
| 312 | MockLock lockManager; |
| 313 | // Insert the request1 into the lock table |
| 314 | const LockRequests& t = request1; |
| 315 | auto rc1 = lockManager.isConflictWithTable(t); |
| 316 | std::vector<uint32_t> tids = {1}; |
| 317 | const std::vector<uint32_t>& p = tids; |
| 318 | std::string hmcid = "hmc-id"; |
| 319 | std::string sessionid = "xxxxx"; |
| 320 | std::pair<SType, SType> ids = std::make_pair(hmcid, sessionid); |
| 321 | auto rc = lockManager.isItMyLock(p, ids); |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 322 | EXPECT_TRUE(rc.first); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | TEST_F(LockTest, ValidateisItMyLockBadTestCase) |
| 326 | { |
| 327 | MockLock lockManager; |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 328 | // Corrupt the client identifier |
| 329 | std::get<1>(request1[0]) = "randomid"; |
| 330 | // Insert the request1 into the lock table |
| 331 | const LockRequests& t = request1; |
| 332 | auto rc1 = lockManager.isConflictWithTable(t); |
| 333 | std::vector<uint32_t> tids = {1}; |
| 334 | const std::vector<uint32_t>& p = tids; |
| 335 | std::string hmcid = "hmc-id"; |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 336 | std::string sessionid = "random"; |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 337 | std::pair<SType, SType> ids = std::make_pair(hmcid, sessionid); |
| 338 | auto rc = lockManager.isItMyLock(p, ids); |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 339 | EXPECT_FALSE(rc.first); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | TEST_F(LockTest, ValidateSessionIDForGetlocklistBadTestCase) |
| 343 | { |
| 344 | MockLock lockManager; |
| 345 | // Insert the request1 into the lock table |
| 346 | const LockRequests& t = request1; |
| 347 | auto rc1 = lockManager.isConflictWithTable(t); |
| 348 | std::vector<std::string> sessionid = {"random"}; |
| 349 | auto status = lockManager.getLockList(sessionid); |
| 350 | auto result = |
| 351 | std::get<std::vector<std::pair<uint32_t, LockRequests>>>(status); |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 352 | EXPECT_THAT(result, IsEmpty()); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | TEST_F(LockTest, ValidateSessionIDForGetlocklistGoodTestCase) |
| 356 | { |
| 357 | MockLock lockManager; |
| 358 | // Insert the request1 into the lock table |
| 359 | const LockRequests& t = request1; |
| 360 | auto rc1 = lockManager.isConflictWithTable(t); |
| 361 | std::vector<std::string> sessionid = {"xxxxx"}; |
| 362 | auto status = lockManager.getLockList(sessionid); |
| 363 | auto result = |
| 364 | std::get<std::vector<std::pair<uint32_t, LockRequests>>>(status); |
Nan Zhou | b5a10a2 | 2022-07-04 01:18:14 +0000 | [diff] [blame] | 365 | EXPECT_EQ(result.size(), 1); |
manojkiraneda | 4eaf2ee | 2019-12-13 17:10:41 +0530 | [diff] [blame] | 366 | } |
Sunitha Harish | 3e919b5 | 2020-10-13 01:21:48 -0500 | [diff] [blame] | 367 | |
Nan Zhou | 38ead5e | 2022-07-03 23:07:27 +0000 | [diff] [blame] | 368 | } // namespace |
| 369 | } // namespace crow::ibm_mc_lock |