YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/common/transaction-test-util.h
Line
Count
Source (jump to first uncovered line)
1
//
2
// Copyright (c) YugaByte, Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5
// in compliance with the License.  You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software distributed under the License
10
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11
// or implied.  See the License for the specific language governing permissions and limitations
12
// under the License.
13
//
14
//
15
16
#ifndef YB_COMMON_TRANSACTION_TEST_UTIL_H
17
#define YB_COMMON_TRANSACTION_TEST_UTIL_H
18
19
#include <functional>
20
#include <type_traits>
21
22
#include <gtest/gtest.h>
23
24
#include "yb/common/hybrid_time.h"
25
#include "yb/common/transaction.h"
26
27
#include "yb/util/enums.h"
28
#include "yb/util/math_util.h"
29
#include "yb/util/result.h"
30
#include "yb/util/string_trim.h"
31
#include "yb/util/test_macros.h"
32
#include "yb/util/tsan_util.h"
33
34
namespace yb {
35
36
class TransactionStatusManagerMock : public TransactionStatusManager {
37
 public:
38
0
  HybridTime LocalCommitTime(const TransactionId& id) override {
39
0
    return HybridTime::kInvalid;
40
0
  }
41
42
33.0k
  boost::optional<CommitMetadata> LocalCommitData(const TransactionId& id) override {
43
33.0k
    return boost::none;
44
33.0k
  }
45
46
  void RequestStatusAt(const StatusRequest& request) override;
47
48
  void Commit(const TransactionId& txn_id, HybridTime commit_time) {
49
    ASSERT_TRUE(txn_commit_time_.emplace(txn_id, commit_time).second) << "Transaction " << txn_id
50
        << " has been already committed.";
51
  }
52
53
0
  Result<TransactionMetadata> PrepareMetadata(const TransactionMetadataPB& pb) override {
54
0
    return STATUS(Expired, "");
55
0
  }
56
57
0
  void Abort(const TransactionId& id, TransactionStatusCallback callback) override {
58
0
  }
59
60
0
  void Cleanup(TransactionIdSet&& set) override {
61
0
  }
62
63
0
  int64_t RegisterRequest() override {
64
0
    return 0;
65
0
  }
66
67
0
  void UnregisterRequest(int64_t) override {
68
0
  }
69
70
  void FillPriorities(
71
0
      boost::container::small_vector_base<std::pair<TransactionId, uint64_t>>* inout) override {}
72
73
3.36k
  HybridTime MinRunningHybridTime() const override {
74
3.36k
    return HybridTime::kMin;
75
3.36k
  }
76
77
0
  Result<HybridTime> WaitForSafeTime(HybridTime safe_time, CoarseTimePoint deadline) override {
78
0
    return STATUS(NotSupported, "WaitForSafeTime not implemented");
79
0
  }
80
81
0
  const TabletId& tablet_id() const override {
82
0
    static TabletId tablet_id;
83
0
    return tablet_id;
84
0
  }
85
86
 private:
87
  std::unordered_map<TransactionId, HybridTime, TransactionIdHash> txn_commit_time_;
88
};
89
90
} // namespace yb
91
92
#endif // YB_COMMON_TRANSACTION_TEST_UTIL_H