修改GET/PUT对外接口;cache miss不算fail;
This commit is contained in:
66
cache/test/tango_cache_test.c
vendored
66
cache/test/tango_cache_test.c
vendored
@@ -50,28 +50,27 @@ void get_future_success(future_result_t* result, void * user)
|
||||
struct future_pdata *pdata = (struct future_pdata *)user;
|
||||
char buffer[1024];
|
||||
|
||||
if(res != NULL)
|
||||
switch(res->type)
|
||||
{
|
||||
switch(res->type)
|
||||
{
|
||||
case RESULT_TYPE_BODY:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
|
||||
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;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
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:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
case RESULT_TYPE_MISS:
|
||||
printf("cache not hit/fresh\n");
|
||||
case RESULT_TYPE_END:
|
||||
if(res->type != RESULT_TYPE_MISS)
|
||||
printf("get cache over, total length: %ld\n", res->tlength);
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +165,8 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
char *dellist[16];
|
||||
char *pstart, *save_ptr=NULL;
|
||||
int delnum=0;
|
||||
struct tango_cache_meta meta;
|
||||
struct tango_cache_meta_put putmeta;
|
||||
struct tango_cache_meta_get getmeta;
|
||||
struct future_pdata *pdata;
|
||||
|
||||
struct tango_cache_ctx *ctx;
|
||||
@@ -181,12 +181,14 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
{
|
||||
p = method;
|
||||
|
||||
memset(&meta, 0, sizeof(struct tango_cache_meta));
|
||||
meta.url = s;
|
||||
meta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
meta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
meta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
meta.usertag_len = strlen(meta.usertag);
|
||||
memset(&putmeta, 0, sizeof(struct tango_cache_meta_put));
|
||||
putmeta.url = s;
|
||||
putmeta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
putmeta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
putmeta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
putmeta.usertag_len = strlen(putmeta.usertag);
|
||||
|
||||
getmeta.url = s;
|
||||
|
||||
while(*p=='\r'||*p=='\n')p++;
|
||||
if(*p=='\0') continue;
|
||||
@@ -197,7 +199,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
pdata->future = future_create(get_future_success, get_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
tango_cache_fetch_object(tango_instance, pdata->future, &meta);
|
||||
tango_cache_fetch_object(tango_instance, pdata->future, &getmeta);
|
||||
}
|
||||
else if(!strcasecmp(p, "PUTONCE"))
|
||||
{
|
||||
@@ -206,7 +208,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
tango_cache_upload_once_data(tango_instance, pdata->future, PUT_MEM_FREE, p, filelen, &meta, pdata->filename, 256);
|
||||
tango_cache_upload_once_data(tango_instance, pdata->future, PUT_MEM_FREE, p, filelen, &putmeta, pdata->filename, 256);
|
||||
}
|
||||
else if(!strcasecmp(p, "PUTONCEEV"))
|
||||
{
|
||||
@@ -227,7 +229,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
evbuffer_add(evbuf, buffer, readlen);
|
||||
}
|
||||
fclose(fp);
|
||||
tango_cache_upload_once_evbuf(tango_instance, pdata->future, EVBUFFER_MOVE, evbuf, &meta, pdata->filename, 256);
|
||||
tango_cache_upload_once_evbuf(tango_instance, pdata->future, EVBUFFER_MOVE, evbuf, &putmeta, pdata->filename, 256);
|
||||
}
|
||||
else if(!strcasecmp(p, "DEL"))
|
||||
{
|
||||
@@ -253,7 +255,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
ctx = tango_cache_update_start(tango_instance, pdata->future, &meta);
|
||||
ctx = tango_cache_update_start(tango_instance, pdata->future, &putmeta);
|
||||
tango_cache_get_object_path(ctx, pdata->filename, 256);
|
||||
|
||||
FILE *fp = fopen(s, "r");
|
||||
|
||||
Reference in New Issue
Block a user