Skip to content

Commit

Permalink
[Refactor] Format change (#192)
Browse files Browse the repository at this point in the history
* Added clang-format file.
  • Loading branch information
greensky00 authored Apr 5, 2021
1 parent 026cf96 commit 365f3ae
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
22 changes: 22 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
Language: Cpp
UseTab: Never
IndentWidth: 4
AccessModifierOffset: -4
TabWidth: 4
ColumnLimit: 90
BreakConstructorInitializersBeforeComma: true
BreakBeforeTernaryOperators: true
BreakBeforeBinaryOperators: NonAssignment
PointerAlignment: Left
AllowShortIfStatementsOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
SpaceBeforeRangeBasedForLoopColon: false
BinPackArguments: false
BinPackParameters: false
AlwaysBreakBeforeMultilineStrings: false
AlignEscapedNewlines: Left
#IndentPPDirectives: BeforeHash
AllowShortLambdasOnASingleLine: Inline
AlignAfterOpenBracket: true
AlignOperands: true
1 change: 1 addition & 0 deletions include/libnuraft/raft_params.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ public:
/**
* Wait ms for response after forwarding request to leader.
* must be larger than client_req_timeout_.
* If 0, there will be no timeout for auto forwarding.
*/
int32 auto_forwarding_req_timeout_;
};
Expand Down
4 changes: 3 additions & 1 deletion include/libnuraft/rpc_cli.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class rpc_client {
__interface_body__(rpc_client);

public:
virtual void send(ptr<req_msg>& req, rpc_handler& when_done, uint64_t send_timeout_ms = 0) = 0;
virtual void send(ptr<req_msg>& req,
rpc_handler& when_done,
uint64_t send_timeout_ms = 0) = 0;

virtual uint64_t get_id() const = 0;

Expand Down
12 changes: 8 additions & 4 deletions src/asio_service.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,10 @@ class asio_rpc_client
send(req, when_done, send_timeout_ms);
}

virtual void send(ptr<req_msg>& req, rpc_handler& when_done, uint64_t send_timeout_ms = 0) __override__ {
virtual void send(ptr<req_msg>& req,
rpc_handler& when_done,
uint64_t send_timeout_ms = 0) __override__
{
if (abandoned_) {
p_er( "client %p to %s:%s is already stale (SSL %s)",
this, host_.c_str(), port_.c_str(),
Expand Down Expand Up @@ -1106,8 +1109,8 @@ class asio_rpc_client
( std::chrono::duration_cast<std::chrono::nanoseconds>
( std::chrono::milliseconds( send_timeout_ms ) ) );
operation_timer_.async_wait( std::bind( &asio_rpc_client::cancel_socket,
this,
std::placeholders::_1 ) );
this,
std::placeholders::_1 ) );
}


Expand Down Expand Up @@ -1162,8 +1165,9 @@ class asio_rpc_client
}

void cancel_socket(const ERROR_CODE& err) {
if (err) // Timer was cancelled itself, it's OK.
if (err) { // Timer was cancelled itself, it's OK.
return;
}

if (socket().is_open()) {
p_wn("cancelling operations due to socket (%s:%s) timeout",
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/asio_service_test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,8 @@ int auto_forwarding_timeout_test() {
raft_server::init_options opt;

/// Make leader quite slow
opt.raft_callback_ = [](cb_func::Type type, cb_func::Param* param) -> cb_func::ReturnCode {
opt.raft_callback_ = [](cb_func::Type type, cb_func::Param* param)
-> cb_func::ReturnCode {
if (type == cb_func::Type::AppendLogs) {
TestSuite::sleep_ms(150);
}
Expand Down Expand Up @@ -1245,7 +1246,7 @@ int auto_forwarding_timeout_test() {
// Forwarded as expected
auto ret1 = s3.raftServer->append_entries({msg});
CHK_TRUE(ret1->get_accepted());
CHK_EQ(ret1->get_result_code(), nuraft::cmd_result_code::OK)
CHK_EQ(nuraft::cmd_result_code::OK, ret1->get_result_code());

for (auto& entry: pkgs) {
RaftAsioPkg* pp = entry;
Expand All @@ -1269,7 +1270,7 @@ int auto_forwarding_timeout_test() {
// Work again
auto ret3 = s3.raftServer->append_entries({msg});
CHK_TRUE(ret3->get_accepted());
CHK_EQ(ret3->get_result_code(), nuraft::cmd_result_code::OK)
CHK_EQ(nuraft::cmd_result_code::OK, ret3->get_result_code());

s1.raftServer->shutdown();
s2.raftServer->shutdown();
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/fake_network.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ FakeClient::FakeClient(FakeNetwork* mother,

FakeClient::~FakeClient() {}

void FakeClient::send(ptr<req_msg>& req, rpc_handler& when_done, uint64_t /*send_timeout_ms*/) {
void FakeClient::send(ptr<req_msg>& req,
rpc_handler& when_done,
uint64_t /*send_timeout_ms*/)
{
SimpleLogger* ll = motherNet->getBase()->getLogger();
_log_info(ll, "got request %s -> %s, %s",
motherNet->getEndpoint().c_str(),
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/raft_package_asio.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public:

void initServer(bool enable_ssl = false,
bool use_global_asio = false,
const raft_server::init_options & opt = raft_server::init_options()) {
const raft_server::init_options& opt = raft_server::init_options()) {
std::string log_file_name = "./srv" + std::to_string(myId) + ".log";
myLogWrapper = cs_new<logger_wrapper>(log_file_name);
myLog = myLogWrapper;
Expand Down

0 comments on commit 365f3ae

Please sign in to comment.