X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ffunction.c;h=0b2c15d480035539fedb8bb3a2deadf9cb76552e;hb=ed1af1f5b70f7da90f5e8d255df134a8ccf3f526;hp=d3d23e4739eecb98cb28552b8201377b9cf79d3b;hpb=aadde7bff9b295789dbf4a1eeb9b37825a970c02;p=awesomized%2Flibmemcached diff --git a/tests/function.c b/tests/function.c index d3d23e47..0b2c15d4 100644 --- a/tests/function.c +++ b/tests/function.c @@ -24,8 +24,9 @@ #include "test.h" -#define GLOBAL_COUNT 100000 -#define GLOBAL2_COUNT 1000 +#define GLOBAL_COUNT 10000 +#define GLOBAL2_COUNT 100 +#define SERVERS_TO_CREATE 5 static uint32_t global_count; static pairs_st *global_pairs; @@ -102,6 +103,36 @@ test_return server_sort_test(memcached_st *ptr) return 0; } +test_return server_sort2_test(memcached_st *ptr) +{ + uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */ + memcached_return rc; + memcached_server_function callbacks[1]; + memcached_st *local_memc; + + local_memc= memcached_create(NULL); + assert(local_memc); + rc= memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1); + assert(rc == MEMCACHED_SUCCESS); + + rc= memcached_server_add(local_memc, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043); + assert(rc == MEMCACHED_SUCCESS); + assert(local_memc->hosts[0].port == 43043); + + rc= memcached_server_add(local_memc, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042); + assert(rc == MEMCACHED_SUCCESS); + assert(local_memc->hosts[0].port == 43042); + assert(local_memc->hosts[1].port == 43043); + + callbacks[0]= server_display_function; + memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1); + + + memcached_free(local_memc); + + return 0; +} + memcached_return server_display_unsort_function(memcached_st *ptr, memcached_server_st *server, void *context) { /* Do Nothing */ @@ -566,7 +597,8 @@ test_return bad_key_test(memcached_st *memc) clone= memcached_clone(NULL, memc); assert(clone); - (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); string= memcached_get(clone, key, strlen(key), &string_length, &flags, &rc); @@ -575,13 +607,39 @@ test_return bad_key_test(memcached_st *memc) assert(!string); set= 0; - (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); string= memcached_get(clone, key, strlen(key), &string_length, &flags, &rc); assert(rc == MEMCACHED_NOTFOUND); assert(string_length == 0); assert(!string); + /* Test multi key for bad keys */ + { + char *keys[] = { "GoodKey", "Bad Key", "NotMine" }; + size_t key_lengths[] = { 7, 7, 7 }; + set= 1; + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); + + rc= memcached_mget(clone, keys, key_lengths, 3); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + + rc= memcached_mget_by_key(clone, "foo daddy", 9, keys, key_lengths, 1); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + } + + /* Make sure zero length keys are marked as bad */ + set= 1; + rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + assert(rc == MEMCACHED_SUCCESS); + string= memcached_get(clone, key, 0, + &string_length, &flags, &rc); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + assert(string_length == 0); + assert(!string); + memcached_free(clone); return 0; @@ -633,7 +691,7 @@ test_return read_through(memcached_st *memc) return 0; } -memcached_return delete_trigger(memcached_st *ptr, char *key, size_t key_length) +memcached_return delete_trigger(memcached_st *ptr, const char *key, size_t key_length) { assert(key); @@ -2003,6 +2061,59 @@ test_return user_supplied_bug15(memcached_st *memc) return 0; } +/* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */ +test_return user_supplied_bug16(memcached_st *memc) +{ + memcached_return rc; + char *key= "mykey"; + char *value; + size_t length; + uint32_t flags; + + rc= memcached_set(memc, key, strlen(key), + NULL, 0, + (time_t)0, UINT32_MAX); + + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_get(memc, key, strlen(key), + &length, &flags, &rc); + + assert(rc == MEMCACHED_SUCCESS); + assert(value == NULL); + assert(length == 0); + assert(flags == UINT32_MAX); + + return 0; +} + +/* Check the validity of chinese key*/ +test_return user_supplied_bug17(memcached_st *memc) +{ + memcached_return rc; + char *key= "豆瓣"; + char *value="我们在炎热抑郁的夏天无法停止豆瓣"; + char *value2; + size_t length; + uint32_t flags; + + rc= memcached_set(memc, key, strlen(key), + value, strlen(value), + (time_t)0, 0); + + assert(rc == MEMCACHED_SUCCESS); + + value2= memcached_get(memc, key, strlen(key), + &length, &flags, &rc); + + assert(length==strlen(value)); + assert(rc == MEMCACHED_SUCCESS); + assert(memcmp(value, value2, length)==0); + + return 0; +} + + test_return result_static(memcached_st *memc) { memcached_result_st result; @@ -2164,6 +2275,23 @@ test_return generate_data(memcached_st *memc) return 0; } +test_return generate_data_with_stats(memcached_st *memc) +{ + memcached_stat_st *stat_p= NULL; + memcached_return rc; + int host_index= 0; + execute_set(memc, global_pairs, global_count); + + //TODO: hosts used size stats + stat_p = memcached_stat(memc, NULL, &rc); + for (host_index = 0; host_index < SERVERS_TO_CREATE; ++host_index) + { + printf("\nserver %d|%s|%d bytes: %lld\n", host_index, (memc->hosts)[host_index].hostname, (memc->hosts)[host_index].port, (stat_p + host_index)->bytes); + } + + + return 0; +} test_return generate_buffer_data(memcached_st *memc) { int latch= 0; @@ -2448,6 +2576,24 @@ memcached_return pre_behavior_ketama(memcached_st *memc) return MEMCACHED_SUCCESS; } +memcached_return pre_behavior_ketama_weighted(memcached_st *memc) +{ + memcached_return rc; + uint64_t value; + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); + assert(value == 1); + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH); + assert(value == MEMCACHED_HASH_MD5); + return MEMCACHED_SUCCESS; +} void my_free(memcached_st *ptr, void *mem) { free(mem); @@ -2463,6 +2609,71 @@ void *my_realloc(memcached_st *ptr, void *mem, const size_t size) return realloc(mem, size); } +memcached_return set_prefix(memcached_st *memc) +{ + memcached_return rc; + const char *key= "mine"; + char *value; + + /* Make sure be default none exists */ + value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + assert(rc == MEMCACHED_FAILURE); + + /* Test a clean set */ + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + assert(memcmp(value, key, 4) == 0); + assert(rc == MEMCACHED_SUCCESS); + + /* Test that we can turn it off */ + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + assert(rc == MEMCACHED_FAILURE); + + /* Now setup for main test */ + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + assert(rc == MEMCACHED_SUCCESS); + assert(memcmp(value, key, 4) == 0); + + /* Set to Zero, and then Set to something too large */ + { + char *long_key; + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc); + assert(rc == MEMCACHED_FAILURE); + assert(value == NULL); + + /* Test a long key for failure */ + long_key= "Thisismorethentheallottednumberofcharacters"; + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + + /* Now test a key with spaces (which will fail from long key, since bad key is not set) */ + long_key= "This is more then the allotted number of characters"; + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + + /* Test for a bad prefix, but with a short key */ + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, 1); + assert(rc == MEMCACHED_SUCCESS); + + long_key= "dog cat"; + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key); + assert(rc == MEMCACHED_BAD_KEY_PROVIDED); + } + + return MEMCACHED_SUCCESS; +} + memcached_return set_memory_alloc(memcached_st *memc) { { @@ -2501,23 +2712,6 @@ memcached_return set_memory_alloc(memcached_st *memc) return MEMCACHED_SUCCESS; } -memcached_return enable_wheel(memcached_st *memc) -{ - memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL; - memcached_hash hash; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value); - pre_hsieh(memc); - - value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); - assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT_WHEEL); - - hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); - assert(hash == MEMCACHED_HASH_HSIEH); - - - return MEMCACHED_SUCCESS; -} - memcached_return enable_consistent(memcached_st *memc) { memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT; @@ -2630,6 +2824,7 @@ test_st tests[] ={ {"server_list_null_test", 0, server_list_null_test}, {"server_unsort", 0, server_unsort_test}, {"server_sort", 0, server_sort_test}, + {"server_sort2", 0, server_sort2_test}, {"clone_test", 0, clone_test }, {"error", 0, error_test }, {"set", 0, set_test }, @@ -2709,6 +2904,8 @@ test_st user_tests[] ={ {"user_supplied_bug13", 1, user_supplied_bug13 }, {"user_supplied_bug14", 1, user_supplied_bug14 }, {"user_supplied_bug15", 1, user_supplied_bug15 }, + {"user_supplied_bug16", 1, user_supplied_bug16 }, + {"user_supplied_bug17", 1, user_supplied_bug17 }, {0, 0, 0} }; @@ -2739,6 +2936,14 @@ test_st consistent_tests[] ={ {0, 0, 0} }; +test_st consistent_weighted_tests[] ={ + {"generate_pairs", 1, generate_pairs }, + {"generate_data", 1, generate_data_with_stats }, + {"get_read", 0, get_read_count }, + {"cleanup", 1, cleanup_pairs }, + {0, 0, 0} +}; + collection_st collection[] ={ {"block", 0, 0, tests}, {"nonblock", pre_nonblock, 0, tests}, @@ -2756,8 +2961,8 @@ collection_st collection[] ={ {"poll_timeout", poll_timeout, 0, tests}, {"gets", enable_cas, 0, tests}, {"consistent", enable_consistent, 0, tests}, - {"wheel", enable_wheel, 0, tests}, {"memory_allocators", set_memory_alloc, 0, tests}, + {"prefix", set_prefix, 0, tests}, // {"udp", pre_udp, 0, tests}, {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3}, {"string", 0, 0, string_tests}, @@ -2773,7 +2978,7 @@ collection_st collection[] ={ {"generate_nonblock", pre_nonblock, 0, generate_tests}, {"consistent_not", 0, 0, consistent_tests}, {"consistent_ketama", pre_behavior_ketama, 0, consistent_tests}, - {"consistent_wheel", enable_wheel, 0, consistent_tests}, + {"consistent_ketama_weighted", pre_behavior_ketama_weighted, 0, consistent_weighted_tests}, {0, 0, 0, 0} };