From: mike tsai Date: Thu, 22 Oct 2009 22:53:58 +0000 (-0700) Subject: Added a new test called output_ketama_weighted_keys. It prints the hashing result X-Git-Tag: 0.35~5^2~1^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=1772068739e47eb45a8a7cebe9f594c6334b182f;p=m6w6%2Flibmemcached Added a new test called output_ketama_weighted_keys. It prints the hashing result for hashing keys 0-9999 and outputs a file called ketama_keys.test. We can then use this file to test ketama hashing in other libraries like spymemcached. With a new class I just checked in called KetamaKeysTest (must download source from github). javac -cp target/classes src/test/manual/net/spy/memcached/test/KetamaKeysTest.java java -cp target/test/classes:target/classes:src/test/manual net.spy.memcached.test.KetamaKeysTest > ketama_keys.txt To test the ketama hashing is working the same for both libraries, I ran this command: $ cmp ketama_keys.txt /sandbox/b-server-3-4/srcroot/svr/import/common/java/java-memcached-client/ketama_keys.txt --- diff --git a/tests/function.c b/tests/function.c index 2bc0192b..affa176f 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2756,6 +2756,57 @@ static test_return_t auto_eject_hosts(memcached_st *trash) return TEST_SUCCESS; } +static test_return_t output_ketama_weighted_keys(memcached_st *trash) +{ + (void) trash; + + memcached_return rc; + memcached_st *memc= memcached_create(NULL); + assert(memc); + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1); + assert(rc == MEMCACHED_SUCCESS); + + uint64_t 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); + + 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"); + memcached_server_push(memc, server_pool); + + FILE *fp; + if ((fp = fopen("ketama_keys.txt", "w"))) + { + // noop + } else { + printf("cannot write to file ketama_keys.txt"); + return TEST_FAILURE; + } + + for (int x= 0; x < 10000; x++) + { + char key[10]; + sprintf(key, "%d", x); + + uint32_t server_idx = memcached_generate_hash(memc, key, strlen(key)); + char *hostname = memc->hosts[server_idx].hostname; + unsigned int port = memc->hosts[server_idx].port; + fprintf(fp, "key %s is on host /%s:%u\n", key, hostname, port); + } + fclose(fp); + memcached_server_list_free(server_pool); + memcached_free(memc); + + return TEST_SUCCESS; +} + + static test_return_t result_static(memcached_st *memc) { memcached_result_st result; @@ -5217,6 +5268,7 @@ test_st hsieh_availability[] ={ test_st ketama_auto_eject_hosts[] ={ {"auto_eject_hosts", 1, auto_eject_hosts }, + {"output_ketama_weighted_keys", 1, output_ketama_weighted_keys }, {0, 0, 0} }; diff --git a/tests/ketama_test_cases.h b/tests/ketama_test_cases.h index a0d72b08..fb6f03d8 100644 --- a/tests/ketama_test_cases.h +++ b/tests/ketama_test_cases.h @@ -6,103 +6,103 @@ typedef struct { } TestCase; static TestCase test_cases[99] = { - { "SVa_]_V41)", 443691461UL, 445379617UL, "10.0.1.7" }, - { "*/Z;?V(.\\8", 1422915503UL, 1428303028UL, "10.0.1.1" }, + { "SVa_]_V41)", 443691461UL, 445379617UL, "10.0.1.2" }, + { "*/Z;?V(.\\8", 1422915503UL, 1428303028UL, "10.0.1.4" }, { "30C1*Z*S/_", 1473165754UL, 1480075959UL, "10.0.1.2" }, { "ERR:EC58G>", 2148406511UL, 2168579133UL, "10.0.1.7" }, - { "1I=cTMNTKF", 2882686667UL, 2885206587UL, "10.0.1.5" }, + { "1I=cTMNTKF", 2882686667UL, 2885206587UL, "10.0.1.4" }, { "]VG<`I*Z8)", 1103544263UL, 1104827657UL, "10.0.1.5" }, - { "UUTC`-V159", 3716288206UL, 3727224240UL, "10.0.1.5" }, - { "@7RU6C6T+Z", 3862737685UL, 3871917949UL, "10.0.1.5" }, - { "/XLN0@+36;", 1623269830UL, 1627683651UL, "10.0.1.1" }, - { "4(`X;\\V.^c", 373546328UL, 383925769UL, "10.0.1.1" }, - { "726bW=9*a4", 4213440020UL, 4213950705UL, "10.0.1.7" }, - { "\\`)32", 536016577UL, 539988520UL, "10.0.1.7" }, { "U))Fb-(`,.", 4128682289UL, 4136854163UL, "10.0.1.7" }, { "R-08RNTaRT", 3718170086UL, 3727224240UL, "10.0.1.5" }, - { "(LHcO203I3", 1007779411UL, 1014643570UL, "10.0.1.5" }, - { "=256P+;Qc8", 3976201210UL, 3976304873UL, "10.0.1.5" }, - { "OI5XZ_BBT(", 2155922164UL, 2168579133UL, "10.0.1.7" }, - { "2TLRL/UL;:", 1086800909UL, 1095659802UL, "10.0.1.7" }, - { "WHD\\O1`ZRW", 3087923411UL, 3095471560UL, "10.0.1.5" }, - { ".=54)_c;=T", 2497691631UL, 2502731301UL, "10.0.1.1" }, - { ";GE`)FT\\4", 580747448UL, 581063326UL, "10.0.1.2" }, - { "HZAU*;P*N]", 2564670474UL, 2565697267UL, "10.0.1.7" }, + { "(LHcO203I3", 1007779411UL, 1014643570UL, "10.0.1.1" }, + { "=256P+;Qc8", 3976201210UL, 3976304873UL, "10.0.1.3" }, + { "OI5XZ_BBT(", 2155922164UL, 2168579133UL, "10.0.1.5" }, + { "2TLRL/UL;:", 1086800909UL, 1095659802UL, "10.0.1.2" }, + { "WHD\\O1`ZRW", 3087923411UL, 3095471560UL, "10.0.1.1" }, + { ".=54)_c;=T", 2497691631UL, 2502731301UL, "10.0.1.6" }, + { ";GE`)FT\\4", 580747448UL, 581063326UL, "10.0.1.5" }, + { "HZAU*;P*N]", 2564670474UL, 2565697267UL, "10.0.1.1" }, { "NZ@ZE=O84_", 533335275UL, 539988520UL, "10.0.1.7" }, - { "6,cEI`F_P>", 3972869246UL, 3974773167UL, "10.0.1.6" }, - { "c,5AQ/T5)6", 2835605783UL, 2847870057UL, "10.0.1.8" }, - { ".O,>>BT)RX", 3857978174UL, 3871917949UL, "10.0.1.5" }, - { "XY\\X::LX50", 1749241099UL, 1752196488UL, "10.0.1.6" }, - { "+550F^/.01", 3781824099UL, 3783248219UL, "10.0.1.6" }, + { "6,cEI`F_P>", 3972869246UL, 3974773167UL, "10.0.1.3" }, + { "c,5AQ/T5)6", 2835605783UL, 2847870057UL, "10.0.1.7" }, + { ".O,>>BT)RX", 3857978174UL, 3871917949UL, "10.0.1.7" }, + { "XY\\X::LX50", 1749241099UL, 1752196488UL, "10.0.1.7" }, + { "+550F^/.01", 3781824099UL, 3783248219UL, "10.0.1.2" }, { "<.X9E2S5+9", 3232479481UL, 3234387706UL, "10.0.1.7" }, - { "]\\.UH8_0a1", 2419699252UL, 2423002920UL, "10.0.1.4" }, - { "8(6=(T0/Z0", 728266737UL, 729026070UL, "10.0.1.7" }, - { "8*6a;Sc*X+", 4223431086UL, 4230156966UL, "10.0.1.2" }, - { "J5/", 2776949824UL, 2784182515UL, "10.0.1.7" }, - { "[>RZHG97Q9", 71954686UL, 72034069UL, "10.0.1.6" }, - { "J3/G[)9<^Z", 2799896459UL, 2805183696UL, "10.0.1.7" }, - { "N-)88>[O`,", 50404102UL, 51792557UL, "10.0.1.5" }, + { "aPb3E1WD4K", 2500489218UL, 2502731301UL, "10.0.1.2" }, + { "?@12R<=1BH", 1494795329UL, 1502505505UL, "10.0.1.1" }, + { "QR(a+Q=1FU", 3238535074UL, 3238996435UL, "10.0.1.5" }, + { "`C9^FV,960", 2628553463UL, 2628733766UL, "10.0.1.3" }, + { "UNHVP..^8H", 977096483UL, 977319837UL, "10.0.1.6" }, + { ":Y.2W2[(35", 2777083668UL, 2784182515UL, "10.0.1.6" }, + { "M/HV^_HZ4O", 3623390946UL, 3624445007UL, "10.0.1.4" }, + { "ZY16KQJ5/", 2776949824UL, 2784182515UL, "10.0.1.6" }, + { "[>RZHG97Q9", 71954686UL, 72034069UL, "10.0.1.4" }, + { "J3/G[)9<^Z", 2799896459UL, 2805183696UL, "10.0.1.6" }, + { "N-)88>[O`,", 50404102UL, 51792557UL, "10.0.1.2" }, { "NP:=FR\\OaA", 3837333776UL, 3837792034UL, "10.0.1.7" }, - { "`@L+W;a,O[", 1512157148UL, 1522285852UL, "10.0.1.6" }, - { "W2`P:-+1T[", 2945171975UL, 2946196424UL, "10.0.1.5" }, - { "-6G7K^YDIN", 3168617340UL, 3170513015UL, "10.0.1.7" }, - { "U>*>9ZI6V5", 668514946UL, 674097631UL, "10.0.1.6" }, + { "`@L+W;a,O[", 1512157148UL, 1522285852UL, "10.0.1.5" }, + { "W2`P:-+1T[", 2945171975UL, 2946196424UL, "10.0.1.7" }, + { "-6G7K^YDIN", 3168617340UL, 3170513015UL, "10.0.1.5" }, + { "U>*>9ZI6V5", 668514946UL, 674097631UL, "10.0.1.5" }, { ".I?^6Ic9RK", 938419020UL, 942832691UL, "10.0.1.6" }, - { "0OZH^9BKM[", 3682518606UL, 3686781297UL, "10.0.1.8" }, - { "5?50UGZ:ML", 868610882UL, 869425986UL, "10.0.1.5" }, - { "?K2NF@3=IU", 381218851UL, 383925769UL, "10.0.1.1" }, - { "YI@G-2X?UB", 3688706179UL, 3693197681UL, "10.0.1.5" }, - { "7cY", 2590140172UL, 2598117636UL, "10.0.1.7" }, - { "\\[a\\^=V_M0", 689410119UL, 698690782UL, "10.0.1.6" }, + { "\\R^7=9UCG`", 126218373UL, 129199837UL, "10.0.1.6" }, + { "1bQS5]WOXB", 1853470245UL, 1855329369UL, "10.0.1.7" }, + { "M(@X^b[L:K", 3019630308UL, 3022260113UL, "10.0.1.4" }, + { "431cBF8,YO", 1679726993UL, 1685224295UL, "10.0.1.1" }, + { "(bEIQJ:E./", 2922607787UL, 2925521819UL, "10.0.1.7" }, + { "WS/3H*)7F;", 419488232UL, 422140585UL, "10.0.1.3" }, + { "ZJF[Ia6Q)+", 3960568056UL, 3962489998UL, "10.0.1.5" }, + { "<]*QCK8U,>", 2590140172UL, 2598117636UL, "10.0.1.5" }, + { "\\[a\\^=V_M0", 689410119UL, 698690782UL, "10.0.1.7" }, { "7;RM+8J9YC", 1530175299UL, 1531107082UL, "10.0.1.7" }, - { "4*=.SPR[AV", 3928582722UL, 3928853792UL, "10.0.1.1" }, + { "4*=.SPR[AV", 3928582722UL, 3928853792UL, "10.0.1.3" }, { "-2F+^88P4U", 3023552752UL, 3025823613UL, "10.0.1.7" }, - { "X;-F`(N?9D", 570465234UL, 572485994UL, "10.0.1.7" }, - { "R=F_D-K2a]", 1287750228UL, 1290935562UL, "10.0.1.7" }, - { "X*+2aaC.EG", 3200948713UL, 3201088518UL, "10.0.1.5" }, - { "[1ZXONX2]a", 4108881567UL, 4109865744UL, "10.0.1.4" }, - { "FL;\\GWacaV", 458449508UL, 467374054UL, "10.0.1.4" }, - { "\\MQ_XNT7L-", 1259349383UL, 1259509450UL, "10.0.1.7" }, - { "VD6D0]ba_\\", 3842502950UL, 3842588691UL, "10.0.1.1" }, + { "X;-F`(N?9D", 570465234UL, 572485994UL, "10.0.1.5" }, + { "R=F_D-K2a]", 1287750228UL, 1290935562UL, "10.0.1.1" }, + { "X*+2aaC.EG", 3200948713UL, 3201088518UL, "10.0.1.3" }, + { "[1ZXONX2]a", 4108881567UL, 4109865744UL, "10.0.1.7" }, + { "FL;\\GWacaV", 458449508UL, 467374054UL, "10.0.1.7" }, + { "\\MQ_XNT7L-", 1259349383UL, 1259509450UL, "10.0.1.5" }, + { "VD6D0]ba_\\", 3842502950UL, 3842588691UL, "10.0.1.7" }, };