]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/common/test_prioritized_queue.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / common / test_prioritized_queue.cc
index bfe5cb8bdfebc0b21467e2c1e11de85020f7195f..83bd41f8cbd37a1d8fc77e072559844a349f791f 100644 (file)
@@ -7,6 +7,7 @@
 #include <numeric>
 #include <vector>
 #include <algorithm>
+#include <random>
 
 using std::vector;
 
@@ -23,7 +24,9 @@ protected:
     for (int i = 0; i < item_size; i++) {
       items.push_back(Item(i));
     }
-    std::random_shuffle(items.begin(), items.end());
+    std::random_device rd;
+    std::default_random_engine rng(rd());
+    std::shuffle(items.begin(), items.end(), rng);
   }
   void TearDown() override {
     items.clear();
@@ -60,7 +63,8 @@ TEST_F(PrioritizedQueueTest, strict_pq) {
   // 0 .. item_size-1
   for (unsigned i = 0; i < item_size; i++) {
     unsigned priority = items[i];
-    pq.enqueue_strict(Klass(0), priority, items[i]);
+    const Item& item = items[i];
+    pq.enqueue_strict(Klass(0), priority, Item(item));
   }
   // item_size-1 .. 0
   for (unsigned i = item_size; i > 0; i--) {
@@ -88,7 +92,7 @@ TEST_F(PrioritizedQueueTest, lowest_among_eligible_otherwise_highest) {
     } else {
       num_high_cost++;
     }
-    pq.enqueue(Klass(0), priority, cost, item);
+    pq.enqueue(Klass(0), priority, cost, Item(item));
   }
   // the token in all buckets is 0 at the beginning, so dequeue() should pick
   // the first one with the highest priority.
@@ -140,7 +144,7 @@ TEST_F(PrioritizedQueueTest, fairness_by_class) {
     Klass k = ITEM_TO_CLASS(item);
     unsigned priority = 0;
     unsigned cost = 1;
-    pq.enqueue(k, priority, cost, item);
+    pq.enqueue(k, priority, cost, Item(item));
   }
   // just sample first 1/2 of the items
   // if i pick too small a dataset, the result won't be statisitcally
@@ -171,7 +175,7 @@ TEST_F(PrioritizedQueueTest, remove_by_class) {
   for (int i = 0; i < item_size; i++) {
     const Item& item = items[i];
     Klass k = ITEM_TO_CLASS(item);
-    pq.enqueue(k, 0, 0, item);
+    pq.enqueue(k, 0, 0, Item(item));
     if (k == class_to_remove) {
       num_to_remove++;
     }