Commit a13730a4 authored by helei's avatar helei

add explicit key word

parent cc6642bd
...@@ -27,9 +27,9 @@ namespace brpc { ...@@ -27,9 +27,9 @@ namespace brpc {
class AdaptiveMaxConcurrency{ class AdaptiveMaxConcurrency{
public: public:
AdaptiveMaxConcurrency(); explicit AdaptiveMaxConcurrency();
AdaptiveMaxConcurrency(int max_concurrency); explicit AdaptiveMaxConcurrency(int max_concurrency);
AdaptiveMaxConcurrency(const butil::StringPiece& value); explicit AdaptiveMaxConcurrency(const butil::StringPiece& value);
// Non-trivial destructor to prevent AdaptiveMaxConcurrency from being // Non-trivial destructor to prevent AdaptiveMaxConcurrency from being
// passed to variadic arguments without explicit type conversion. // passed to variadic arguments without explicit type conversion.
......
...@@ -39,8 +39,8 @@ const char* ProtocolTypeToString(ProtocolType); ...@@ -39,8 +39,8 @@ const char* ProtocolTypeToString(ProtocolType);
// Assignable by both ProtocolType and names. // Assignable by both ProtocolType and names.
class AdaptiveProtocolType { class AdaptiveProtocolType {
public: public:
AdaptiveProtocolType() : _type(PROTOCOL_UNKNOWN) {} explicit AdaptiveProtocolType() : _type(PROTOCOL_UNKNOWN) {}
AdaptiveProtocolType(ProtocolType type) : _type(type) {} explicit AdaptiveProtocolType(ProtocolType type) : _type(type) {}
~AdaptiveProtocolType() {} ~AdaptiveProtocolType() {}
void operator=(ProtocolType type) { void operator=(ProtocolType type) {
......
...@@ -690,7 +690,7 @@ static bool CreateConcurrencyLimiter(const AdaptiveMaxConcurrency& amc, ...@@ -690,7 +690,7 @@ static bool CreateConcurrencyLimiter(const AdaptiveMaxConcurrency& amc,
return true; return true;
} }
static AdaptiveMaxConcurrency g_default_max_concurrency_of_method = 0; static AdaptiveMaxConcurrency g_default_max_concurrency_of_method(0);
int Server::StartInternal(const butil::ip_t& ip, int Server::StartInternal(const butil::ip_t& ip,
const PortRange& port_range, const PortRange& port_range,
......
// brpc - A framework to host and access services throughout Baidu.
// Copyright (c) 2014 Baidu, Inc.
// Date: 2019/04/16 23:41:04
#include <gtest/gtest.h>
#include "brpc/adaptive_max_concurrency.h"
#include "brpc/adaptive_protocol_type.h"
#include "brpc/adaptive_connection_type.h"
const std::string kAutoCL = "aUto";
const std::string kHttp = "hTTp";
const std::string kPooled = "PoOled";
TEST(AdaptiveMaxConcurrencyTest, ShouldConvertCorrectly) {
brpc::AdaptiveMaxConcurrency amc(0);
EXPECT_EQ(brpc::AdaptiveMaxConcurrency::UNLIMITED(), amc.type());
EXPECT_EQ(brpc::AdaptiveMaxConcurrency::UNLIMITED(), amc.value());
EXPECT_EQ(0, int(amc));
EXPECT_TRUE(amc == brpc::AdaptiveMaxConcurrency::UNLIMITED());
amc = 10;
EXPECT_EQ(brpc::AdaptiveMaxConcurrency::CONSTANT(), amc.type());
EXPECT_EQ("10", amc.value());
EXPECT_EQ(10, int(amc));
EXPECT_EQ(amc, "10");
amc = kAutoCL;
EXPECT_EQ(kAutoCL, amc.type());
EXPECT_EQ(kAutoCL, amc.value());
EXPECT_EQ(int(amc), -1);
EXPECT_TRUE(amc == "auto");
}
TEST(AdaptiveProtocolType, ShouldConvertCorrectly) {
brpc::AdaptiveProtocolType apt;
apt = kHttp;
EXPECT_EQ(apt, brpc::ProtocolType::PROTOCOL_HTTP);
apt = brpc::ProtocolType::PROTOCOL_HTTP;
EXPECT_EQ(apt, brpc::ProtocolType::PROTOCOL_HTTP);
}
TEST(AdaptiveConnectionTypeTest, ShouldConvertCorrectly) {
brpc::AdaptiveConnectionType act;
act = brpc::ConnectionType::CONNECTION_TYPE_POOLED;
EXPECT_EQ(act, brpc::ConnectionType::CONNECTION_TYPE_POOLED);
act = kPooled;
EXPECT_EQ(act, brpc::ConnectionType::CONNECTION_TYPE_POOLED);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment