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

« back to all changes in this revision

Viewing changes to src/test/test_stress_watch.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
1
#include "include/rados/librados.h"
2
2
#include "include/rados/librados.hpp"
 
3
#include "include/atomic.h"
 
4
#include "include/utime.h"
 
5
#include "common/Thread.h"
 
6
#include "common/Clock.h"
3
7
#include "test/rados-api/test.h"
4
8
 
5
9
#include "gtest/gtest.h"
10
14
#include <iostream>
11
15
#include <string>
12
16
 
 
17
 
13
18
using namespace librados;
14
19
using ceph::buffer;
15
20
using std::map;
17
22
using std::string;
18
23
 
19
24
static sem_t sem;
 
25
static atomic_t stop_flag;
20
26
 
21
27
class WatchNotifyTestCtx : public WatchCtx
22
28
{
27
33
    }
28
34
};
29
35
 
 
36
struct WatcherUnwatcher : public Thread {
 
37
  string pool;
 
38
  WatcherUnwatcher(string& _pool) : pool(_pool) {}
 
39
 
 
40
  void *entry() {
 
41
    while (!stop_flag.read()) {
 
42
      Rados cluster;
 
43
      IoCtx ioctx;
 
44
      connect_cluster_pp(cluster);
 
45
      cluster.ioctx_create(pool.c_str(), ioctx);
 
46
 
 
47
      uint64_t handle;
 
48
      WatchNotifyTestCtx watch_ctx;
 
49
      ioctx.watch("foo", 0, &handle, &watch_ctx);
 
50
      bufferlist bl;
 
51
      ioctx.unwatch("foo", handle);
 
52
      ioctx.close();
 
53
    }
 
54
    return NULL;
 
55
  }
 
56
};
30
57
TEST(WatchStress, Stress1) {
31
58
  ASSERT_EQ(0, sem_init(&sem, 0, 0));
32
59
  Rados cluster;
35
62
  IoCtx ioctx;
36
63
  cluster.ioctx_create(pool_name.c_str(), ioctx);
37
64
  WatchNotifyTestCtx ctx;
38
 
  
 
65
 
 
66
  WatcherUnwatcher *thr = new WatcherUnwatcher(pool_name);
 
67
  thr->create();
39
68
  ASSERT_EQ(0, ioctx.create("foo", false));
40
69
 
41
70
  for (int i = 0; i < 10000; ++i) {
44
73
    WatchNotifyTestCtx ctx;
45
74
    ASSERT_EQ(0, ioctx.watch("foo", 0, &handle, &ctx));
46
75
    bufferlist bl2;
 
76
    utime_t timestamp = ceph_clock_now(NULL);
47
77
    ASSERT_EQ(0, ioctx.notify("foo", 0, bl2));
 
78
    timestamp = ceph_clock_now(NULL) - timestamp;
 
79
    ASSERT_LT(timestamp.sec(), 5);
48
80
    TestAlarm alarm;
49
81
    sem_wait(&sem);
50
82
    ioctx.unwatch("foo", handle);
51
83
  }
52
 
 
 
84
  stop_flag.set(1);
 
85
  thr->join();
53
86
  ioctx.close();
54
87
  ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster));
55
88
  sem_destroy(&sem);