17 #include <boost/thread.hpp>
18 #include <glog/logging.h>
19 #include <gtest/gtest.h>
28 using boost::thread_group;
30 using namespace impala;
38 ASSERT_EQ(2, c.
size());
39 ASSERT_FALSE(c.
Pop(99, &result));
42 ASSERT_FALSE(c.
Pop(0, &result));
51 ASSERT_EQ(3, c.
size());
53 ASSERT_EQ(3, c.
size());
54 ASSERT_FALSE(c.
Pop(0, &result));
55 ASSERT_TRUE(c.
Pop(1, &result));
57 ASSERT_FALSE(c.
Pop(1, &result));
58 ASSERT_EQ(2, c.
size());
64 for (
int i = 0; i < 1000; ++i) {
67 ASSERT_EQ(1000, c.
size());
68 for (
int i = 0; i < 1000; ++i) {
69 c.
Pop(rand() % 1000, &result);
70 c.
Put(rand() % 1000, i);
71 ASSERT_EQ(1000, c.
size());
80 for (
int i = 1; i <= 1000; ++i) {
85 ASSERT_EQ((n * (n + 1)) / 2,
del_sum);
93 for (
int i = start; i < end; ++i) {
95 if (shelf->
Pop(i, &val)) {
108 size_t count = 100000;
109 size_t thread_count = 10;
110 size_t part = count / thread_count;
111 for (
int i = 0; i < thread_count; ++i) {
112 group.add_thread(
new thread(
ParallelPut, 0, part, &c));
115 ASSERT_EQ(10, c.
size());
125 ASSERT_TRUE(c.
Pop(1, &result));
126 ASSERT_EQ(3, result);
129 ASSERT_EQ(3, c.
size());
130 ASSERT_TRUE(c.
Pop(1, &result));
131 ASSERT_EQ(4, result);
132 ASSERT_EQ(2, c.
size());
133 ASSERT_TRUE(c.
Pop(1, &result));
134 ASSERT_EQ(3, result);
135 ASSERT_EQ(1, c.
size());
136 ASSERT_TRUE(c.
Pop(1, &result));
137 ASSERT_EQ(2, result);
138 ASSERT_EQ(0, c.
size());
141 int main(
int argc,
char** argv) {
142 ::testing::InitGoogleTest(&argc, argv);
143 return RUN_ALL_TESTS();
int main(int argc, char **argv)
void Put(const Key &k, const Value &v)
size_t capacity() const
Returns the capacity of the cache.
bool Pop(const Key &k, Value *out)
void ParallelPut(const int start, const int end, FifoMultimap< int, int > *shelf)
size_t size()
Returns the total number of entries in the collection.
void TestCountDeleter(int *v)