支持Head获取对象元信息操作,支持从redis获取元信息;调整内部超时检查逻辑;
This commit is contained in:
49
cache/test/cache_evbase_test.cpp
vendored
49
cache/test/cache_evbase_test.cpp
vendored
@@ -68,6 +68,43 @@ void get_future_failed(enum e_future_error err, const char * what, void * user)
|
||||
runing_over = 2;
|
||||
}
|
||||
|
||||
void head_future_success(future_result_t* result, void * user)
|
||||
{
|
||||
struct tango_cache_result *res = cache_evbase_read_result(result);
|
||||
struct future_pdata *pdata = (struct future_pdata *)user;
|
||||
char buffer[1024];
|
||||
|
||||
switch(res->type)
|
||||
{
|
||||
case RESULT_TYPE_USERTAG:
|
||||
case RESULT_TYPE_HEADER:
|
||||
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
|
||||
buffer[res->size] = '\0';
|
||||
printf("%s", buffer);
|
||||
break;
|
||||
case RESULT_TYPE_BODY:
|
||||
assert(0);
|
||||
break;
|
||||
case RESULT_TYPE_MISS:
|
||||
printf("cache not hit/fresh\n");
|
||||
case RESULT_TYPE_END:
|
||||
if(res->type != RESULT_TYPE_MISS)
|
||||
printf("HEAD cache over, total length: %ld\n", res->tlength);
|
||||
future_destroy(pdata->future);
|
||||
free(pdata);
|
||||
runing_over = 1;
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
void head_future_failed(enum e_future_error err, const char * what, void * user)
|
||||
{
|
||||
printf("HEAD fail: %s\n", what);
|
||||
runing_over = 2;
|
||||
}
|
||||
|
||||
|
||||
void put_future_success(future_result_t* result, void * user)
|
||||
{
|
||||
struct future_pdata *pdata = (struct future_pdata *)user;
|
||||
@@ -201,15 +238,18 @@ int main(int argc, char **argv)
|
||||
{
|
||||
sprintf(filename_out, "file_index_%u.bin", index);
|
||||
pdata->future = future_create(get_future_success, get_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
pdata->fp = fopen(filename_out, "w");
|
||||
|
||||
cache_evbase_fetch_object(instance_asyn, pdata->future, &getmeta);
|
||||
}
|
||||
else if(!strcasecmp(p, "HEAD"))
|
||||
{
|
||||
pdata->future = future_create(head_future_success, head_future_failed, pdata);
|
||||
cache_evbase_head_object(instance_asyn, pdata->future, &getmeta);
|
||||
}
|
||||
else if(!strcasecmp(p, "DEL"))
|
||||
{
|
||||
pdata->future = future_create(del_future_success, del_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
sprintf(pdata->filename, "%s", filename_in);
|
||||
cache_evbase_delete_object(instance_asyn, pdata->future, filename_in);
|
||||
}
|
||||
@@ -218,7 +258,6 @@ int main(int argc, char **argv)
|
||||
size_t filelen;
|
||||
p = get_file_content(filename_in, &filelen);
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
cache_evbase_upload_once_data(instance_asyn, pdata->future, PUT_MEM_FREE, p, filelen, &putmeta, pdata->filename, 256);
|
||||
}
|
||||
@@ -226,7 +265,6 @@ int main(int argc, char **argv)
|
||||
{
|
||||
size_t readlen;
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
struct evbuffer *evbuf = evbuffer_new();
|
||||
char buffer[1024];
|
||||
|
||||
@@ -246,7 +284,6 @@ int main(int argc, char **argv)
|
||||
else
|
||||
{
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
ctx = cache_evbase_update_start(instance_asyn, pdata->future, &putmeta);
|
||||
cache_evbase_get_object_path(ctx, pdata->filename, 256);
|
||||
@@ -265,7 +302,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
printf("Waiting to finish.......\n");
|
||||
static int num=0;
|
||||
//static int num=0;
|
||||
while(!runing_over)
|
||||
{
|
||||
/*if(++num==10)
|
||||
|
||||
Reference in New Issue
Block a user