summaryrefslogtreecommitdiffstats
path: root/src/test/system/rados_watch_notify.cc
blob: e69e932eccec551e3673ba17978e0b573cb60ad0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2011 New Dream Network
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation.  See file COPYING.
*
*/

#include "cross_process_sem.h"
#include "include/rados/librados.h"
#include "st_rados_create_pool.h"
#include "st_rados_delete_pool.h"
#include "st_rados_delete_objs.h"
#include "st_rados_watch.h"
#include "st_rados_notify.h"
#include "systest_runnable.h"
#include "systest_settings.h"
#include "include/stringify.h"

#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <sstream>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#include <sys/types.h>
#include <unistd.h>

using std::ostringstream;
using std::string;
using std::vector;

/*
 * rados_watch_notify
 *
 * This tests watch/notify with pool and object deletion.
 *
 * EXPECT:            * notifies to a deleted object or pool are not received
 *                    * notifies to existing objects are received
 *
 * DO NOT EXPECT      * hangs, crashes
 */

const char *get_id_str()
{
  return "main";
}

int main(int argc, const char **argv)
{
  std::string pool = "foo." + stringify(getpid());
  CrossProcessSem *setup_sem = NULL;
  RETURN1_IF_NONZERO(CrossProcessSem::create(0, &setup_sem));
  CrossProcessSem *watch_sem = NULL;
  RETURN1_IF_NONZERO(CrossProcessSem::create(0, &watch_sem));
  CrossProcessSem *notify_sem = NULL;
  RETURN1_IF_NONZERO(CrossProcessSem::create(0, &notify_sem));

  // create a pool and an object, watch the object, notify.
  {
    StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 1, ".obj");
    StRadosWatch r2(argc, argv, setup_sem, watch_sem, notify_sem,
		    1, 0, pool, "0.obj");
    StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
		     0, pool, "0.obj");
    StRadosDeletePool r4(argc, argv, notify_sem, NULL, pool);
    vector<SysTestRunnable*> vec;
    vec.push_back(&r1);
    vec.push_back(&r2);
    vec.push_back(&r3);
    vec.push_back(&r4);
    std::string error = SysTestRunnable::run_until_finished(vec);
    if (!error.empty()) {
      printf("test1: got error: %s\n", error.c_str());
      return EXIT_FAILURE;
    }
  }

  RETURN1_IF_NONZERO(setup_sem->reinit(0));
  RETURN1_IF_NONZERO(watch_sem->reinit(0));
  RETURN1_IF_NONZERO(notify_sem->reinit(0));

  // create a pool and an object, watch a non-existent object,
  // notify non-existent object.watch
  pool += ".";
  {
    StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 0, ".obj");
    StRadosWatch r2(argc, argv, setup_sem, watch_sem, notify_sem,
		    0, -ENOENT, pool, "0.obj");
    StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
		     -ENOENT, pool, "0.obj");
    StRadosDeletePool r4(argc, argv, notify_sem, NULL, pool);
    vector<SysTestRunnable*> vec;
    vec.push_back(&r1);
    vec.push_back(&r2);
    vec.push_back(&r3);
    vec.push_back(&r4);
    std::string error = SysTestRunnable::run_until_finished(vec);
    if (!error.empty()) {
      printf("test2: got error: %s\n", error.c_str());
      return EXIT_FAILURE;
    }
  }

  RETURN1_IF_NONZERO(setup_sem->reinit(0));
  RETURN1_IF_NONZERO(watch_sem->reinit(0));
  RETURN1_IF_NONZERO(notify_sem->reinit(0));

  CrossProcessSem *finished_notifies_sem = NULL;
  RETURN1_IF_NONZERO(CrossProcessSem::create(0, &finished_notifies_sem));
  CrossProcessSem *deleted_sem = NULL;
  RETURN1_IF_NONZERO(CrossProcessSem::create(0, &deleted_sem));
  CrossProcessSem *second_pool_sem = NULL;
  RETURN1_IF_NONZERO(CrossProcessSem::create(0, &second_pool_sem));

  // create a pool and an object, watch the object, notify,
  // then delete the pool.
  // Create a new pool and write to it to make the osd get the updated map,
  // then try notifying on the deleted pool.
  pool += ".";
  {
    StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 1, ".obj");
    StRadosWatch r2(argc, argv, setup_sem, watch_sem, finished_notifies_sem,
		    1, 0, pool, "0.obj");
    StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
		     0, pool, "0.obj");
    StRadosDeletePool r4(argc, argv, notify_sem, deleted_sem, pool);
    StRadosCreatePool r5(argc, argv, deleted_sem, second_pool_sem, NULL,
			 "bar", 1, ".obj");
    StRadosNotify r6(argc, argv, second_pool_sem, NULL, finished_notifies_sem,
		     0, "bar", "0.obj");
    StRadosDeletePool r7(argc, argv, finished_notifies_sem, NULL, "bar");
    vector<SysTestRunnable*> vec;
    vec.push_back(&r1);
    vec.push_back(&r2);
    vec.push_back(&r3);
    vec.push_back(&r4);
    vec.push_back(&r5);
    vec.push_back(&r6);
    vec.push_back(&r7);
    std::string error = SysTestRunnable::run_until_finished(vec);
    if (!error.empty()) {
      printf("test3: got error: %s\n", error.c_str());
      return EXIT_FAILURE;
    }
  }

  RETURN1_IF_NONZERO(setup_sem->reinit(0));
  RETURN1_IF_NONZERO(watch_sem->reinit(0));
  RETURN1_IF_NONZERO(notify_sem->reinit(0));
  RETURN1_IF_NONZERO(finished_notifies_sem->reinit(0));
  RETURN1_IF_NONZERO(deleted_sem->reinit(0));

  // create a pool and an object, watch the object, notify,
  // then delete the object, notify
  // this test is enabled for the resolution of bug #2339.
  pool += ".";
  {
    StRadosCreatePool r1(argc, argv, NULL, setup_sem, NULL, pool, 1, ".obj");
    StRadosWatch r2(argc, argv, setup_sem, watch_sem, finished_notifies_sem,
		    1, 0, pool, "0.obj");
    StRadosNotify r3(argc, argv, setup_sem, watch_sem, notify_sem,
		     0, pool, "0.obj");
    StRadosDeleteObjs r4(argc, argv, notify_sem, deleted_sem, 1, pool, ".obj");
    StRadosNotify r5(argc, argv, setup_sem, deleted_sem, finished_notifies_sem,
		     -ENOENT, pool, "0.obj");
    StRadosDeletePool r6(argc, argv, finished_notifies_sem, NULL, pool);

    vector<SysTestRunnable*> vec;
    vec.push_back(&r1);
    vec.push_back(&r2);
    vec.push_back(&r3);
    vec.push_back(&r4);
    vec.push_back(&r5);
    vec.push_back(&r6);
    std::string error = SysTestRunnable::run_until_finished(vec);
    if (!error.empty()) {
      printf("test4: got error: %s\n", error.c_str());
      return EXIT_FAILURE;
    }
  }

  printf("******* SUCCESS **********\n");
  return EXIT_SUCCESS;
}