From: Brian Aker Date: Wed, 23 Jan 2008 02:52:58 +0000 (-0800) Subject: Refactor of generate tests. X-Git-Tag: 0.15~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=285c6e033a3739a1733b8729d91c7f649220461e;p=m6w6%2Flibmemcached Refactor of generate tests. --- diff --git a/lib/memcached_callback.c b/lib/memcached_callback.c index ad14300a..95d6a384 100644 --- a/lib/memcached_callback.c +++ b/lib/memcached_callback.c @@ -59,6 +59,10 @@ void *memcached_callback_get(memcached_st *ptr, memcached_callback flag, memcached_return *error) { + memcached_return local_error; + if (!error) + error = &local_error; + switch (flag) { case MEMCACHED_CALLBACK_USER_DATA: diff --git a/src/generator.c b/src/generator.c index caeda926..793157ef 100644 --- a/src/generator.c +++ b/src/generator.c @@ -36,7 +36,7 @@ void pairs_free(pairs_st *pairs) free(pairs); } -pairs_st *pairs_generate(unsigned long long number_of) +pairs_st *pairs_generate(unsigned long long number_of, size_t value_length) { unsigned int x; pairs_st *pairs; @@ -56,11 +56,11 @@ pairs_st *pairs_generate(unsigned long long number_of) get_random_string(pairs[x].key, 100); pairs[x].key_length= 100; - pairs[x].value= (char *)malloc(sizeof(char) * 400); + pairs[x].value= (char *)malloc(sizeof(char) * value_length); if (!pairs[x].value) goto error; - get_random_string(pairs[x].value, 400); - pairs[x].value_length= 400; + get_random_string(pairs[x].value, value_length); + pairs[x].value_length= value_length; } return pairs; diff --git a/src/generator.h b/src/generator.h index 8582ffb3..c3fcab32 100644 --- a/src/generator.h +++ b/src/generator.h @@ -14,7 +14,7 @@ struct pairs_st { size_t value_length; }; -pairs_st *pairs_generate(unsigned long long number_of); +pairs_st *pairs_generate(unsigned long long number_of, size_t length); void pairs_free(pairs_st *pairs); #endif diff --git a/src/memslap.c b/src/memslap.c index 486ff7ce..6027fddd 100644 --- a/src/memslap.c +++ b/src/memslap.c @@ -174,7 +174,7 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) if (opt_test == SET_TEST) { - context->execute_pairs= pairs_generate(opt_execute_number); + context->execute_pairs= pairs_generate(opt_execute_number, 400); context->execute_number= opt_execute_number; } @@ -376,7 +376,7 @@ pairs_st *load_create_data(memcached_st *memc, unsigned int number_of, /* We always used non-blocking IO for load since it is faster */ memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL ); - pairs= pairs_generate(number_of); + pairs= pairs_generate(number_of, 400); *actual_loaded= execute_set(clone, pairs, number_of); memcached_free(clone); diff --git a/tests/function.c b/tests/function.c index 514fe3c2..b2bcd4ad 100644 --- a/tests/function.c +++ b/tests/function.c @@ -26,6 +26,9 @@ #include "test.h" #define GLOBAL_COUNT 100000 +#define GLOBAL2_COUNT 1000 +static uint32_t global_count; + static pairs_st *global_pairs; static char *global_keys[GLOBAL_COUNT]; static size_t global_keys_length[GLOBAL_COUNT]; @@ -1764,13 +1767,13 @@ uint8_t cleanup_pairs(memcached_st *memc) return 0; } -uint8_t generate_data(memcached_st *memc) +uint8_t generate_pairs(memcached_st *memc) { unsigned long long x; - global_pairs= pairs_generate(GLOBAL_COUNT); - execute_set(memc, global_pairs, GLOBAL_COUNT); + global_pairs= pairs_generate(GLOBAL_COUNT, 400); + global_count= GLOBAL_COUNT; - for (x= 0; x < GLOBAL_COUNT; x++) + for (x= 0; x < global_count; x++) { global_keys[x]= global_pairs[x].key; global_keys_length[x]= global_pairs[x].key_length; @@ -1779,34 +1782,38 @@ uint8_t generate_data(memcached_st *memc) return 0; } -uint8_t generate_buffer_data(memcached_st *memc) +uint8_t generate_large_pairs(memcached_st *memc) { - int latch= 0; + unsigned long long x; + global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10); + global_count= GLOBAL2_COUNT; - latch= 1; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch); - generate_data(memc); + for (x= 0; x < global_count; x++) + { + global_keys[x]= global_pairs[x].key; + global_keys_length[x]= global_pairs[x].key_length; + } return 0; } -#ifdef NOT_DONE -uint8_t mset_data(memcached_st *memc) +uint8_t generate_data(memcached_st *memc) { - unsigned long long x; - global_pairs= pairs_generate(GLOBAL_COUNT); + execute_set(memc, global_pairs, global_count); - (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); + return 0; +} - for (x= 0; x < GLOBAL_COUNT; x++) - { - global_keys[x]= global_pairs[x].key; - global_keys_length[x]= global_pairs[x].key_length; - } +uint8_t generate_buffer_data(memcached_st *memc) +{ + int latch= 0; + + latch= 1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch); + generate_data(memc); return 0; } -#endif uint8_t get_read(memcached_st *memc) { @@ -1818,7 +1825,7 @@ uint8_t get_read(memcached_st *memc) size_t return_value_length; uint32_t flags; - for (x= 0; x < GLOBAL_COUNT; x++) + for (x= 0; x < global_count; x++) { return_value= memcached_get(memc, global_keys[x], global_keys_length[x], &return_value_length, &flags, &rc); @@ -1838,7 +1845,7 @@ uint8_t mget_read(memcached_st *memc) { memcached_return rc; - rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT); + rc= memcached_mget(memc, global_keys, global_keys_length, global_count); assert(rc == MEMCACHED_SUCCESS); /* Turn this into a help function */ { @@ -1864,7 +1871,7 @@ uint8_t mget_read_result(memcached_st *memc) { memcached_return rc; - rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT); + rc= memcached_mget(memc, global_keys, global_keys_length, global_count); assert(rc == MEMCACHED_SUCCESS); /* Turn this into a help function */ { @@ -1891,7 +1898,7 @@ uint8_t mget_read_function(memcached_st *memc) unsigned int counter; unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *); - rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT); + rc= memcached_mget(memc, global_keys, global_keys_length, global_count); assert(rc == MEMCACHED_SUCCESS); callbacks[0]= &callback_counter; @@ -1905,7 +1912,7 @@ uint8_t delete_generate(memcached_st *memc) { unsigned int x; - for (x= 0; x < GLOBAL_COUNT; x++) + for (x= 0; x < global_count; x++) { (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); } @@ -1921,7 +1928,7 @@ uint8_t delete_buffer_generate(memcached_st *memc) latch= 1; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, &latch); - for (x= 0; x < GLOBAL_COUNT; x++) + for (x= 0; x < global_count; x++) { (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); } @@ -2278,6 +2285,7 @@ test_st user_tests[] ={ }; test_st generate_tests[] ={ + {"generate_pairs", 1, generate_pairs }, {"generate_data", 1, generate_data }, {"get_read", 0, get_read }, {"delete_generate", 0, delete_generate }, @@ -2288,6 +2296,10 @@ test_st generate_tests[] ={ {"mget_read_result", 0, mget_read_result }, {"mget_read_function", 0, mget_read_function }, {"cleanup", 1, cleanup_pairs }, + {"generate_large_pairs", 1, generate_large_pairs }, + {"generate_data", 1, generate_data }, + {"generate_buffer_data", 1, generate_buffer_data }, + {"cleanup", 1, cleanup_pairs }, {0, 0, 0} };