proxygen
WindowTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
12 
13 using namespace proxygen;
14 
15 TEST(WindowTest, Basic) {
16  Window w(100);
17  ASSERT_TRUE(w.free(10));
18  ASSERT_EQ(w.getSize(), 110);
19  ASSERT_EQ(w.getCapacity(), 100);
20  ASSERT_TRUE(w.reserve(20));
21  ASSERT_EQ(w.getSize(), 90);
22  ASSERT_TRUE(w.reserve(90));
23  ASSERT_EQ(w.getSize(), 0);
24  ASSERT_TRUE(w.free(5));
25  ASSERT_EQ(w.getSize(), 5);
26  ASSERT_TRUE(w.free(0));
27  ASSERT_EQ(w.getSize(), 5);
28 }
29 
30 TEST(WindowTest, ChangeCapacity) {
31  Window w(100);
32  ASSERT_TRUE(w.setCapacity(10));
33  ASSERT_EQ(w.getSize(), 10);
34  ASSERT_EQ(w.getCapacity(), 10);
35  ASSERT_TRUE(w.reserve(7));
37  ASSERT_EQ(w.getCapacity(), 5);
38  ASSERT_EQ(w.getSize(), -2);
39  ASSERT_TRUE(w.free(1));
40  ASSERT_EQ(w.getSize(), -1);
42  ASSERT_EQ(w.getSize(), 0);
43  ASSERT_EQ(w.getCapacity(), 6);
45  ASSERT_EQ(w.getSize(), 1);
46  ASSERT_EQ(w.getCapacity(), 7);
47  ASSERT_EQ(w.getOutstanding(), 6);
48 }
49 
50 TEST(WindowTest, ExceedWindow) {
51  Window w(100);
52  ASSERT_TRUE(w.reserve(50));
53  ASSERT_TRUE(w.reserve(40));
54  ASSERT_EQ(w.getSize(), 10);
55  ASSERT_FALSE(w.reserve(20));
56 }
57 
58 TEST(WindowTest, Overflow) {
59  Window w(0);
61 }
62 
63 TEST(WindowTest, Underflow) {
64  Window w(100);
65  ASSERT_TRUE(w.free(100)); // You can manually bump up the window
66  ASSERT_TRUE(w.free(100)); // You can manually bump up the window
67  ASSERT_EQ(w.getSize(), 300);
69 }
70 
71 TEST(WindowTest, HugeReserve) {
72  Window w(100);
74 }
75 
76 TEST(WindowTest, HugeFree) {
77  Window w1(0);
79  Window w2(1);
81 }
82 
83 TEST(WindowTest, HugeFree2) {
84  for (unsigned i = 0; i < 10; ++i) {
85  Window w(i);
87  ASSERT_FALSE(w.free(1));
88  }
89 }
90 
91 TEST(WindowTest, BytesOutstanding) {
92  Window w(100);
93  ASSERT_EQ(w.getOutstanding(), 0);
94  ASSERT_TRUE(w.reserve(20));
95  ASSERT_EQ(w.getOutstanding(), 20);
96  ASSERT_TRUE(w.free(30));
97  // outstanding bytes is -10, but the API clamps this to 0
98  ASSERT_EQ(w.getOutstanding(), 0);
99 }
100 
101 TEST(WindowTest, BytesOutstandingAfterFail) {
102  Window w(100);
103  ASSERT_EQ(w.getOutstanding(), 0);
104  ASSERT_FALSE(w.reserve(110));
105  ASSERT_EQ(w.getOutstanding(), 0);
106 }
107 
108 TEST(WindowTest, NonStrict) {
109  Window w(100);
110  ASSERT_TRUE(w.reserve(110, false));
111  ASSERT_EQ(w.getOutstanding(), 110);
112  ASSERT_EQ(w.getSize(), -10);
113 }
114 
115 TEST(WindowTest, NewCapacityOverflow) {
116  Window w(0);
117  ASSERT_TRUE(w.free(10));
118  ASSERT_EQ(w.getOutstanding(), 0);
119  ASSERT_EQ(w.getSize(), 10);
123 }
uint32_t getCapacity() const
Definition: Window.cpp:32
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
LogLevel max
Definition: LogLevel.cpp:31
uint32_t getOutstanding() const
Definition: Window.cpp:37
int32_t getSize() const
Definition: Window.cpp:23
bool reserve(uint32_t amount, bool strict=true)
Definition: Window.cpp:41
bool setCapacity(uint32_t capacity)
Definition: Window.cpp:84
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
bool free(uint32_t amount)
Definition: Window.cpp:63
TEST(Window, basic)
Definition: WindowTest.cpp:31
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865