X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ffunction.c;h=0b2c15d480035539fedb8bb3a2deadf9cb76552e;hb=ed1af1f5b70f7da90f5e8d255df134a8ccf3f526;hp=9c57ec4da926720d39eb250ab201bf993c6113d9;hpb=46c20d43fbb4f84f30e06a55702c58c17f498d0e;p=awesomized%2Flibmemcached diff --git a/tests/function.c b/tests/function.c index 9c57ec4d..0b2c15d4 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2,7 +2,6 @@ Sample test application. */ #include -#include #include #include #include @@ -11,18 +10,30 @@ #include #include #include -#include "../lib/common.h" -#include "../src/generator.h" -#include "../src/execute.h" +#include "server.h" +#include "../clients/generator.h" +#include "../clients/execute.h" + +#ifndef INT64_MAX +#define INT64_MAX LONG_MAX +#endif +#ifndef INT32_MAX +#define INT32_MAX INT_MAX +#endif + #include "test.h" -#define GLOBAL_COUNT 100000 +#define GLOBAL_COUNT 10000 +#define GLOBAL2_COUNT 100 +#define SERVERS_TO_CREATE 5 +static uint32_t global_count; + static pairs_st *global_pairs; static char *global_keys[GLOBAL_COUNT]; static size_t global_keys_length[GLOBAL_COUNT]; -uint8_t init_test(memcached_st *not_used) +test_return init_test(memcached_st *not_used) { memcached_st memc; @@ -32,7 +43,143 @@ uint8_t init_test(memcached_st *not_used) return 0; } -uint8_t allocation_test(memcached_st *not_used) +test_return server_list_null_test(memcached_st *ptr) +{ + memcached_server_st *server_list; + memcached_return rc; + + server_list= memcached_server_list_append(NULL, NULL, 0, NULL); + assert(server_list == NULL); + + server_list= memcached_server_list_append(NULL, "localhost", 0, NULL); + assert(server_list == NULL); + + server_list= memcached_server_list_append(NULL, NULL, 0, &rc); + assert(server_list == NULL); + + return 0; +} + +#define TEST_PORT_COUNT 7 +uint32_t test_ports[TEST_PORT_COUNT]; + +memcached_return server_display_function(memcached_st *ptr, memcached_server_st *server, void *context) +{ + /* Do Nothing */ + uint32_t bigger= *((uint32_t *)(context)); + assert(bigger <= server->port); + *((uint32_t *)(context))= server->port; + + return MEMCACHED_SUCCESS; +} + +test_return server_sort_test(memcached_st *ptr) +{ + uint8_t x; + 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); + memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1); + + 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_function; + memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1); + + + memcached_free(local_memc); + + 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 */ + uint32_t x= *((uint32_t *)(context)); + + assert(test_ports[x] == server->port); + *((uint32_t *)(context))= ++x; + + return MEMCACHED_SUCCESS; +} + +test_return 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; +} + +test_return allocation_test(memcached_st *not_used) { memcached_st *memc; memc= memcached_create(NULL); @@ -42,7 +189,7 @@ uint8_t allocation_test(memcached_st *not_used) return 0; } -uint8_t clone_test(memcached_st *memc) +test_return clone_test(memcached_st *memc) { /* All null? */ { @@ -81,7 +228,7 @@ uint8_t clone_test(memcached_st *memc) return 0; } -uint8_t connection_test(memcached_st *memc) +test_return connection_test(memcached_st *memc) { memcached_return rc; @@ -91,7 +238,7 @@ uint8_t connection_test(memcached_st *memc) return 0; } -uint8_t error_test(memcached_st *memc) +test_return error_test(memcached_st *memc) { memcached_return rc; @@ -103,7 +250,7 @@ uint8_t error_test(memcached_st *memc) return 0; } -uint8_t set_test(memcached_st *memc) +test_return set_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -111,36 +258,36 @@ uint8_t set_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); return 0; } -uint8_t append_test(memcached_st *memc) +test_return append_test(memcached_st *memc) { memcached_return rc; char *key= "fig"; char *value= "we"; size_t value_length; - uint16_t flags; + uint32_t flags; rc= memcached_flush(memc, 0); assert(rc == MEMCACHED_SUCCESS); rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); rc= memcached_append(memc, key, strlen(key), " the", strlen(" the"), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); rc= memcached_append(memc, key, strlen(key), " people", strlen(" people"), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); value= memcached_get(memc, key, strlen(key), @@ -153,7 +300,7 @@ uint8_t append_test(memcached_st *memc) return 0; } -uint8_t append_binary_test(memcached_st *memc) +test_return append_binary_test(memcached_st *memc) { memcached_return rc; char *key= "numbers"; @@ -161,7 +308,7 @@ uint8_t append_binary_test(memcached_st *memc) unsigned int store_list[] = { 23, 56, 499, 98, 32847, 0 }; char *value; size_t value_length; - uint16_t flags; + uint32_t flags; unsigned int x; rc= memcached_flush(memc, 0); @@ -170,7 +317,7 @@ uint8_t append_binary_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), NULL, 0, - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); for (x= 0; store_list[x] ; x++) @@ -178,7 +325,7 @@ uint8_t append_binary_test(memcached_st *memc) rc= memcached_append(memc, key, strlen(key), (char *)&store_list[x], sizeof(unsigned int), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); } @@ -199,7 +346,7 @@ uint8_t append_binary_test(memcached_st *memc) return 0; } -uint8_t cas2_test(memcached_st *memc) +test_return cas2_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -214,13 +361,13 @@ uint8_t cas2_test(memcached_st *memc) rc= memcached_flush(memc, 0); assert(rc == MEMCACHED_SUCCESS); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, &set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set); for (x= 0; x < 3; x++) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], - (time_t)50, (uint16_t)9); + (time_t)50, (uint32_t)9); assert(rc == MEMCACHED_SUCCESS); } @@ -243,7 +390,7 @@ uint8_t cas2_test(memcached_st *memc) return 0; } -uint8_t cas_test(memcached_st *memc) +test_return cas_test(memcached_st *memc) { memcached_return rc; char *key= "fun"; @@ -257,11 +404,11 @@ uint8_t cas_test(memcached_st *memc) rc= memcached_flush(memc, 0); assert(rc == MEMCACHED_SUCCESS); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, &set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set); rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); rc= memcached_mget(memc, &key, &key_length, 1); @@ -277,35 +424,48 @@ uint8_t cas_test(memcached_st *memc) assert(strlen("we the people") == value_length); assert(rc == MEMCACHED_SUCCESS); + rc= memcached_cas(memc, key, key_length, + "change the value", strlen("change the value"), + 0, 0, memcached_result_cas(results)); + + assert(rc == MEMCACHED_SUCCESS); + + rc= memcached_cas(memc, key, key_length, + "change the value", strlen("change the value"), + 0, 0, 23); + + assert(rc == MEMCACHED_DATA_EXISTS); + + memcached_result_free(&results_obj); return 0; } -uint8_t prepend_test(memcached_st *memc) +test_return prepend_test(memcached_st *memc) { memcached_return rc; char *key= "fig"; char *value= "people"; size_t value_length; - uint16_t flags; + uint32_t flags; rc= memcached_flush(memc, 0); assert(rc == MEMCACHED_SUCCESS); rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); rc= memcached_prepend(memc, key, strlen(key), "the ", strlen("the "), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); rc= memcached_prepend(memc, key, strlen(key), "we ", strlen("we "), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); value= memcached_get(memc, key, strlen(key), @@ -322,40 +482,64 @@ uint8_t prepend_test(memcached_st *memc) Set the value, then quit to make sure it is flushed. Come back in and test that add fails. */ -uint8_t add_test(memcached_st *memc) +test_return add_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; char *value= "when we sanitize"; + unsigned long long setting_value; + + setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK); rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); memcached_quit(memc); rc= memcached_add(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_NOTSTORED); + (time_t)0, (uint32_t)0); + + /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */ + if (setting_value) + assert(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED); + else + assert(rc == MEMCACHED_NOTSTORED); return 0; } -uint8_t replace_test(memcached_st *memc) +test_return add_wrapper(memcached_st *memc) +{ + unsigned int x; + + for (x= 0; x < 10000; x++) + add_test(memc); + + return 0; +} + +test_return replace_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; char *value= "when we sanitize"; + char *original= "first we insert some data"; + + rc= memcached_set(memc, key, strlen(key), + original, strlen(original), + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); rc= memcached_replace(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); return 0; } -uint8_t delete_test(memcached_st *memc) +test_return delete_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -363,16 +547,16 @@ uint8_t delete_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); rc= memcached_delete(memc, key, strlen(key), (time_t)0); - assert(rc == MEMCACHED_SUCCESS); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); return 0; } -uint8_t flush_test(memcached_st *memc) +test_return flush_test(memcached_st *memc) { memcached_return rc; @@ -382,16 +566,161 @@ uint8_t flush_test(memcached_st *memc) return 0; } -uint8_t get_test(memcached_st *memc) +memcached_return server_function(memcached_st *ptr, memcached_server_st *server, void *context) +{ + /* Do Nothing */ + + return MEMCACHED_SUCCESS; +} + +test_return memcached_server_cursor_test(memcached_st *memc) +{ + char *context= "foo bad"; + memcached_server_function callbacks[1]; + + callbacks[0]= server_function; + memcached_server_cursor(memc, callbacks, context, 1); + + return 0; +} + +test_return bad_key_test(memcached_st *memc) +{ + memcached_return rc; + char *key= "foo bad"; + char *string; + size_t string_length; + uint32_t flags; + memcached_st *clone; + unsigned int set= 1; + + clone= memcached_clone(NULL, memc); + assert(clone); + + 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_BAD_KEY_PROVIDED); + assert(string_length == 0); + assert(!string); + + set= 0; + 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; +} + +#define READ_THROUGH_VALUE "set for me" +memcached_return read_through_trigger(memcached_st *memc, + char *key, size_t key_length, + memcached_result_st *result) +{ + + return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE)); +} + +test_return read_through(memcached_st *memc) +{ + memcached_return rc; + char *key= "foo"; + char *string; + size_t string_length; + uint32_t flags; + + string= memcached_get(memc, key, strlen(key), + &string_length, &flags, &rc); + + assert(rc == MEMCACHED_NOTFOUND); + assert(string_length == 0); + assert(!string); + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, read_through_trigger); + assert(rc == MEMCACHED_SUCCESS); + + string= memcached_get(memc, key, strlen(key), + &string_length, &flags, &rc); + + 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); + + assert(rc == MEMCACHED_SUCCESS); + assert(string_length == strlen(READ_THROUGH_VALUE)); + assert(!strcmp(READ_THROUGH_VALUE, string)); + free(string); + + return 0; +} + +memcached_return delete_trigger(memcached_st *ptr, const char *key, size_t key_length) +{ + assert(key); + + return MEMCACHED_SUCCESS; +} + +test_return delete_through(memcached_st *memc) +{ + memcached_trigger_delete_key callback; + memcached_return rc; + + callback= delete_trigger; + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, callback); + assert(rc == MEMCACHED_SUCCESS); + + return 0; +} + +test_return get_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; char *string; size_t string_length; - uint16_t flags; + uint32_t flags; rc= memcached_delete(memc, key, strlen(key), (time_t)0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND); + assert(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND); string= memcached_get(memc, key, strlen(key), &string_length, &flags, &rc); @@ -403,19 +732,19 @@ uint8_t get_test(memcached_st *memc) return 0; } -uint8_t get_test2(memcached_st *memc) +test_return get_test2(memcached_st *memc) { memcached_return rc; char *key= "foo"; char *value= "when we sanitize"; char *string; size_t string_length; - uint16_t flags; + uint32_t flags; rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); string= memcached_get(memc, key, strlen(key), &string_length, &flags, &rc); @@ -430,7 +759,7 @@ uint8_t get_test2(memcached_st *memc) return 0; } -uint8_t set_test2(memcached_st *memc) +test_return set_test2(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -442,14 +771,14 @@ uint8_t set_test2(memcached_st *memc) { rc= memcached_set(memc, key, strlen(key), value, value_length, - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } return 0; } -uint8_t set_test3(memcached_st *memc) +test_return set_test3(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -467,8 +796,8 @@ uint8_t set_test3(memcached_st *memc) { rc= memcached_set(memc, key, strlen(key), value, value_length, - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } free(value); @@ -476,7 +805,7 @@ uint8_t set_test3(memcached_st *memc) return 0; } -uint8_t get_test3(memcached_st *memc) +test_return get_test3(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -484,7 +813,7 @@ uint8_t get_test3(memcached_st *memc) size_t value_length= 8191; char *string; size_t string_length; - uint16_t flags; + uint32_t flags; int x; value = (char*)malloc(value_length); @@ -495,8 +824,8 @@ uint8_t get_test3(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, value_length, - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); string= memcached_get(memc, key, strlen(key), &string_length, &flags, &rc); @@ -512,7 +841,7 @@ uint8_t get_test3(memcached_st *memc) return 0; } -uint8_t get_test4(memcached_st *memc) +test_return get_test4(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -520,7 +849,7 @@ uint8_t get_test4(memcached_st *memc) size_t value_length= 8191; char *string; size_t string_length; - uint16_t flags; + uint32_t flags; int x; value = (char*)malloc(value_length); @@ -531,8 +860,8 @@ uint8_t get_test4(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, value_length, - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); for (x= 0; x < 10; x++) { @@ -552,7 +881,7 @@ uint8_t get_test4(memcached_st *memc) } /* Do not copy the style of this code, I just access hosts to testthis function */ -uint8_t stats_servername_test(memcached_st *memc) +test_return stats_servername_test(memcached_st *memc) { memcached_return rc; memcached_stat_st stat; @@ -563,7 +892,7 @@ uint8_t stats_servername_test(memcached_st *memc) return 0; } -uint8_t increment_test(memcached_st *memc) +test_return increment_test(memcached_st *memc) { uint64_t new_number; memcached_return rc; @@ -572,8 +901,8 @@ uint8_t increment_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); rc= memcached_increment(memc, key, strlen(key), 1, &new_number); @@ -588,7 +917,7 @@ uint8_t increment_test(memcached_st *memc) return 0; } -uint8_t decrement_test(memcached_st *memc) +test_return decrement_test(memcached_st *memc) { uint64_t new_number; memcached_return rc; @@ -597,8 +926,8 @@ uint8_t decrement_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)0, (uint16_t)0); - assert(rc == MEMCACHED_SUCCESS); + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); rc= memcached_decrement(memc, key, strlen(key), 1, &new_number); @@ -613,7 +942,7 @@ uint8_t decrement_test(memcached_st *memc) return 0; } -uint8_t quit_test(memcached_st *memc) +test_return quit_test(memcached_st *memc) { memcached_return rc; char *key= "fudge"; @@ -621,19 +950,19 @@ uint8_t quit_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)10, (uint16_t)3); - assert(rc == MEMCACHED_SUCCESS); + (time_t)10, (uint32_t)3); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); memcached_quit(memc); rc= memcached_set(memc, key, strlen(key), value, strlen(value), - (time_t)50, (uint16_t)9); - assert(rc == MEMCACHED_SUCCESS); + (time_t)50, (uint32_t)9); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); return 0; } -uint8_t mget_result_test(memcached_st *memc) +test_return mget_result_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -667,8 +996,8 @@ uint8_t mget_result_test(memcached_st *memc) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], - (time_t)50, (uint16_t)9); - assert(rc == MEMCACHED_SUCCESS); + (time_t)50, (uint32_t)9); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } rc= memcached_mget(memc, keys, key_length, 3); @@ -690,7 +1019,7 @@ uint8_t mget_result_test(memcached_st *memc) return 0; } -uint8_t mget_result_alloc_test(memcached_st *memc) +test_return mget_result_alloc_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; @@ -717,8 +1046,8 @@ uint8_t mget_result_alloc_test(memcached_st *memc) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], - (time_t)50, (uint16_t)9); - assert(rc == MEMCACHED_SUCCESS); + (time_t)50, (uint32_t)9); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } rc= memcached_mget(memc, keys, key_length, 3); @@ -740,13 +1069,54 @@ uint8_t mget_result_alloc_test(memcached_st *memc) return 0; } -uint8_t mget_test(memcached_st *memc) +/* Count the results */ +unsigned int callback_counter(memcached_st *ptr, memcached_result_st *result, void *context) +{ + unsigned int *counter= (unsigned int *)context; + + *counter= *counter + 1; + + return 0; +} + +test_return mget_result_function(memcached_st *memc) +{ + memcached_return rc; + char *keys[]= {"fudge", "son", "food"}; + size_t key_length[]= {5, 3, 4}; + unsigned int x; + unsigned int counter; + memcached_execute_function callbacks[1]; + + /* We need to empty the server before continueing test */ + rc= memcached_flush(memc, 0); + for (x= 0; x < 3; x++) + { + rc= memcached_set(memc, keys[x], key_length[x], + keys[x], key_length[x], + (time_t)50, (uint32_t)9); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + } + + rc= memcached_mget(memc, keys, key_length, 3); + assert(rc == MEMCACHED_SUCCESS); + + callbacks[0]= &callback_counter; + counter= 0; + rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1); + + assert(counter == 3); + + return 0; +} + +test_return mget_test(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; size_t key_length[]= {5, 3, 4}; unsigned int x; - uint16_t flags; + uint32_t flags; char return_key[MEMCACHED_MAX_KEY]; size_t return_key_length; @@ -773,8 +1143,8 @@ uint8_t mget_test(memcached_st *memc) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], - (time_t)50, (uint16_t)9); - assert(rc == MEMCACHED_SUCCESS); + (time_t)50, (uint32_t)9); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } rc= memcached_mget(memc, keys, key_length, 3); @@ -795,7 +1165,7 @@ uint8_t mget_test(memcached_st *memc) return 0; } -uint8_t get_stats_keys(memcached_st *memc) +test_return get_stats_keys(memcached_st *memc) { char **list; char **ptr; @@ -805,7 +1175,7 @@ uint8_t get_stats_keys(memcached_st *memc) list= memcached_stat_get_keys(memc, &stat, &rc); assert(rc == MEMCACHED_SUCCESS); for (ptr= list; *ptr; ptr++) - printf("Found key %s\n", *ptr); + assert(*ptr); fflush(stdout); free(list); @@ -813,7 +1183,18 @@ uint8_t get_stats_keys(memcached_st *memc) return 0; } -uint8_t get_stats(memcached_st *memc) +test_return version_string_test(memcached_st *memc) +{ + const char *version_string; + + version_string= memcached_lib_version(); + + assert(!strcmp(version_string, LIBMEMCACHED_VERSION_STRING)); + + return 0; +} + +test_return get_stats(memcached_st *memc) { unsigned int x; char **list; @@ -841,7 +1222,7 @@ uint8_t get_stats(memcached_st *memc) return 0; } -uint8_t add_host_test(memcached_st *memc) +test_return add_host_test(memcached_st *memc) { unsigned int x; memcached_server_st *servers; @@ -873,42 +1254,91 @@ uint8_t add_host_test(memcached_st *memc) return 0; } -/* We don't test the behavior itself, we test the switches */ -uint8_t behavior_test(memcached_st *memc) +memcached_return clone_test_callback(memcached_st *parent, memcached_st *clone) { - unsigned long long value; - unsigned int set= 1; + return MEMCACHED_SUCCESS; +} - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set); - value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK); - assert(value == 1); +memcached_return cleanup_test_callback(memcached_st *ptr) +{ + return MEMCACHED_SUCCESS; +} - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set); - value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY); - assert(value == 1); +test_return callback_test(memcached_st *memc) +{ + /* Test User Data */ + { + int x= 5; + int *test_ptr; + memcached_return rc; - set= MEMCACHED_HASH_MD5; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set); - value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); - assert(value == MEMCACHED_HASH_MD5); + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_USER_DATA, &x); + assert(rc == MEMCACHED_SUCCESS); + test_ptr= (int *)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc); + assert(*test_ptr == x); + } - set= 0; + /* Test Clone Callback */ + { + memcached_clone_func temp_function; + memcached_return rc; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set); + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, clone_test_callback); + assert(rc == MEMCACHED_SUCCESS); + temp_function= (memcached_clone_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc); + assert(temp_function == clone_test_callback); + } + + /* Test Cleanup Callback */ + { + memcached_cleanup_func temp_function; + memcached_return rc; + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, cleanup_test_callback); + assert(rc == MEMCACHED_SUCCESS); + temp_function= (memcached_cleanup_func)memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc); + assert(temp_function == cleanup_test_callback); + } + + return 0; +} + +/* We don't test the behavior itself, we test the switches */ +test_return behavior_test(memcached_st *memc) +{ + unsigned long long value; + unsigned int set= 1; + + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, set); + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK); + assert(value == 1); + + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY); + assert(value == 1); + + set= MEMCACHED_HASH_MD5; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set); + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); + assert(value == MEMCACHED_HASH_MD5); + + set= 0; + + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, set); value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK); assert(value == 0); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY); assert(value == 0); set= MEMCACHED_HASH_DEFAULT; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set); value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); assert(value == MEMCACHED_HASH_DEFAULT); set= MEMCACHED_HASH_CRC; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set); value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH); assert(value == MEMCACHED_HASH_CRC); @@ -922,7 +1352,7 @@ uint8_t behavior_test(memcached_st *memc) } /* Test case provided by Cal Haldenbrand */ -uint8_t user_supplied_bug1(memcached_st *memc) +test_return user_supplied_bug1(memcached_st *memc) { unsigned int setter= 1; unsigned int x; @@ -938,8 +1368,8 @@ uint8_t user_supplied_bug1(memcached_st *memc) /* We just keep looking at the same values over and over */ srandom(10); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter); /* add key */ @@ -959,17 +1389,17 @@ uint8_t user_supplied_bug1(memcached_st *memc) rc = memcached_set(memc, key, strlen(key), randomstuff, strlen(randomstuff), 10, 0); /* If we fail, lets try again */ - if (rc != MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED) rc = memcached_set(memc, key, strlen(key), randomstuff, strlen(randomstuff), 10, 0); - assert(rc == MEMCACHED_SUCCESS); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } return 0; } /* Test case provided by Cal Haldenbrand */ -uint8_t user_supplied_bug2(memcached_st *memc) +test_return user_supplied_bug2(memcached_st *memc) { int errors; unsigned int setter; @@ -977,13 +1407,13 @@ uint8_t user_supplied_bug2(memcached_st *memc) unsigned long long total; setter= 1; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter); #ifdef NOT_YET setter = 20 * 1024576; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, setter); setter = 20 * 1024576; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, setter); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); @@ -994,7 +1424,7 @@ uint8_t user_supplied_bug2(memcached_st *memc) { memcached_return rc= MEMCACHED_SUCCESS; char buffer[SMALL_STRING_LEN]; - uint16_t flags= 0; + uint32_t flags= 0; size_t val_len= 0; char *getval; @@ -1008,7 +1438,10 @@ uint8_t user_supplied_bug2(memcached_st *memc) if (rc == MEMCACHED_NOTFOUND) errors++; else + { + WATCHPOINT_ERROR(rc); assert(0); + } continue; } @@ -1022,7 +1455,7 @@ uint8_t user_supplied_bug2(memcached_st *memc) /* Do a large mget() over all the keys we think exist */ #define KEY_COUNT 3000 // * 1024576 -uint8_t user_supplied_bug3(memcached_st *memc) +test_return user_supplied_bug3(memcached_st *memc) { memcached_return rc; unsigned int setter; @@ -1031,13 +1464,13 @@ uint8_t user_supplied_bug3(memcached_st *memc) size_t key_lengths[KEY_COUNT]; setter= 1; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter); #ifdef NOT_YET setter = 20 * 1024576; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, setter); setter = 20 * 1024576; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, setter); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE); getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE); #endif @@ -1063,7 +1496,7 @@ uint8_t user_supplied_bug3(memcached_st *memc) size_t return_key_length; char *return_value; size_t return_value_length; - uint16_t flags; + uint32_t flags; while ((return_value= memcached_fetch(memc, return_key, &return_key_length, &return_value_length, &flags, &rc))) @@ -1082,13 +1515,17 @@ uint8_t user_supplied_bug3(memcached_st *memc) } /* Make sure we behave properly if server list has no values */ -uint8_t user_supplied_bug4(memcached_st *memc) +test_return user_supplied_bug4(memcached_st *memc) { memcached_return rc; char *keys[]= {"fudge", "son", "food"}; size_t key_length[]= {5, 3, 4}; unsigned int x; - uint16_t flags; + uint32_t flags; + char return_key[MEMCACHED_MAX_KEY]; + size_t return_key_length; + char *return_value; + size_t return_value_length; /* Here we free everything before running a bunch of mget tests */ { @@ -1097,10 +1534,6 @@ uint8_t user_supplied_bug4(memcached_st *memc) memc->number_of_hosts= 0; } - char return_key[MEMCACHED_MAX_KEY]; - size_t return_key_length; - char *return_value; - size_t return_value_length; /* We need to empty the server before continueing test */ rc= memcached_flush(memc, 0); @@ -1122,7 +1555,7 @@ uint8_t user_supplied_bug4(memcached_st *memc) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], - (time_t)50, (uint16_t)9); + (time_t)50, (uint32_t)9); assert(rc == MEMCACHED_NO_SERVERS); } @@ -1145,7 +1578,7 @@ uint8_t user_supplied_bug4(memcached_st *memc) } #define VALUE_SIZE_BUG5 1048064 -uint8_t user_supplied_bug5(memcached_st *memc) +test_return user_supplied_bug5(memcached_st *memc) { memcached_return rc; char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"}; @@ -1154,7 +1587,7 @@ uint8_t user_supplied_bug5(memcached_st *memc) size_t return_key_length; char *value; size_t value_length; - uint16_t flags; + uint32_t flags; unsigned int count; unsigned int x; char insert_data[VALUE_SIZE_BUG5]; @@ -1178,7 +1611,7 @@ uint8_t user_supplied_bug5(memcached_st *memc) { rc= memcached_set(memc, keys[x], key_length[x], insert_data, VALUE_SIZE_BUG5, - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); } @@ -1203,7 +1636,7 @@ uint8_t user_supplied_bug5(memcached_st *memc) return 0; } -uint8_t user_supplied_bug6(memcached_st *memc) +test_return user_supplied_bug6(memcached_st *memc) { memcached_return rc; char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"}; @@ -1212,7 +1645,7 @@ uint8_t user_supplied_bug6(memcached_st *memc) size_t return_key_length; char *value; size_t value_length; - uint16_t flags; + uint32_t flags; unsigned int count; unsigned int x; char insert_data[VALUE_SIZE_BUG5]; @@ -1239,7 +1672,7 @@ uint8_t user_supplied_bug6(memcached_st *memc) { rc= memcached_set(memc, keys[x], key_length[x], insert_data, VALUE_SIZE_BUG5, - (time_t)0, (uint16_t)0); + (time_t)0, (uint32_t)0); assert(rc == MEMCACHED_SUCCESS); } @@ -1268,7 +1701,7 @@ uint8_t user_supplied_bug6(memcached_st *memc) return 0; } -uint8_t user_supplied_bug8(memcached_st *memc) +test_return user_supplied_bug8(memcached_st *memc) { memcached_return rc; memcached_st *mine; @@ -1299,7 +1732,7 @@ uint8_t user_supplied_bug8(memcached_st *memc) } /* Test flag store/retrieve */ -uint8_t user_supplied_bug7(memcached_st *memc) +test_return user_supplied_bug7(memcached_st *memc) { memcached_return rc; char *keys= "036790384900"; @@ -1308,7 +1741,7 @@ uint8_t user_supplied_bug7(memcached_st *memc) size_t return_key_length; char *value; size_t value_length; - uint16_t flags; + uint32_t flags; unsigned int x; char insert_data[VALUE_SIZE_BUG5]; @@ -1343,13 +1776,13 @@ uint8_t user_supplied_bug7(memcached_st *memc) return 0; } -uint8_t user_supplied_bug9(memcached_st *memc) +test_return user_supplied_bug9(memcached_st *memc) { memcached_return rc; char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"}; size_t key_length[3]; unsigned int x; - uint16_t flags; + uint32_t flags; unsigned count= 0; char return_key[MEMCACHED_MAX_KEY]; @@ -1367,7 +1800,7 @@ uint8_t user_supplied_bug9(memcached_st *memc) { rc= memcached_set(memc, keys[x], key_length[x], keys[x], key_length[x], - (time_t)50, (uint16_t)9); + (time_t)50, (uint32_t)9); assert(rc == MEMCACHED_SUCCESS); } @@ -1388,7 +1821,7 @@ uint8_t user_supplied_bug9(memcached_st *memc) } /* We are testing with aggressive timeout to get failures */ -uint8_t user_supplied_bug10(memcached_st *memc) +test_return user_supplied_bug10(memcached_st *memc) { char *key= "foo"; char *value; @@ -1400,10 +1833,10 @@ uint8_t user_supplied_bug10(memcached_st *memc) memcached_st *mclone= memcached_clone(NULL, memc); int32_t timeout; - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set); - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); timeout= 2; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); value = (char*)malloc(value_length * sizeof(char)); @@ -1414,7 +1847,7 @@ uint8_t user_supplied_bug10(memcached_st *memc) { rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_BUFFERED); if (rc == MEMCACHED_WRITE_FAILURE) x--; @@ -1429,7 +1862,7 @@ uint8_t user_supplied_bug10(memcached_st *memc) /* We are looking failures in the async protocol */ -uint8_t user_supplied_bug11(memcached_st *memc) +test_return user_supplied_bug11(memcached_st *memc) { char *key= "foo"; char *value; @@ -1441,12 +1874,12 @@ uint8_t user_supplied_bug11(memcached_st *memc) int32_t timeout; memcached_st *mclone= memcached_clone(NULL, memc); - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set); - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); timeout= -1; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout); + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); - timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); + timeout= (int32_t)memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); assert(timeout == -1); @@ -1458,9 +1891,6 @@ uint8_t user_supplied_bug11(memcached_st *memc) for (x= 1; x <= 100000; ++x) { rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0); - - WATCHPOINT_IFERROR(rc); - //assert(rc == MEMCACHED_SUCCESS); } free(value); @@ -1469,7 +1899,222 @@ uint8_t user_supplied_bug11(memcached_st *memc) return 0; } -uint8_t result_static(memcached_st *memc) +/* + Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist. +*/ +test_return user_supplied_bug12(memcached_st *memc) +{ + memcached_return rc; + uint32_t flags; + size_t value_length; + char *value; + uint64_t number_value; + + value= memcached_get(memc, "autoincrement", strlen("autoincrement"), + &value_length, &flags, &rc); + assert(value == NULL); + assert(rc == MEMCACHED_NOTFOUND); + + rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"), + 1, &number_value); + + assert(value == NULL); + assert(rc == MEMCACHED_NOTFOUND); + + rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0); + + value= memcached_get(memc, "autoincrement", strlen("autoincrement"), + &value_length, &flags, &rc); + assert(value); + assert(rc == MEMCACHED_SUCCESS); + free(value); + + rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"), + 1, &number_value); + assert(number_value == 2); + assert(rc == MEMCACHED_SUCCESS); + + return 0; +} + +/* + Bug found where command total one more than MEMCACHED_MAX_BUFFER + set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169 + */ +test_return user_supplied_bug13(memcached_st *memc) +{ + char key[] = "key34567890"; + char *overflow; + memcached_return rc; + size_t overflowSize; + + char commandFirst[]= "set key34567890 0 0 "; + char commandLast[] = " \r\n"; /* first line of command sent to server */ + size_t commandLength; + size_t testSize; + + commandLength = strlen(commandFirst) + strlen(commandLast) + 4; /* 4 is number of characters in size, probably 8196 */ + + overflowSize = MEMCACHED_MAX_BUFFER - commandLength; + + for (testSize= overflowSize - 1; testSize < overflowSize + 1; testSize++) + { + overflow= malloc(testSize); + assert(overflow != NULL); + + memset(overflow, 'x', testSize); + rc= memcached_set(memc, key, strlen(key), + overflow, testSize, 0, 0); + assert(rc == MEMCACHED_SUCCESS); + free(overflow); + } + + return 0; +} + + +/* + Test values of many different sizes + Bug found where command total one more than MEMCACHED_MAX_BUFFER + set key34567890 0 0 8169 \r\n + is sent followed by buffer of size 8169, followed by 8169 + */ +test_return user_supplied_bug14(memcached_st *memc) +{ + int setter= 1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter); + memcached_return rc; + char *key= "foo"; + char *value; + size_t value_length= 18000; + char *string; + size_t string_length; + uint32_t flags; + unsigned int x; + size_t current_length; + + value = (char*)malloc(value_length); + assert(value); + + for (x= 0; x < value_length; x++) + value[x] = (char) (x % 127); + + for (current_length= 0; current_length < value_length; current_length++) + { + rc= memcached_set(memc, key, strlen(key), + value, current_length, + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + + string= memcached_get(memc, key, strlen(key), + &string_length, &flags, &rc); + + assert(rc == MEMCACHED_SUCCESS); + assert(string_length == current_length); + assert(!memcmp(string, value, string_length)); + + free(string); + } + + free(value); + + return 0; +} + +/* + Look for zero length value problems + */ +test_return user_supplied_bug15(memcached_st *memc) +{ + uint32_t x; + memcached_return rc; + char *key= "mykey"; + char *value; + size_t length; + uint32_t flags; + + for (x= 0; x < 2; x++) + { + rc= memcached_set(memc, key, strlen(key), + NULL, 0, + (time_t)0, (uint32_t)0); + + 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 == 0); + + value= memcached_get(memc, key, strlen(key), + &length, &flags, &rc); + + assert(rc == MEMCACHED_SUCCESS); + assert(value == NULL); + assert(length == 0); + assert(flags == 0); + } + + 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; memcached_result_st *result_ptr; @@ -1482,7 +2127,7 @@ uint8_t result_static(memcached_st *memc) return 0; } -uint8_t result_alloc(memcached_st *memc) +test_return result_alloc(memcached_st *memc) { memcached_result_st *result; @@ -1493,7 +2138,7 @@ uint8_t result_alloc(memcached_st *memc) return 0; } -uint8_t string_static_null(memcached_st *memc) +test_return string_static_null(memcached_st *memc) { memcached_string_st string; memcached_string_st *string_ptr; @@ -1506,7 +2151,7 @@ uint8_t string_static_null(memcached_st *memc) return 0; } -uint8_t string_alloc_null(memcached_st *memc) +test_return string_alloc_null(memcached_st *memc) { memcached_string_st *string; @@ -1517,7 +2162,7 @@ uint8_t string_alloc_null(memcached_st *memc) return 0; } -uint8_t string_alloc_with_size(memcached_st *memc) +test_return string_alloc_with_size(memcached_st *memc) { memcached_string_st *string; @@ -1528,7 +2173,7 @@ uint8_t string_alloc_with_size(memcached_st *memc) return 0; } -uint8_t string_alloc_with_size_toobig(memcached_st *memc) +test_return string_alloc_with_size_toobig(memcached_st *memc) { memcached_string_st *string; @@ -1538,7 +2183,7 @@ uint8_t string_alloc_with_size_toobig(memcached_st *memc) return 0; } -uint8_t string_alloc_append(memcached_st *memc) +test_return string_alloc_append(memcached_st *memc) { unsigned int x; char buffer[SMALL_STRING_LEN]; @@ -1561,7 +2206,7 @@ uint8_t string_alloc_append(memcached_st *memc) return 0; } -uint8_t string_alloc_append_toobig(memcached_st *memc) +test_return string_alloc_append_toobig(memcached_st *memc) { memcached_return rc; unsigned int x; @@ -1586,20 +2231,35 @@ uint8_t string_alloc_append_toobig(memcached_st *memc) return 0; } -uint8_t cleanup_pairs(memcached_st *memc) +test_return cleanup_pairs(memcached_st *memc) { pairs_free(global_pairs); return 0; } -uint8_t generate_data(memcached_st *memc) +test_return generate_pairs(memcached_st *memc) +{ + unsigned long long x; + global_pairs= pairs_generate(GLOBAL_COUNT, 400); + global_count= GLOBAL_COUNT; + + for (x= 0; x < global_count; x++) + { + global_keys[x]= global_pairs[x].key; + global_keys_length[x]= global_pairs[x].key_length; + } + + return 0; +} + +test_return generate_large_pairs(memcached_st *memc) { unsigned long long x; - global_pairs= pairs_generate(GLOBAL_COUNT); - execute_set(memc, global_pairs, GLOBAL_COUNT); + global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10); + global_count= GLOBAL2_COUNT; - for (x= 0; x < GLOBAL_COUNT; x++) + for (x= 0; x < global_count; x++) { global_keys[x]= global_pairs[x].key; global_keys_length[x]= global_pairs[x].key_length; @@ -1608,7 +2268,78 @@ uint8_t generate_data(memcached_st *memc) return 0; } -uint8_t get_read(memcached_st *memc) +test_return generate_data(memcached_st *memc) +{ + execute_set(memc, global_pairs, global_count); + + 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; + + latch= 1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, latch); + generate_data(memc); + + return 0; +} + +test_return get_read_count(memcached_st *memc) +{ + unsigned int x; + memcached_return rc; + memcached_st *clone; + + clone= memcached_clone(NULL, memc); + assert(clone); + + memcached_server_add(clone, "localhost", 6666); + + { + char *return_value; + size_t return_value_length; + uint32_t flags; + uint32_t count; + + for (x= count= 0; x < global_count; x++) + { + return_value= memcached_get(clone, global_keys[x], global_keys_length[x], + &return_value_length, &flags, &rc); + if (rc == MEMCACHED_SUCCESS) + { + count++; + if (return_value) + free(return_value); + } + } + fprintf(stderr, "\t%u -> %u", global_count, count); + } + + memcached_free(clone); + + return 0; +} + +test_return get_read(memcached_st *memc) { unsigned int x; memcached_return rc; @@ -1616,9 +2347,9 @@ uint8_t get_read(memcached_st *memc) { char *return_value; size_t return_value_length; - uint16_t flags; + uint32_t flags; - for (x= 0; x < GLOBAL_COUNT; x++) + for (x= 0; x < global_count; x++) { return_value= memcached_get(memc, global_keys[x], global_keys_length[x], &return_value_length, &flags, &rc); @@ -1634,11 +2365,11 @@ uint8_t get_read(memcached_st *memc) return 0; } -uint8_t mget_read(memcached_st *memc) +test_return mget_read(memcached_st *memc) { memcached_return rc; - rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT); + rc= memcached_mget(memc, global_keys, global_keys_length, global_count); assert(rc == MEMCACHED_SUCCESS); /* Turn this into a help function */ { @@ -1646,7 +2377,7 @@ uint8_t mget_read(memcached_st *memc) size_t return_key_length; char *return_value; size_t return_value_length; - uint16_t flags; + uint32_t flags; while ((return_value= memcached_fetch(memc, return_key, &return_key_length, &return_value_length, &flags, &rc))) @@ -1660,11 +2391,11 @@ uint8_t mget_read(memcached_st *memc) return 0; } -uint8_t mget_read_result(memcached_st *memc) +test_return mget_read_result(memcached_st *memc) { memcached_return rc; - rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT); + rc= memcached_mget(memc, global_keys, global_keys_length, global_count); assert(rc == MEMCACHED_SUCCESS); /* Turn this into a help function */ { @@ -1685,14 +2416,58 @@ uint8_t mget_read_result(memcached_st *memc) return 0; } -uint8_t free_data(memcached_st *memc) +test_return mget_read_function(memcached_st *memc) +{ + memcached_return rc; + unsigned int counter; + unsigned int (*callbacks[1])(memcached_st *, memcached_result_st *, void *); + + rc= memcached_mget(memc, global_keys, global_keys_length, global_count); + assert(rc == MEMCACHED_SUCCESS); + + callbacks[0]= &callback_counter; + counter= 0; + rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1); + + return 0; +} + +test_return delete_generate(memcached_st *memc) +{ + unsigned int x; + + for (x= 0; x < global_count; x++) + { + (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); + } + + return 0; +} + +test_return delete_buffer_generate(memcached_st *memc) +{ + int latch= 0; + unsigned int x; + + latch= 1; + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, latch); + + for (x= 0; x < global_count; x++) + { + (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0); + } + + return 0; +} + +test_return free_data(memcached_st *memc) { pairs_free(global_pairs); return 0; } -uint8_t add_host_test1(memcached_st *memc) +test_return add_host_test1(memcached_st *memc) { unsigned int x; memcached_return rc; @@ -1726,71 +2501,213 @@ uint8_t add_host_test1(memcached_st *memc) memcached_return pre_nonblock(memcached_st *memc) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); + + return MEMCACHED_SUCCESS; +} + +memcached_return pre_murmur(memcached_st *memc) +{ + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR); return MEMCACHED_SUCCESS; } memcached_return pre_md5(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_MD5; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MD5); return MEMCACHED_SUCCESS; } memcached_return pre_crc(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_CRC; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_CRC); return MEMCACHED_SUCCESS; } memcached_return pre_hsieh(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_HSIEH; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH); return MEMCACHED_SUCCESS; } memcached_return pre_hash_fnv1_64(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_FNV1_64; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1_64); return MEMCACHED_SUCCESS; } memcached_return pre_hash_fnv1a_64(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_FNV1A_64; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_64); return MEMCACHED_SUCCESS; } memcached_return pre_hash_fnv1_32(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_FNV1_32; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1_32); return MEMCACHED_SUCCESS; } memcached_return pre_hash_fnv1a_32(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_FNV1A_32; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_32); return MEMCACHED_SUCCESS; } -memcached_return pre_hash_ketama(memcached_st *memc) +memcached_return pre_behavior_ketama(memcached_st *memc) { - memcached_hash value= MEMCACHED_HASH_KETAMA; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value); + memcached_return rc; + uint64_t value; + + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1); + assert(rc == MEMCACHED_SUCCESS); + + value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA); + assert(value == 1); + + 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); +} + +void *my_malloc(memcached_st *ptr, const size_t size) +{ + return malloc(size); +} + +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) +{ + { + memcached_malloc_function test_ptr; + memcached_return rc; + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &my_malloc); + assert(rc == MEMCACHED_SUCCESS); + test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &rc); + assert(rc == MEMCACHED_SUCCESS); + assert(test_ptr == my_malloc); + } + + { + memcached_realloc_function test_ptr; + memcached_return rc; + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &my_realloc); + assert(rc == MEMCACHED_SUCCESS); + test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &rc); + assert(rc == MEMCACHED_SUCCESS); + assert(test_ptr == my_realloc); + } + + { + memcached_free_function test_ptr; + memcached_return rc; + + rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, my_free); + assert(rc == MEMCACHED_SUCCESS); + test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, &rc); + assert(rc == MEMCACHED_SUCCESS); + assert(test_ptr == my_free); + } return MEMCACHED_SUCCESS; } @@ -1799,7 +2716,7 @@ memcached_return enable_consistent(memcached_st *memc) { memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT; memcached_hash hash; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, &value); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value); pre_hsieh(memc); value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION); @@ -1822,7 +2739,7 @@ memcached_return enable_cas(memcached_st *memc) memc->hosts[0].minor_version >= 2 && memc->hosts[0].micro_version >= 4) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, &set); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set); return MEMCACHED_SUCCESS; } @@ -1877,8 +2794,8 @@ memcached_return pre_udp(memcached_st *memc) memcached_return pre_nodelay(memcached_st *memc) { - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 0); return MEMCACHED_SUCCESS; } @@ -1889,7 +2806,7 @@ memcached_return poll_timeout(memcached_st *memc) timeout= 100; - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); @@ -1904,13 +2821,17 @@ test_st tests[] ={ {"flush", 0, flush_test }, {"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}, + {"server_sort2", 0, server_sort2_test}, {"clone_test", 0, clone_test }, {"error", 0, error_test }, {"set", 0, set_test }, {"set2", 0, set_test2 }, {"set3", 0, set_test3 }, {"add", 1, add_test }, - {"replace", 0, replace_test }, + {"replace", 1, replace_test }, {"delete", 1, delete_test }, {"get", 1, get_test }, {"get2", 0, get_test2 }, @@ -1923,10 +2844,22 @@ test_st tests[] ={ {"mget", 1, mget_test }, {"mget_result", 1, mget_result_test }, {"mget_result_alloc", 1, mget_result_alloc_test }, + {"mget_result_function", 1, mget_result_function }, {"get_stats", 0, get_stats }, {"add_host_test", 0, add_host_test }, {"get_stats_keys", 0, get_stats_keys }, {"behavior_test", 0, get_stats_keys }, + {"callback_test", 0, get_stats_keys }, + {"version_string_test", 0, version_string_test}, + {"bad_key", 1, bad_key_test }, + {"memcached_server_cursor", 1, memcached_server_cursor_test }, + {"read_through", 1, read_through }, + {"delete_through", 1, delete_through }, + {0, 0, 0} +}; + +test_st async_tests[] ={ + {"add", 1, add_wrapper }, {0, 0, 0} }; @@ -1967,18 +2900,49 @@ test_st user_tests[] ={ {"user_supplied_bug9", 1, user_supplied_bug9 }, {"user_supplied_bug10", 1, user_supplied_bug10 }, {"user_supplied_bug11", 1, user_supplied_bug11 }, + {"user_supplied_bug12", 1, user_supplied_bug12 }, + {"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} }; test_st generate_tests[] ={ - {"generate_data", 0, generate_data }, + {"generate_pairs", 1, generate_pairs }, + {"generate_data", 1, generate_data }, {"get_read", 0, get_read }, + {"delete_generate", 0, delete_generate }, + {"generate_buffer_data", 1, generate_buffer_data }, + {"delete_buffer", 0, delete_buffer_generate}, + {"generate_data", 1, generate_data }, {"mget_read", 0, mget_read }, {"mget_read_result", 0, mget_read_result }, - {"cleanup", 0, cleanup_pairs }, + {"mget_read_function", 0, mget_read_function }, + {"cleanup", 1, cleanup_pairs }, + {"generate_large_pairs", 1, generate_large_pairs }, + {"generate_data", 1, generate_data }, + {"generate_buffer_data", 1, generate_buffer_data }, + {"cleanup", 1, cleanup_pairs }, {0, 0, 0} }; +test_st consistent_tests[] ={ + {"generate_pairs", 1, generate_pairs }, + {"generate_data", 1, generate_data }, + {"get_read", 0, get_read_count }, + {"cleanup", 1, cleanup_pairs }, + {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}, @@ -1991,26 +2955,61 @@ collection_st collection[] ={ {"fnv1a_64", pre_hash_fnv1a_64, 0, tests}, {"fnv1_32", pre_hash_fnv1_32, 0, tests}, {"fnv1a_32", pre_hash_fnv1a_32, 0, tests}, - {"ketama", pre_hash_ketama, 0, tests}, + {"ketama", pre_behavior_ketama, 0, tests}, {"unix_socket", pre_unix_socket, 0, tests}, {"unix_socket_nodelay", pre_nodelay, 0, tests}, {"poll_timeout", poll_timeout, 0, tests}, {"gets", enable_cas, 0, tests}, {"consistent", enable_consistent, 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}, {"result", 0, 0, result_tests}, + {"async", pre_nonblock, 0, async_tests}, {"user", 0, 0, user_tests}, {"generate", 0, 0, generate_tests}, {"generate_hsieh", pre_hsieh, 0, generate_tests}, + {"generate_ketama", pre_behavior_ketama, 0, generate_tests}, {"generate_hsieh_consistent", enable_consistent, 0, generate_tests}, {"generate_md5", pre_md5, 0, generate_tests}, + {"generate_murmur", pre_murmur, 0, generate_tests}, {"generate_nonblock", pre_nonblock, 0, generate_tests}, + {"consistent_not", 0, 0, consistent_tests}, + {"consistent_ketama", pre_behavior_ketama, 0, consistent_tests}, + {"consistent_ketama_weighted", pre_behavior_ketama_weighted, 0, consistent_weighted_tests}, {0, 0, 0, 0} }; -collection_st *gets_collections(void) +#define SERVERS_TO_CREATE 5 + +void *world_create(void) +{ + server_startup_st *construct; + + construct= (server_startup_st *)malloc(sizeof(server_startup_st)); + memset(construct, 0, sizeof(server_startup_st)); + construct->count= SERVERS_TO_CREATE; + construct->udp= 0; + server_startup(construct); + + return construct; +} + +void world_destroy(void *p) +{ + server_startup_st *construct= (server_startup_st *)p; + memcached_server_st *servers= (memcached_server_st *)construct->servers; + memcached_server_list_free(servers); + + server_shutdown(construct); + free(construct); +} + +void get_world(world_st *world) { - return collection; + world->collections= collection; + world->create= world_create; + world->destroy= world_destroy; }