#include <semaphore.h>
#include "gtest/gtest.h"
#include "include/encoding.h"
+#include <set>
using namespace librados;
ASSERT_EQ(-ENOTCONN, rados_watch_check(ioctx, handle));
// a subsequent notify should not reach us
- char *reply_buf;
+ char *reply_buf = 0;
size_t reply_buf_len;
ASSERT_EQ(0, rados_notify2(ioctx, notify_oid,
"notify", 6, 0,
bufferlist reply;
reply.append(reply_buf, reply_buf_len);
std::multimap<uint64_t, bufferlist> reply_map;
+ std::multiset<uint64_t> missed_map;
bufferlist::iterator reply_p = reply.begin();
::decode(reply_map, reply_p);
+ ::decode(missed_map, reply_p);
ASSERT_EQ(0u, reply_map.size());
+ ASSERT_EQ(0u, missed_map.size());
}
ASSERT_EQ(0u, notify_cookies.size());
ASSERT_EQ(-ENOTCONN, rados_watch_check(ioctx, handle));
+ rados_buffer_free(reply_buf);
// re-watch
rados_unwatch2(ioctx, handle);
bufferlist reply;
reply.append(reply_buf, reply_buf_len);
std::multimap<uint64_t, bufferlist> reply_map;
+ std::multiset<uint64_t> missed_map;
bufferlist::iterator reply_p = reply.begin();
::decode(reply_map, reply_p);
+ ::decode(missed_map, reply_p);
ASSERT_EQ(1u, reply_map.size());
+ ASSERT_EQ(0, missed_map.size());
ASSERT_EQ(1, notify_cookies.count(handle));
ASSERT_EQ(5, reply_map.begin()->second.length());
ASSERT_EQ(0, strncmp("reply", reply_map.begin()->second.c_str(), 5));
watch_notify2_test_failcb,
watch_notify2_test_errcb, NULL));
ASSERT_TRUE(rados_watch_check(ioctx, handle) > 0);
- char *reply_buf;
+ char *reply_buf = 0;
size_t reply_buf_len;
ASSERT_EQ(0, rados_notify2(ioctx, notify_oid,
"notify", 6, 0,
bufferlist reply;
reply.append(reply_buf, reply_buf_len);
std::multimap<uint64_t, bufferlist> reply_map;
+ std::multiset<uint64_t> missed_map;
bufferlist::iterator reply_p = reply.begin();
::decode(reply_map, reply_p);
+ ::decode(missed_map, reply_p);
ASSERT_EQ(1u, reply_map.size());
+ ASSERT_EQ(0, missed_map.size());
ASSERT_EQ(1u, notify_cookies.size());
ASSERT_EQ(1, notify_cookies.count(handle));
ASSERT_EQ(5, reply_map.begin()->second.length());
ASSERT_EQ(0, strncmp("reply", reply_map.begin()->second.c_str(), 5));
ASSERT_TRUE(rados_watch_check(ioctx, handle) > 0);
+ rados_buffer_free(reply_buf);
+
+ // try it on a non-existent object ... our buffer pointers
+ // should get zeroed.
+ ASSERT_EQ(-ENOENT, rados_notify2(ioctx, "doesnotexist",
+ "notify", 6, 0,
+ &reply_buf, &reply_buf_len));
+ ASSERT_EQ(NULL, reply_buf);
+ ASSERT_EQ(0, reply_buf_len);
+
rados_unwatch2(ioctx, handle);
}
ASSERT_EQ(0, ioctx.notify(notify_oid, bl2, 0, &bl_reply));
bufferlist::iterator p = bl_reply.begin();
std::multimap<uint64_t,bufferlist> reply_map;
+ std::multiset<uint64_t> missed_map;
::decode(reply_map, p);
+ ::decode(missed_map, p);
ASSERT_EQ(1u, notify_cookies.size());
ASSERT_EQ(1, notify_cookies.count(handle));
ASSERT_EQ(1u, reply_map.size());
ASSERT_EQ(5, reply_map.begin()->second.length());
ASSERT_EQ(0, strncmp("reply", reply_map.begin()->second.c_str(), 5));
+ ASSERT_EQ(0, missed_map.size());
ASSERT_TRUE(ioctx.watch_check(handle) > 0);
ioctx.unwatch(handle);
}
ASSERT_TRUE(rados_watch_check(ioctx, handle1) > 0);
ASSERT_TRUE(rados_watch_check(ioctx, handle2) > 0);
ASSERT_NE(handle1, handle2);
- char *reply_buf;
+ char *reply_buf = 0;
size_t reply_buf_len;
ASSERT_EQ(0, rados_notify2(ioctx, notify_oid,
"notify", 6, 0,
bufferlist reply;
reply.append(reply_buf, reply_buf_len);
std::multimap<uint64_t, bufferlist> reply_map;
+ std::multiset<uint64_t> missed_map;
bufferlist::iterator reply_p = reply.begin();
::decode(reply_map, reply_p);
+ ::decode(missed_map, reply_p);
ASSERT_EQ(2u, reply_map.size());
ASSERT_EQ(5, reply_map.begin()->second.length());
+ ASSERT_EQ(0, missed_map.size());
ASSERT_EQ(2u, notify_cookies.size());
ASSERT_EQ(1, notify_cookies.count(handle1));
ASSERT_EQ(1, notify_cookies.count(handle2));
ASSERT_EQ(0, strncmp("reply", reply_map.begin()->second.c_str(), 5));
ASSERT_TRUE(rados_watch_check(ioctx, handle1) > 0);
ASSERT_TRUE(rados_watch_check(ioctx, handle2) > 0);
+ rados_buffer_free(reply_buf);
rados_unwatch2(ioctx, handle1);
rados_unwatch2(ioctx, handle2);
}
watch_notify2_test_failcb,
watch_notify2_test_errcb, NULL));
ASSERT_TRUE(rados_watch_check(ioctx, handle) > 0);
- char *reply_buf;
+ char *reply_buf = 0;
size_t reply_buf_len;
ASSERT_EQ(-ETIMEDOUT, rados_notify2(ioctx, notify_oid,
"notify", 6, 1000, // 1s
while (!notify_failed && --wait)
sleep(1);
ASSERT_TRUE(notify_failed);
+ {
+ bufferlist reply;
+ reply.append(reply_buf, reply_buf_len);
+ std::multimap<uint64_t, bufferlist> reply_map;
+ std::multiset<uint64_t> missed_map;
+ bufferlist::iterator reply_p = reply.begin();
+ ::decode(reply_map, reply_p);
+ ::decode(missed_map, reply_p);
+ ASSERT_EQ(0, reply_map.size());
+ ASSERT_EQ(1, missed_map.size());
+ }
+ rados_buffer_free(reply_buf);
// we should get the next notify, though!
notify_failed = false;