/Users/deen/code/yugabyte-db/src/yb/consensus/quorum_util-test.cc
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include <string> |
34 | | |
35 | | #include <gtest/gtest.h> |
36 | | |
37 | | #include "yb/consensus/quorum_util.h" |
38 | | |
39 | | #include "yb/util/status.h" |
40 | | #include "yb/util/test_macros.h" |
41 | | |
42 | | namespace yb { |
43 | | namespace consensus { |
44 | | |
45 | | using std::string; |
46 | | |
47 | | static void SetPeerInfo(const string& uuid, |
48 | | PeerMemberType type, |
49 | 3 | RaftPeerPB* peer) { |
50 | 3 | peer->set_permanent_uuid(uuid); |
51 | 3 | peer->set_member_type(type); |
52 | 3 | } |
53 | | |
54 | 1 | TEST(QuorumUtilTest, TestMemberExtraction) { |
55 | 1 | RaftConfigPB config; |
56 | 1 | SetPeerInfo("A", PeerMemberType::VOTER, config.add_peers()); |
57 | 1 | SetPeerInfo("B", PeerMemberType::VOTER, config.add_peers()); |
58 | 1 | SetPeerInfo("C", PeerMemberType::VOTER, config.add_peers()); |
59 | | |
60 | | // Basic test for GetRaftConfigMember(). |
61 | 1 | RaftPeerPB peer_pb; |
62 | 1 | Status s = GetRaftConfigMember(config, "invalid", &peer_pb); |
63 | 2 | ASSERT_TRUE(s.IsNotFound()) << s.ToString(); |
64 | 1 | ASSERT_OK(GetRaftConfigMember(config, "A", &peer_pb)); |
65 | 1 | ASSERT_EQ("A", peer_pb.permanent_uuid()); |
66 | | |
67 | | // Basic test for GetRaftConfigLeader(). |
68 | 1 | ConsensusStatePB cstate; |
69 | 1 | *cstate.mutable_config() = config; |
70 | 1 | s = GetRaftConfigLeader(cstate, &peer_pb); |
71 | 2 | ASSERT_TRUE(s.IsNotFound()) << s.ToString(); |
72 | 1 | cstate.set_leader_uuid("B"); |
73 | 1 | ASSERT_OK(GetRaftConfigLeader(cstate, &peer_pb)); |
74 | 1 | ASSERT_EQ("B", peer_pb.permanent_uuid()); |
75 | 1 | } |
76 | | |
77 | | } // namespace consensus |
78 | | } // namespace yb |