~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/test/old/testnewbuffers.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <list>
 
3
#include <iostream>
 
4
using namespace std;
 
5
 
 
6
 
 
7
#include "include/newbuffer.h"
 
8
//#include "include/bufferlist.h"
 
9
 
 
10
#include "common/Thread.h"
 
11
 
 
12
 
 
13
  class Th : public Thread {
 
14
  public:
 
15
        bufferlist bl;
 
16
        Th(bufferlist& o) : bl(o) { }
 
17
        
 
18
        void *entry() {
 
19
          //cout << "start" << endl;
 
20
          // thrash it a bit.
 
21
          for (int n=0; n<10000; n++) {
 
22
                bufferlist bl2;
 
23
                unsigned off = rand() % (bl.length() -1);
 
24
                unsigned len = 1 + rand() % (bl.length() - off - 1);
 
25
                bl2.substr_of(bl, off, len);
 
26
                bufferlist bl3;
 
27
                bl3.append(bl);
 
28
                bl3.append(bl2);
 
29
                //cout << bl3 << endl;
 
30
                bl2.clear();
 
31
                bl3.clear();
 
32
          }
 
33
          //cout << "end" << endl;
 
34
        }
 
35
  };
 
36
 
 
37
int main()
 
38
{
 
39
 
 
40
  bufferptr p1 = buffer::copy("123456",7);
 
41
  //bufferptr p1 = new buffer("123456",7);
 
42
  bufferptr p2 = p1;
 
43
 
 
44
  cout << "p1 is '" << p1.c_str() << "'" << " " << p1 << endl;
 
45
  cout << "p2 is '" << p2.c_str() << "'" << " " << p2 << endl;
 
46
 
 
47
  bufferptr p3 = buffer::copy("abcdef",7);
 
48
  //bufferptr p3 = new buffer("abcdef",7);
 
49
  
 
50
  cout << "p3 is " << p3.c_str() << " " << p3 << endl;
 
51
 
 
52
  bufferlist bl;
 
53
  bl.push_back(p2);
 
54
  bl.push_back(p1);
 
55
  bl.push_back(p3);
 
56
 
 
57
  cout << "bl is " << bl << endl;
 
58
 
 
59
  bufferlist took;
 
60
  bl.splice(10,4,&took);
 
61
 
 
62
  cout << "took out " << took << ", leftover is " << bl << endl;
 
63
  //cout << "len is " << bl.length() << endl;
 
64
 
 
65
  bufferlist bl2;
 
66
  bl2.substr_of(bl, 3, 5);
 
67
  cout << "bl2 is " << bl2 << endl;
 
68
 
 
69
 
 
70
  cout << "bl before " << bl << endl;
 
71
 
 
72
  list<Th*> ls;
 
73
  for (int t=0; t<40; t++) {
 
74
        Th *t = new Th(bl);
 
75
        cout << "create" << endl;
 
76
        t->create();
 
77
        ls.push_back(t);
 
78
  }
 
79
 
 
80
  bl.clear();
 
81
 
 
82
  while (!ls.empty()) {
 
83
        cout << "join" << endl;
 
84
        ls.front()->join();
 
85
        delete ls.front();
 
86
        ls.pop_front();
 
87
  }
 
88
 
 
89
  cout << "bl after " << bl << endl;
 
90
 
 
91
}