#include "global/global_init.h"
#include <gtest/gtest.h>
-using namespace std::tr1;
-
class SharedLRUTest : public SharedLRU<unsigned int, int> {
public:
Mutex &get_lock() { return lock; }
unsigned int key = 1;
{
int value = 2;
- ASSERT_TRUE(cache.add(key, new int(value)));
- ASSERT_TRUE(cache.lookup(key));
+ ASSERT_TRUE(cache.add(key, new int(value)).get());
+ ASSERT_TRUE(cache.lookup(key).get());
ASSERT_EQ(value, *cache.lookup(key));
}
- ASSERT_TRUE(cache.lookup(key));
+ ASSERT_TRUE(cache.lookup(key).get());
}
TEST_F(SharedLRU_all, lookup_or_create) {
SharedLRUTest cache;
{
int value = 2;
unsigned int key = 1;
- ASSERT_TRUE(cache.add(key, new int(value)));
- ASSERT_TRUE(cache.lookup_or_create(key));
+ ASSERT_TRUE(cache.add(key, new int(value)).get());
+ ASSERT_TRUE(cache.lookup_or_create(key).get());
ASSERT_EQ(value, *cache.lookup(key));
}
{
unsigned int key = 2;
- ASSERT_TRUE(cache.lookup_or_create(key));
+ ASSERT_TRUE(cache.lookup_or_create(key).get());
ASSERT_EQ(0, *cache.lookup(key));
}
- ASSERT_TRUE(cache.lookup(1));
- ASSERT_TRUE(cache.lookup(2));
+ ASSERT_TRUE(cache.lookup(1).get());
+ ASSERT_TRUE(cache.lookup(2).get());
}
TEST_F(SharedLRU_all, wait_lookup) {
ASSERT_TRUE(wait_for(cache, 1));
EXPECT_EQ(value, *t.ptr);
// waiting on a key does not block lookups on other keys
- EXPECT_TRUE(cache.lookup_or_create(key + 12345));
+ EXPECT_TRUE(cache.lookup_or_create(key + 12345).get());
{
Mutex::Locker l(cache.get_lock());
cache.get_weak_refs().erase(key);
ASSERT_FALSE(cache.lower_bound(key));
int value = 2;
- ASSERT_TRUE(cache.add(key, new int(value)));
- ASSERT_TRUE(cache.lower_bound(key));
+ ASSERT_TRUE(cache.add(key, new int(value)).get());
+ ASSERT_TRUE(cache.lower_bound(key).get());
EXPECT_EQ(value, *cache.lower_bound(key));
}
}
unsigned int other_key = key + 1;
int other_value = value + 1;
- ASSERT_TRUE(cache.add(other_key, new int(other_value)));
+ ASSERT_TRUE(cache.add(other_key, new int(other_value)).get());
{
shared_ptr<int> ptr(new int);
ASSERT_TRUE(wait_for(cache, 1));
EXPECT_FALSE(t.ptr);
// waiting on a key does not block getting lower_bound on other keys
- EXPECT_TRUE(cache.lower_bound(other_key));
+ EXPECT_TRUE(cache.lower_bound(other_key).get());
{
Mutex::Locker l(cache.get_lock());
cache.get_weak_refs().erase(key);
}
ASSERT_TRUE(wait_for(cache, 0));
t.join();
- EXPECT_TRUE(t.ptr);
+ EXPECT_TRUE(t.ptr.get());
}
TEST_F(SharedLRU_all, get_next) {
ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
ASSERT_EQ(value, *cache.lookup(key));
}
- ASSERT_TRUE(cache.lookup(key));
+ ASSERT_TRUE(cache.lookup(key).get());
cache.clear(key);
ASSERT_FALSE(cache.lookup(key));
{
ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
}
- ASSERT_TRUE(cache.lookup(key));
+ ASSERT_TRUE(cache.lookup(key).get());
cache.clear(key);
ASSERT_FALSE(cache.lookup(key));
}
ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
ASSERT_EQ(value, *cache.lookup(key));
}
- ASSERT_TRUE(cache.lookup(key));
+ ASSERT_TRUE(cache.lookup(key).get());
cache.clear();
ASSERT_FALSE(cache.lookup(key));
ceph::shared_ptr<int> ptr2 = cache.add(key, new int(value));
- ASSERT_TRUE(cache.lookup(key));
+ ASSERT_TRUE(cache.lookup(key).get());
cache.clear();
- ASSERT_TRUE(cache.lookup(key));
+ ASSERT_TRUE(cache.lookup(key).get());
ASSERT_FALSE(cache.empty());
}
ASSERT_FALSE(existed);
}
- ASSERT_TRUE(cache.lookup(0));
+ ASSERT_TRUE(cache.lookup(0).get());
ASSERT_EQ(0, *cache.lookup(0));
ASSERT_FALSE(cache.lookup(SIZE-1));
ASSERT_FALSE(cache.lookup(SIZE));
- ASSERT_TRUE(cache.lookup(SIZE+1));
+ ASSERT_TRUE(cache.lookup(SIZE+1).get());
ASSERT_EQ((int)SIZE+1, *cache.lookup(SIZE+1));
cache.purge(0);
shared_ptr<int> ptr2 = cache.add(0, new int(0), &existed);
ASSERT_FALSE(ptr == ptr2);
ptr = shared_ptr<int>();
- ASSERT_TRUE(cache.lookup(0));
+ ASSERT_TRUE(cache.lookup(0).get());
}
int main(int argc, char **argv) {
#include "global/global_init.h"
#include <gtest/gtest.h>
-using namespace std::tr1;
-
class SharedPtrRegistryTest : public SharedPtrRegistry<unsigned int, int> {
public:
Mutex &get_lock() { return lock; }
ASSERT_TRUE(wait_for(registry, 1));
EXPECT_FALSE(t.ptr);
// waiting on a key does not block lookups on other keys
- EXPECT_TRUE(registry.lookup_or_create(key + 12345));
+ EXPECT_TRUE(registry.lookup_or_create(key + 12345).get());
registry.remove(key);
ASSERT_TRUE(wait_for(registry, 0));
t.join();
- EXPECT_TRUE(t.ptr);
+ EXPECT_TRUE(t.ptr.get());
}
{
unsigned int key = 2;
int other_value = value + 1;
unsigned int other_key = key + 1;
shared_ptr<int> ptr = registry.lookup_or_create<int>(other_key, other_value);
- EXPECT_TRUE(ptr);
+ EXPECT_TRUE(ptr.get());
EXPECT_EQ(other_value, *ptr);
}
registry.remove(key);
ASSERT_TRUE(wait_for(registry, 0));
t.join();
- EXPECT_TRUE(t.ptr);
+ EXPECT_TRUE(t.ptr.get());
EXPECT_EQ(value, *t.ptr);
}
}
{
shared_ptr<TellDie> a = registry.lookup_or_create(key);
EXPECT_EQ(NO, died);
- EXPECT_TRUE(a);
+ EXPECT_TRUE(a.get());
}
EXPECT_EQ(YES, died);
EXPECT_FALSE(registry.lookup(key));