X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fmem_functions.c;h=cf48940bbeca39573c0d9428fe70bd1f7a6c980c;hb=d590ead1014a271bd96bebd5790f1bf8818e5cab;hp=700003f3b43d77ce4ff5d2fd00b6bb8d3bedd392;hpb=c7f0791996a3814f4de76ba933890264a63feb99;p=awesomized%2Flibmemcached diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 700003f3..cf48940b 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -258,8 +258,8 @@ static test_return_t clone_test(memcached_st *memc) test_true(memc_clone->flags.randomize_replica_read == memc->flags.randomize_replica_read); } test_true(memc_clone->get_key_failure == memc->get_key_failure); - test_true(memc_clone->hash == memc->hash); - test_true(memc_clone->distribution_hash == memc->distribution_hash); + test_true(hashkit_compare(&memc_clone->hashkit, &memc->hashkit)); + test_true(hashkit_compare(&memc_clone->distribution_hashkit, &memc->distribution_hashkit)); test_true(memc_clone->io_bytes_watermark == memc->io_bytes_watermark); test_true(memc_clone->io_msg_watermark == memc->io_msg_watermark); test_true(memc_clone->io_key_prefetch == memc->io_key_prefetch); @@ -332,16 +332,21 @@ static test_return_t error_test(memcached_st *memc) 4269430871U, 610793021U, 527273862U, 1437122909U, 2300930706U, 2943759320U, 674306647U, 2400528935U, 54481931U, 4186304426U, 1741088401U, 2979625118U, - 4159057246U, 3425930182U, 2593724503U}; + 4159057246U, 3425930182U, 2593724503U, 1868899624U}; // You have updated the memcache_error messages but not updated docs/tests. - test_true(MEMCACHED_MAXIMUM_RETURN == 39); + test_true(MEMCACHED_MAXIMUM_RETURN == 40); for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++) { uint32_t hash_val; const char *msg= memcached_strerror(memc, rc); hash_val= memcached_generate_hash_value(msg, strlen(msg), MEMCACHED_HASH_JENKINS); + if (values[rc] != hash_val) + { + fprintf(stderr, "\n\nYou have updated memcached_return_t without updating the error_test\n"); + fprintf(stderr, "%u, %s, (%u)\n\n", (uint32_t)rc, memcached_strerror(memc, rc), hash_val); + } test_true(values[rc] == hash_val); } @@ -473,7 +478,7 @@ static test_return_t cas2_test(memcached_st *memc) results= memcached_fetch_result(memc, &results_obj, &rc); test_true(results); - test_true(results->cas); + test_true(results->item_cas); test_true(rc == MEMCACHED_SUCCESS); test_true(memcached_result_cas(results)); @@ -3399,8 +3404,13 @@ static test_return_t pre_cork(memcached_st *memc) { memcached_return_t rc; bool set= true; + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CORK, set); +#ifdef __APPLE__ + return TEST_SKIPPED; +#endif + if (rc == MEMCACHED_SUCCESS) return TEST_SUCCESS; @@ -3413,6 +3423,10 @@ static test_return_t pre_cork_and_nonblock(memcached_st *memc) rc= pre_cork(memc); +#ifdef __APPLE__ + return TEST_SKIPPED; +#endif + if (rc != TEST_SUCCESS) return rc; @@ -4906,6 +4920,22 @@ static test_return_t hsieh_avaibility_test (memcached_st *memc) return TEST_SUCCESS; } +static test_return_t one_at_a_time_run (memcached_st *memc __attribute__((unused))) +{ + uint32_t x; + const char **ptr; + + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_DEFAULT); + test_true(one_at_a_time_values[x] == hash_val); + } + + return TEST_SUCCESS; +} + static test_return_t md5_run (memcached_st *memc __attribute__((unused))) { uint32_t x; @@ -5056,6 +5086,81 @@ static test_return_t jenkins_run (memcached_st *memc __attribute__((unused))) return TEST_SUCCESS; } +static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *context) +{ + (void)context; + return libhashkit_md5(string, string_length); +} + +static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *context) +{ + (void)context; + return libhashkit_crc32(string, string_length); +} + +static test_return_t memcached_get_hashkit_test (memcached_st *memc) +{ + uint32_t x; + const char **ptr; + hashkit_st *kit; + hashkit_return_t hash_rc; + + uint32_t md5_hosts[]= {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U}; + uint32_t crc_hosts[]= {2U, 4U, 1U, 0U, 2U, 4U, 4U, 4U, 1U, 2U, 3U, 4U, 3U, 4U, 1U, 3U, 3U, 2U, 0U, 0U, 0U, 1U, 2U, 4U, 0U}; + + kit= memcached_get_hashkit(memc); + + hash_rc= hashkit_set_custom_function(kit, hash_md5_test_function, NULL); + test_true(hash_rc == HASHKIT_SUCCESS); + + /* + Verify Setting the hash. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= hashkit_digest(kit, *ptr, strlen(*ptr)); + test_true(md5_values[x] == hash_val); + } + + + /* + Now check memcached_st. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr)); + test_true(md5_hosts[x] == hash_val); + } + + hash_rc= hashkit_set_custom_function(kit, hash_crc_test_function, NULL); + test_true(hash_rc == HASHKIT_SUCCESS); + + /* + Verify Setting the hash. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= hashkit_digest(kit, *ptr, strlen(*ptr)); + test_true(crc_values[x] == hash_val); + } + + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr)); + test_true(crc_hosts[x] == hash_val); + } + + return TEST_SUCCESS; +} + static test_return_t ketama_compatibility_libmemcached(memcached_st *trash) { @@ -5973,6 +6078,7 @@ test_st ketama_auto_eject_hosts[] ={ }; test_st hash_tests[] ={ + {"one_at_a_time_run", 0, (test_callback_fn)one_at_a_time_run }, {"md5", 0, (test_callback_fn)md5_run }, {"crc", 0, (test_callback_fn)crc_run }, {"fnv1_64", 0, (test_callback_fn)fnv1_64_run }, @@ -5982,6 +6088,7 @@ test_st hash_tests[] ={ {"hsieh", 0, (test_callback_fn)hsieh_run }, {"murmur", 0, (test_callback_fn)murmur_run }, {"jenkis", 0, (test_callback_fn)jenkins_run }, + {"memcached_get_hashkit", 0, (test_callback_fn)memcached_get_hashkit_test }, {0, 0, (test_callback_fn)0} };