brpc_adaptive_class_unittest.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Licensed to the Apache Software Foundation (ASF) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. // brpc - A framework to host and access services throughout Baidu.
  18. // Date: 2019/04/16 23:41:04
  19. #include <gtest/gtest.h>
  20. #include "brpc/adaptive_max_concurrency.h"
  21. #include "brpc/adaptive_protocol_type.h"
  22. #include "brpc/adaptive_connection_type.h"
  23. const std::string kAutoCL = "aUto";
  24. const std::string kHttp = "hTTp";
  25. const std::string kPooled = "PoOled";
  26. TEST(AdaptiveMaxConcurrencyTest, ShouldConvertCorrectly) {
  27. brpc::AdaptiveMaxConcurrency amc(0);
  28. EXPECT_EQ(brpc::AdaptiveMaxConcurrency::UNLIMITED(), amc.type());
  29. EXPECT_EQ(brpc::AdaptiveMaxConcurrency::UNLIMITED(), amc.value());
  30. EXPECT_EQ(0, int(amc));
  31. EXPECT_TRUE(amc == brpc::AdaptiveMaxConcurrency::UNLIMITED());
  32. amc = 10;
  33. EXPECT_EQ(brpc::AdaptiveMaxConcurrency::CONSTANT(), amc.type());
  34. EXPECT_EQ("10", amc.value());
  35. EXPECT_EQ(10, int(amc));
  36. EXPECT_EQ(amc, "10");
  37. amc = kAutoCL;
  38. EXPECT_EQ(kAutoCL, amc.type());
  39. EXPECT_EQ(kAutoCL, amc.value());
  40. EXPECT_EQ(int(amc), -1);
  41. EXPECT_TRUE(amc == "auto");
  42. }
  43. TEST(AdaptiveProtocolTypeTest, ShouldConvertCorrectly) {
  44. brpc::AdaptiveProtocolType apt;
  45. apt = kHttp;
  46. EXPECT_EQ(apt, brpc::ProtocolType::PROTOCOL_HTTP);
  47. EXPECT_NE(apt, brpc::ProtocolType::PROTOCOL_BAIDU_STD);
  48. apt = brpc::ProtocolType::PROTOCOL_HTTP;
  49. EXPECT_EQ(apt, brpc::ProtocolType::PROTOCOL_HTTP);
  50. EXPECT_NE(apt, brpc::ProtocolType::PROTOCOL_BAIDU_STD);
  51. }
  52. TEST(AdaptiveConnectionTypeTest, ShouldConvertCorrectly) {
  53. brpc::AdaptiveConnectionType act;
  54. act = brpc::ConnectionType::CONNECTION_TYPE_POOLED;
  55. EXPECT_EQ(act, brpc::ConnectionType::CONNECTION_TYPE_POOLED);
  56. EXPECT_NE(act, brpc::ConnectionType::CONNECTION_TYPE_SINGLE);
  57. act = kPooled;
  58. EXPECT_EQ(act, brpc::ConnectionType::CONNECTION_TYPE_POOLED);
  59. EXPECT_NE(act, brpc::ConnectionType::CONNECTION_TYPE_SINGLE);
  60. }