Commit a13730a4 authored by helei's avatar helei

add explicit key word

parent cc6642bd
// Copyright (c) 2015 Baidu, Inc. // Copyright (c) 2015 Baidu, Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -38,7 +38,7 @@ const char* ConnectionTypeToString(ConnectionType); ...@@ -38,7 +38,7 @@ const char* ConnectionTypeToString(ConnectionType);
// Assignable by both ConnectionType and names. // Assignable by both ConnectionType and names.
class AdaptiveConnectionType { class AdaptiveConnectionType {
public: public:
AdaptiveConnectionType() : _type(CONNECTION_TYPE_UNKNOWN), _error(false) {} AdaptiveConnectionType() : _type(CONNECTION_TYPE_UNKNOWN), _error(false) {}
AdaptiveConnectionType(ConnectionType type) : _type(type), _error(false) {} AdaptiveConnectionType(ConnectionType type) : _type(type), _error(false) {}
~AdaptiveConnectionType() {} ~AdaptiveConnectionType() {}
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
operator ConnectionType() const { return _type; } operator ConnectionType() const { return _type; }
const char* name() const { return ConnectionTypeToString(_type); } const char* name() const { return ConnectionTypeToString(_type); }
bool has_error() const { return _error; } bool has_error() const { return _error; }
private: private:
ConnectionType _type; ConnectionType _type;
// Since this structure occupies 8 bytes in 64-bit machines anyway, // Since this structure occupies 8 bytes in 64-bit machines anyway,
......
// Copyright (c) 2014 Baidu, Inc.G // Copyright (c) 2014 Baidu, Inc.G
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
...@@ -27,13 +27,13 @@ namespace brpc { ...@@ -27,13 +27,13 @@ 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.
// eg: // eg:
// printf("%d", options.max_concurrency) // compile error // printf("%d", options.max_concurrency) // compile error
// printf("%s", options.max_concurrency.value().c_str()) // ok // printf("%s", options.max_concurrency.value().c_str()) // ok
~AdaptiveMaxConcurrency() {} ~AdaptiveMaxConcurrency() {}
......
// Copyright (c) 2015 Baidu, Inc. // Copyright (c) 2015 Baidu, Inc.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
// //
// http://www.apache.org/licenses/LICENSE-2.0 // http://www.apache.org/licenses/LICENSE-2.0
// //
// Unless required by applicable law or agreed to in writing, software // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, // distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -38,9 +38,9 @@ const char* ProtocolTypeToString(ProtocolType); ...@@ -38,9 +38,9 @@ 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) {
...@@ -77,7 +77,7 @@ public: ...@@ -77,7 +77,7 @@ public:
bool has_param() const { return !_param.empty(); } bool has_param() const { return !_param.empty(); }
const std::string& param() const { return _param; } const std::string& param() const { return _param; }
private: private:
ProtocolType _type; ProtocolType _type;
std::string _name; std::string _name;
......
This diff is collapsed.
// 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