proxygen
LoadShedConfigurationTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
17 
18 #include <gtest/gtest.h>
19 
20 using namespace wangle;
21 using namespace testing;
22 
23 TEST(LoadShedConfigurationTest, TestSettersAndGetters) {
25 
26  lsc.setMaxConnections(10);
27  EXPECT_EQ(10, lsc.getMaxConnections());
28 
31 
35 
39 
40  lsc.setMinFreeMem(30);
41  EXPECT_EQ(30, lsc.getMinFreeMem());
42 
43  lsc.setMaxMemUsage(0.1);
44  EXPECT_EQ(0.1, lsc.getMaxMemUsage());
45 
46  lsc.setMaxCpuUsage(0.2);
47  EXPECT_EQ(0.2, lsc.getMaxCpuUsage());
48 
49  lsc.setMinCpuIdle(0.03);
50  EXPECT_EQ(0.03, lsc.getMinCpuIdle());
51 
55 
56  lsc.setLoadUpdatePeriod(std::chrono::milliseconds(1200));
57  EXPECT_EQ(std::chrono::milliseconds(1200), lsc.getLoadUpdatePeriod());
58 
60  folly::SocketAddress("127.0.0.1", 1100),
61  folly::SocketAddress("127.0.0.2", 1200),
62  folly::SocketAddress("127.0.0.3", 1300),
63  };
64  lsc.setWhitelistAddrs(addressSet);
65 
66  EXPECT_EQ(addressSet, lsc.getWhitelistAddrs());
67  EXPECT_TRUE(lsc.isWhitelisted(folly::SocketAddress("127.0.0.1", 1100)));
68  EXPECT_TRUE(lsc.isWhitelisted(folly::SocketAddress("127.0.0.2", 1200)));
69  EXPECT_TRUE(lsc.isWhitelisted(folly::SocketAddress("127.0.0.3", 1300)));
70  EXPECT_FALSE(lsc.isWhitelisted(folly::SocketAddress("127.0.0.4", 1400)));
71  lsc.addWhitelistAddr(folly::StringPiece("127.0.0.4"));
72  EXPECT_TRUE(lsc.isWhitelisted(folly::SocketAddress("127.0.0.4", 0)));
73 
75  NetworkAddress(folly::SocketAddress("127.0.0.5", 1500), 28),
76  NetworkAddress(folly::SocketAddress("127.0.0.6", 1600), 24),
77  };
78  lsc.setWhitelistNetworks(networkSet);
79  EXPECT_EQ(networkSet, lsc.getWhitelistNetworks());
80  EXPECT_TRUE(lsc.isWhitelisted(folly::SocketAddress("127.0.0.5", 1500)));
81  EXPECT_TRUE(lsc.isWhitelisted(folly::SocketAddress("127.0.0.6", 1300)));
82  EXPECT_FALSE(lsc.isWhitelisted(folly::SocketAddress("10.0.0.7", 1700)));
83  lsc.addWhitelistAddr(folly::StringPiece("10.0.0.7/20"));
84  EXPECT_TRUE(lsc.isWhitelisted(folly::SocketAddress("10.0.0.7", 0)));
85 }
void setCpuUsageExceedWindowSize(const uint64_t size)
void setMaxConnections(uint64_t maxConns)
std::chrono::milliseconds getLoadUpdatePeriod() const
uint64_t getCpuUsageExceedWindowSize() const
TEST(Wangle, ClientServerTest)
void setWhitelistNetworks(const NetworkSet &networks)
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void setMaxActiveConnections(uint64_t maxActiveConns)
void setWhitelistAddrs(const AddressSet &addrs)
bool isWhitelisted(const folly::SocketAddress &addr) const
const NetworkSet & getWhitelistNetworks() const
std::set< folly::SocketAddress, AddressOnlyCompare > AddressSet
void setLoadUpdatePeriod(std::chrono::milliseconds period)
std::set< NetworkAddress > NetworkSet
const AddressSet & getWhitelistAddrs() const
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
uint64_t getAcceptPauseOnAcceptorQueueSize() const
void setAcceptPauseOnAcceptorQueueSize(const uint64_t acceptPauseOnAcceptorQueueSize)
void addWhitelistAddr(folly::StringPiece)
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
void setAcceptResumeOnAcceptorQueueSize(const uint64_t acceptResumeOnAcceptorQueueSize)
uint64_t getAcceptResumeOnAcceptorQueueSize() const