X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ffunction.c;h=dc4e6e9a2e9c6099f5794991af5f4a95aa3fa29c;hb=83d63a1f916b073f8cf44cf91b6c0b3d118dabe5;hp=a306a4a44ed187c284db1bd32ecf5f9e985c384f;hpb=52f68c3a89697bf2169885bdeb3306fe84b11529;p=m6w6%2Flibmemcached diff --git a/tests/function.c b/tests/function.c index a306a4a4..dc4e6e9a 100644 --- a/tests/function.c +++ b/tests/function.c @@ -67,7 +67,7 @@ memcached_return server_display_function(memcached_st *ptr, memcached_server_st /* Do Nothing */ uint32_t bigger= *((uint32_t *)(context)); assert(bigger <= server->port); - *((uint32_t *)(context))= bigger; + *((uint32_t *)(context))= server->port; return MEMCACHED_SUCCESS; } @@ -102,6 +102,52 @@ uint8_t server_sort_test(memcached_st *ptr) return 0; } +memcached_return server_display_unsort_function(memcached_st *ptr, memcached_server_st *server, void *context) +{ + /* Do Nothing */ + uint32_t x= *((uint32_t *)(context)); + + assert(test_ports[x] == server->port); + *((uint32_t *)(context))= ++x; + + return MEMCACHED_SUCCESS; +} + +uint8_t server_unsort_test(memcached_st *ptr) +{ + uint8_t x; + uint32_t counter= 0; /* Prime the value for the assert in server_display_function */ + 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); + + for (x= 0; x < TEST_PORT_COUNT; x++) + { + test_ports[x]= random() % 64000; + rc= memcached_server_add(local_memc, "localhost", test_ports[x]); + assert(local_memc->number_of_hosts == x+1); + assert(local_memc->hosts[0].count == x+1); + assert(rc == MEMCACHED_SUCCESS); + } + + callbacks[0]= server_display_unsort_function; + memcached_server_cursor(local_memc, callbacks, (void *)&counter, 1); + + /* Now we sort old data! */ + memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1); + callbacks[0]= server_display_function; + memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1); + + + memcached_free(local_memc); + + return 0; +} + uint8_t allocation_test(memcached_st *not_used) { memcached_st *memc; @@ -574,6 +620,7 @@ uint8_t read_through(memcached_st *memc) assert(rc == MEMCACHED_SUCCESS); assert(string_length == strlen(READ_THROUGH_VALUE)); assert(!strcmp(READ_THROUGH_VALUE, string)); + free(string); string= memcached_get(memc, key, strlen(key), &string_length, &flags, &rc); @@ -581,6 +628,7 @@ uint8_t read_through(memcached_st *memc) assert(rc == MEMCACHED_SUCCESS); assert(string_length == strlen(READ_THROUGH_VALUE)); assert(!strcmp(READ_THROUGH_VALUE, string)); + free(string); return 0; } @@ -1904,8 +1952,6 @@ uint8_t user_supplied_bug14(memcached_st *memc) &string_length, &flags, &rc); assert(rc == MEMCACHED_SUCCESS); - if (current_length > 0) - assert(string); assert(string_length == current_length); assert(!memcmp(string, value, string_length)); @@ -2412,6 +2458,23 @@ 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; @@ -2522,6 +2585,7 @@ test_st tests[] ={ {"init", 0, init_test }, {"allocation", 0, allocation_test }, {"server_list_null_test", 0, server_list_null_test}, + {"server_unsort", 0, server_unsort_test}, {"server_sort", 0, server_sort_test}, {"clone_test", 0, clone_test }, {"error", 0, error_test }, @@ -2642,6 +2706,7 @@ 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}, // {"udp", pre_udp, 0, tests}, {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},