]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/common/test_shared_cache.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / common / test_shared_cache.cc
index 7b7602ffe08ba4dec359de6102b22a36824675a7..eeb526236c9b824eb2c67b62a3352ef1fd72ba7f 100644 (file)
@@ -28,9 +28,9 @@
 
 class SharedLRUTest : public SharedLRU<unsigned int, int> {
 public:
-  Mutex &get_lock() { return lock; }
-  Cond &get_cond() { return cond; }
-  map<unsigned int, pair< ceph::weak_ptr<int>, int* > > &get_weak_refs() {
+  auto& get_lock() { return lock; }
+  auto& get_cond() { return cond; }
+  map<unsigned int, pair< std::weak_ptr<int>, int* > > &get_weak_refs() {
     return weak_refs;
   }
 };
@@ -43,7 +43,7 @@ public:
     SharedLRUTest &cache;
     unsigned int key;
     int value;
-    ceph::shared_ptr<int> ptr;
+    std::shared_ptr<int> ptr;
     enum in_method_t { LOOKUP, LOWER_BOUND } in_method;
 
     Thread_wait(SharedLRUTest& _cache, unsigned int _key, 
@@ -59,7 +59,7 @@ public:
         ptr = cache.lower_bound(key);
         break;
       case LOOKUP:
-        ptr = ceph::shared_ptr<int>(new int);
+        ptr = std::shared_ptr<int>(new int);
         *ptr = value;
         ptr = cache.lookup(key);
         break;
@@ -82,7 +82,7 @@ public:
       if (delay > 0)
         usleep(delay);
       {
-        Mutex::Locker l(cache.get_lock());
+        std::lock_guard l{cache.get_lock()};
         if (cache.waiting == waitting) {
           break;
         }
@@ -103,15 +103,17 @@ TEST_F(SharedLRU_all, add) {
   int value1 = 2;
   bool existed = false;
   {
-    ceph::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
+    std::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
     ASSERT_EQ(value1, *ptr);
     ASSERT_FALSE(existed);
   }
   {
     int value2 = 3;
-    ceph::shared_ptr<int> ptr = cache.add(key, new int(value2), &existed);
+    auto p = new int(value2);
+    std::shared_ptr<int> ptr = cache.add(key, p, &existed);
     ASSERT_EQ(value1, *ptr);
     ASSERT_TRUE(existed);
+    delete p;
   }
 }
 TEST_F(SharedLRU_all, empty) {
@@ -122,7 +124,7 @@ TEST_F(SharedLRU_all, empty) {
   ASSERT_TRUE(cache.empty());
   {
     int value1 = 2;
-    ceph::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
+    std::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
     ASSERT_EQ(value1, *ptr);
     ASSERT_FALSE(existed);
   }
@@ -167,7 +169,7 @@ TEST_F(SharedLRU_all, wait_lookup) {
   int value = 2;
 
   {
-    ceph::shared_ptr<int> ptr(new int);
+    std::shared_ptr<int> ptr(new int);
     cache.get_weak_refs()[key] = make_pair(ptr, &*ptr);
   }
   EXPECT_FALSE(cache.get_weak_refs()[key].first.lock());
@@ -179,9 +181,9 @@ TEST_F(SharedLRU_all, wait_lookup) {
   // waiting on a key does not block lookups on other keys
   EXPECT_FALSE(cache.lookup(key + 12345));
   {
-    Mutex::Locker l(cache.get_lock());
+    std::lock_guard l{cache.get_lock()};
     cache.get_weak_refs().erase(key);
-    cache.get_cond().Signal();
+    cache.get_cond().notify_one();
   }
   ASSERT_TRUE(wait_for(cache, 0));
   t.join();
@@ -193,7 +195,7 @@ TEST_F(SharedLRU_all, wait_lookup_or_create) {
   int value = 2;
 
   {
-    ceph::shared_ptr<int> ptr(new int);
+    std::shared_ptr<int> ptr(new int);
     cache.get_weak_refs()[key] = make_pair(ptr, &*ptr);
   }
   EXPECT_FALSE(cache.get_weak_refs()[key].first.lock());
@@ -205,9 +207,9 @@ TEST_F(SharedLRU_all, wait_lookup_or_create) {
   // waiting on a key does not block lookups on other keys
   EXPECT_TRUE(cache.lookup_or_create(key + 12345).get());
   {
-    Mutex::Locker l(cache.get_lock());
+    std::lock_guard l{cache.get_lock()};
     cache.get_weak_refs().erase(key);
-    cache.get_cond().Signal();
+    cache.get_cond().notify_one();
   }
   ASSERT_TRUE(wait_for(cache, 0));
   t.join();
@@ -238,7 +240,7 @@ TEST_F(SharedLRU_all, wait_lower_bound) {
   ASSERT_TRUE(cache.add(other_key, new int(other_value)).get());
 
   {
-    ceph::shared_ptr<int> ptr(new int);
+    std::shared_ptr<int> ptr(new int);
     cache.get_weak_refs()[key] = make_pair(ptr, &*ptr);
   }
   EXPECT_FALSE(cache.get_weak_refs()[key].first.lock());
@@ -250,9 +252,9 @@ TEST_F(SharedLRU_all, wait_lower_bound) {
   // waiting on a key does not block getting lower_bound on other keys
   EXPECT_TRUE(cache.lower_bound(other_key).get());
   {
-    Mutex::Locker l(cache.get_lock());
+    std::lock_guard l{cache.get_lock()};
     cache.get_weak_refs().erase(key);
-    cache.get_cond().Signal();
+    cache.get_cond().notify_one();
   }
   ASSERT_TRUE(wait_for(cache, 0));
   t.join();
@@ -270,15 +272,15 @@ TEST_F(SharedLRU_all, get_next) {
     SharedLRUTest cache;
 
     const unsigned int key2 = 333;
-    ceph::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
+    std::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
     const int value2 = *ptr2 = 400;
 
     // entries with expired pointers are silently ignored
     const unsigned int key_gone = 222;
-    cache.get_weak_refs()[key_gone] = make_pair(ceph::shared_ptr<int>(), (int*)0);
+    cache.get_weak_refs()[key_gone] = make_pair(std::shared_ptr<int>(), (int*)0);
 
     const unsigned int key1 = 111;
-    ceph::shared_ptr<int> ptr1 = cache.lookup_or_create(key1);
+    std::shared_ptr<int> ptr1 = cache.lookup_or_create(key1);
     const int value1 = *ptr1 = 800;
 
     pair<unsigned int, int> i;
@@ -297,11 +299,11 @@ TEST_F(SharedLRU_all, get_next) {
   {
     SharedLRUTest cache;
     const unsigned int key1 = 111;
-    ceph::shared_ptr<int> *ptr1 = new shared_ptr<int>(cache.lookup_or_create(key1));
+    std::shared_ptr<int> *ptr1 = new shared_ptr<int>(cache.lookup_or_create(key1));
     const unsigned int key2 = 222;
-    ceph::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
+    std::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
 
-    pair<unsigned int, ceph::shared_ptr<int> > i;
+    pair<unsigned int, std::shared_ptr<int> > i;
     EXPECT_TRUE(cache.get_next(i.first, &i));
     EXPECT_EQ(key1, i.first);
     delete ptr1;
@@ -315,7 +317,7 @@ TEST_F(SharedLRU_all, clear) {
   unsigned int key = 1;
   int value = 2;
   {
-    ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+    std::shared_ptr<int> ptr = cache.add(key, new int(value));
     ASSERT_EQ(value, *cache.lookup(key));
   }
   ASSERT_TRUE(cache.lookup(key).get());
@@ -323,7 +325,7 @@ TEST_F(SharedLRU_all, clear) {
   ASSERT_FALSE(cache.lookup(key));
 
   {
-    ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+    std::shared_ptr<int> ptr = cache.add(key, new int(value));
   }
   ASSERT_TRUE(cache.lookup(key).get());
   cache.clear(key);
@@ -334,14 +336,14 @@ TEST_F(SharedLRU_all, clear_all) {
   unsigned int key = 1;
   int value = 2;
   {
-    ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+    std::shared_ptr<int> ptr = cache.add(key, new int(value));
     ASSERT_EQ(value, *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));
+  std::shared_ptr<int> ptr2 = cache.add(key, new int(value));
   ASSERT_TRUE(cache.lookup(key).get());
   cache.clear();
   ASSERT_TRUE(cache.lookup(key).get());
@@ -352,7 +354,7 @@ TEST(SharedCache_all, add) {
   SharedLRU<int, int> cache;
   unsigned int key = 1;
   int value = 2;
-  ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+  std::shared_ptr<int> ptr = cache.add(key, new int(value));
   ASSERT_EQ(ptr, cache.lookup(key));
   ASSERT_EQ(value, *cache.lookup(key));
 }
@@ -362,11 +364,11 @@ TEST(SharedCache_all, lru) {
   SharedLRU<int, int> cache(NULL, SIZE);
 
   bool existed = false;
-  ceph::shared_ptr<int> ptr = cache.add(0, new int(0), &existed);
+  std::shared_ptr<int> ptr = cache.add(0, new int(0), &existed);
   ASSERT_FALSE(existed);
   {
     int *tmpint = new int(0);
-    ceph::shared_ptr<int> ptr2 = cache.add(0, tmpint, &existed);
+    std::shared_ptr<int> ptr2 = cache.add(0, tmpint, &existed);
     ASSERT_TRUE(existed);
     delete tmpint;
   }
@@ -385,9 +387,9 @@ TEST(SharedCache_all, lru) {
 
   cache.purge(0);
   ASSERT_FALSE(cache.lookup(0));
-  ceph::shared_ptr<int> ptr2 = cache.add(0, new int(0), &existed);
+  std::shared_ptr<int> ptr2 = cache.add(0, new int(0), &existed);
   ASSERT_FALSE(ptr == ptr2);
-  ptr = ceph::shared_ptr<int>();
+  ptr = std::shared_ptr<int>();
   ASSERT_TRUE(cache.lookup(0).get());
 }