Loading...
Searching...
No Matches
system_info_test.cpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
21
22#include <gmock/gmock.h>
23#include <gtest/gtest.h>
24
26
27namespace resdb {
28namespace {
29
30using ::resdb::testing::EqualsProto;
31using ::testing::ElementsAre;
32using ::testing::ElementsAreArray;
33
34ReplicaInfo GenerateReplicaInfo(const std::string& ip, int port,
35 int64_t node_id) {
36 ReplicaInfo info;
37 info.set_ip(ip);
38 info.set_port(port);
39 info.set_id(node_id);
40 return info;
41}
42
43TEST(SystemInfoTest, GetReplicas) {
44 std::vector<ReplicaInfo> replicas;
45 replicas.push_back(GenerateReplicaInfo("127.0.0.1", 1234, 1));
46 replicas.push_back(GenerateReplicaInfo("127.0.0.1", 1235, 2));
47
48 ResDBConfig config(replicas, GenerateReplicaInfo("127.0.0.1", 1111, 0),
49 KeyInfo(), CertificateInfo());
50
51 SystemInfo system(config);
52 EXPECT_THAT(system.GetReplicas(),
53 ElementsAre(EqualsProto(replicas[0]), EqualsProto(replicas[1])));
54
55 std::vector<ReplicaInfo> new_replicas;
56 new_replicas.push_back(GenerateReplicaInfo("127.0.0.1", 1236, 3));
57 system.SetReplicas(new_replicas);
58
59 EXPECT_THAT(system.GetReplicas(), ElementsAre(EqualsProto(new_replicas[0])));
60
61 ReplicaInfo new_replica = GenerateReplicaInfo("127.0.0.1", 1237, 4);
62 system.AddReplica(new_replica);
63
64 EXPECT_THAT(system.GetReplicas(), ElementsAre(EqualsProto(new_replicas[0]),
65 EqualsProto(new_replica)));
66
67 ReplicaInfo deplicate_new_replica = GenerateReplicaInfo("127.0.0.1", 1238, 4);
68 system.AddReplica(deplicate_new_replica);
69 EXPECT_THAT(system.GetReplicas(), ElementsAre(EqualsProto(new_replicas[0]),
70 EqualsProto(new_replica)));
71}
72
73} // namespace
74
75} // namespace resdb
ReplicaInfo GenerateReplicaInfo(int id, const std::string &ip, int port)
TEST(NetworkUtilsTest, GetDNSName)