proxygen
MapTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST (Map, basic)
 
 TEST (Map, executor)
 
 TEST (Map, semifuture)
 

Function Documentation

TEST ( Map  ,
basic   
)

Definition at line 22 of file MapTest.cpp.

References c, folly::collect(), EXPECT_EQ, EXPECT_TRUE, folly::Promise< T >::getFuture(), i, folly::futures::map(), and folly::Promise< T >::setValue().

22  {
23  Promise<int> p1;
24  Promise<int> p2;
25  Promise<int> p3;
26 
27  std::vector<Future<int>> fs;
28  fs.push_back(p1.getFuture());
29  fs.push_back(p2.getFuture());
30  fs.push_back(p3.getFuture());
31 
32  int c = 0;
33  std::vector<Future<Unit>> fs2 = futures::map(fs, [&](int i) { c += i; });
34 
35  // Ensure we call the callbacks as the futures complete regardless of order
36  p2.setValue(1);
37  EXPECT_EQ(1, c);
38  p3.setValue(1);
39  EXPECT_EQ(2, c);
40  p1.setValue(1);
41  EXPECT_EQ(3, c);
42 
43  EXPECT_TRUE(collect(fs2).isReady());
44 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static auto collect
Definition: StringTest.cpp:37
static Map map(mapCap)
Future< T > getFuture()
Definition: Promise-inl.h:97
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
char c
TEST ( Map  ,
executor   
)

Definition at line 46 of file MapTest.cpp.

References c, folly::collect(), EXPECT_EQ, EXPECT_TRUE, folly::Promise< T >::getFuture(), i, folly::futures::map(), and folly::Promise< T >::setValue().

46  {
47  Promise<int> p1;
48  Promise<int> p2;
49  Promise<int> p3;
51 
52  std::vector<Future<int>> fs;
53  fs.push_back(p1.getFuture());
54  fs.push_back(p2.getFuture());
55  fs.push_back(p3.getFuture());
56 
57  int c = 0;
58  std::vector<Future<Unit>> fs2 =
59  futures::map(exec, fs, [&](int i) { c += i; });
60 
61  // Ensure we call the callbacks as the futures complete regardless of order
62  p2.setValue(1);
63  EXPECT_EQ(1, c);
64  p3.setValue(1);
65  EXPECT_EQ(2, c);
66  p1.setValue(1);
67  EXPECT_EQ(3, c);
68 
69  EXPECT_TRUE(collect(fs2).isReady());
70 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static auto collect
Definition: StringTest.cpp:37
static Map map(mapCap)
Future< T > getFuture()
Definition: Promise-inl.h:97
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
char c
TEST ( Map  ,
semifuture   
)

Definition at line 72 of file MapTest.cpp.

References c, folly::collect(), EXPECT_EQ, EXPECT_TRUE, folly::Promise< T >::getSemiFuture(), i, folly::futures::map(), and folly::Promise< T >::setValue().

72  {
73  Promise<int> p1;
74  Promise<int> p2;
75  Promise<int> p3;
77 
78  std::vector<SemiFuture<int>> fs;
79  fs.push_back(p1.getSemiFuture());
80  fs.push_back(p2.getSemiFuture());
81  fs.push_back(p3.getSemiFuture());
82 
83  int c = 0;
84  std::vector<Future<Unit>> fs2 =
85  futures::map(exec, fs, [&](int i) { c += i; });
86 
87  // Ensure we call the callbacks as the futures complete regardless of order
88  p2.setValue(1);
89  EXPECT_EQ(1, c);
90  p3.setValue(1);
91  EXPECT_EQ(2, c);
92  p1.setValue(1);
93  EXPECT_EQ(3, c);
94 
95  EXPECT_TRUE(collect(fs2).isReady());
96 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static auto collect
Definition: StringTest.cpp:37
static Map map(mapCap)
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
std::enable_if< std::is_same< Unit, B >::value, void >::type setValue()
Definition: Promise.h:326
SemiFuture< T > getSemiFuture()
Definition: Promise-inl.h:88
char c