brpc_adaptive_class_unittest.cpp 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

helei's avatar
helei committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
// brpc - A framework to host and access services throughout Baidu.

// 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");
}

helei's avatar
helei committed
52
TEST(AdaptiveProtocolTypeTest, ShouldConvertCorrectly) {
helei's avatar
helei committed
53 54 55 56
    brpc::AdaptiveProtocolType apt;

    apt = kHttp;
    EXPECT_EQ(apt, brpc::ProtocolType::PROTOCOL_HTTP);
helei's avatar
helei committed
57
    EXPECT_NE(apt, brpc::ProtocolType::PROTOCOL_BAIDU_STD);
helei's avatar
helei committed
58 59 60

    apt = brpc::ProtocolType::PROTOCOL_HTTP;
    EXPECT_EQ(apt, brpc::ProtocolType::PROTOCOL_HTTP);
helei's avatar
helei committed
61
    EXPECT_NE(apt, brpc::ProtocolType::PROTOCOL_BAIDU_STD);
helei's avatar
helei committed
62 63 64 65 66 67 68
}

TEST(AdaptiveConnectionTypeTest, ShouldConvertCorrectly) {
    brpc::AdaptiveConnectionType act;

    act = brpc::ConnectionType::CONNECTION_TYPE_POOLED;
    EXPECT_EQ(act, brpc::ConnectionType::CONNECTION_TYPE_POOLED);
helei's avatar
helei committed
69
    EXPECT_NE(act, brpc::ConnectionType::CONNECTION_TYPE_SINGLE);
helei's avatar
helei committed
70 71 72

    act = kPooled;
    EXPECT_EQ(act, brpc::ConnectionType::CONNECTION_TYPE_POOLED);
helei's avatar
helei committed
73
    EXPECT_NE(act, brpc::ConnectionType::CONNECTION_TYPE_SINGLE);
helei's avatar
helei committed
74 75
}