Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / old / testbucket.cc
1
2
3 #include "../crush/Bucket.h"
4 using namespace crush;
5
6 #include <iostream>
7 #include <vector>
8 using namespace std;
9
10
11 ostream& operator<<(ostream &out, const vector<int> &v)
12 {
13   out << "[";
14   for (int i=0; i<v.size(); i++) {
15     if (i) out << " ";
16     out << v[i];
17   }
18   out << "]";
19   return out;
20 }
21
22
23 int main() 
24 {
25   Hash h(73);
26
27   vector<int> disks;
28   for (int i=0; i<20; i++)
29     disks.push_back(i);
30
31
32   /*
33   UniformBucket ub(1, 1, 0, 10, disks);
34   ub.make_primes(h);
35   cout << "primes are " << ub.primes << endl;
36   */
37
38   MixedBucket mb(2, 1);
39   for (int i=0;i<20;i++)
40     mb.add_item(i, 10);
41
42   /*
43   MixedBucket b(3, 1);
44   b.add_item(1, ub.get_weight());
45   b.add_item(2, mb.get_weight());
46   */
47   MixedBucket b= mb;
48
49   vector<int> ocount(disks.size());
50   int numrep = 3;
51
52   vector<int> v(numrep);
53   for (int x=1; x<1000000; x++) {
54     //cout << H(x) << "\t" << h(x) << endl;
55     for (int i=0; i<numrep; i++) {
56       int d = b.choose_r(x, i, h);
57       v[i] = d;
58       ocount[d]++;
59     }
60     //cout << v << "\t" << endl;//ocount << endl;
61   }
62
63   for (int i=0; i<ocount.size(); i++) {
64     cout << "disk " << i << " has " << ocount[i] << endl;
65   }
66
67 }