using namespace librados;
-typedef RadosTest LibRadosWatchNotify;
-typedef RadosTestParamPP LibRadosWatchNotifyPP;
typedef RadosTestEC LibRadosWatchNotifyEC;
typedef RadosTestECPP LibRadosWatchNotifyECPP;
}
};
-// notify 2
-bufferlist notify_bl;
-std::set<uint64_t> notify_cookies;
-rados_ioctx_t notify_io;
-const char *notify_oid = 0;
-int notify_err = 0;
+class LibRadosWatchNotify : public RadosTest
+{
+protected:
+ // notify 2
+ bufferlist notify_bl;
+ std::set<uint64_t> notify_cookies;
+ rados_ioctx_t notify_io;
+ const char *notify_oid = nullptr;
+ int notify_err = 0;
+
+ static void watch_notify2_test_cb(void *arg,
+ uint64_t notify_id,
+ uint64_t cookie,
+ uint64_t notifier_gid,
+ void *data,
+ size_t data_len);
+ static void watch_notify2_test_errcb(void *arg, uint64_t cookie, int err);
+};
+
-static void watch_notify2_test_cb(void *arg,
+void LibRadosWatchNotify::watch_notify2_test_cb(void *arg,
uint64_t notify_id,
uint64_t cookie,
uint64_t notifier_gid,
std::cout << __func__ << " from " << notifier_gid << " notify_id " << notify_id
<< " cookie " << cookie << std::endl;
assert(notifier_gid > 0);
- notify_cookies.insert(cookie);
- notify_bl.clear();
- notify_bl.append((char*)data, data_len);
+ auto thiz = reinterpret_cast<LibRadosWatchNotify*>(arg);
+ assert(thiz);
+ thiz->notify_cookies.insert(cookie);
+ thiz->notify_bl.clear();
+ thiz->notify_bl.append((char*)data, data_len);
if (notify_sleep)
sleep(notify_sleep);
- rados_notify_ack(notify_io, notify_oid, notify_id, cookie, "reply", 5);
+ rados_notify_ack(thiz->notify_io, thiz->notify_oid, notify_id, cookie,
+ "reply", 5);
}
-static void watch_notify2_test_errcb(void *arg, uint64_t cookie, int err)
+void LibRadosWatchNotify::watch_notify2_test_errcb(void *arg,
+ uint64_t cookie,
+ int err)
{
std::cout << __func__ << " cookie " << cookie << " err " << err << std::endl;
assert(cookie > 1000);
- notify_err = err;
+ auto thiz = reinterpret_cast<LibRadosWatchNotify*>(arg);
+ assert(thiz);
+ thiz->notify_err = err;
}
+class WatchNotifyTestCtx2;
+class LibRadosWatchNotifyPP : public RadosTestParamPP
+{
+protected:
+ bufferlist notify_bl;
+ std::set<uint64_t> notify_cookies;
+ rados_ioctx_t notify_io;
+ const char *notify_oid = nullptr;
+ int notify_err = 0;
+
+ friend class WatchNotifyTestCtx2;
+};
+
IoCtx *notify_ioctx;
+
class WatchNotifyTestCtx2 : public WatchCtx2
{
+ LibRadosWatchNotifyPP *notify;
+
public:
+ WatchNotifyTestCtx2(LibRadosWatchNotifyPP *notify)
+ : notify(notify)
+ {}
+
void handle_notify(uint64_t notify_id, uint64_t cookie, uint64_t notifier_gid,
bufferlist& bl) {
std::cout << __func__ << " cookie " << cookie << " notify_id " << notify_id
<< " notifier_gid " << notifier_gid << std::endl;
- notify_bl = bl;
- notify_cookies.insert(cookie);
+ notify->notify_bl = bl;
+ notify->notify_cookies.insert(cookie);
bufferlist reply;
reply.append("reply", 5);
if (notify_sleep)
sleep(notify_sleep);
- notify_ioctx->notify_ack(notify_oid, notify_id, cookie, reply);
+ notify_ioctx->notify_ack(notify->notify_oid, notify_id, cookie, reply);
}
void handle_error(uint64_t cookie, int err) {
std::cout << __func__ << " cookie " << cookie
<< " err " << err << std::endl;
assert(cookie > 1000);
- notify_err = err;
+ notify->notify_err = err;
}
};
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
ASSERT_EQ(0, rados_remove(ioctx, notify_oid));
int left = 300;
std::cout << "waiting up to " << left << " for disconnect notification ..."
uint64_t handle;
ASSERT_EQ(0, rados_aio_create_completion(NULL, NULL, NULL, &comp));
rados_aio_watch(ioctx, notify_oid, comp, &handle,
- watch_notify2_test_cb, watch_notify2_test_errcb, NULL);
+ watch_notify2_test_cb, watch_notify2_test_errcb, this);
ASSERT_EQ(0, rados_aio_wait_for_complete(comp));
ASSERT_EQ(0, rados_aio_get_return_value(comp));
rados_aio_release(comp);
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
int age = rados_watch_check(ioctx, handle);
time_t age_bound = time(0) + 1 - start;
ASSERT_LT(age, age_bound * 1000);
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
ASSERT_GT(rados_watch_check(ioctx, handle), 0);
// and now a notify will work.
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
ASSERT_GT(rados_watch_check(ioctx, handle), 0);
char *reply_buf = 0;
size_t reply_buf_len;
uint64_t handle;
ASSERT_EQ(0, rados_aio_create_completion(NULL, NULL, NULL, &comp));
rados_aio_watch(ioctx, notify_oid, comp, &handle,
- watch_notify2_test_cb, watch_notify2_test_errcb, NULL);
+ watch_notify2_test_cb, watch_notify2_test_errcb, this);
ASSERT_EQ(0, rados_aio_wait_for_complete(comp));
ASSERT_EQ(0, rados_aio_get_return_value(comp));
rados_aio_release(comp);
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
ASSERT_GT(rados_watch_check(ioctx, handle), 0);
char *reply_buf = 0;
size_t reply_buf_len;
bl1.append(buf, sizeof(buf));
ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0));
uint64_t handle;
- WatchNotifyTestCtx2 ctx;
+ WatchNotifyTestCtx2 ctx(this);
ASSERT_EQ(0, ioctx.watch2(notify_oid, &handle, &ctx));
ASSERT_GT(ioctx.watch_check(handle), 0);
std::list<obj_watch_t> watches;
ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0));
uint64_t handle;
- WatchNotifyTestCtx2 ctx;
+ WatchNotifyTestCtx2 ctx(this);
librados::AioCompletion *comp = cluster.aio_create_completion();
ASSERT_EQ(0, ioctx.aio_watch(notify_oid, comp, &handle, &ctx));
ASSERT_EQ(0, comp->wait_for_complete());
bl1.append(buf, sizeof(buf));
ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0));
uint64_t handle;
- WatchNotifyTestCtx2 ctx;
+ WatchNotifyTestCtx2 ctx(this);
ASSERT_EQ(0, ioctx.watch2(notify_oid, &handle, &ctx));
ASSERT_GT(ioctx.watch_check(handle), 0);
std::list<obj_watch_t> watches;
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle1,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle2,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
ASSERT_GT(rados_watch_check(ioctx, handle1), 0);
ASSERT_GT(rados_watch_check(ioctx, handle2), 0);
ASSERT_NE(handle1, handle2);
ASSERT_EQ(0,
rados_watch2(ioctx, notify_oid, &handle,
watch_notify2_test_cb,
- watch_notify2_test_errcb, NULL));
+ watch_notify2_test_errcb, this));
ASSERT_GT(rados_watch_check(ioctx, handle), 0);
char *reply_buf = 0;
size_t reply_buf_len;
bl1.append(buf, sizeof(buf));
ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0));
uint64_t handle;
- WatchNotifyTestCtx2 ctx;
+ WatchNotifyTestCtx2 ctx(this);
ASSERT_EQ(0, ioctx.watch2(notify_oid, &handle, &ctx));
ASSERT_GT(ioctx.watch_check(handle), 0);
std::list<obj_watch_t> watches;
bl1.append(buf, sizeof(buf));
ASSERT_EQ(0, ioctx.write(notify_oid, bl1, sizeof(buf), 0));
uint64_t handle;
- WatchNotifyTestCtx2 ctx;
+ WatchNotifyTestCtx2 ctx(this);
ASSERT_EQ(0, ioctx.watch3(notify_oid, &handle, &ctx, timeout));
ASSERT_GT(ioctx.watch_check(handle), 0);
std::list<obj_watch_t> watches;
uint64_t handle;
ASSERT_EQ(0, rados_aio_create_completion(NULL, NULL, NULL, &comp));
rados_aio_watch2(ioctx, notify_oid, comp, &handle,
- watch_notify2_test_cb, watch_notify2_test_errcb, timeout, NULL);
+ watch_notify2_test_cb, watch_notify2_test_errcb, timeout, this);
ASSERT_EQ(0, rados_aio_wait_for_complete(comp));
ASSERT_EQ(0, rados_aio_get_return_value(comp));
rados_aio_release(comp);