return true;
}
- auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
- ObjectCacheRequest*>([this, snap_id, read_data, dispatch_result, on_dispatched,
+ CacheGenContextURef ctx = make_gen_lambda_context<ObjectCacheRequest*,
+ std::function<void(ObjectCacheRequest*)>>
+ ([this, snap_id, read_data, dispatch_result, on_dispatched,
oid, object_off, object_len](ObjectCacheRequest* ack) {
-
if (ack->type == RBDSC_READ_REPLY) {
std::string file_path = ((ObjectCacheReadReplyData*)ack)->cache_path;
ceph_assert(file_path != "");
m_cache_client->lookup_object(m_image_ctx->data_ctx.get_namespace(),
m_image_ctx->data_ctx.get_id(),
- (uint64_t)snap_id, oid, ctx);
+ (uint64_t)snap_id, oid, std::move(ctx));
}
return true;
}
MOCK_METHOD0(close, void());
MOCK_METHOD0(stop, void());
MOCK_METHOD0(connect, int());
- MOCK_METHOD5(lookup_object, void(std::string pool_nspace,
+ void lookup_object(std::string pool_nspace, uint64_t pool_id, uint64_t snap_id,
+ std::string oid, CacheGenContextURef&& on_finish) {
+ // gmock don't support move
+ internal_lookup(pool_nspace, pool_id, snap_id, oid);
+ };
+ MOCK_METHOD4(internal_lookup, void(std::string pool_nspace,
uint64_t pool_id, uint64_t snap_id,
- std::string oid,
- GenContext<ObjectCacheRequest*>* on_finish));
+ std::string oid));
MOCK_METHOD1(register_client, int(Context*));
};
m_send_request_index.store(0);
m_recv_ack_index.store(0);
for (uint64_t index = 0; index < times; index++) {
- auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
- ObjectCacheRequest*>([this, thinking, times](ObjectCacheRequest* ack){
+ auto ctx = make_gen_lambda_context<ObjectCacheRequest*, std::function<void(ObjectCacheRequest*)>>
+ ([this, thinking, times](ObjectCacheRequest* ack){
if (thinking != 0) {
usleep(thinking); // handling message
}
usleep(1);
}
- m_cache_client->lookup_object("pool_nspace", 1, 2, "object_name", ctx);
+ m_cache_client->lookup_object("pool_nspace", 1, 2, "object_name", std::move(ctx));
m_send_request_index++;
}
m_wait_event.wait();
bool startup_lookupobject_testing(std::string pool_nspace, std::string object_id) {
bool hit;
- auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
- ObjectCacheRequest*>([this, &hit](ObjectCacheRequest* ack){
+ //auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
+ // ObjectCacheRequest*>([this, &hit](ObjectCacheRequest* ack){
+ auto ctx = make_gen_lambda_context<ObjectCacheRequest*, std::function<void(ObjectCacheRequest*)>>
+ ([this, &hit](ObjectCacheRequest* ack){
hit = ack->type == RBDSC_READ_REPLY;
m_wait_event.signal();
});
- m_cache_client->lookup_object(pool_nspace, 1, 2, object_id, ctx);
+ m_cache_client->lookup_object(pool_nspace, 1, 2, object_id, std::move(ctx));
m_wait_event.wait();
return hit;
}
uint64_t request_num, bool is_last) {
for (uint64_t i = 0; i < request_num; i++) {
- auto ctx = new LambdaGenContext<std::function<void(ObjectCacheRequest*)>,
- ObjectCacheRequest*>([this](ObjectCacheRequest* ack) {
+ auto ctx = make_gen_lambda_context<ObjectCacheRequest*,
+ std::function<void(ObjectCacheRequest*)>>([this](ObjectCacheRequest* ack) {
m_recv_ack_index++;
});
m_send_request_index++;
// here just for concurrently testing register + lookup, so fix object id.
- m_cache_client_vec[index]->lookup_object(pool_nspace, 1, 2, "1234", ctx);
+ m_cache_client_vec[index]->lookup_object(pool_nspace, 1, 2, "1234", std::move(ctx));
}
if (is_last) {
void expect_cache_lookup_object(MockParentImageCache& mparent_image_cache,
Context* on_finish) {
- auto& expect = EXPECT_CALL(*(mparent_image_cache.m_cache_client), lookup_object(
- _, _, _, _, _));
+ auto& expect = EXPECT_CALL(*(mparent_image_cache.m_cache_client),
+ internal_lookup(_, _, _, _));
- expect.WillOnce(WithArg<4>(Invoke([on_finish](GenContext<ObjectCacheRequest*>* ctx) {
- on_finish->complete(0);
- })));
+ expect.WillOnce(WithArg<3>(Invoke([on_finish](std::string oid) {
+ on_finish->complete(0);
+ })));
}
void expect_cache_close(MockParentImageCache& mparent_image_cache, int ret_val) {
void CacheClient::lookup_object(std::string pool_nspace, uint64_t pool_id,
uint64_t snap_id, std::string oid,
- GenContext<ObjectCacheRequest*>* on_finish) {
+ CacheGenContextURef&& on_finish) {
ObjectCacheRequest* req = new ObjectCacheReadData(RBDSC_READ,
++m_sequence_id, 0, 0,
pool_id, snap_id, oid, pool_nspace);
- req->process_msg = on_finish;
+ req->process_msg = std::move(on_finish);
req->encode();
{
// dedicated thrad to execute this context.
}
current_request->process_msg->complete(reply);
- delete current_request;
- delete reply;
+ //delete current_request;
+ //delete reply;
});
if (m_worker_thread_num != 0) {
int connect();
void lookup_object(std::string pool_nspace, uint64_t pool_id,
uint64_t snap_id, std::string oid,
- GenContext<ObjectCacheRequest*>* on_finish);
+ CacheGenContextURef&& on_finish);
int register_client(Context* on_finish);
private:
class ObjectCacheRequest;
class CacheSession;
+typedef GenContextURef<ObjectCacheRequest*> CacheGenContextURef;
+
typedef std::function<void(CacheSession*, ObjectCacheRequest*)> ProcessMsg;
} // namespace immutable_obj_cache
bufferlist payload;
- GenContext<ObjectCacheRequest*>* process_msg;
+ CacheGenContextURef process_msg;
ObjectCacheRequest();
ObjectCacheRequest(uint16_t type, uint64_t seq);