From 965bde2b42f5ef2dd7b55b6b4b74822e7cfaa1de Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Wed, 16 Dec 2009 23:20:58 -0800 Subject: [PATCH] Updating interface. --- ChangeLog | 3 + libmemcached/behavior.c | 199 ++++++++++++++++++++++----------------- libmemcached/behavior.h | 18 ++++ libmemcached/callback.c | 2 + libmemcached/connect.c | 3 + libmemcached/constants.h | 19 ++-- libmemcached/hash.c | 13 ++- libmemcached/hosts.c | 6 +- libmemcached/memcached.c | 5 +- libmemcached/memcached.h | 2 +- tests/function.c | 36 ++++--- tests/test.h | 6 +- 12 files changed, 189 insertions(+), 123 deletions(-) diff --git a/ChangeLog b/ChangeLog index cea8e72b..706285c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * We removed the MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE added in 0.35. Instead use + memcached_behavior_set_distribution(). + 0.35 Mon Nov 9 11:18:33 PST 2009 * Added support for by_key operations for inc/dec methods. * Added mget test to memslap. diff --git a/libmemcached/behavior.c b/libmemcached/behavior.c index e020258d..509f4222 100644 --- a/libmemcached/behavior.c +++ b/libmemcached/behavior.c @@ -15,6 +15,29 @@ #include #include +static bool set_flag(uint64_t data) +{ + // Wordy :) + return data ? true : false; +} + +static memcached_return_t set_hash(memcached_hash_t *store, memcached_hash_t type) +{ +#ifndef HAVE_HSIEH_HASH + if (type == MEMCACHED_HASH_HSIEH) + return MEMCACHED_FAILURE; +#endif + if (type < MEMCACHED_HASH_MAX) + { + *store= type; + } + else + { + return MEMCACHED_FAILURE; + } + + return MEMCACHED_SUCCESS; +} /* This function is used to modify the behavior of running client. @@ -50,106 +73,82 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, break; case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL: if (data) - ptr->flags.verify_key= false; - - ptr->flags.binary_protocol= data ? true : false; + { + ptr->flags.verify_key= false; + } + ptr->flags.binary_protocol= set_flag(data); break; case MEMCACHED_BEHAVIOR_SUPPORT_CAS: - ptr->flags.support_cas= data ? true: false; + ptr->flags.support_cas= set_flag(data); break; case MEMCACHED_BEHAVIOR_NO_BLOCK: - ptr->flags.no_block= data ? true: false; + ptr->flags.no_block= set_flag(data); memcached_quit(ptr); break; case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS: - ptr->flags.buffer_requests= data ? true : false; + ptr->flags.buffer_requests= set_flag(data); memcached_quit(ptr); break; case MEMCACHED_BEHAVIOR_USE_UDP: if (ptr->number_of_hosts) + { return MEMCACHED_FAILURE; - ptr->flags.use_udp= data ? true : false; - + } + ptr->flags.use_udp= set_flag(data); if (data) - ptr->flags.no_reply= data ? true : false; + { + ptr->flags.no_reply= set_flag(data); + } break; - case MEMCACHED_BEHAVIOR_TCP_NODELAY: - ptr->flags.tcp_nodelay= data ? true : false; + ptr->flags.tcp_nodelay= set_flag(data); memcached_quit(ptr); break; case MEMCACHED_BEHAVIOR_DISTRIBUTION: - { - ptr->distribution= (memcached_server_distribution_t)(data); - if (ptr->distribution == MEMCACHED_DISTRIBUTION_RANDOM) - { - srandom((uint32_t) time(NULL)); - } - run_distribution(ptr); - break; - } + return memcached_behavior_set_distribution(ptr, (memcached_server_distribution_t)data); case MEMCACHED_BEHAVIOR_KETAMA: { if (data) { - ptr->hash= MEMCACHED_HASH_MD5; - ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA; + (void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_MD5); + (void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_MD5); + (void)memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA); } else { - ptr->hash= 0; - ptr->distribution= 0; + (void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_DEFAULT); + (void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_DEFAULT); + (void)memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_MODULA); } - run_distribution(ptr); + break; } case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED: { - ptr->hash= MEMCACHED_HASH_MD5; - ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA; - ptr->flags.ketama_weighted= data ? true : false; - run_distribution(ptr); - break; - } - case MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE: - switch (data) - { - case MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED: - ptr->hash= MEMCACHED_HASH_MD5; - ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA; - break; - case MEMCACHED_KETAMA_COMPAT_SPY: - ptr->hash= MEMCACHED_HASH_MD5; - ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY; - break; - default: - return MEMCACHED_FAILURE; + (void)memcached_behavior_set_key_hash(ptr, MEMCACHED_HASH_MD5); + (void)memcached_behavior_set_distribution_hash(ptr, MEMCACHED_HASH_MD5); + ptr->flags.ketama_weighted= set_flag(data); + /** + @note We try to keep the same distribution going. This should be deprecated and rewritten. + */ + return memcached_behavior_set_distribution(ptr, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA); } - run_distribution(ptr); - break; case MEMCACHED_BEHAVIOR_HASH: -#ifndef HAVE_HSIEH_HASH - if ((memcached_hash_t)(data) == MEMCACHED_HASH_HSIEH) - return MEMCACHED_FAILURE; -#endif - ptr->hash= (memcached_hash_t)(data); - break; + return memcached_behavior_set_key_hash(ptr, (memcached_hash_t)(data)); case MEMCACHED_BEHAVIOR_KETAMA_HASH: - ptr->hash_continuum= (memcached_hash_t)(data); - run_distribution(ptr); - break; + return memcached_behavior_set_distribution_hash(ptr, (memcached_hash_t)(data)); case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS: - ptr->flags.use_cache_lookups= data ? true : false; + ptr->flags.use_cache_lookups= set_flag(data); memcached_quit(ptr); break; case MEMCACHED_BEHAVIOR_VERIFY_KEY: if (ptr->flags.binary_protocol) - break; - ptr->flags.verify_key= data ? true : false; + return MEMCACHED_FAILURE; + ptr->flags.verify_key= set_flag(data); break; case MEMCACHED_BEHAVIOR_SORT_HOSTS: { - ptr->flags.use_sort_hosts= data ? true : false; + ptr->flags.use_sort_hosts= set_flag(data); run_distribution(ptr); break; @@ -174,21 +173,23 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_USER_DATA: return MEMCACHED_FAILURE; case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY: - ptr->flags.hash_with_prefix_key= data ? true : false; + ptr->flags.hash_with_prefix_key= set_flag(data); break; case MEMCACHED_BEHAVIOR_NOREPLY: - ptr->flags.no_reply= data ? true : false; + ptr->flags.no_reply= set_flag(data); break; case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS: - ptr->flags.auto_eject_hosts= data ? true : false; + ptr->flags.auto_eject_hosts= set_flag(data); break; case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ: srandom((uint32_t) time(NULL)); - ptr->flags.randomize_replica_read= data ? true : false; + ptr->flags.randomize_replica_read= set_flag(data); break; + case MEMCACHED_BEHAVIOR_MAX: default: /* Shouldn't get here */ - WATCHPOINT_ASSERT(flag); + WATCHPOINT_ASSERT(0); + return MEMCACHED_FAILURE; break; } @@ -230,24 +231,10 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return ptr->distribution; case MEMCACHED_BEHAVIOR_KETAMA: return (ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) ? (uint64_t) 1 : 0; - case MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE: - switch (ptr->distribution) - { - case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA: - return MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED; - case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: - return MEMCACHED_KETAMA_COMPAT_SPY; - case MEMCACHED_DISTRIBUTION_MODULA: - case MEMCACHED_DISTRIBUTION_CONSISTENT: - case MEMCACHED_DISTRIBUTION_RANDOM: - default: - return (uint64_t)-1; - } - /* NOTREACHED */ case MEMCACHED_BEHAVIOR_HASH: return ptr->hash; case MEMCACHED_BEHAVIOR_KETAMA_HASH: - return ptr->hash_continuum; + return ptr->distribution_hash; case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT: return ptr->server_failure_limit; case MEMCACHED_BEHAVIOR_SORT_HOSTS: @@ -283,7 +270,9 @@ uint64_t memcached_behavior_get(memcached_st *ptr, int sock_size; socklen_t sock_length= sizeof(int); - /* REFACTOR */ + /** + @note REFACTOR + */ /* We just try the first host, and if it is down we return zero */ if ((memcached_connect(&ptr->hosts[0])) != MEMCACHED_SUCCESS) return 0; @@ -304,11 +293,53 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return ptr->flags.auto_eject_hosts; case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ: return ptr->flags.randomize_replica_read; + case MEMCACHED_BEHAVIOR_MAX: default: - WATCHPOINT_ASSERT(flag); - break; + WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */ + return 0; + } + + /* NOTREACHED */ +} + + +memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcached_server_distribution_t type) +{ + if (type < MEMCACHED_DISTRIBUTION_CONSISTENT_MAX) + { + ptr->distribution= type; + run_distribution(ptr); } + else + { + return MEMCACHED_FAILURE; + } + + return MEMCACHED_SUCCESS; +} + + +memcached_server_distribution_t memcached_behavior_get_distribution(memcached_st *ptr) +{ + return ptr->distribution; +} - WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */ - return 0; +memcached_return_t memcached_behavior_set_key_hash(memcached_st *ptr, memcached_hash_t type) +{ + return set_hash(&ptr->hash, type); +} + +memcached_hash_t memcached_behavior_get_key_hash(memcached_st *ptr) +{ + return ptr->hash; +} + +memcached_return_t memcached_behavior_set_distribution_hash(memcached_st *ptr, memcached_hash_t type) +{ + return set_hash(&ptr->distribution_hash, type); +} + +memcached_hash_t memcached_behavior_get_distribution_hash(memcached_st *ptr) +{ + return ptr->distribution_hash; } diff --git a/libmemcached/behavior.h b/libmemcached/behavior.h index 5abc0331..7a008731 100644 --- a/libmemcached/behavior.h +++ b/libmemcached/behavior.h @@ -22,6 +22,24 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, const memcached_beh LIBMEMCACHED_API uint64_t memcached_behavior_get(memcached_st *ptr, const memcached_behavior_t flag); +LIBMEMCACHED_API +memcached_return_t memcached_behavior_set_distribution(memcached_st *ptr, memcached_server_distribution_t type); + +LIBMEMCACHED_API +memcached_server_distribution_t memcached_behavior_get_distribution(memcached_st *ptr); + +LIBMEMCACHED_API +memcached_return_t memcached_behavior_set_key_hash(memcached_st *ptr, memcached_hash_t type); + +LIBMEMCACHED_API +memcached_hash_t memcached_behavior_get_key_hash(memcached_st *ptr); + +LIBMEMCACHED_API +memcached_return_t memcached_behavior_set_distribution_hash(memcached_st *ptr, memcached_hash_t type); + +LIBMEMCACHED_API +memcached_hash_t memcached_behavior_get_distribution_hash(memcached_st *ptr); + #ifdef __cplusplus } diff --git a/libmemcached/callback.c b/libmemcached/callback.c index aadde22c..e87d775c 100644 --- a/libmemcached/callback.c +++ b/libmemcached/callback.c @@ -105,6 +105,7 @@ memcached_return_t memcached_callback_set(memcached_st *ptr, ptr->delete_trigger= func; break; } + case MEMCACHED_CALLBACK_MAX: default: return MEMCACHED_FAILURE; } @@ -178,6 +179,7 @@ void *memcached_callback_get(memcached_st *ptr, *error= ptr->delete_trigger ? MEMCACHED_SUCCESS : MEMCACHED_FAILURE; return *(void **)&ptr->delete_trigger; } + case MEMCACHED_CALLBACK_MAX: default: WATCHPOINT_ASSERT(0); *error= MEMCACHED_FAILURE; diff --git a/libmemcached/connect.c b/libmemcached/connect.c index 24328f4c..98ef44d5 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.c @@ -322,7 +322,9 @@ memcached_return_t memcached_connect(memcached_server_st *ptr) if (curr_time.tv_sec < ptr->next_retry) { if (memcached_behavior_get(ptr->root, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS)) + { run_distribution(ptr->root); + } ptr->root->last_disconnected_server = ptr; return MEMCACHED_SERVER_MARKED_DEAD; @@ -343,6 +345,7 @@ memcached_return_t memcached_connect(memcached_server_st *ptr) case MEMCACHED_CONNECTION_UNIX_SOCKET: rc= unix_socket_connect(ptr); break; + case MEMCACHED_CONNECTION_MAX: default: WATCHPOINT_ASSERT(0); } diff --git a/libmemcached/constants.h b/libmemcached/constants.h index cbdbf4b5..980a32bf 100644 --- a/libmemcached/constants.h +++ b/libmemcached/constants.h @@ -76,7 +76,8 @@ typedef enum { MEMCACHED_DISTRIBUTION_CONSISTENT, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, MEMCACHED_DISTRIBUTION_RANDOM, - MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY + MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY, + MEMCACHED_DISTRIBUTION_CONSISTENT_MAX } memcached_server_distribution_t; typedef enum { @@ -110,13 +111,10 @@ typedef enum { MEMCACHED_BEHAVIOR_USE_UDP, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, - MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE, - MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ + MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, + MEMCACHED_BEHAVIOR_MAX } memcached_behavior_t; -#define MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED 0 -#define MEMCACHED_KETAMA_COMPAT_SPY 1 - typedef enum { MEMCACHED_CALLBACK_PREFIX_KEY = 0, MEMCACHED_CALLBACK_USER_DATA = 1, @@ -128,7 +126,8 @@ typedef enum { MEMCACHED_CALLBACK_FREE_FUNCTION = 6, #endif MEMCACHED_CALLBACK_GET_FAILURE = 7, - MEMCACHED_CALLBACK_DELETE_TRIGGER = 8 + MEMCACHED_CALLBACK_DELETE_TRIGGER = 8, + MEMCACHED_CALLBACK_MAX } memcached_callback_t; typedef enum { @@ -141,14 +140,16 @@ typedef enum { MEMCACHED_HASH_FNV1A_32, MEMCACHED_HASH_HSIEH, MEMCACHED_HASH_MURMUR, - MEMCACHED_HASH_JENKINS + MEMCACHED_HASH_JENKINS, + MEMCACHED_HASH_MAX } memcached_hash_t; typedef enum { MEMCACHED_CONNECTION_UNKNOWN, MEMCACHED_CONNECTION_TCP, MEMCACHED_CONNECTION_UDP, - MEMCACHED_CONNECTION_UNIX_SOCKET + MEMCACHED_CONNECTION_UNIX_SOCKET, + MEMCACHED_CONNECTION_MAX } memcached_connection_t; #endif /* __MEMCACHED_CONSTANTS_H__ */ diff --git a/libmemcached/hash.c b/libmemcached/hash.c index 395020a3..7683761e 100644 --- a/libmemcached/hash.c +++ b/libmemcached/hash.c @@ -92,15 +92,17 @@ uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca } case MEMCACHED_HASH_JENKINS: { - hash=jenkins_hash(key, key_length, 13); + hash= jenkins_hash(key, key_length, 13); break; } + case MEMCACHED_HASH_MAX: default: { - WATCHPOINT_ASSERT(hash_algorithm); + WATCHPOINT_ASSERT(0); break; } } + return hash; } @@ -151,11 +153,11 @@ static uint32_t dispatch_host(memcached_st *ptr, uint32_t hash) return hash % ptr->number_of_hosts; case MEMCACHED_DISTRIBUTION_RANDOM: return (uint32_t) random() % ptr->number_of_hosts; + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: default: WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */ return hash % ptr->number_of_hosts; } - /* NOTREACHED */ } @@ -191,12 +193,15 @@ uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_ WATCHPOINT_ASSERT(hash); - if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS) && ptr->next_distribution_rebuild) { + if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS) && ptr->next_distribution_rebuild) + { struct timeval now; if (gettimeofday(&now, NULL) == 0 && now.tv_sec > ptr->next_distribution_rebuild) + { run_distribution(ptr); + } } return dispatch_host(ptr, hash); diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 8cc5f3e6..a5649a6d 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -47,7 +47,9 @@ memcached_return_t run_distribution(memcached_st *ptr) sort_hosts(ptr); break; case MEMCACHED_DISTRIBUTION_RANDOM: + srandom((uint32_t) time(NULL)); break; + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: default: WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */ } @@ -235,7 +237,7 @@ memcached_return_t update_continuum(memcached_st *ptr) } else { - value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum); + value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->distribution_hash); ptr->continuum[continuum_index].index= host_index; ptr->continuum[continuum_index++].value= value; } @@ -279,7 +281,7 @@ memcached_return_t update_continuum(memcached_st *ptr) } else { - value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->hash_continuum); + value= memcached_generate_hash_value(sort_host, sort_host_length, ptr->distribution_hash); ptr->continuum[continuum_index].index= host_index; ptr->continuum[continuum_index++].value= value; } diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index a363c249..90d3a708 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -98,7 +98,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) new_clone->retry_timeout= source->retry_timeout; new_clone->distribution= source->distribution; new_clone->hash= source->hash; - new_clone->hash_continuum= source->hash_continuum; + new_clone->distribution_hash= source->distribution_hash; new_clone->user_data= source->user_data; new_clone->snd_timeout= source->snd_timeout; @@ -136,6 +136,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) } rc= run_distribution(new_clone); + if (rc != MEMCACHED_SUCCESS) { memcached_free(new_clone); @@ -148,6 +149,7 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *source) return new_clone; } + void *memcached_get_user_data(memcached_st *ptr) { return ptr->user_data; @@ -157,5 +159,6 @@ void *memcached_set_user_data(memcached_st *ptr, void *data) { void *ret= ptr->user_data; ptr->user_data= data; + return ret; } diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index efe16e0c..fdf08b88 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -128,7 +128,7 @@ struct memcached_st { void *user_data; time_t next_distribution_rebuild; size_t prefix_key_length; - memcached_hash_t hash_continuum; + memcached_hash_t distribution_hash; memcached_result_st result; memcached_continuum_item_st *continuum; memcached_clone_fn on_clone; diff --git a/tests/function.c b/tests/function.c index b7778660..65d41482 100644 --- a/tests/function.c +++ b/tests/function.c @@ -252,7 +252,7 @@ static test_return_t clone_test(memcached_st *memc) } test_truth(memc_clone->get_key_failure == memc->get_key_failure); test_truth(memc_clone->hash == memc->hash); - test_truth(memc_clone->hash_continuum == memc->hash_continuum); + test_truth(memc_clone->distribution_hash == memc->distribution_hash); test_truth(memc_clone->io_bytes_watermark == memc->io_bytes_watermark); test_truth(memc_clone->io_msg_watermark == memc->io_msg_watermark); test_truth(memc_clone->io_key_prefetch == memc->io_key_prefetch); @@ -716,6 +716,10 @@ static test_return_t bad_key_test(memcached_st *memc) unsigned int set= 1; size_t max_keylen= 0xffff; + // Just skip if we are in binary mode. + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + return TEST_SKIPPED; + memc_clone= memcached_clone(NULL, memc); test_truth(memc_clone); @@ -2734,7 +2738,7 @@ static test_return_t user_supplied_bug18(memcached_st *trash) { uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); char *hostname = memc->hosts[server_idx].hostname; - test_truth(strcmp(hostname, ketama_test_cases[x].server) == 0); + test_strcmp(hostname, ketama_test_cases[x].server); } memcached_server_list_free(server_pool); @@ -2921,8 +2925,7 @@ static test_return_t output_ketama_weighted_keys(memcached_st *trash) test_truth(value == MEMCACHED_HASH_MD5); - test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE, - MEMCACHED_KETAMA_COMPAT_SPY) == MEMCACHED_SUCCESS); + test_truth(memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY) == MEMCACHED_SUCCESS); memcached_server_st *server_pool; server_pool = memcached_servers_parse("10.0.1.1:11211,10.0.1.2:11211,10.0.1.3:11211,10.0.1.4:11211,10.0.1.5:11211,10.0.1.6:11211,10.0.1.7:11211,10.0.1.8:11211,192.168.1.1:11211,192.168.100.1:11211"); @@ -4865,19 +4868,17 @@ static test_return_t ketama_compatibility_libmemcached(memcached_st *trash) (void)trash; memc= memcached_create(NULL); - assert(memc); + test_truth(memc); rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); - assert(value == 1); + test_truth(value == 1); - assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE, - MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED) == MEMCACHED_SUCCESS); + test_truth(memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) == MEMCACHED_SUCCESS); + test_truth(memcached_behavior_get_distribution(memc) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA); - assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE) == - MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED); server_pool = memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); memcached_server_push(memc, server_pool); @@ -4924,19 +4925,16 @@ static test_return_t ketama_compatibility_spymemcached(memcached_st *trash) (void)trash; memc= memcached_create(NULL); - assert(memc); + test_truth(memc); rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED); - assert(value == 1); - - assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE, - MEMCACHED_KETAMA_COMPAT_SPY) == MEMCACHED_SUCCESS); + test_truth(value == 1); - assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE) == - MEMCACHED_KETAMA_COMPAT_SPY); + test_truth(memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY) == MEMCACHED_SUCCESS); + test_truth(memcached_behavior_get_distribution(memc) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY); server_pool = memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100"); memcached_server_push(memc, server_pool); diff --git a/tests/test.h b/tests/test.h index 064dc0b2..d74038c2 100644 --- a/tests/test.h +++ b/tests/test.h @@ -126,7 +126,7 @@ void create_core(void); do \ { \ if (! (A)) { \ - fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ + fprintf(stderr, "\nAssertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ create_core(); \ return TEST_FAILURE; \ } \ @@ -136,7 +136,7 @@ do \ do \ { \ if ((A)) { \ - fprintf(stderr, "Assertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ + fprintf(stderr, "\nAssertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\ create_core(); \ return TEST_FAILURE; \ } \ @@ -147,7 +147,7 @@ do \ { \ if (strcmp((A), (B))) \ { \ - fprintf(stderr, "%d", __LINE__); \ + fprintf(stderr, "\n%s:%d: %s -> %s\n", __FILE__, __LINE__, (A), (B)); \ create_core(); \ return TEST_FAILURE; \ } \ -- 2.30.2