Skip to content

Commit

Permalink
fix gtest compile failed
Browse files Browse the repository at this point in the history
  • Loading branch information
ehds committed Apr 14, 2024
1 parent 3cf62f0 commit 43fa414
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 114 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cc_library(
"-Woverloaded-virtual",
"-Wnon-virtual-dtor",
"-Wno-missing-field-initializers",
"-std=c++11",
"-std=c++17",
"-DGFLAGS_NS=google",
],
linkopts = [
Expand Down
13 changes: 8 additions & 5 deletions src/braft/ballot.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once
#include <algorithm>
#include <vector>
#include <optional>
#include <vector>

#include "braft/configuration.h"

Expand All @@ -32,12 +32,15 @@ class Ballot {
};

Ballot() : _quorum(0), _old_quorum(0){};
//FIXME(ehds): Remove optional.
// void init(const Configuration& conf, const Configuration& old_conf);
void init(const Configuration& conf, std::optional<const Configuration> old_conf);
// FIXME(ehds): Remove optional.
// void init(const Configuration& conf, const Configuration& old_conf);
void init(const Configuration& conf,
std::optional<const Configuration> old_conf);
PosHint grant(const PeerId& peer, PosHint hint);
void grant(const PeerId& peer);
bool granted() const { return _quorum <= 0 && _old_quorum <= 0; }
bool granted() const { return quorum() <= 0 && old_quorum() <= 0; }
int quorum() const { return _quorum; }
int old_quorum() const { return _old_quorum; }

private:
struct UnfoundPeerId {
Expand Down
6 changes: 6 additions & 0 deletions test/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#ifdef private
#undef private
#endif
#include <gtest/gtest.h>
#define private public
50 changes: 26 additions & 24 deletions test/test_ballot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

// Authors: Zhangyi Chen([email protected])

#include <gtest/gtest.h>
#include <optional>

#include "braft/ballot.h"
#include "common.h"

class BallotTest : public testing::Test {};

Expand All @@ -29,17 +31,17 @@ TEST(BallotTest, sanity) {
conf.add_peer(peer2);
conf.add_peer(peer3);
braft::Ballot bl;
bl.init(conf, NULL);
ASSERT_EQ(2, bl._quorum);
ASSERT_EQ(0, bl._old_quorum);
bl.init(conf, std::nullopt);
ASSERT_EQ(2, bl.quorum());
ASSERT_EQ(0, bl.old_quorum());
bl.grant(peer1);
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl.quorum());
braft::Ballot::PosHint hint = bl.grant(peer1, braft::Ballot::PosHint());
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl.quorum());
hint = bl.grant(peer1, hint);
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl.quorum());
hint = bl.grant(peer4, hint);
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl.quorum());
hint = bl.grant(peer2, hint);
ASSERT_TRUE(bl.granted());
}
Expand All @@ -54,27 +56,27 @@ TEST(BallotTest, joint_consensus_same_conf) {
conf.add_peer(peer2);
conf.add_peer(peer3);
braft::Ballot bl;
bl.init(conf, &conf);
ASSERT_EQ(2, bl._quorum);
ASSERT_EQ(2, bl._old_quorum);
bl.init(conf, conf);
ASSERT_EQ(2, bl.quorum());
ASSERT_EQ(2, bl.old_quorum());
bl.grant(peer1);
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl._old_quorum);
ASSERT_EQ(1, bl.quorum());
ASSERT_EQ(1, bl.old_quorum());
braft::Ballot::PosHint hint = bl.grant(peer1, braft::Ballot::PosHint());
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl._old_quorum);
ASSERT_EQ(1, bl.quorum());
ASSERT_EQ(1, bl.old_quorum());
hint = bl.grant(peer1, hint);
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl._old_quorum);
ASSERT_EQ(1, bl.quorum());
ASSERT_EQ(1, bl.old_quorum());
hint = bl.grant(peer4, hint);
ASSERT_EQ(1, bl._quorum);
ASSERT_EQ(1, bl._old_quorum);
ASSERT_EQ(1, bl.quorum());
ASSERT_EQ(1, bl.old_quorum());
ASSERT_FALSE(bl.granted());
hint = bl.grant(peer2, hint);
ASSERT_TRUE(bl.granted());
hint = bl.grant(peer3, hint);
ASSERT_EQ(-1, bl._quorum);
ASSERT_EQ(-1, bl._old_quorum);
ASSERT_EQ(-1, bl.quorum());
ASSERT_EQ(-1, bl.old_quorum());
}

TEST(BallotTest, joint_consensus_different_conf) {
Expand All @@ -92,12 +94,12 @@ TEST(BallotTest, joint_consensus_different_conf) {
conf2.add_peer(peer3);
conf2.add_peer(peer4);
braft::Ballot bl;
bl.init(conf, &conf2);
bl.init(conf, conf2);
bl.grant(peer1);
bl.grant(peer2);
ASSERT_FALSE(bl.granted());
ASSERT_EQ(0, bl._quorum);
ASSERT_EQ(1, bl._old_quorum);
ASSERT_EQ(0, bl.quorum());
ASSERT_EQ(1, bl.old_quorum());
bl.grant(peer4);
ASSERT_TRUE(bl.granted());
}
6 changes: 4 additions & 2 deletions test/test_ballot_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// Author: Zhangyi Chen ([email protected])
// Date: 2016/02/03 15:59:18

#include <algorithm>
#include <gtest/gtest.h>
#include <butil/string_printf.h>

#include <algorithm>

#include "braft/ballot_box.h"
#include "braft/configuration.h"
#include "braft/fsm_caller.h"
#include "common.h"

class BallotBoxTest : public testing::Test {
protected:
Expand Down
3 changes: 2 additions & 1 deletion test/test_checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// Author: Zhangyi Chen ([email protected])
// Date: 2016/04/11 12:15:37

#include <gtest/gtest.h>
#include <braft/util.h>
#include <butil/crc32c.h>

#include "common.h"

class ChecksumTest : public testing::Test {
protected:
void SetUp() {}
Expand Down
9 changes: 5 additions & 4 deletions test/test_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// Author: Zhangyi Chen ([email protected])
// Date: 2018/01/12 12:56:17

#include <gtest/gtest.h>
#include <gflags/gflags.h>
#include <butil/unique_ptr.h>
#include <brpc/server.h>
#include "braft/raft.h"
#include <butil/unique_ptr.h>
#include <gflags/gflags.h>

#include "braft/cli.h"
#include "braft/node.h"
#include "braft/raft.h"
#include "common.h"

class CliTest : public testing::Test {
public:
Expand Down
5 changes: 3 additions & 2 deletions test/test_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* =====================================================================================
*/

#include <gtest/gtest.h>
#include <butil/logging.h>
#include "braft/raft.h"

#include "braft/configuration_manager.h"
#include "braft/raft.h"
#include "common.h"

class TestUsageSuits : public testing::Test {
protected:
Expand Down
12 changes: 6 additions & 6 deletions test/test_file_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
// Author: Zhangyi Chen ([email protected])
// Date: 2015/11/06 15:40:45

#include <gtest/gtest.h>
#include <gflags/gflags.h>
#include <butil/logging.h>
#include <brpc/server.h>
#include <butil/file_util.h>
#include <butil/logging.h>
#include <gflags/gflags.h>

#include <brpc/server.h>
#include "braft/file_service.h"
#include "braft/util.h"
#include "braft/remote_file_copier.h"
#include "braft/file_system_adaptor.h"
#include "braft/remote_file_copier.h"
#include "braft/util.h"
#include "common.h"

namespace braft {
DECLARE_bool(raft_file_check_hole);
Expand Down
2 changes: 1 addition & 1 deletion test/test_file_system_adaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// Author: ZhengPengFei ([email protected])
// Date: 2017/06/16 10:29:05

#include <gtest/gtest.h>
#include "braft/file_system_adaptor.h"
#include "common.h"

class TestFileSystemAdaptorSuits : public testing::Test {
protected:
Expand Down
9 changes: 5 additions & 4 deletions test/test_fsm_caller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// Author: Zhangyi Chen ([email protected])
// Date: 2015/12/01 17:03:46

#include <gtest/gtest.h>
#include <butil/string_printf.h>
#include <butil/memory/scoped_ptr.h>
#include <butil/string_printf.h>

#include "braft/configuration.h"
#include "braft/fsm_caller.h"
#include "braft/raft.h"
#include "braft/log.h"
#include "braft/configuration.h"
#include "braft/log_manager.h"
#include "braft/raft.h"
#include "common.h"

class FSMCallerTest : public testing::Test {
protected:
Expand Down
13 changes: 7 additions & 6 deletions test/test_fsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// Author: Zhangyi Chen ([email protected])
// Date: 2016/02/23 16:22:15

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <gtest/gtest.h>
#include <butil/fd_guard.h>
#include <butil/time.h>
#include <butil/logging.h>
#include <butil/time.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include "common.h"

class FsyncTest : public testing::Test {
};
Expand Down
9 changes: 5 additions & 4 deletions test/test_leader_lease.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

// Authors: Pengfei Zheng ([email protected])

#include <gtest/gtest.h>
#include <butil/logging.h>
#include "braft/util.h"
#include "braft/node.h"
#include "braft/lease.h"

#include "../test/util.h"
#include "braft/lease.h"
#include "braft/node.h"
#include "braft/util.h"
#include "common.h"

namespace braft {
DECLARE_bool(raft_enable_leader_lease);
Expand Down
17 changes: 9 additions & 8 deletions test/test_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
// Author: WangYao (fisherman), [email protected]
// Date: 2015/10/08 17:00:05

#include <gtest/gtest.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <butil/atomicops.h>
#include <butil/file_util.h>
#include <butil/files/file_path.h>
#include <butil/files/file_enumerator.h>
#include <butil/files/dir_reader_posix.h>
#include <butil/string_printf.h>
#include <butil/files/file_enumerator.h>
#include <butil/files/file_path.h>
#include <butil/logging.h>
#include "braft/util.h"
#include <butil/string_printf.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>

#include "braft/log.h"
#include "braft/storage.h"
#include "braft/util.h"
#include "common.h"

namespace braft {
DECLARE_bool(raft_trace_append_entry_latency);
Expand Down
5 changes: 3 additions & 2 deletions test/test_log_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* =====================================================================================
*/

#include <gtest/gtest.h>
#include <butil/logging.h>
#include <butil/iobuf.h>
#include <butil/logging.h>

#include "braft/log_entry.h"
#include "common.h"

class TestUsageSuits : public testing::Test {
protected:
Expand Down
9 changes: 4 additions & 5 deletions test/test_log_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
// Author: Zhangyi Chen ([email protected])
// Date: 2015/11/24 16:30:49

#include <gtest/gtest.h>

#include <bthread/countdown_event.h>
#include <butil/macros.h>
#include <butil/memory/scoped_ptr.h>
#include <butil/string_printf.h>
#include <butil/macros.h>

#include <bthread/countdown_event.h>
#include "braft/log_manager.h"
#include "braft/configuration.h"
#include "braft/log.h"
#include "braft/log_manager.h"
#include "common.h"

class LogManagerTest : public testing::Test {
protected:
Expand Down
2 changes: 1 addition & 1 deletion test/test_memory_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Author: [email protected]
// Date: 2017/05/23

#include <gtest/gtest.h>
#include "braft/memory_log.h"
#include "common.h"

namespace braft {
extern void global_init_once_or_die();
Expand Down
5 changes: 3 additions & 2 deletions test/test_meta.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include <gflags/gflags.h>
#include <gtest/gtest.h>
#include <butil/status.h>
#include <gflags/gflags.h>

#include "braft/raft.h"
#include "braft/raft_meta.h"
#include "common.h"

namespace braft {
extern void global_init_once_or_die();
Expand Down
Loading

0 comments on commit 43fa414

Please sign in to comment.