proxygen
LoadShedConfigurationTest.cpp File Reference
#include <wangle/acceptor/LoadShedConfiguration.h>
#include <gtest/gtest.h>

Go to the source code of this file.

Functions

 TEST (LoadShedConfigurationTest, TestSettersAndGetters)
 

Function Documentation

TEST ( LoadShedConfigurationTest  ,
TestSettersAndGetters   
)

Definition at line 23 of file LoadShedConfigurationTest.cpp.

References wangle::LoadShedConfiguration::addWhitelistAddr(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, wangle::LoadShedConfiguration::getAcceptPauseOnAcceptorQueueSize(), wangle::LoadShedConfiguration::getAcceptResumeOnAcceptorQueueSize(), wangle::LoadShedConfiguration::getCpuUsageExceedWindowSize(), wangle::LoadShedConfiguration::getLoadUpdatePeriod(), wangle::LoadShedConfiguration::getMaxActiveConnections(), wangle::LoadShedConfiguration::getMaxConnections(), wangle::LoadShedConfiguration::getMaxCpuUsage(), wangle::LoadShedConfiguration::getMaxMemUsage(), wangle::LoadShedConfiguration::getMinCpuIdle(), wangle::LoadShedConfiguration::getMinFreeMem(), wangle::LoadShedConfiguration::getWhitelistAddrs(), wangle::LoadShedConfiguration::getWhitelistNetworks(), wangle::LoadShedConfiguration::isWhitelisted(), wangle::LoadShedConfiguration::setAcceptPauseOnAcceptorQueueSize(), wangle::LoadShedConfiguration::setAcceptResumeOnAcceptorQueueSize(), wangle::LoadShedConfiguration::setCpuUsageExceedWindowSize(), wangle::LoadShedConfiguration::setLoadUpdatePeriod(), wangle::LoadShedConfiguration::setMaxActiveConnections(), wangle::LoadShedConfiguration::setMaxConnections(), wangle::LoadShedConfiguration::setMaxCpuUsage(), wangle::LoadShedConfiguration::setMaxMemUsage(), wangle::LoadShedConfiguration::setMinCpuIdle(), wangle::LoadShedConfiguration::setMinFreeMem(), wangle::LoadShedConfiguration::setWhitelistAddrs(), and wangle::LoadShedConfiguration::setWhitelistNetworks().

23  {
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
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