vinted-memcached 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/BENCHMARKS +142 -0
- data/CHANGELOG +176 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/LICENSE +184 -0
- data/Manifest +209 -0
- data/README.rdoc +124 -0
- data/Rakefile +134 -0
- data/TODO +1 -0
- data/ext/extconf-make.rb +25 -0
- data/ext/extconf.rb +78 -0
- data/ext/libmemcached-0.32/AUTHORS +7 -0
- data/ext/libmemcached-0.32/COPYING +32 -0
- data/ext/libmemcached-0.32/ChangeLog +303 -0
- data/ext/libmemcached-0.32/INSTALL +302 -0
- data/ext/libmemcached-0.32/Makefile.am +36 -0
- data/ext/libmemcached-0.32/Makefile.in +911 -0
- data/ext/libmemcached-0.32/NEWS +1 -0
- data/ext/libmemcached-0.32/README +33 -0
- data/ext/libmemcached-0.32/THANKS +14 -0
- data/ext/libmemcached-0.32/TODO +11 -0
- data/ext/libmemcached-0.32/aclocal.m4 +2108 -0
- data/ext/libmemcached-0.32/clients/Makefile.am +80 -0
- data/ext/libmemcached-0.32/clients/Makefile.in +773 -0
- data/ext/libmemcached-0.32/clients/client_options.h +32 -0
- data/ext/libmemcached-0.32/clients/execute.c +64 -0
- data/ext/libmemcached-0.32/clients/execute.h +5 -0
- data/ext/libmemcached-0.32/clients/generator.c +74 -0
- data/ext/libmemcached-0.32/clients/generator.h +20 -0
- data/ext/libmemcached-0.32/clients/memcat.c +178 -0
- data/ext/libmemcached-0.32/clients/memcp.c +251 -0
- data/ext/libmemcached-0.32/clients/memdump.c +170 -0
- data/ext/libmemcached-0.32/clients/memerror.c +80 -0
- data/ext/libmemcached-0.32/clients/memflush.c +143 -0
- data/ext/libmemcached-0.32/clients/memrm.c +160 -0
- data/ext/libmemcached-0.32/clients/memslap.c +441 -0
- data/ext/libmemcached-0.32/clients/memstat.c +326 -0
- data/ext/libmemcached-0.32/clients/utilities.c +207 -0
- data/ext/libmemcached-0.32/clients/utilities.h +41 -0
- data/ext/libmemcached-0.32/config/compile +143 -0
- data/ext/libmemcached-0.32/config/config.guess +1561 -0
- data/ext/libmemcached-0.32/config/config.rpath +666 -0
- data/ext/libmemcached-0.32/config/config.sub +1686 -0
- data/ext/libmemcached-0.32/config/depcomp +630 -0
- data/ext/libmemcached-0.32/config/install-sh +520 -0
- data/ext/libmemcached-0.32/config/ltmain.sh +9636 -0
- data/ext/libmemcached-0.32/config/missing +376 -0
- data/ext/libmemcached-0.32/config.h.in +254 -0
- data/ext/libmemcached-0.32/configure +23843 -0
- data/ext/libmemcached-0.32/configure.ac +120 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.am +111 -0
- data/ext/libmemcached-0.32/libmemcached/Makefile.in +1069 -0
- data/ext/libmemcached-0.32/libmemcached/byteorder.c +31 -0
- data/ext/libmemcached-0.32/libmemcached/common.h +189 -0
- data/ext/libmemcached-0.32/libmemcached/crc.c +86 -0
- data/ext/libmemcached-0.32/libmemcached/hsieh_hash.c +68 -0
- data/ext/libmemcached-0.32/libmemcached/jenkins_hash.c +213 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached.ver +1 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.d +30 -0
- data/ext/libmemcached-0.32/libmemcached/libmemcached_probes.h +82 -0
- data/ext/libmemcached-0.32/libmemcached/md5.c +354 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/README.txt +7 -0
- data/ext/libmemcached-0.32/libmemcached/memcached/protocol_binary.h +385 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.c +153 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.h +305 -0
- data/ext/libmemcached-0.32/libmemcached/memcached.hpp +799 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_allocators.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_analyze.c +100 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_auto.c +207 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_behavior.c +290 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_callback.c +175 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_configure.h.in +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_connect.c +371 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_constants.h +146 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_delete.c +0 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_do.c +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_dump.c +79 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_exist.c +114 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_exist.h +20 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_fetch.c +102 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush.c +89 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_flush_buffers.c +23 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.c +494 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_get.h +87 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hash.c +252 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_hosts.c +510 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_internal.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.c +594 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_io.h +72 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_key.c +28 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_parse.c +74 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_pool.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_purge.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_quit.c +75 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_response.c +529 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.c +57 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_result.h +59 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.c +225 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_sasl.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.c +159 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_server.h +93 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_stats.c +437 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.c +514 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_storage.h +107 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_strerror.c +92 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.c +138 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_string.h +53 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_touch.c +60 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_touch.h +31 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_types.h +44 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_util.h +15 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_verbosity.c +36 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_version.c +112 -0
- data/ext/libmemcached-0.32/libmemcached/memcached_watchpoint.h +38 -0
- data/ext/libmemcached-0.32/libmemcached/murmur_hash.c +76 -0
- data/ext/libmemcached-0.32/libmemcached/visibility.h +51 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.am +11 -0
- data/ext/libmemcached-0.32/libmemcachedutil/Makefile.in +604 -0
- data/ext/libmemcached-0.32/libmemcachedutil/libmemcachedutil.ver +1 -0
- data/ext/libmemcached-0.32/libmemcachedutil/memcached_pool.c +170 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_compile_stdcxx_0x.m4 +103 -0
- data/ext/libmemcached-0.32/m4/ac_cxx_header_stdcxx_98.m4 +67 -0
- data/ext/libmemcached-0.32/m4/acx_pthread.m4 +276 -0
- data/ext/libmemcached-0.32/m4/byteorder.m4 +40 -0
- data/ext/libmemcached-0.32/m4/deprecated.m4 +17 -0
- data/ext/libmemcached-0.32/m4/enable_utillib.m4 +16 -0
- data/ext/libmemcached-0.32/m4/extensions.m4 +94 -0
- data/ext/libmemcached-0.32/m4/hsieh.m4 +18 -0
- data/ext/libmemcached-0.32/m4/lib-prefix.m4 +221 -0
- data/ext/libmemcached-0.32/m4/libtool.m4 +7831 -0
- data/ext/libmemcached-0.32/m4/ltoptions.m4 +369 -0
- data/ext/libmemcached-0.32/m4/ltsugar.m4 +123 -0
- data/ext/libmemcached-0.32/m4/ltversion.m4 +23 -0
- data/ext/libmemcached-0.32/m4/lt~obsolete.m4 +98 -0
- data/ext/libmemcached-0.32/m4/memcached.m4 +30 -0
- data/ext/libmemcached-0.32/m4/pandora_64bit.m4 +55 -0
- data/ext/libmemcached-0.32/m4/pandora_canonical.m4 +151 -0
- data/ext/libmemcached-0.32/m4/pandora_check_compiler_version.m4 +37 -0
- data/ext/libmemcached-0.32/m4/pandora_check_cxx_standard.m4 +16 -0
- data/ext/libmemcached-0.32/m4/pandora_enable_dtrace.m4 +41 -0
- data/ext/libmemcached-0.32/m4/pandora_ensure_gcc_version.m4 +36 -0
- data/ext/libmemcached-0.32/m4/pandora_have_better_malloc.m4 +54 -0
- data/ext/libmemcached-0.32/m4/pandora_have_sasl.m4 +133 -0
- data/ext/libmemcached-0.32/m4/pandora_header_assert.m4 +23 -0
- data/ext/libmemcached-0.32/m4/pandora_libtool.m4 +15 -0
- data/ext/libmemcached-0.32/m4/pandora_optimize.m4 +79 -0
- data/ext/libmemcached-0.32/m4/pandora_shared_ptr.m4 +56 -0
- data/ext/libmemcached-0.32/m4/pandora_vc_build.m4 +32 -0
- data/ext/libmemcached-0.32/m4/pandora_warnings.m4 +262 -0
- data/ext/libmemcached-0.32/m4/pod2man.m4 +7 -0
- data/ext/libmemcached-0.32/m4/protocol_binary.m4 +23 -0
- data/ext/libmemcached-0.32/m4/setsockopt.m4 +57 -0
- data/ext/libmemcached-0.32/m4/visibility.m4 +52 -0
- data/ext/libmemcached-0.32/support/Makefile.am +4 -0
- data/ext/libmemcached-0.32/support/Makefile.in +487 -0
- data/ext/libmemcached-0.32/support/libmemcached-fc.spec.in +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.pc.in +10 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec +105 -0
- data/ext/libmemcached-0.32/support/libmemcached.spec.in +105 -0
- data/ext/libmemcached-0.32/support/set_benchmark.sh +5 -0
- data/ext/libmemcached-0.32/tests/Makefile.am +113 -0
- data/ext/libmemcached-0.32/tests/Makefile.in +762 -0
- data/ext/libmemcached-0.32/tests/atomsmasher.c +245 -0
- data/ext/libmemcached-0.32/tests/function.c +4904 -0
- data/ext/libmemcached-0.32/tests/ketama_test_cases.h +108 -0
- data/ext/libmemcached-0.32/tests/output.cmp +7 -0
- data/ext/libmemcached-0.32/tests/output.res +7 -0
- data/ext/libmemcached-0.32/tests/output2.res +46 -0
- data/ext/libmemcached-0.32/tests/plus.cpp +293 -0
- data/ext/libmemcached-0.32/tests/r/memcat.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memcp.res +27 -0
- data/ext/libmemcached-0.32/tests/r/memrm.res +19 -0
- data/ext/libmemcached-0.32/tests/r/memslap.res +33 -0
- data/ext/libmemcached-0.32/tests/r/memstat.res +33 -0
- data/ext/libmemcached-0.32/tests/server.c +118 -0
- data/ext/libmemcached-0.32/tests/server.h +25 -0
- data/ext/libmemcached-0.32/tests/start.c +16 -0
- data/ext/libmemcached-0.32/tests/t/memcat.test +4 -0
- data/ext/libmemcached-0.32/tests/t/memcp.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memrm.test +3 -0
- data/ext/libmemcached-0.32/tests/t/memslap.test +5 -0
- data/ext/libmemcached-0.32/tests/t/memstat.test +3 -0
- data/ext/libmemcached-0.32/tests/test.c +137 -0
- data/ext/libmemcached-0.32/tests/test.h +46 -0
- data/ext/libmemcached-0.32/tests/udp.c +76 -0
- data/ext/rlibmemcached.i +258 -0
- data/ext/rlibmemcached_wrap.c +13917 -0
- data/lib/memcached/auth.rb +16 -0
- data/lib/memcached/behaviors.rb +78 -0
- data/lib/memcached/exceptions.rb +84 -0
- data/lib/memcached/experimental.rb +48 -0
- data/lib/memcached/marshal_codec.rb +10 -0
- data/lib/memcached/memcached.rb +732 -0
- data/lib/memcached/rails.rb +250 -0
- data/lib/memcached.rb +33 -0
- data/memcached.gemspec +0 -0
- data/test/profile/benchmark.rb +280 -0
- data/test/profile/c_profiler.rb +14 -0
- data/test/profile/exercise.rb +185 -0
- data/test/profile/rb_profiler.rb +21 -0
- data/test/profile/valgrind.rb +10 -0
- data/test/setup.rb +30 -0
- data/test/teardown.rb +0 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/binding_test.rb +8 -0
- data/test/unit/memcached_experimental_test.rb +272 -0
- data/test/unit/memcached_test.rb +1487 -0
- data/test/unit/rails_test.rb +330 -0
- metadata +336 -0
@@ -0,0 +1,4904 @@
|
|
1
|
+
/*
|
2
|
+
Sample test application.
|
3
|
+
*/
|
4
|
+
|
5
|
+
#include "libmemcached/common.h"
|
6
|
+
|
7
|
+
#include <assert.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <sys/time.h>
|
12
|
+
#include <sys/types.h>
|
13
|
+
#include <sys/stat.h>
|
14
|
+
#include <unistd.h>
|
15
|
+
#include <time.h>
|
16
|
+
#include "server.h"
|
17
|
+
#include "clients/generator.h"
|
18
|
+
#include "clients/execute.h"
|
19
|
+
|
20
|
+
#ifndef INT64_MAX
|
21
|
+
#define INT64_MAX LONG_MAX
|
22
|
+
#endif
|
23
|
+
#ifndef INT32_MAX
|
24
|
+
#define INT32_MAX INT_MAX
|
25
|
+
#endif
|
26
|
+
|
27
|
+
|
28
|
+
#include "test.h"
|
29
|
+
|
30
|
+
#ifdef HAVE_LIBMEMCACHEDUTIL
|
31
|
+
#include <pthread.h>
|
32
|
+
#include "libmemcached/memcached_util.h"
|
33
|
+
#endif
|
34
|
+
|
35
|
+
#define GLOBAL_COUNT 10000
|
36
|
+
#define GLOBAL2_COUNT 100
|
37
|
+
#define SERVERS_TO_CREATE 5
|
38
|
+
static uint32_t global_count;
|
39
|
+
|
40
|
+
static pairs_st *global_pairs;
|
41
|
+
static const char *global_keys[GLOBAL_COUNT];
|
42
|
+
static size_t global_keys_length[GLOBAL_COUNT];
|
43
|
+
|
44
|
+
static test_return init_test(memcached_st *not_used __attribute__((unused)))
|
45
|
+
{
|
46
|
+
memcached_st memc;
|
47
|
+
|
48
|
+
(void)memcached_create(&memc);
|
49
|
+
memcached_free(&memc);
|
50
|
+
|
51
|
+
return 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
static test_return server_list_null_test(memcached_st *ptr __attribute__((unused)))
|
55
|
+
{
|
56
|
+
memcached_server_st *server_list;
|
57
|
+
memcached_return rc;
|
58
|
+
|
59
|
+
server_list= memcached_server_list_append_with_weight(NULL, NULL, 0, 0, NULL);
|
60
|
+
assert(server_list == NULL);
|
61
|
+
|
62
|
+
server_list= memcached_server_list_append_with_weight(NULL, "localhost", 0, 0, NULL);
|
63
|
+
assert(server_list == NULL);
|
64
|
+
|
65
|
+
server_list= memcached_server_list_append_with_weight(NULL, NULL, 0, 0, &rc);
|
66
|
+
assert(server_list == NULL);
|
67
|
+
|
68
|
+
return 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
#define TEST_PORT_COUNT 7
|
72
|
+
uint32_t test_ports[TEST_PORT_COUNT];
|
73
|
+
|
74
|
+
static memcached_return server_display_function(memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context)
|
75
|
+
{
|
76
|
+
/* Do Nothing */
|
77
|
+
uint32_t bigger= *((uint32_t *)(context));
|
78
|
+
assert(bigger <= server->port);
|
79
|
+
*((uint32_t *)(context))= server->port;
|
80
|
+
|
81
|
+
return MEMCACHED_SUCCESS;
|
82
|
+
}
|
83
|
+
|
84
|
+
static test_return server_sort_test(memcached_st *ptr __attribute__((unused)))
|
85
|
+
{
|
86
|
+
uint32_t x;
|
87
|
+
uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */
|
88
|
+
memcached_return rc;
|
89
|
+
memcached_server_function callbacks[1];
|
90
|
+
memcached_st *local_memc;
|
91
|
+
|
92
|
+
local_memc= memcached_create(NULL);
|
93
|
+
assert(local_memc);
|
94
|
+
memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1);
|
95
|
+
|
96
|
+
for (x= 0; x < TEST_PORT_COUNT; x++)
|
97
|
+
{
|
98
|
+
test_ports[x]= (uint32_t)random() % 64000;
|
99
|
+
rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0);
|
100
|
+
assert(local_memc->number_of_hosts == x + 1);
|
101
|
+
assert(local_memc->hosts[0].count == x+1);
|
102
|
+
assert(rc == MEMCACHED_SUCCESS);
|
103
|
+
}
|
104
|
+
|
105
|
+
callbacks[0]= server_display_function;
|
106
|
+
memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1);
|
107
|
+
|
108
|
+
|
109
|
+
memcached_free(local_memc);
|
110
|
+
|
111
|
+
return 0;
|
112
|
+
}
|
113
|
+
|
114
|
+
static test_return server_sort2_test(memcached_st *ptr __attribute__((unused)))
|
115
|
+
{
|
116
|
+
uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */
|
117
|
+
memcached_return rc;
|
118
|
+
memcached_server_function callbacks[1];
|
119
|
+
memcached_st *local_memc;
|
120
|
+
|
121
|
+
local_memc= memcached_create(NULL);
|
122
|
+
assert(local_memc);
|
123
|
+
rc= memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1);
|
124
|
+
assert(rc == MEMCACHED_SUCCESS);
|
125
|
+
|
126
|
+
rc= memcached_server_add_with_weight(local_memc, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
|
127
|
+
assert(rc == MEMCACHED_SUCCESS);
|
128
|
+
assert(local_memc->hosts[0].port == 43043);
|
129
|
+
|
130
|
+
rc= memcached_server_add_with_weight(local_memc, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
|
131
|
+
assert(rc == MEMCACHED_SUCCESS);
|
132
|
+
assert(local_memc->hosts[0].port == 43042);
|
133
|
+
assert(local_memc->hosts[1].port == 43043);
|
134
|
+
|
135
|
+
callbacks[0]= server_display_function;
|
136
|
+
memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1);
|
137
|
+
|
138
|
+
|
139
|
+
memcached_free(local_memc);
|
140
|
+
|
141
|
+
return 0;
|
142
|
+
}
|
143
|
+
|
144
|
+
static memcached_return server_display_unsort_function(memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context)
|
145
|
+
{
|
146
|
+
/* Do Nothing */
|
147
|
+
uint32_t x= *((uint32_t *)(context));
|
148
|
+
|
149
|
+
assert(test_ports[x] == server->port);
|
150
|
+
*((uint32_t *)(context))= ++x;
|
151
|
+
|
152
|
+
return MEMCACHED_SUCCESS;
|
153
|
+
}
|
154
|
+
|
155
|
+
static test_return server_unsort_test(memcached_st *ptr __attribute__((unused)))
|
156
|
+
{
|
157
|
+
uint32_t x;
|
158
|
+
uint32_t counter= 0; /* Prime the value for the assert in server_display_function */
|
159
|
+
uint32_t bigger= 0; /* Prime the value for the assert in server_display_function */
|
160
|
+
memcached_return rc;
|
161
|
+
memcached_server_function callbacks[1];
|
162
|
+
memcached_st *local_memc;
|
163
|
+
|
164
|
+
local_memc= memcached_create(NULL);
|
165
|
+
assert(local_memc);
|
166
|
+
|
167
|
+
for (x= 0; x < TEST_PORT_COUNT; x++)
|
168
|
+
{
|
169
|
+
test_ports[x]= (uint32_t)(random() % 64000);
|
170
|
+
rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0);
|
171
|
+
assert(local_memc->number_of_hosts == x+1);
|
172
|
+
assert(local_memc->hosts[0].count == x+1);
|
173
|
+
assert(rc == MEMCACHED_SUCCESS);
|
174
|
+
}
|
175
|
+
|
176
|
+
callbacks[0]= server_display_unsort_function;
|
177
|
+
memcached_server_cursor(local_memc, callbacks, (void *)&counter, 1);
|
178
|
+
|
179
|
+
/* Now we sort old data! */
|
180
|
+
memcached_behavior_set(local_memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, 1);
|
181
|
+
callbacks[0]= server_display_function;
|
182
|
+
memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1);
|
183
|
+
|
184
|
+
|
185
|
+
memcached_free(local_memc);
|
186
|
+
|
187
|
+
return 0;
|
188
|
+
}
|
189
|
+
|
190
|
+
static test_return allocation_test(memcached_st *not_used __attribute__((unused)))
|
191
|
+
{
|
192
|
+
memcached_st *memc;
|
193
|
+
memc= memcached_create(NULL);
|
194
|
+
assert(memc);
|
195
|
+
memcached_free(memc);
|
196
|
+
|
197
|
+
return 0;
|
198
|
+
}
|
199
|
+
|
200
|
+
static test_return clone_test(memcached_st *memc)
|
201
|
+
{
|
202
|
+
/* All null? */
|
203
|
+
{
|
204
|
+
memcached_st *memc_clone;
|
205
|
+
memc_clone= memcached_clone(NULL, NULL);
|
206
|
+
assert(memc_clone);
|
207
|
+
memcached_free(memc_clone);
|
208
|
+
}
|
209
|
+
|
210
|
+
/* Can we init from null? */
|
211
|
+
{
|
212
|
+
memcached_st *memc_clone;
|
213
|
+
memc_clone= memcached_clone(NULL, memc);
|
214
|
+
assert(memc_clone);
|
215
|
+
|
216
|
+
assert(memc_clone->call_free == memc->call_free);
|
217
|
+
assert(memc_clone->call_malloc == memc->call_malloc);
|
218
|
+
assert(memc_clone->call_realloc == memc->call_realloc);
|
219
|
+
assert(memc_clone->call_calloc == memc->call_calloc);
|
220
|
+
assert(memc_clone->connect_timeout == memc->connect_timeout);
|
221
|
+
assert(memc_clone->delete_trigger == memc->delete_trigger);
|
222
|
+
assert(memc_clone->distribution == memc->distribution);
|
223
|
+
assert(memc_clone->flags == memc->flags);
|
224
|
+
assert(memc_clone->get_key_failure == memc->get_key_failure);
|
225
|
+
assert(memc_clone->hash == memc->hash);
|
226
|
+
assert(memc_clone->hash_continuum == memc->hash_continuum);
|
227
|
+
assert(memc_clone->io_bytes_watermark == memc->io_bytes_watermark);
|
228
|
+
assert(memc_clone->io_msg_watermark == memc->io_msg_watermark);
|
229
|
+
assert(memc_clone->io_key_prefetch == memc->io_key_prefetch);
|
230
|
+
assert(memc_clone->on_cleanup == memc->on_cleanup);
|
231
|
+
assert(memc_clone->on_clone == memc->on_clone);
|
232
|
+
assert(memc_clone->poll_timeout == memc->poll_timeout);
|
233
|
+
assert(memc_clone->poll_max_retries == memc->poll_max_retries);
|
234
|
+
assert(memc_clone->rcv_timeout == memc->rcv_timeout);
|
235
|
+
assert(memc_clone->recv_size == memc->recv_size);
|
236
|
+
assert(memc_clone->retry_timeout == memc->retry_timeout);
|
237
|
+
assert(memc_clone->send_size == memc->send_size);
|
238
|
+
assert(memc_clone->server_failure_limit == memc->server_failure_limit);
|
239
|
+
assert(memc_clone->snd_timeout == memc->snd_timeout);
|
240
|
+
assert(memc_clone->user_data == memc->user_data);
|
241
|
+
|
242
|
+
memcached_free(memc_clone);
|
243
|
+
}
|
244
|
+
|
245
|
+
/* Can we init from struct? */
|
246
|
+
{
|
247
|
+
memcached_st declared_clone;
|
248
|
+
memcached_st *memc_clone;
|
249
|
+
memset(&declared_clone, 0 , sizeof(memcached_st));
|
250
|
+
memc_clone= memcached_clone(&declared_clone, NULL);
|
251
|
+
assert(memc_clone);
|
252
|
+
memcached_free(memc_clone);
|
253
|
+
}
|
254
|
+
|
255
|
+
/* Can we init from struct? */
|
256
|
+
{
|
257
|
+
memcached_st declared_clone;
|
258
|
+
memcached_st *memc_clone;
|
259
|
+
memset(&declared_clone, 0 , sizeof(memcached_st));
|
260
|
+
memc_clone= memcached_clone(&declared_clone, memc);
|
261
|
+
assert(memc_clone);
|
262
|
+
memcached_free(memc_clone);
|
263
|
+
}
|
264
|
+
|
265
|
+
return 0;
|
266
|
+
}
|
267
|
+
|
268
|
+
static test_return userdata_test(memcached_st *memc)
|
269
|
+
{
|
270
|
+
void* foo= NULL;
|
271
|
+
assert(memcached_set_user_data(memc, foo) == NULL);
|
272
|
+
assert(memcached_get_user_data(memc) == foo);
|
273
|
+
assert(memcached_set_user_data(memc, NULL) == foo);
|
274
|
+
|
275
|
+
return TEST_SUCCESS;
|
276
|
+
}
|
277
|
+
|
278
|
+
static test_return connection_test(memcached_st *memc)
|
279
|
+
{
|
280
|
+
memcached_return rc;
|
281
|
+
|
282
|
+
rc= memcached_server_add_with_weight(memc, "localhost", 0, 0);
|
283
|
+
assert(rc == MEMCACHED_SUCCESS);
|
284
|
+
|
285
|
+
return 0;
|
286
|
+
}
|
287
|
+
|
288
|
+
static test_return error_test(memcached_st *memc)
|
289
|
+
{
|
290
|
+
memcached_return rc;
|
291
|
+
uint32_t values[] = { 851992627U, 2337886783U, 3196981036U, 4001849190U, 982370485U, 1263635348U, 4242906218U, 3829656100U, 1891735253U,
|
292
|
+
334139633U, 2257084983U, 3088286104U, 13199785U, 2542027183U, 1097051614U, 199566778U, 2748246961U, 2465192557U,
|
293
|
+
1664094137U, 2405439045U, 1842224848U, 692413798U, 3479807801U, 919913813U, 4269430871U, 610793021U, 527273862U,
|
294
|
+
1437122909U, 2300930706U, 2943759320U, 674306647U, 2400528935U, 54481931U, 4186304426U, 1741088401U, 2979625118U,
|
295
|
+
4159057246U, 1769812374U, 2302537950U, 1110330676U};
|
296
|
+
|
297
|
+
/* You have updated the memcache_error messages but not updated docs/tests. */
|
298
|
+
assert(MEMCACHED_SUCCESS == 0 && MEMCACHED_MAXIMUM_RETURN == 40);
|
299
|
+
for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
|
300
|
+
{
|
301
|
+
uint32_t hash_val;
|
302
|
+
hash_val= memcached_generate_hash_value(memcached_strerror(memc, rc), strlen(memcached_strerror(memc, rc)), MEMCACHED_HASH_JENKINS);
|
303
|
+
assert(values[rc] == hash_val);
|
304
|
+
}
|
305
|
+
|
306
|
+
return 0;
|
307
|
+
}
|
308
|
+
|
309
|
+
static test_return set_test(memcached_st *memc)
|
310
|
+
{
|
311
|
+
memcached_return rc;
|
312
|
+
const char *key= "foo";
|
313
|
+
const char *value= "when we sanitize";
|
314
|
+
|
315
|
+
rc= memcached_set(memc, key, strlen(key),
|
316
|
+
value, strlen(value),
|
317
|
+
(time_t)0, (uint32_t)0);
|
318
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
319
|
+
|
320
|
+
return 0;
|
321
|
+
}
|
322
|
+
|
323
|
+
static test_return append_test(memcached_st *memc)
|
324
|
+
{
|
325
|
+
memcached_return rc;
|
326
|
+
const char *key= "fig";
|
327
|
+
const char *in_value= "we";
|
328
|
+
char *out_value= NULL;
|
329
|
+
size_t value_length;
|
330
|
+
uint32_t flags;
|
331
|
+
|
332
|
+
rc= memcached_flush(memc, 0);
|
333
|
+
assert(rc == MEMCACHED_SUCCESS);
|
334
|
+
|
335
|
+
rc= memcached_set(memc, key, strlen(key),
|
336
|
+
in_value, strlen(in_value),
|
337
|
+
(time_t)0, (uint32_t)0);
|
338
|
+
assert(rc == MEMCACHED_SUCCESS);
|
339
|
+
|
340
|
+
rc= memcached_append(memc, key, strlen(key),
|
341
|
+
" the", strlen(" the"),
|
342
|
+
(time_t)0, (uint32_t)0);
|
343
|
+
assert(rc == MEMCACHED_SUCCESS);
|
344
|
+
|
345
|
+
rc= memcached_append(memc, key, strlen(key),
|
346
|
+
" people", strlen(" people"),
|
347
|
+
(time_t)0, (uint32_t)0);
|
348
|
+
assert(rc == MEMCACHED_SUCCESS);
|
349
|
+
|
350
|
+
out_value= memcached_get(memc, key, strlen(key),
|
351
|
+
&value_length, &flags, &rc);
|
352
|
+
assert(!memcmp(out_value, "we the people", strlen("we the people")));
|
353
|
+
assert(strlen("we the people") == value_length);
|
354
|
+
assert(rc == MEMCACHED_SUCCESS);
|
355
|
+
free(out_value);
|
356
|
+
|
357
|
+
return 0;
|
358
|
+
}
|
359
|
+
|
360
|
+
static test_return append_binary_test(memcached_st *memc)
|
361
|
+
{
|
362
|
+
memcached_return rc;
|
363
|
+
const char *key= "numbers";
|
364
|
+
unsigned int *store_ptr;
|
365
|
+
unsigned int store_list[] = { 23, 56, 499, 98, 32847, 0 };
|
366
|
+
char *value;
|
367
|
+
size_t value_length;
|
368
|
+
uint32_t flags;
|
369
|
+
unsigned int x;
|
370
|
+
|
371
|
+
rc= memcached_flush(memc, 0);
|
372
|
+
assert(rc == MEMCACHED_SUCCESS);
|
373
|
+
|
374
|
+
rc= memcached_set(memc,
|
375
|
+
key, strlen(key),
|
376
|
+
NULL, 0,
|
377
|
+
(time_t)0, (uint32_t)0);
|
378
|
+
assert(rc == MEMCACHED_SUCCESS);
|
379
|
+
|
380
|
+
for (x= 0; store_list[x] ; x++)
|
381
|
+
{
|
382
|
+
rc= memcached_append(memc,
|
383
|
+
key, strlen(key),
|
384
|
+
(char *)&store_list[x], sizeof(unsigned int),
|
385
|
+
(time_t)0, (uint32_t)0);
|
386
|
+
assert(rc == MEMCACHED_SUCCESS);
|
387
|
+
}
|
388
|
+
|
389
|
+
value= memcached_get(memc, key, strlen(key),
|
390
|
+
&value_length, &flags, &rc);
|
391
|
+
assert((value_length == (sizeof(unsigned int) * x)));
|
392
|
+
assert(rc == MEMCACHED_SUCCESS);
|
393
|
+
|
394
|
+
store_ptr= (unsigned int *)value;
|
395
|
+
x= 0;
|
396
|
+
while ((size_t)store_ptr < (size_t)(value + value_length))
|
397
|
+
{
|
398
|
+
assert(*store_ptr == store_list[x++]);
|
399
|
+
store_ptr++;
|
400
|
+
}
|
401
|
+
free(value);
|
402
|
+
|
403
|
+
return 0;
|
404
|
+
}
|
405
|
+
|
406
|
+
static test_return cas2_test(memcached_st *memc)
|
407
|
+
{
|
408
|
+
memcached_return rc;
|
409
|
+
const char *keys[]= {"fudge", "son", "food"};
|
410
|
+
size_t key_length[]= {5, 3, 4};
|
411
|
+
const char *value= "we the people";
|
412
|
+
size_t value_length= strlen("we the people");
|
413
|
+
unsigned int x;
|
414
|
+
memcached_result_st results_obj;
|
415
|
+
memcached_result_st *results;
|
416
|
+
unsigned int set= 1;
|
417
|
+
|
418
|
+
rc= memcached_flush(memc, 0);
|
419
|
+
assert(rc == MEMCACHED_SUCCESS);
|
420
|
+
|
421
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
|
422
|
+
|
423
|
+
for (x= 0; x < 3; x++)
|
424
|
+
{
|
425
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
426
|
+
keys[x], key_length[x],
|
427
|
+
(time_t)50, (uint32_t)9);
|
428
|
+
assert(rc == MEMCACHED_SUCCESS);
|
429
|
+
}
|
430
|
+
|
431
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
432
|
+
|
433
|
+
results= memcached_result_create(memc, &results_obj);
|
434
|
+
|
435
|
+
results= memcached_fetch_result(memc, &results_obj, &rc);
|
436
|
+
assert(results);
|
437
|
+
assert(results->cas);
|
438
|
+
assert(rc == MEMCACHED_SUCCESS);
|
439
|
+
assert(memcached_result_cas(results));
|
440
|
+
|
441
|
+
assert(!memcmp(value, "we the people", strlen("we the people")));
|
442
|
+
assert(strlen("we the people") == value_length);
|
443
|
+
assert(rc == MEMCACHED_SUCCESS);
|
444
|
+
|
445
|
+
memcached_result_free(&results_obj);
|
446
|
+
|
447
|
+
return 0;
|
448
|
+
}
|
449
|
+
|
450
|
+
static test_return cas_test(memcached_st *memc)
|
451
|
+
{
|
452
|
+
memcached_return rc;
|
453
|
+
const char *key= "fun";
|
454
|
+
size_t key_length= strlen(key);
|
455
|
+
const char *value= "we the people";
|
456
|
+
const char* keys[2] = { key, NULL };
|
457
|
+
size_t keylengths[2] = { strlen(key), 0 };
|
458
|
+
size_t value_length= strlen(value);
|
459
|
+
const char *value2= "change the value";
|
460
|
+
size_t value2_length= strlen(value2);
|
461
|
+
uint64_t cas;
|
462
|
+
|
463
|
+
memcached_result_st results_obj;
|
464
|
+
memcached_result_st *results;
|
465
|
+
unsigned int set= 1;
|
466
|
+
|
467
|
+
rc= memcached_flush(memc, 0);
|
468
|
+
assert(rc == MEMCACHED_SUCCESS);
|
469
|
+
|
470
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
|
471
|
+
|
472
|
+
rc= memcached_set(memc, key, strlen(key),
|
473
|
+
value, strlen(value),
|
474
|
+
(time_t)0, (uint32_t)0);
|
475
|
+
assert(rc == MEMCACHED_SUCCESS);
|
476
|
+
|
477
|
+
rc= memcached_mget(memc, keys, keylengths, 1);
|
478
|
+
|
479
|
+
results= memcached_result_create(memc, &results_obj);
|
480
|
+
|
481
|
+
results= memcached_fetch_result(memc, &results_obj, &rc);
|
482
|
+
assert(results);
|
483
|
+
assert(rc == MEMCACHED_SUCCESS);
|
484
|
+
assert(memcached_result_cas(results));
|
485
|
+
assert(!memcmp(value, memcached_result_value(results), value_length));
|
486
|
+
assert(strlen(memcached_result_value(results)) == value_length);
|
487
|
+
assert(rc == MEMCACHED_SUCCESS);
|
488
|
+
cas = memcached_result_cas(results);
|
489
|
+
|
490
|
+
#if 0
|
491
|
+
results= memcached_fetch_result(memc, &results_obj, &rc);
|
492
|
+
assert(rc == MEMCACHED_END);
|
493
|
+
assert(results == NULL);
|
494
|
+
#endif
|
495
|
+
|
496
|
+
rc= memcached_cas(memc, key, key_length, value2, value2_length, 0, 0, cas);
|
497
|
+
assert(rc == MEMCACHED_SUCCESS);
|
498
|
+
|
499
|
+
/*
|
500
|
+
* The item will have a new cas value, so try to set it again with the old
|
501
|
+
* value. This should fail!
|
502
|
+
*/
|
503
|
+
rc= memcached_cas(memc, key, key_length, value2, value2_length, 0, 0, cas);
|
504
|
+
assert(rc == MEMCACHED_DATA_EXISTS);
|
505
|
+
|
506
|
+
memcached_result_free(&results_obj);
|
507
|
+
|
508
|
+
return 0;
|
509
|
+
}
|
510
|
+
|
511
|
+
static test_return mget_len_no_cas_test(memcached_st *memc)
|
512
|
+
{
|
513
|
+
unsigned int x;
|
514
|
+
memcached_return rc;
|
515
|
+
uint32_t number_of_keys = 3;
|
516
|
+
const char *keys[]= {"fudge_for_me", "son_of_bonnie", "food_a_la_carte"};
|
517
|
+
size_t keys_length[]= {12, 13, 15};
|
518
|
+
const unsigned int specified_length = 4;
|
519
|
+
char *result_str;
|
520
|
+
|
521
|
+
memcached_result_st results_obj;
|
522
|
+
memcached_result_st *results;
|
523
|
+
|
524
|
+
results= memcached_result_create(memc, &results_obj);
|
525
|
+
assert(results);
|
526
|
+
assert(&results_obj == results);
|
527
|
+
|
528
|
+
/* We need to empty the server before continuing test */
|
529
|
+
rc= memcached_flush(memc, 0);
|
530
|
+
assert(rc == MEMCACHED_SUCCESS);
|
531
|
+
|
532
|
+
rc= memcached_mget(memc, keys, keys_length, number_of_keys);
|
533
|
+
assert(rc == MEMCACHED_SUCCESS);
|
534
|
+
|
535
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
536
|
+
{
|
537
|
+
assert(results);
|
538
|
+
}
|
539
|
+
|
540
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
541
|
+
assert(!results);
|
542
|
+
assert(rc == MEMCACHED_END);
|
543
|
+
|
544
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 0);
|
545
|
+
|
546
|
+
for (x= 0; x < number_of_keys; x++)
|
547
|
+
{
|
548
|
+
rc= memcached_set(memc, keys[x], keys_length[x],
|
549
|
+
keys[x], keys_length[x],
|
550
|
+
(time_t)50, (uint32_t)9);
|
551
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
552
|
+
}
|
553
|
+
|
554
|
+
rc= memcached_mget_len(memc, keys, keys_length, number_of_keys, specified_length);
|
555
|
+
|
556
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1) {
|
557
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
558
|
+
return 0;
|
559
|
+
}
|
560
|
+
|
561
|
+
assert(rc == MEMCACHED_SUCCESS);
|
562
|
+
|
563
|
+
x = 0;
|
564
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
|
565
|
+
{
|
566
|
+
assert(results);
|
567
|
+
assert(&results_obj == results);
|
568
|
+
assert(rc == MEMCACHED_SUCCESS);
|
569
|
+
assert(!memcached_result_cas(results));
|
570
|
+
|
571
|
+
result_str = memcached_result_value(results);
|
572
|
+
assert(strlen(result_str) == specified_length);
|
573
|
+
|
574
|
+
x++;
|
575
|
+
}
|
576
|
+
assert(x == number_of_keys);
|
577
|
+
|
578
|
+
memcached_result_free(&results_obj);
|
579
|
+
|
580
|
+
return 0;
|
581
|
+
}
|
582
|
+
|
583
|
+
static test_return mget_len_cas_test(memcached_st *memc)
|
584
|
+
{
|
585
|
+
unsigned int x;
|
586
|
+
memcached_return rc;
|
587
|
+
uint32_t number_of_keys = 3;
|
588
|
+
const char *keys[]= {"fudge_for_me", "son_of_bonnie", "food_a_la_carte"};
|
589
|
+
size_t keys_length[]= {12, 13, 15};
|
590
|
+
const unsigned int specified_length = 4;
|
591
|
+
const char *value2= "change the value";
|
592
|
+
size_t value2_length= strlen(value2);
|
593
|
+
memcached_st *mclone;
|
594
|
+
char *result_str;
|
595
|
+
uint64_t cas;
|
596
|
+
char *key;
|
597
|
+
uint32_t key_length;
|
598
|
+
|
599
|
+
memcached_result_st results_obj;
|
600
|
+
memcached_result_st *results;
|
601
|
+
|
602
|
+
results= memcached_result_create(memc, &results_obj);
|
603
|
+
assert(results);
|
604
|
+
assert(&results_obj == results);
|
605
|
+
|
606
|
+
/* We need to empty the server before continuing test */
|
607
|
+
rc= memcached_flush(memc, 0);
|
608
|
+
assert(rc == MEMCACHED_SUCCESS);
|
609
|
+
|
610
|
+
rc= memcached_mget(memc, keys, keys_length, number_of_keys);
|
611
|
+
assert(rc == MEMCACHED_SUCCESS);
|
612
|
+
|
613
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
614
|
+
{
|
615
|
+
assert(results);
|
616
|
+
}
|
617
|
+
|
618
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
619
|
+
assert(!results);
|
620
|
+
assert(rc == MEMCACHED_END);
|
621
|
+
|
622
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 1);
|
623
|
+
|
624
|
+
for (x= 0; x < number_of_keys; x++)
|
625
|
+
{
|
626
|
+
rc= memcached_set(memc, keys[x], keys_length[x],
|
627
|
+
keys[x], keys_length[x],
|
628
|
+
(time_t)50, (uint32_t)9);
|
629
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
630
|
+
}
|
631
|
+
|
632
|
+
rc= memcached_mget_len(memc, keys, keys_length, number_of_keys, specified_length);
|
633
|
+
|
634
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1) {
|
635
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
636
|
+
return 0;
|
637
|
+
}
|
638
|
+
|
639
|
+
assert(rc == MEMCACHED_SUCCESS);
|
640
|
+
|
641
|
+
/*
|
642
|
+
* memcached_cas() calls below truncate memcached_fetch_result()'s
|
643
|
+
* results so clone the memcached_st state and move on with life.
|
644
|
+
* This happens when using memcached_mget() and memcached_mget_len().
|
645
|
+
*/
|
646
|
+
mclone= memcached_clone(NULL, memc);
|
647
|
+
|
648
|
+
x = 0;
|
649
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
|
650
|
+
{
|
651
|
+
assert(results);
|
652
|
+
assert(&results_obj == results);
|
653
|
+
assert(rc == MEMCACHED_SUCCESS);
|
654
|
+
|
655
|
+
result_str = memcached_result_value(results);
|
656
|
+
assert(strlen(result_str) == specified_length);
|
657
|
+
|
658
|
+
assert(memcached_result_cas(results));
|
659
|
+
|
660
|
+
cas = memcached_result_cas(results);
|
661
|
+
key = memcached_result_key_value(results);
|
662
|
+
key_length = memcached_result_key_length(results);
|
663
|
+
rc= memcached_cas(mclone, key, key_length, value2, value2_length, 0, 0, cas);
|
664
|
+
|
665
|
+
/*
|
666
|
+
* The item will have a new cas value, so try to set it again with the old
|
667
|
+
* value. This should fail!
|
668
|
+
*/
|
669
|
+
rc= memcached_cas(mclone, key, key_length, value2, value2_length, 0, 0, cas);
|
670
|
+
assert(rc == MEMCACHED_DATA_EXISTS);
|
671
|
+
|
672
|
+
x++;
|
673
|
+
}
|
674
|
+
assert(x == number_of_keys);
|
675
|
+
|
676
|
+
memcached_result_free(&results_obj);
|
677
|
+
|
678
|
+
return 0;
|
679
|
+
}
|
680
|
+
|
681
|
+
static test_return prepend_test(memcached_st *memc)
|
682
|
+
{
|
683
|
+
memcached_return rc;
|
684
|
+
const char *key= "fig";
|
685
|
+
const char *value= "people";
|
686
|
+
char *out_value= NULL;
|
687
|
+
size_t value_length;
|
688
|
+
uint32_t flags;
|
689
|
+
|
690
|
+
rc= memcached_flush(memc, 0);
|
691
|
+
assert(rc == MEMCACHED_SUCCESS);
|
692
|
+
|
693
|
+
rc= memcached_set(memc, key, strlen(key),
|
694
|
+
value, strlen(value),
|
695
|
+
(time_t)0, (uint32_t)0);
|
696
|
+
assert(rc == MEMCACHED_SUCCESS);
|
697
|
+
|
698
|
+
rc= memcached_prepend(memc, key, strlen(key),
|
699
|
+
"the ", strlen("the "),
|
700
|
+
(time_t)0, (uint32_t)0);
|
701
|
+
assert(rc == MEMCACHED_SUCCESS);
|
702
|
+
|
703
|
+
rc= memcached_prepend(memc, key, strlen(key),
|
704
|
+
"we ", strlen("we "),
|
705
|
+
(time_t)0, (uint32_t)0);
|
706
|
+
assert(rc == MEMCACHED_SUCCESS);
|
707
|
+
|
708
|
+
out_value= memcached_get(memc, key, strlen(key),
|
709
|
+
&value_length, &flags, &rc);
|
710
|
+
assert(!memcmp(out_value, "we the people", strlen("we the people")));
|
711
|
+
assert(strlen("we the people") == value_length);
|
712
|
+
assert(rc == MEMCACHED_SUCCESS);
|
713
|
+
free(out_value);
|
714
|
+
|
715
|
+
return 0;
|
716
|
+
}
|
717
|
+
|
718
|
+
/*
|
719
|
+
Set the value, then quit to make sure it is flushed.
|
720
|
+
Come back in and test that add fails.
|
721
|
+
*/
|
722
|
+
static test_return add_test(memcached_st *memc)
|
723
|
+
{
|
724
|
+
memcached_return rc;
|
725
|
+
const char *key= "foo";
|
726
|
+
const char *value= "when we sanitize";
|
727
|
+
unsigned long long setting_value;
|
728
|
+
|
729
|
+
setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
|
730
|
+
|
731
|
+
rc= memcached_set(memc, key, strlen(key),
|
732
|
+
value, strlen(value),
|
733
|
+
(time_t)0, (uint32_t)0);
|
734
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
735
|
+
memcached_quit(memc);
|
736
|
+
rc= memcached_add(memc, key, strlen(key),
|
737
|
+
value, strlen(value),
|
738
|
+
(time_t)0, (uint32_t)0);
|
739
|
+
|
740
|
+
/* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
|
741
|
+
if (setting_value)
|
742
|
+
assert(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED);
|
743
|
+
else
|
744
|
+
assert(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_DATA_EXISTS);
|
745
|
+
|
746
|
+
return 0;
|
747
|
+
}
|
748
|
+
|
749
|
+
/*
|
750
|
+
** There was a problem of leaking filedescriptors in the initial release
|
751
|
+
** of MacOSX 10.5. This test case triggers the problem. On some Solaris
|
752
|
+
** systems it seems that the kernel is slow on reclaiming the resources
|
753
|
+
** because the connects starts to time out (the test doesn't do much
|
754
|
+
** anyway, so just loop 10 iterations)
|
755
|
+
*/
|
756
|
+
static test_return add_wrapper(memcached_st *memc)
|
757
|
+
{
|
758
|
+
unsigned int x;
|
759
|
+
unsigned int max= 10000;
|
760
|
+
#ifdef __sun
|
761
|
+
max= 10;
|
762
|
+
#endif
|
763
|
+
|
764
|
+
for (x= 0; x < max; x++)
|
765
|
+
add_test(memc);
|
766
|
+
|
767
|
+
return 0;
|
768
|
+
}
|
769
|
+
|
770
|
+
static test_return replace_test(memcached_st *memc)
|
771
|
+
{
|
772
|
+
memcached_return rc;
|
773
|
+
const char *key= "foo";
|
774
|
+
const char *value= "when we sanitize";
|
775
|
+
const char *original= "first we insert some data";
|
776
|
+
|
777
|
+
rc= memcached_set(memc, key, strlen(key),
|
778
|
+
original, strlen(original),
|
779
|
+
(time_t)0, (uint32_t)0);
|
780
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
781
|
+
|
782
|
+
rc= memcached_replace(memc, key, strlen(key),
|
783
|
+
value, strlen(value),
|
784
|
+
(time_t)0, (uint32_t)0);
|
785
|
+
assert(rc == MEMCACHED_SUCCESS);
|
786
|
+
|
787
|
+
return 0;
|
788
|
+
}
|
789
|
+
|
790
|
+
static test_return delete_test(memcached_st *memc)
|
791
|
+
{
|
792
|
+
memcached_return rc;
|
793
|
+
const char *key= "foo";
|
794
|
+
const char *value= "when we sanitize";
|
795
|
+
|
796
|
+
rc= memcached_set(memc, key, strlen(key),
|
797
|
+
value, strlen(value),
|
798
|
+
(time_t)0, (uint32_t)0);
|
799
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
800
|
+
|
801
|
+
rc= memcached_delete(memc, key, strlen(key), (time_t)0);
|
802
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
803
|
+
|
804
|
+
return 0;
|
805
|
+
}
|
806
|
+
|
807
|
+
static test_return flush_test(memcached_st *memc)
|
808
|
+
{
|
809
|
+
memcached_return rc;
|
810
|
+
|
811
|
+
rc= memcached_flush(memc, 0);
|
812
|
+
assert(rc == MEMCACHED_SUCCESS);
|
813
|
+
|
814
|
+
return 0;
|
815
|
+
}
|
816
|
+
|
817
|
+
static memcached_return server_function(memcached_st *ptr __attribute__((unused)),
|
818
|
+
memcached_server_st *server __attribute__((unused)),
|
819
|
+
void *context __attribute__((unused)))
|
820
|
+
{
|
821
|
+
/* Do Nothing */
|
822
|
+
|
823
|
+
return MEMCACHED_SUCCESS;
|
824
|
+
}
|
825
|
+
|
826
|
+
static test_return memcached_server_cursor_test(memcached_st *memc)
|
827
|
+
{
|
828
|
+
char context[8];
|
829
|
+
strcpy(context, "foo bad");
|
830
|
+
memcached_server_function callbacks[1];
|
831
|
+
|
832
|
+
callbacks[0]= server_function;
|
833
|
+
memcached_server_cursor(memc, callbacks, context, 1);
|
834
|
+
return 0;
|
835
|
+
}
|
836
|
+
|
837
|
+
static test_return bad_key_test(memcached_st *memc)
|
838
|
+
{
|
839
|
+
memcached_return rc;
|
840
|
+
const char *key= "foo bad";
|
841
|
+
char *string;
|
842
|
+
size_t string_length;
|
843
|
+
uint32_t flags;
|
844
|
+
memcached_st *memc_clone;
|
845
|
+
unsigned int set= 1;
|
846
|
+
size_t max_keylen= 0xffff;
|
847
|
+
const char *keys[] = { "GoodKey", "Bad Key", "NotMine" };
|
848
|
+
|
849
|
+
memc_clone= memcached_clone(NULL, memc);
|
850
|
+
assert(memc_clone);
|
851
|
+
|
852
|
+
rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
|
853
|
+
assert(rc == MEMCACHED_SUCCESS);
|
854
|
+
|
855
|
+
/* All keys are valid in the binary protocol (except for length) */
|
856
|
+
if (memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 0)
|
857
|
+
{
|
858
|
+
string= memcached_get(memc_clone, key, strlen(key),
|
859
|
+
&string_length, &flags, &rc);
|
860
|
+
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
861
|
+
assert(string_length == 0);
|
862
|
+
assert(!string);
|
863
|
+
|
864
|
+
set= 0;
|
865
|
+
rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
|
866
|
+
assert(rc == MEMCACHED_SUCCESS);
|
867
|
+
string= memcached_get(memc_clone, key, strlen(key),
|
868
|
+
&string_length, &flags, &rc);
|
869
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
870
|
+
assert(string_length == 0);
|
871
|
+
assert(!string);
|
872
|
+
|
873
|
+
/* Test multi key for bad keys */
|
874
|
+
size_t key_lengths[] = { 7, 7, 7 };
|
875
|
+
set= 1;
|
876
|
+
rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
|
877
|
+
assert(rc == MEMCACHED_SUCCESS);
|
878
|
+
|
879
|
+
rc= memcached_mget(memc_clone, keys, key_lengths, 3);
|
880
|
+
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
881
|
+
|
882
|
+
rc= memcached_mget_by_key(memc_clone, "foo daddy", 9, keys, key_lengths,
|
883
|
+
1, GET_LEN_ARG_UNSPECIFIED);
|
884
|
+
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
885
|
+
|
886
|
+
max_keylen= 250;
|
887
|
+
|
888
|
+
/* The following test should be moved to the end of this function when the
|
889
|
+
memcached server is updated to allow max size length of the keys in the
|
890
|
+
binary protocol
|
891
|
+
*/
|
892
|
+
rc= memcached_callback_set(memc_clone, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
|
893
|
+
assert(rc == MEMCACHED_SUCCESS);
|
894
|
+
|
895
|
+
char *longkey= malloc(max_keylen + 1);
|
896
|
+
if (longkey != NULL)
|
897
|
+
{
|
898
|
+
memset(longkey, 'a', max_keylen + 1);
|
899
|
+
string= memcached_get(memc_clone, longkey, max_keylen,
|
900
|
+
&string_length, &flags, &rc);
|
901
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
902
|
+
assert(string_length == 0);
|
903
|
+
assert(!string);
|
904
|
+
|
905
|
+
string= memcached_get(memc_clone, longkey, max_keylen + 1,
|
906
|
+
&string_length, &flags, &rc);
|
907
|
+
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
908
|
+
assert(string_length == 0);
|
909
|
+
assert(!string);
|
910
|
+
|
911
|
+
free(longkey);
|
912
|
+
}
|
913
|
+
}
|
914
|
+
|
915
|
+
/* Make sure zero length keys are marked as bad */
|
916
|
+
set= 1;
|
917
|
+
rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
|
918
|
+
assert(rc == MEMCACHED_SUCCESS);
|
919
|
+
string= memcached_get(memc_clone, key, 0,
|
920
|
+
&string_length, &flags, &rc);
|
921
|
+
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
922
|
+
assert(string_length == 0);
|
923
|
+
assert(!string);
|
924
|
+
|
925
|
+
memcached_free(memc_clone);
|
926
|
+
|
927
|
+
return 0;
|
928
|
+
}
|
929
|
+
|
930
|
+
#define READ_THROUGH_VALUE "set for me"
|
931
|
+
static memcached_return read_through_trigger(memcached_st *memc __attribute__((unused)),
|
932
|
+
char *key __attribute__((unused)),
|
933
|
+
size_t key_length __attribute__((unused)),
|
934
|
+
memcached_result_st *result)
|
935
|
+
{
|
936
|
+
|
937
|
+
return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE));
|
938
|
+
}
|
939
|
+
|
940
|
+
static test_return read_through(memcached_st *memc)
|
941
|
+
{
|
942
|
+
memcached_return rc;
|
943
|
+
const char *key= "foo";
|
944
|
+
char *string;
|
945
|
+
size_t string_length;
|
946
|
+
uint32_t flags;
|
947
|
+
memcached_trigger_key cb= (memcached_trigger_key)read_through_trigger;
|
948
|
+
|
949
|
+
string= memcached_get(memc, key, strlen(key),
|
950
|
+
&string_length, &flags, &rc);
|
951
|
+
|
952
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
953
|
+
assert(string_length == 0);
|
954
|
+
assert(!string);
|
955
|
+
|
956
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE,
|
957
|
+
*(void **)&cb);
|
958
|
+
assert(rc == MEMCACHED_SUCCESS);
|
959
|
+
|
960
|
+
string= memcached_get(memc, key, strlen(key),
|
961
|
+
&string_length, &flags, &rc);
|
962
|
+
|
963
|
+
assert(rc == MEMCACHED_SUCCESS);
|
964
|
+
assert(string_length == strlen(READ_THROUGH_VALUE));
|
965
|
+
assert(!strcmp(READ_THROUGH_VALUE, string));
|
966
|
+
free(string);
|
967
|
+
|
968
|
+
string= memcached_get(memc, key, strlen(key),
|
969
|
+
&string_length, &flags, &rc);
|
970
|
+
|
971
|
+
assert(rc == MEMCACHED_SUCCESS);
|
972
|
+
assert(string_length == strlen(READ_THROUGH_VALUE));
|
973
|
+
assert(!strcmp(READ_THROUGH_VALUE, string));
|
974
|
+
free(string);
|
975
|
+
|
976
|
+
return 0;
|
977
|
+
}
|
978
|
+
|
979
|
+
static memcached_return delete_trigger(memcached_st *ptr __attribute__((unused)),
|
980
|
+
const char *key,
|
981
|
+
size_t key_length __attribute__((unused)))
|
982
|
+
{
|
983
|
+
assert(key);
|
984
|
+
|
985
|
+
return MEMCACHED_SUCCESS;
|
986
|
+
}
|
987
|
+
|
988
|
+
static test_return delete_through(memcached_st *memc)
|
989
|
+
{
|
990
|
+
memcached_trigger_delete_key callback;
|
991
|
+
memcached_return rc;
|
992
|
+
|
993
|
+
callback= (memcached_trigger_delete_key)delete_trigger;
|
994
|
+
|
995
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, *(void**)&callback);
|
996
|
+
assert(rc == MEMCACHED_SUCCESS);
|
997
|
+
|
998
|
+
return 0;
|
999
|
+
}
|
1000
|
+
|
1001
|
+
static test_return get_test(memcached_st *memc)
|
1002
|
+
{
|
1003
|
+
memcached_return rc;
|
1004
|
+
const char *key= "foo";
|
1005
|
+
char *string;
|
1006
|
+
size_t string_length;
|
1007
|
+
uint32_t flags;
|
1008
|
+
|
1009
|
+
rc= memcached_delete(memc, key, strlen(key), (time_t)0);
|
1010
|
+
assert(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND);
|
1011
|
+
|
1012
|
+
string= memcached_get(memc, key, strlen(key),
|
1013
|
+
&string_length, &flags, &rc);
|
1014
|
+
|
1015
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
1016
|
+
assert(string_length == 0);
|
1017
|
+
assert(!string);
|
1018
|
+
|
1019
|
+
return 0;
|
1020
|
+
}
|
1021
|
+
|
1022
|
+
static test_return get_test2(memcached_st *memc)
|
1023
|
+
{
|
1024
|
+
memcached_return rc;
|
1025
|
+
const char *key= "foo";
|
1026
|
+
const char *value= "when we sanitize";
|
1027
|
+
char *string;
|
1028
|
+
size_t string_length;
|
1029
|
+
uint32_t flags;
|
1030
|
+
|
1031
|
+
rc= memcached_set(memc, key, strlen(key),
|
1032
|
+
value, strlen(value),
|
1033
|
+
(time_t)0, (uint32_t)0);
|
1034
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1035
|
+
|
1036
|
+
string= memcached_get(memc, key, strlen(key),
|
1037
|
+
&string_length, &flags, &rc);
|
1038
|
+
|
1039
|
+
assert(string);
|
1040
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1041
|
+
assert(string_length == strlen(value));
|
1042
|
+
assert(!memcmp(string, value, string_length));
|
1043
|
+
|
1044
|
+
free(string);
|
1045
|
+
|
1046
|
+
return 0;
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
static test_return get_len_test(memcached_st *memc)
|
1050
|
+
{
|
1051
|
+
memcached_return rc;
|
1052
|
+
const char *key= "foo_never_found_thank_you";
|
1053
|
+
const uint32_t user_spec_len = 4;
|
1054
|
+
char *string;
|
1055
|
+
size_t string_length;
|
1056
|
+
uint32_t flags;
|
1057
|
+
|
1058
|
+
rc= memcached_delete(memc, key, strlen(key), (time_t)0);
|
1059
|
+
assert(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND);
|
1060
|
+
|
1061
|
+
string= memcached_get_len(memc, key, strlen(key), user_spec_len,
|
1062
|
+
&string_length, &flags, &rc);
|
1063
|
+
|
1064
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1) {
|
1065
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
1066
|
+
} else {
|
1067
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
1068
|
+
assert(string_length == 0);
|
1069
|
+
assert(!string);
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
return 0;
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
static test_return get_len_test2(memcached_st *memc)
|
1076
|
+
{
|
1077
|
+
memcached_return rc;
|
1078
|
+
const char *key= "foo";
|
1079
|
+
const char *value= "when we sanitize";
|
1080
|
+
const uint32_t user_spec_len = 6;
|
1081
|
+
const char *ret_value= "when w";
|
1082
|
+
char *string;
|
1083
|
+
size_t string_length;
|
1084
|
+
uint32_t flags;
|
1085
|
+
|
1086
|
+
rc= memcached_set(memc, key, strlen(key),
|
1087
|
+
value, strlen(value),
|
1088
|
+
(time_t)0, (uint32_t)0);
|
1089
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1090
|
+
|
1091
|
+
string= memcached_get_len(memc, key, strlen(key), user_spec_len,
|
1092
|
+
&string_length, &flags, &rc);
|
1093
|
+
|
1094
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1) {
|
1095
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
1096
|
+
} else {
|
1097
|
+
assert(string);
|
1098
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1099
|
+
assert(string_length == strlen(ret_value));
|
1100
|
+
assert(!memcmp(string, ret_value, string_length));
|
1101
|
+
|
1102
|
+
free(string);
|
1103
|
+
}
|
1104
|
+
|
1105
|
+
return 0;
|
1106
|
+
}
|
1107
|
+
|
1108
|
+
static test_return get_len_test3(memcached_st *memc)
|
1109
|
+
{
|
1110
|
+
memcached_return rc;
|
1111
|
+
const char *key= "test";
|
1112
|
+
const char *value= "bar";
|
1113
|
+
const uint32_t user_spec_len = 2;
|
1114
|
+
const char *ret_value= "ba";
|
1115
|
+
char *string;
|
1116
|
+
size_t string_length;
|
1117
|
+
uint32_t flags;
|
1118
|
+
|
1119
|
+
rc= memcached_set(memc, key, strlen(key),
|
1120
|
+
value, strlen(value),
|
1121
|
+
(time_t)0, (uint32_t)0);
|
1122
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1123
|
+
|
1124
|
+
string= memcached_get_len(memc, key, strlen(key), user_spec_len,
|
1125
|
+
&string_length, &flags, &rc);
|
1126
|
+
|
1127
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1) {
|
1128
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
1129
|
+
} else {
|
1130
|
+
assert(string);
|
1131
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1132
|
+
assert(string_length == strlen(ret_value));
|
1133
|
+
assert(!memcmp(string, ret_value, string_length));
|
1134
|
+
|
1135
|
+
free(string);
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
return 0;
|
1139
|
+
}
|
1140
|
+
|
1141
|
+
|
1142
|
+
|
1143
|
+
static test_return set_test2(memcached_st *memc)
|
1144
|
+
{
|
1145
|
+
memcached_return rc;
|
1146
|
+
const char *key= "foo";
|
1147
|
+
const char *value= "train in the brain";
|
1148
|
+
size_t value_length= strlen(value);
|
1149
|
+
unsigned int x;
|
1150
|
+
|
1151
|
+
for (x= 0; x < 10; x++)
|
1152
|
+
{
|
1153
|
+
rc= memcached_set(memc, key, strlen(key),
|
1154
|
+
value, value_length,
|
1155
|
+
(time_t)0, (uint32_t)0);
|
1156
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
return 0;
|
1160
|
+
}
|
1161
|
+
|
1162
|
+
static test_return set_test3(memcached_st *memc)
|
1163
|
+
{
|
1164
|
+
memcached_return rc;
|
1165
|
+
char *value;
|
1166
|
+
size_t value_length= 8191;
|
1167
|
+
unsigned int x;
|
1168
|
+
|
1169
|
+
value = (char*)malloc(value_length);
|
1170
|
+
assert(value);
|
1171
|
+
|
1172
|
+
for (x= 0; x < value_length; x++)
|
1173
|
+
value[x] = (char) (x % 127);
|
1174
|
+
|
1175
|
+
/* The dump test relies on there being at least 32 items in memcached */
|
1176
|
+
for (x= 0; x < 32; x++)
|
1177
|
+
{
|
1178
|
+
char key[16];
|
1179
|
+
|
1180
|
+
sprintf(key, "foo%u", x);
|
1181
|
+
|
1182
|
+
rc= memcached_set(memc, key, strlen(key),
|
1183
|
+
value, value_length,
|
1184
|
+
(time_t)0, (uint32_t)0);
|
1185
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1186
|
+
}
|
1187
|
+
|
1188
|
+
free(value);
|
1189
|
+
|
1190
|
+
return 0;
|
1191
|
+
}
|
1192
|
+
|
1193
|
+
static test_return get_test3(memcached_st *memc)
|
1194
|
+
{
|
1195
|
+
memcached_return rc;
|
1196
|
+
const char *key= "foo";
|
1197
|
+
char *value;
|
1198
|
+
size_t value_length= 8191;
|
1199
|
+
char *string;
|
1200
|
+
size_t string_length;
|
1201
|
+
uint32_t flags;
|
1202
|
+
uint32_t x;
|
1203
|
+
|
1204
|
+
value = (char*)malloc(value_length);
|
1205
|
+
assert(value);
|
1206
|
+
|
1207
|
+
for (x= 0; x < value_length; x++)
|
1208
|
+
value[x] = (char) (x % 127);
|
1209
|
+
|
1210
|
+
rc= memcached_set(memc, key, strlen(key),
|
1211
|
+
value, value_length,
|
1212
|
+
(time_t)0, (uint32_t)0);
|
1213
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1214
|
+
|
1215
|
+
string= memcached_get(memc, key, strlen(key),
|
1216
|
+
&string_length, &flags, &rc);
|
1217
|
+
|
1218
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1219
|
+
assert(string);
|
1220
|
+
assert(string_length == value_length);
|
1221
|
+
assert(!memcmp(string, value, string_length));
|
1222
|
+
|
1223
|
+
free(string);
|
1224
|
+
free(value);
|
1225
|
+
|
1226
|
+
return 0;
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
static test_return get_test4(memcached_st *memc)
|
1230
|
+
{
|
1231
|
+
memcached_return rc;
|
1232
|
+
const char *key= "foo";
|
1233
|
+
char *value;
|
1234
|
+
size_t value_length= 8191;
|
1235
|
+
char *string;
|
1236
|
+
size_t string_length;
|
1237
|
+
uint32_t flags;
|
1238
|
+
uint32_t x;
|
1239
|
+
|
1240
|
+
value = (char*)malloc(value_length);
|
1241
|
+
assert(value);
|
1242
|
+
|
1243
|
+
for (x= 0; x < value_length; x++)
|
1244
|
+
value[x] = (char) (x % 127);
|
1245
|
+
|
1246
|
+
rc= memcached_set(memc, key, strlen(key),
|
1247
|
+
value, value_length,
|
1248
|
+
(time_t)0, (uint32_t)0);
|
1249
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1250
|
+
|
1251
|
+
for (x= 0; x < 10; x++)
|
1252
|
+
{
|
1253
|
+
string= memcached_get(memc, key, strlen(key),
|
1254
|
+
&string_length, &flags, &rc);
|
1255
|
+
|
1256
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1257
|
+
assert(string);
|
1258
|
+
assert(string_length == value_length);
|
1259
|
+
assert(!memcmp(string, value, string_length));
|
1260
|
+
free(string);
|
1261
|
+
}
|
1262
|
+
|
1263
|
+
free(value);
|
1264
|
+
|
1265
|
+
return 0;
|
1266
|
+
}
|
1267
|
+
|
1268
|
+
/*
|
1269
|
+
* This test verifies that memcached_read_one_response doesn't try to
|
1270
|
+
* dereference a NIL-pointer if you issue a multi-get and don't read out all
|
1271
|
+
* responses before you execute a storage command.
|
1272
|
+
*/
|
1273
|
+
static test_return get_test5(memcached_st *memc)
|
1274
|
+
{
|
1275
|
+
/*
|
1276
|
+
** Request the same key twice, to ensure that we hash to the same server
|
1277
|
+
** (so that we have multiple response values queued up) ;-)
|
1278
|
+
*/
|
1279
|
+
const char *keys[]= { "key", "key" };
|
1280
|
+
size_t lengths[]= { 3, 3 };
|
1281
|
+
uint32_t flags;
|
1282
|
+
size_t rlen;
|
1283
|
+
|
1284
|
+
memcached_return rc= memcached_set(memc, keys[0], lengths[0],
|
1285
|
+
keys[0], lengths[0], 0, 0);
|
1286
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1287
|
+
rc= memcached_mget(memc, keys, lengths, 2);
|
1288
|
+
|
1289
|
+
memcached_result_st results_obj;
|
1290
|
+
memcached_result_st *results;
|
1291
|
+
results=memcached_result_create(memc, &results_obj);
|
1292
|
+
assert(results);
|
1293
|
+
results=memcached_fetch_result(memc, &results_obj, &rc);
|
1294
|
+
assert(results);
|
1295
|
+
memcached_result_free(&results_obj);
|
1296
|
+
|
1297
|
+
/* Don't read out the second result, but issue a set instead.. */
|
1298
|
+
rc= memcached_set(memc, keys[0], lengths[0], keys[0], lengths[0], 0, 0);
|
1299
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1300
|
+
|
1301
|
+
char *val= memcached_get_by_key(memc, keys[0], lengths[0], "yek", 3,
|
1302
|
+
GET_LEN_ARG_UNSPECIFIED,
|
1303
|
+
&rlen, &flags, &rc);
|
1304
|
+
assert(val == NULL);
|
1305
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
1306
|
+
val= memcached_get(memc, keys[0], lengths[0], &rlen, &flags, &rc);
|
1307
|
+
assert(val != NULL);
|
1308
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1309
|
+
free(val);
|
1310
|
+
|
1311
|
+
return TEST_SUCCESS;
|
1312
|
+
}
|
1313
|
+
|
1314
|
+
/*
|
1315
|
+
* This test verifies that dummy NOOP response will be fetched when
|
1316
|
+
* client try to GET missing key.
|
1317
|
+
*/
|
1318
|
+
static test_return get_test6(memcached_st *memc)
|
1319
|
+
{
|
1320
|
+
const char *key= "getkey";
|
1321
|
+
const char *val= "getval";
|
1322
|
+
size_t len;
|
1323
|
+
uint32_t flags;
|
1324
|
+
char *value;
|
1325
|
+
memcached_return rc;
|
1326
|
+
|
1327
|
+
value= memcached_get(memc, key, strlen(key), &len, &flags, &rc);
|
1328
|
+
assert(len == 0);
|
1329
|
+
assert(value == 0);
|
1330
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
1331
|
+
|
1332
|
+
rc= memcached_set(memc, key, strlen(key), val, strlen(val), 2, 0);
|
1333
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1334
|
+
|
1335
|
+
return TEST_SUCCESS;
|
1336
|
+
}
|
1337
|
+
|
1338
|
+
|
1339
|
+
/* Do not copy the style of this code, I just access hosts to testthis function */
|
1340
|
+
static test_return stats_servername_test(memcached_st *memc)
|
1341
|
+
{
|
1342
|
+
memcached_return rc;
|
1343
|
+
memcached_stat_st memc_stat;
|
1344
|
+
rc= memcached_stat_servername(&memc_stat, NULL,
|
1345
|
+
memc->hosts[0].hostname,
|
1346
|
+
memc->hosts[0].port);
|
1347
|
+
|
1348
|
+
return 0;
|
1349
|
+
}
|
1350
|
+
|
1351
|
+
static test_return increment_test(memcached_st *memc)
|
1352
|
+
{
|
1353
|
+
uint64_t new_number;
|
1354
|
+
memcached_return rc;
|
1355
|
+
const char *key= "number";
|
1356
|
+
const char *value= "0";
|
1357
|
+
|
1358
|
+
rc= memcached_set(memc, key, strlen(key),
|
1359
|
+
value, strlen(value),
|
1360
|
+
(time_t)0, (uint32_t)0);
|
1361
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1362
|
+
|
1363
|
+
rc= memcached_increment(memc, key, strlen(key),
|
1364
|
+
1, &new_number);
|
1365
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1366
|
+
assert(new_number == 1);
|
1367
|
+
|
1368
|
+
rc= memcached_increment(memc, key, strlen(key),
|
1369
|
+
1, &new_number);
|
1370
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1371
|
+
assert(new_number == 2);
|
1372
|
+
|
1373
|
+
return 0;
|
1374
|
+
}
|
1375
|
+
|
1376
|
+
static test_return increment_with_initial_test(memcached_st *memc)
|
1377
|
+
{
|
1378
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) != 0)
|
1379
|
+
{
|
1380
|
+
uint64_t new_number;
|
1381
|
+
memcached_return rc;
|
1382
|
+
const char *key= "number";
|
1383
|
+
uint64_t initial= 0;
|
1384
|
+
|
1385
|
+
rc= memcached_increment_with_initial(memc, key, strlen(key),
|
1386
|
+
1, initial, 0, &new_number);
|
1387
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1388
|
+
assert(new_number == initial);
|
1389
|
+
|
1390
|
+
rc= memcached_increment_with_initial(memc, key, strlen(key),
|
1391
|
+
1, initial, 0, &new_number);
|
1392
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1393
|
+
assert(new_number == (initial + 1));
|
1394
|
+
}
|
1395
|
+
return 0;
|
1396
|
+
}
|
1397
|
+
|
1398
|
+
static test_return decrement_test(memcached_st *memc)
|
1399
|
+
{
|
1400
|
+
uint64_t new_number;
|
1401
|
+
memcached_return rc;
|
1402
|
+
const char *key= "number";
|
1403
|
+
const char *value= "3";
|
1404
|
+
|
1405
|
+
rc= memcached_set(memc, key, strlen(key),
|
1406
|
+
value, strlen(value),
|
1407
|
+
(time_t)0, (uint32_t)0);
|
1408
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1409
|
+
|
1410
|
+
rc= memcached_decrement(memc, key, strlen(key),
|
1411
|
+
1, &new_number);
|
1412
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1413
|
+
assert(new_number == 2);
|
1414
|
+
|
1415
|
+
rc= memcached_decrement(memc, key, strlen(key),
|
1416
|
+
1, &new_number);
|
1417
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1418
|
+
assert(new_number == 1);
|
1419
|
+
|
1420
|
+
return 0;
|
1421
|
+
}
|
1422
|
+
|
1423
|
+
static test_return decrement_with_initial_test(memcached_st *memc)
|
1424
|
+
{
|
1425
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) != 0)
|
1426
|
+
{
|
1427
|
+
uint64_t new_number;
|
1428
|
+
memcached_return rc;
|
1429
|
+
const char *key= "number";
|
1430
|
+
uint64_t initial= 3;
|
1431
|
+
|
1432
|
+
rc= memcached_decrement_with_initial(memc, key, strlen(key),
|
1433
|
+
1, initial, 0, &new_number);
|
1434
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1435
|
+
assert(new_number == initial);
|
1436
|
+
|
1437
|
+
rc= memcached_decrement_with_initial(memc, key, strlen(key),
|
1438
|
+
1, initial, 0, &new_number);
|
1439
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1440
|
+
assert(new_number == (initial - 1));
|
1441
|
+
}
|
1442
|
+
return 0;
|
1443
|
+
}
|
1444
|
+
|
1445
|
+
static test_return quit_test(memcached_st *memc)
|
1446
|
+
{
|
1447
|
+
memcached_return rc;
|
1448
|
+
const char *key= "fudge";
|
1449
|
+
const char *value= "sanford and sun";
|
1450
|
+
|
1451
|
+
rc= memcached_set(memc, key, strlen(key),
|
1452
|
+
value, strlen(value),
|
1453
|
+
(time_t)10, (uint32_t)3);
|
1454
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1455
|
+
memcached_quit(memc);
|
1456
|
+
|
1457
|
+
rc= memcached_set(memc, key, strlen(key),
|
1458
|
+
value, strlen(value),
|
1459
|
+
(time_t)50, (uint32_t)9);
|
1460
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1461
|
+
|
1462
|
+
return 0;
|
1463
|
+
}
|
1464
|
+
|
1465
|
+
static test_return mget_result_test(memcached_st *memc)
|
1466
|
+
{
|
1467
|
+
memcached_return rc;
|
1468
|
+
const char *keys[]= {"fudge", "son", "food"};
|
1469
|
+
size_t key_length[]= {5, 3, 4};
|
1470
|
+
unsigned int x;
|
1471
|
+
|
1472
|
+
memcached_result_st results_obj;
|
1473
|
+
memcached_result_st *results;
|
1474
|
+
|
1475
|
+
results= memcached_result_create(memc, &results_obj);
|
1476
|
+
assert(results);
|
1477
|
+
assert(&results_obj == results);
|
1478
|
+
|
1479
|
+
/* We need to empty the server before continueing test */
|
1480
|
+
rc= memcached_flush(memc, 0);
|
1481
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1482
|
+
|
1483
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
1484
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1485
|
+
|
1486
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
1487
|
+
{
|
1488
|
+
assert(results);
|
1489
|
+
}
|
1490
|
+
|
1491
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
1492
|
+
assert(!results);
|
1493
|
+
assert(rc == MEMCACHED_END);
|
1494
|
+
|
1495
|
+
for (x= 0; x < 3; x++)
|
1496
|
+
{
|
1497
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
1498
|
+
keys[x], key_length[x],
|
1499
|
+
(time_t)50, (uint32_t)9);
|
1500
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1501
|
+
}
|
1502
|
+
|
1503
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
1504
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1505
|
+
|
1506
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
|
1507
|
+
{
|
1508
|
+
assert(results);
|
1509
|
+
assert(&results_obj == results);
|
1510
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1511
|
+
assert(memcached_result_key_length(results) == memcached_result_length(results));
|
1512
|
+
assert(!memcmp(memcached_result_key_value(results),
|
1513
|
+
memcached_result_value(results),
|
1514
|
+
memcached_result_length(results)));
|
1515
|
+
}
|
1516
|
+
|
1517
|
+
memcached_result_free(&results_obj);
|
1518
|
+
|
1519
|
+
return 0;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
static test_return mget_len_result_test(memcached_st *memc)
|
1523
|
+
{
|
1524
|
+
memcached_return rc;
|
1525
|
+
uint32_t number_of_keys = 3;
|
1526
|
+
const char *keys[]= {"fudge_for_me", "son_of_bonnie", "food_a_la_carte"};
|
1527
|
+
size_t key_length[]= {12, 13, 15};
|
1528
|
+
const unsigned int specified_length = 4;
|
1529
|
+
const char *expected_results[]= {"fudg", "son_", "food"};
|
1530
|
+
unsigned int x;
|
1531
|
+
|
1532
|
+
memcached_result_st results_obj;
|
1533
|
+
memcached_result_st *results;
|
1534
|
+
|
1535
|
+
results= memcached_result_create(memc, &results_obj);
|
1536
|
+
assert(results);
|
1537
|
+
assert(&results_obj == results);
|
1538
|
+
|
1539
|
+
/* We need to empty the server before continueing test */
|
1540
|
+
rc= memcached_flush(memc, 0);
|
1541
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1542
|
+
|
1543
|
+
rc= memcached_mget(memc, keys, key_length, number_of_keys);
|
1544
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1545
|
+
|
1546
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
1547
|
+
{
|
1548
|
+
assert(results);
|
1549
|
+
}
|
1550
|
+
|
1551
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
|
1552
|
+
assert(!results);
|
1553
|
+
assert(rc == MEMCACHED_END);
|
1554
|
+
|
1555
|
+
for (x= 0; x < number_of_keys; x++)
|
1556
|
+
{
|
1557
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
1558
|
+
keys[x], key_length[x],
|
1559
|
+
(time_t)50, (uint32_t)9);
|
1560
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1561
|
+
}
|
1562
|
+
|
1563
|
+
rc= memcached_mget_len(memc, keys, key_length, number_of_keys, specified_length);
|
1564
|
+
|
1565
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1) {
|
1566
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
1567
|
+
return 0;
|
1568
|
+
}
|
1569
|
+
|
1570
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1571
|
+
|
1572
|
+
x = 0;
|
1573
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
|
1574
|
+
{
|
1575
|
+
char *result_str = memcached_result_value(results);
|
1576
|
+
size_t str_len = strlen(result_str);
|
1577
|
+
assert(results);
|
1578
|
+
assert(&results_obj == results);
|
1579
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1580
|
+
assert(str_len == specified_length);
|
1581
|
+
assert(strlen(expected_results[0]) == specified_length);
|
1582
|
+
assert(strlen(expected_results[1]) == specified_length);
|
1583
|
+
assert(strlen(expected_results[2]) == specified_length);
|
1584
|
+
assert((memcmp(result_str, expected_results[0], specified_length) == 0) ||
|
1585
|
+
(memcmp(result_str, expected_results[1], specified_length) == 0) ||
|
1586
|
+
(memcmp(result_str, expected_results[2], specified_length) == 0));
|
1587
|
+
x++;
|
1588
|
+
}
|
1589
|
+
assert(x == number_of_keys);
|
1590
|
+
|
1591
|
+
memcached_result_free(&results_obj);
|
1592
|
+
|
1593
|
+
return 0;
|
1594
|
+
}
|
1595
|
+
|
1596
|
+
static test_return mget_result_alloc_test(memcached_st *memc)
|
1597
|
+
{
|
1598
|
+
memcached_return rc;
|
1599
|
+
const char *keys[]= {"fudge", "son", "food"};
|
1600
|
+
size_t key_length[]= {5, 3, 4};
|
1601
|
+
unsigned int x;
|
1602
|
+
|
1603
|
+
memcached_result_st *results;
|
1604
|
+
|
1605
|
+
/* We need to empty the server before continueing test */
|
1606
|
+
rc= memcached_flush(memc, 0);
|
1607
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1608
|
+
|
1609
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
1610
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1611
|
+
|
1612
|
+
while ((results= memcached_fetch_result(memc, NULL, &rc)) != NULL)
|
1613
|
+
{
|
1614
|
+
assert(results);
|
1615
|
+
}
|
1616
|
+
assert(!results);
|
1617
|
+
assert(rc == MEMCACHED_END);
|
1618
|
+
|
1619
|
+
for (x= 0; x < 3; x++)
|
1620
|
+
{
|
1621
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
1622
|
+
keys[x], key_length[x],
|
1623
|
+
(time_t)50, (uint32_t)9);
|
1624
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
1628
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1629
|
+
|
1630
|
+
x= 0;
|
1631
|
+
while ((results= memcached_fetch_result(memc, NULL, &rc)))
|
1632
|
+
{
|
1633
|
+
assert(results);
|
1634
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1635
|
+
assert(memcached_result_key_length(results) == memcached_result_length(results));
|
1636
|
+
assert(!memcmp(memcached_result_key_value(results),
|
1637
|
+
memcached_result_value(results),
|
1638
|
+
memcached_result_length(results)));
|
1639
|
+
memcached_result_free(results);
|
1640
|
+
x++;
|
1641
|
+
}
|
1642
|
+
|
1643
|
+
return 0;
|
1644
|
+
}
|
1645
|
+
|
1646
|
+
/* Count the results */
|
1647
|
+
static memcached_return callback_counter(memcached_st *ptr __attribute__((unused)),
|
1648
|
+
memcached_result_st *result __attribute__((unused)),
|
1649
|
+
void *context)
|
1650
|
+
{
|
1651
|
+
unsigned int *counter= (unsigned int *)context;
|
1652
|
+
|
1653
|
+
*counter= *counter + 1;
|
1654
|
+
|
1655
|
+
return MEMCACHED_SUCCESS;
|
1656
|
+
}
|
1657
|
+
|
1658
|
+
static test_return mget_result_function(memcached_st *memc)
|
1659
|
+
{
|
1660
|
+
memcached_return rc;
|
1661
|
+
const char *keys[]= {"fudge", "son", "food"};
|
1662
|
+
size_t key_length[]= {5, 3, 4};
|
1663
|
+
unsigned int x;
|
1664
|
+
unsigned int counter;
|
1665
|
+
memcached_execute_function callbacks[1];
|
1666
|
+
|
1667
|
+
/* We need to empty the server before continueing test */
|
1668
|
+
rc= memcached_flush(memc, 0);
|
1669
|
+
for (x= 0; x < 3; x++)
|
1670
|
+
{
|
1671
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
1672
|
+
keys[x], key_length[x],
|
1673
|
+
(time_t)50, (uint32_t)9);
|
1674
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1675
|
+
}
|
1676
|
+
|
1677
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
1678
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1679
|
+
|
1680
|
+
callbacks[0]= &callback_counter;
|
1681
|
+
counter= 0;
|
1682
|
+
rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
|
1683
|
+
|
1684
|
+
assert(counter == 3);
|
1685
|
+
|
1686
|
+
return 0;
|
1687
|
+
}
|
1688
|
+
|
1689
|
+
static test_return mget_test(memcached_st *memc)
|
1690
|
+
{
|
1691
|
+
memcached_return rc;
|
1692
|
+
const char *keys[]= {"fudge", "son", "food"};
|
1693
|
+
size_t key_length[]= {5, 3, 4};
|
1694
|
+
unsigned int x;
|
1695
|
+
uint32_t flags;
|
1696
|
+
|
1697
|
+
char return_key[MEMCACHED_MAX_KEY];
|
1698
|
+
size_t return_key_length;
|
1699
|
+
char *return_value;
|
1700
|
+
size_t return_value_length;
|
1701
|
+
|
1702
|
+
/* We need to empty the server before continueing test */
|
1703
|
+
rc= memcached_flush(memc, 0);
|
1704
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1705
|
+
|
1706
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
1707
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1708
|
+
|
1709
|
+
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
|
1710
|
+
&return_value_length, &flags, &rc)) != NULL)
|
1711
|
+
{
|
1712
|
+
assert(return_value);
|
1713
|
+
}
|
1714
|
+
assert(!return_value);
|
1715
|
+
assert(return_value_length == 0);
|
1716
|
+
assert(rc == MEMCACHED_END);
|
1717
|
+
|
1718
|
+
for (x= 0; x < 3; x++)
|
1719
|
+
{
|
1720
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
1721
|
+
keys[x], key_length[x],
|
1722
|
+
(time_t)50, (uint32_t)9);
|
1723
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1724
|
+
}
|
1725
|
+
|
1726
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
1727
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1728
|
+
|
1729
|
+
x= 0;
|
1730
|
+
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
|
1731
|
+
&return_value_length, &flags, &rc)))
|
1732
|
+
{
|
1733
|
+
assert(return_value);
|
1734
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1735
|
+
assert(return_key_length == return_value_length);
|
1736
|
+
assert(!memcmp(return_value, return_key, return_value_length));
|
1737
|
+
free(return_value);
|
1738
|
+
x++;
|
1739
|
+
}
|
1740
|
+
|
1741
|
+
return 0;
|
1742
|
+
}
|
1743
|
+
|
1744
|
+
static test_return get_stats_keys(memcached_st *memc)
|
1745
|
+
{
|
1746
|
+
char **list;
|
1747
|
+
char **ptr;
|
1748
|
+
memcached_stat_st memc_stat;
|
1749
|
+
memcached_return rc;
|
1750
|
+
|
1751
|
+
list= memcached_stat_get_keys(memc, &memc_stat, &rc);
|
1752
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1753
|
+
for (ptr= list; *ptr; ptr++)
|
1754
|
+
assert(*ptr);
|
1755
|
+
fflush(stdout);
|
1756
|
+
|
1757
|
+
free(list);
|
1758
|
+
|
1759
|
+
return 0;
|
1760
|
+
}
|
1761
|
+
|
1762
|
+
static test_return version_string_test(memcached_st *memc __attribute__((unused)))
|
1763
|
+
{
|
1764
|
+
const char *version_string;
|
1765
|
+
|
1766
|
+
version_string= memcached_lib_version();
|
1767
|
+
|
1768
|
+
assert(!strcmp(version_string, LIBMEMCACHED_VERSION_STRING));
|
1769
|
+
|
1770
|
+
return 0;
|
1771
|
+
}
|
1772
|
+
|
1773
|
+
static test_return get_stats(memcached_st *memc)
|
1774
|
+
{
|
1775
|
+
unsigned int x;
|
1776
|
+
char **list;
|
1777
|
+
char **ptr;
|
1778
|
+
memcached_return rc;
|
1779
|
+
memcached_stat_st *memc_stat;
|
1780
|
+
|
1781
|
+
memc_stat= memcached_stat(memc, NULL, &rc);
|
1782
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1783
|
+
|
1784
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1785
|
+
assert(memc_stat);
|
1786
|
+
|
1787
|
+
for (x= 0; x < memcached_server_count(memc); x++)
|
1788
|
+
{
|
1789
|
+
list= memcached_stat_get_keys(memc, memc_stat+x, &rc);
|
1790
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1791
|
+
for (ptr= list; *ptr; ptr++);
|
1792
|
+
|
1793
|
+
free(list);
|
1794
|
+
}
|
1795
|
+
|
1796
|
+
memcached_stat_free(NULL, memc_stat);
|
1797
|
+
|
1798
|
+
return 0;
|
1799
|
+
}
|
1800
|
+
|
1801
|
+
static test_return add_host_test(memcached_st *memc)
|
1802
|
+
{
|
1803
|
+
unsigned int x;
|
1804
|
+
memcached_server_st *servers;
|
1805
|
+
memcached_return rc;
|
1806
|
+
char servername[]= "0.example.com";
|
1807
|
+
|
1808
|
+
servers= memcached_server_list_append_with_weight(NULL, servername, 400, 0, &rc);
|
1809
|
+
assert(servers);
|
1810
|
+
assert(1 == memcached_server_list_count(servers));
|
1811
|
+
|
1812
|
+
for (x= 2; x < 20; x++)
|
1813
|
+
{
|
1814
|
+
char buffer[SMALL_STRING_LEN];
|
1815
|
+
|
1816
|
+
snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
|
1817
|
+
servers= memcached_server_list_append_with_weight(servers, buffer, 401, 0,
|
1818
|
+
&rc);
|
1819
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1820
|
+
assert(x == memcached_server_list_count(servers));
|
1821
|
+
}
|
1822
|
+
|
1823
|
+
rc= memcached_server_push(memc, servers);
|
1824
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1825
|
+
rc= memcached_server_push(memc, servers);
|
1826
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1827
|
+
|
1828
|
+
memcached_server_list_free(servers);
|
1829
|
+
|
1830
|
+
return 0;
|
1831
|
+
}
|
1832
|
+
|
1833
|
+
static memcached_return clone_test_callback(memcached_st *parent __attribute__((unused)), memcached_st *memc_clone __attribute__((unused)))
|
1834
|
+
{
|
1835
|
+
return MEMCACHED_SUCCESS;
|
1836
|
+
}
|
1837
|
+
|
1838
|
+
static memcached_return cleanup_test_callback(memcached_st *ptr __attribute__((unused)))
|
1839
|
+
{
|
1840
|
+
return MEMCACHED_SUCCESS;
|
1841
|
+
}
|
1842
|
+
|
1843
|
+
static test_return callback_test(memcached_st *memc)
|
1844
|
+
{
|
1845
|
+
/* Test User Data */
|
1846
|
+
{
|
1847
|
+
int x= 5;
|
1848
|
+
int *test_ptr;
|
1849
|
+
memcached_return rc;
|
1850
|
+
|
1851
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_USER_DATA, &x);
|
1852
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1853
|
+
test_ptr= (int *)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
|
1854
|
+
assert(*test_ptr == x);
|
1855
|
+
}
|
1856
|
+
|
1857
|
+
/* Test Clone Callback */
|
1858
|
+
{
|
1859
|
+
memcached_clone_func clone_cb= (memcached_clone_func)clone_test_callback;
|
1860
|
+
void *clone_cb_ptr= *(void **)&clone_cb;
|
1861
|
+
void *temp_function= NULL;
|
1862
|
+
memcached_return rc;
|
1863
|
+
|
1864
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION,
|
1865
|
+
clone_cb_ptr);
|
1866
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1867
|
+
temp_function= memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
|
1868
|
+
assert(temp_function == clone_cb_ptr);
|
1869
|
+
}
|
1870
|
+
|
1871
|
+
/* Test Cleanup Callback */
|
1872
|
+
{
|
1873
|
+
memcached_cleanup_func cleanup_cb=
|
1874
|
+
(memcached_cleanup_func)cleanup_test_callback;
|
1875
|
+
void *cleanup_cb_ptr= *(void **)&cleanup_cb;
|
1876
|
+
void *temp_function= NULL;
|
1877
|
+
memcached_return rc;
|
1878
|
+
|
1879
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION,
|
1880
|
+
cleanup_cb_ptr);
|
1881
|
+
assert(rc == MEMCACHED_SUCCESS);
|
1882
|
+
temp_function= memcached_callback_get(memc, MEMCACHED_CALLBACK_CLONE_FUNCTION, &rc);
|
1883
|
+
assert(temp_function == cleanup_cb_ptr);
|
1884
|
+
}
|
1885
|
+
|
1886
|
+
return 0;
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
/* We don't test the behavior itself, we test the switches */
|
1890
|
+
static test_return behavior_test(memcached_st *memc)
|
1891
|
+
{
|
1892
|
+
uint64_t value;
|
1893
|
+
uint32_t set= 1;
|
1894
|
+
|
1895
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
|
1896
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
|
1897
|
+
assert(value == 1);
|
1898
|
+
|
1899
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
|
1900
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
|
1901
|
+
assert(value == 1);
|
1902
|
+
|
1903
|
+
set= MEMCACHED_HASH_MD5;
|
1904
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set);
|
1905
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
|
1906
|
+
assert(value == MEMCACHED_HASH_MD5);
|
1907
|
+
|
1908
|
+
set= 0;
|
1909
|
+
|
1910
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
|
1911
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
|
1912
|
+
assert(value == 0);
|
1913
|
+
|
1914
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
|
1915
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
|
1916
|
+
assert(value == 0);
|
1917
|
+
|
1918
|
+
set= MEMCACHED_HASH_DEFAULT;
|
1919
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set);
|
1920
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
|
1921
|
+
assert(value == MEMCACHED_HASH_DEFAULT);
|
1922
|
+
|
1923
|
+
set= MEMCACHED_HASH_CRC;
|
1924
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set);
|
1925
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
|
1926
|
+
assert(value == MEMCACHED_HASH_CRC);
|
1927
|
+
|
1928
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
|
1929
|
+
assert(value > 0);
|
1930
|
+
|
1931
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
|
1932
|
+
assert(value > 0);
|
1933
|
+
return 0;
|
1934
|
+
}
|
1935
|
+
|
1936
|
+
/* Test case provided by Cal Haldenbrand */
|
1937
|
+
static test_return user_supplied_bug1(memcached_st *memc)
|
1938
|
+
{
|
1939
|
+
unsigned int setter= 1;
|
1940
|
+
unsigned int x;
|
1941
|
+
|
1942
|
+
unsigned long long total= 0;
|
1943
|
+
uint32_t size= 0;
|
1944
|
+
char key[10];
|
1945
|
+
char randomstuff[6 * 1024];
|
1946
|
+
memcached_return rc;
|
1947
|
+
|
1948
|
+
memset(randomstuff, 0, 6 * 1024);
|
1949
|
+
|
1950
|
+
/* We just keep looking at the same values over and over */
|
1951
|
+
srandom(10);
|
1952
|
+
|
1953
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter);
|
1954
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
|
1955
|
+
|
1956
|
+
|
1957
|
+
/* add key */
|
1958
|
+
for (x= 0 ; total < 20 * 1024576 ; x++ )
|
1959
|
+
{
|
1960
|
+
unsigned int j= 0;
|
1961
|
+
|
1962
|
+
size= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
|
1963
|
+
memset(randomstuff, 0, 6 * 1024);
|
1964
|
+
assert(size < 6 * 1024); /* Being safe here */
|
1965
|
+
|
1966
|
+
for (j= 0 ; j < size ;j++)
|
1967
|
+
randomstuff[j] = (signed char) ((rand() % 26) + 97);
|
1968
|
+
|
1969
|
+
total += size;
|
1970
|
+
sprintf(key, "%d", x);
|
1971
|
+
rc = memcached_set(memc, key, strlen(key),
|
1972
|
+
randomstuff, strlen(randomstuff), 10, 0);
|
1973
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1974
|
+
/* If we fail, lets try again */
|
1975
|
+
if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_BUFFERED)
|
1976
|
+
rc = memcached_set(memc, key, strlen(key),
|
1977
|
+
randomstuff, strlen(randomstuff), 10, 0);
|
1978
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
1979
|
+
}
|
1980
|
+
|
1981
|
+
return 0;
|
1982
|
+
}
|
1983
|
+
|
1984
|
+
/* Test case provided by Cal Haldenbrand */
|
1985
|
+
static test_return user_supplied_bug2(memcached_st *memc)
|
1986
|
+
{
|
1987
|
+
int errors;
|
1988
|
+
unsigned int setter;
|
1989
|
+
unsigned int x;
|
1990
|
+
unsigned long long total;
|
1991
|
+
|
1992
|
+
setter= 1;
|
1993
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter);
|
1994
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
|
1995
|
+
#ifdef NOT_YET
|
1996
|
+
setter = 20 * 1024576;
|
1997
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, setter);
|
1998
|
+
setter = 20 * 1024576;
|
1999
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, setter);
|
2000
|
+
getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
|
2001
|
+
getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
|
2002
|
+
|
2003
|
+
for (x= 0, errors= 0, total= 0 ; total < 20 * 1024576 ; x++)
|
2004
|
+
#endif
|
2005
|
+
|
2006
|
+
for (x= 0, errors= 0, total= 0 ; total < 24576 ; x++)
|
2007
|
+
{
|
2008
|
+
memcached_return rc= MEMCACHED_SUCCESS;
|
2009
|
+
char buffer[SMALL_STRING_LEN];
|
2010
|
+
uint32_t flags= 0;
|
2011
|
+
size_t val_len= 0;
|
2012
|
+
char *getval;
|
2013
|
+
|
2014
|
+
memset(buffer, 0, SMALL_STRING_LEN);
|
2015
|
+
|
2016
|
+
snprintf(buffer, SMALL_STRING_LEN, "%u", x);
|
2017
|
+
getval= memcached_get(memc, buffer, strlen(buffer),
|
2018
|
+
&val_len, &flags, &rc);
|
2019
|
+
if (rc != MEMCACHED_SUCCESS)
|
2020
|
+
{
|
2021
|
+
if (rc == MEMCACHED_NOTFOUND)
|
2022
|
+
errors++;
|
2023
|
+
else
|
2024
|
+
{
|
2025
|
+
assert(rc);
|
2026
|
+
}
|
2027
|
+
|
2028
|
+
continue;
|
2029
|
+
}
|
2030
|
+
total+= val_len;
|
2031
|
+
errors= 0;
|
2032
|
+
free(getval);
|
2033
|
+
}
|
2034
|
+
|
2035
|
+
return 0;
|
2036
|
+
}
|
2037
|
+
|
2038
|
+
/* Do a large mget() over all the keys we think exist */
|
2039
|
+
#define KEY_COUNT 3000 // * 1024576
|
2040
|
+
static test_return user_supplied_bug3(memcached_st *memc)
|
2041
|
+
{
|
2042
|
+
memcached_return rc;
|
2043
|
+
unsigned int setter;
|
2044
|
+
unsigned int x;
|
2045
|
+
char **keys;
|
2046
|
+
size_t key_lengths[KEY_COUNT];
|
2047
|
+
|
2048
|
+
setter= 1;
|
2049
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, setter);
|
2050
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
|
2051
|
+
#ifdef NOT_YET
|
2052
|
+
setter = 20 * 1024576;
|
2053
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, setter);
|
2054
|
+
setter = 20 * 1024576;
|
2055
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, setter);
|
2056
|
+
getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
|
2057
|
+
getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
|
2058
|
+
#endif
|
2059
|
+
|
2060
|
+
keys= (char **)malloc(sizeof(char *) * KEY_COUNT);
|
2061
|
+
assert(keys);
|
2062
|
+
memset(keys, 0, (sizeof(char *) * KEY_COUNT));
|
2063
|
+
for (x= 0; x < KEY_COUNT; x++)
|
2064
|
+
{
|
2065
|
+
char buffer[30];
|
2066
|
+
|
2067
|
+
snprintf(buffer, 30, "%u", x);
|
2068
|
+
keys[x]= strdup(buffer);
|
2069
|
+
key_lengths[x]= strlen(keys[x]);
|
2070
|
+
}
|
2071
|
+
|
2072
|
+
rc= memcached_mget(memc, (const char **)keys, key_lengths, KEY_COUNT);
|
2073
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2074
|
+
|
2075
|
+
/* Turn this into a help function */
|
2076
|
+
{
|
2077
|
+
char return_key[MEMCACHED_MAX_KEY];
|
2078
|
+
size_t return_key_length;
|
2079
|
+
char *return_value;
|
2080
|
+
size_t return_value_length;
|
2081
|
+
uint32_t flags;
|
2082
|
+
|
2083
|
+
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
|
2084
|
+
&return_value_length, &flags, &rc)))
|
2085
|
+
{
|
2086
|
+
assert(return_value);
|
2087
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2088
|
+
free(return_value);
|
2089
|
+
}
|
2090
|
+
}
|
2091
|
+
|
2092
|
+
for (x= 0; x < KEY_COUNT; x++)
|
2093
|
+
free(keys[x]);
|
2094
|
+
free(keys);
|
2095
|
+
|
2096
|
+
return 0;
|
2097
|
+
}
|
2098
|
+
|
2099
|
+
/* Make sure we behave properly if server list has no values */
|
2100
|
+
static test_return user_supplied_bug4(memcached_st *memc)
|
2101
|
+
{
|
2102
|
+
memcached_return rc;
|
2103
|
+
const char *keys[]= {"fudge", "son", "food"};
|
2104
|
+
size_t key_length[]= {5, 3, 4};
|
2105
|
+
unsigned int x;
|
2106
|
+
uint32_t flags;
|
2107
|
+
char return_key[MEMCACHED_MAX_KEY];
|
2108
|
+
size_t return_key_length;
|
2109
|
+
char *return_value;
|
2110
|
+
size_t return_value_length;
|
2111
|
+
|
2112
|
+
/* Here we free everything before running a bunch of mget tests */
|
2113
|
+
{
|
2114
|
+
memcached_server_list_free(memc->hosts);
|
2115
|
+
memc->hosts= NULL;
|
2116
|
+
memc->number_of_hosts= 0;
|
2117
|
+
}
|
2118
|
+
|
2119
|
+
|
2120
|
+
/* We need to empty the server before continueing test */
|
2121
|
+
rc= memcached_flush(memc, 0);
|
2122
|
+
assert(rc == MEMCACHED_NO_SERVERS);
|
2123
|
+
|
2124
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
2125
|
+
assert(rc == MEMCACHED_NO_SERVERS);
|
2126
|
+
|
2127
|
+
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
|
2128
|
+
&return_value_length, &flags, &rc)) != NULL)
|
2129
|
+
{
|
2130
|
+
assert(return_value);
|
2131
|
+
}
|
2132
|
+
assert(!return_value);
|
2133
|
+
assert(return_value_length == 0);
|
2134
|
+
assert(rc == MEMCACHED_NO_SERVERS);
|
2135
|
+
|
2136
|
+
for (x= 0; x < 3; x++)
|
2137
|
+
{
|
2138
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
2139
|
+
keys[x], key_length[x],
|
2140
|
+
(time_t)50, (uint32_t)9);
|
2141
|
+
assert(rc == MEMCACHED_NO_SERVERS);
|
2142
|
+
}
|
2143
|
+
|
2144
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
2145
|
+
assert(rc == MEMCACHED_NO_SERVERS);
|
2146
|
+
|
2147
|
+
x= 0;
|
2148
|
+
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
|
2149
|
+
&return_value_length, &flags, &rc)))
|
2150
|
+
{
|
2151
|
+
assert(return_value);
|
2152
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2153
|
+
assert(return_key_length == return_value_length);
|
2154
|
+
assert(!memcmp(return_value, return_key, return_value_length));
|
2155
|
+
free(return_value);
|
2156
|
+
x++;
|
2157
|
+
}
|
2158
|
+
|
2159
|
+
return 0;
|
2160
|
+
}
|
2161
|
+
|
2162
|
+
#define VALUE_SIZE_BUG5 1048064
|
2163
|
+
static test_return user_supplied_bug5(memcached_st *memc)
|
2164
|
+
{
|
2165
|
+
memcached_return rc;
|
2166
|
+
const char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
|
2167
|
+
size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
|
2168
|
+
char return_key[MEMCACHED_MAX_KEY];
|
2169
|
+
size_t return_key_length;
|
2170
|
+
char *value;
|
2171
|
+
size_t value_length;
|
2172
|
+
uint32_t flags;
|
2173
|
+
unsigned int count;
|
2174
|
+
unsigned int x;
|
2175
|
+
char insert_data[VALUE_SIZE_BUG5];
|
2176
|
+
|
2177
|
+
for (x= 0; x < VALUE_SIZE_BUG5; x++)
|
2178
|
+
insert_data[x]= (signed char)rand();
|
2179
|
+
|
2180
|
+
memcached_flush(memc, 0);
|
2181
|
+
value= memcached_get(memc, keys[0], key_length[0],
|
2182
|
+
&value_length, &flags, &rc);
|
2183
|
+
assert(value == NULL);
|
2184
|
+
rc= memcached_mget(memc, keys, key_length, 4);
|
2185
|
+
|
2186
|
+
count= 0;
|
2187
|
+
while ((value= memcached_fetch(memc, return_key, &return_key_length,
|
2188
|
+
&value_length, &flags, &rc)))
|
2189
|
+
count++;
|
2190
|
+
assert(count == 0);
|
2191
|
+
|
2192
|
+
for (x= 0; x < 4; x++)
|
2193
|
+
{
|
2194
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
2195
|
+
insert_data, VALUE_SIZE_BUG5,
|
2196
|
+
(time_t)0, (uint32_t)0);
|
2197
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2198
|
+
}
|
2199
|
+
|
2200
|
+
for (x= 0; x < 10; x++)
|
2201
|
+
{
|
2202
|
+
value= memcached_get(memc, keys[0], key_length[0],
|
2203
|
+
&value_length, &flags, &rc);
|
2204
|
+
assert(value);
|
2205
|
+
free(value);
|
2206
|
+
|
2207
|
+
rc= memcached_mget(memc, keys, key_length, 4);
|
2208
|
+
count= 0;
|
2209
|
+
while ((value= memcached_fetch(memc, return_key, &return_key_length,
|
2210
|
+
&value_length, &flags, &rc)))
|
2211
|
+
{
|
2212
|
+
count++;
|
2213
|
+
free(value);
|
2214
|
+
}
|
2215
|
+
assert(count == 4);
|
2216
|
+
}
|
2217
|
+
|
2218
|
+
return 0;
|
2219
|
+
}
|
2220
|
+
|
2221
|
+
static test_return user_supplied_bug6(memcached_st *memc)
|
2222
|
+
{
|
2223
|
+
memcached_return rc;
|
2224
|
+
const char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
|
2225
|
+
size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
|
2226
|
+
char return_key[MEMCACHED_MAX_KEY];
|
2227
|
+
size_t return_key_length;
|
2228
|
+
char *value;
|
2229
|
+
size_t value_length;
|
2230
|
+
uint32_t flags;
|
2231
|
+
unsigned int count;
|
2232
|
+
unsigned int x;
|
2233
|
+
char insert_data[VALUE_SIZE_BUG5];
|
2234
|
+
|
2235
|
+
for (x= 0; x < VALUE_SIZE_BUG5; x++)
|
2236
|
+
insert_data[x]= (signed char)rand();
|
2237
|
+
|
2238
|
+
memcached_flush(memc, 0);
|
2239
|
+
value= memcached_get(memc, keys[0], key_length[0],
|
2240
|
+
&value_length, &flags, &rc);
|
2241
|
+
assert(value == NULL);
|
2242
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
2243
|
+
rc= memcached_mget(memc, keys, key_length, 4);
|
2244
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2245
|
+
|
2246
|
+
count= 0;
|
2247
|
+
while ((value= memcached_fetch(memc, return_key, &return_key_length,
|
2248
|
+
&value_length, &flags, &rc)))
|
2249
|
+
count++;
|
2250
|
+
assert(count == 0);
|
2251
|
+
assert(rc == MEMCACHED_END);
|
2252
|
+
|
2253
|
+
for (x= 0; x < 4; x++)
|
2254
|
+
{
|
2255
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
2256
|
+
insert_data, VALUE_SIZE_BUG5,
|
2257
|
+
(time_t)0, (uint32_t)0);
|
2258
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2259
|
+
}
|
2260
|
+
|
2261
|
+
for (x= 0; x < 2; x++)
|
2262
|
+
{
|
2263
|
+
value= memcached_get(memc, keys[0], key_length[0],
|
2264
|
+
&value_length, &flags, &rc);
|
2265
|
+
assert(value);
|
2266
|
+
free(value);
|
2267
|
+
|
2268
|
+
rc= memcached_mget(memc, keys, key_length, 4);
|
2269
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2270
|
+
count= 3;
|
2271
|
+
/* We test for purge of partial complete fetches */
|
2272
|
+
for (count= 3; count; count--)
|
2273
|
+
{
|
2274
|
+
value= memcached_fetch(memc, return_key, &return_key_length,
|
2275
|
+
&value_length, &flags, &rc);
|
2276
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2277
|
+
assert(!(memcmp(value, insert_data, value_length)));
|
2278
|
+
assert(value_length);
|
2279
|
+
free(value);
|
2280
|
+
}
|
2281
|
+
}
|
2282
|
+
|
2283
|
+
return 0;
|
2284
|
+
}
|
2285
|
+
|
2286
|
+
static test_return user_supplied_bug8(memcached_st *memc __attribute__((unused)))
|
2287
|
+
{
|
2288
|
+
memcached_return rc;
|
2289
|
+
memcached_st *mine;
|
2290
|
+
memcached_st *memc_clone;
|
2291
|
+
|
2292
|
+
memcached_server_st *servers;
|
2293
|
+
const char *server_list= "memcache1.memcache.bk.sapo.pt:11211, memcache1.memcache.bk.sapo.pt:11212, memcache1.memcache.bk.sapo.pt:11213, memcache1.memcache.bk.sapo.pt:11214, memcache2.memcache.bk.sapo.pt:11211, memcache2.memcache.bk.sapo.pt:11212, memcache2.memcache.bk.sapo.pt:11213, memcache2.memcache.bk.sapo.pt:11214";
|
2294
|
+
|
2295
|
+
servers= memcached_servers_parse(server_list);
|
2296
|
+
assert(servers);
|
2297
|
+
|
2298
|
+
mine= memcached_create(NULL);
|
2299
|
+
rc= memcached_server_push(mine, servers);
|
2300
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2301
|
+
memcached_server_list_free(servers);
|
2302
|
+
|
2303
|
+
assert(mine);
|
2304
|
+
memc_clone= memcached_clone(NULL, mine);
|
2305
|
+
|
2306
|
+
memcached_quit(mine);
|
2307
|
+
memcached_quit(memc_clone);
|
2308
|
+
|
2309
|
+
|
2310
|
+
memcached_free(mine);
|
2311
|
+
memcached_free(memc_clone);
|
2312
|
+
|
2313
|
+
return 0;
|
2314
|
+
}
|
2315
|
+
|
2316
|
+
/* Test flag store/retrieve */
|
2317
|
+
static test_return user_supplied_bug7(memcached_st *memc)
|
2318
|
+
{
|
2319
|
+
memcached_return rc;
|
2320
|
+
const char *keys= "036790384900";
|
2321
|
+
size_t key_length= strlen(keys);
|
2322
|
+
char return_key[MEMCACHED_MAX_KEY];
|
2323
|
+
size_t return_key_length;
|
2324
|
+
char *value;
|
2325
|
+
size_t value_length;
|
2326
|
+
uint32_t flags;
|
2327
|
+
unsigned int x;
|
2328
|
+
char insert_data[VALUE_SIZE_BUG5];
|
2329
|
+
|
2330
|
+
for (x= 0; x < VALUE_SIZE_BUG5; x++)
|
2331
|
+
insert_data[x]= (signed char)rand();
|
2332
|
+
|
2333
|
+
memcached_flush(memc, 0);
|
2334
|
+
|
2335
|
+
flags= 245;
|
2336
|
+
rc= memcached_set(memc, keys, key_length,
|
2337
|
+
insert_data, VALUE_SIZE_BUG5,
|
2338
|
+
(time_t)0, flags);
|
2339
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2340
|
+
|
2341
|
+
flags= 0;
|
2342
|
+
value= memcached_get(memc, keys, key_length,
|
2343
|
+
&value_length, &flags, &rc);
|
2344
|
+
assert(flags == 245);
|
2345
|
+
assert(value);
|
2346
|
+
free(value);
|
2347
|
+
|
2348
|
+
rc= memcached_mget(memc, &keys, &key_length, 1);
|
2349
|
+
|
2350
|
+
flags= 0;
|
2351
|
+
value= memcached_fetch(memc, return_key, &return_key_length,
|
2352
|
+
&value_length, &flags, &rc);
|
2353
|
+
assert(flags == 245);
|
2354
|
+
assert(value);
|
2355
|
+
free(value);
|
2356
|
+
|
2357
|
+
|
2358
|
+
return 0;
|
2359
|
+
}
|
2360
|
+
|
2361
|
+
static test_return user_supplied_bug9(memcached_st *memc)
|
2362
|
+
{
|
2363
|
+
memcached_return rc;
|
2364
|
+
const char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
|
2365
|
+
size_t key_length[3];
|
2366
|
+
unsigned int x;
|
2367
|
+
uint32_t flags;
|
2368
|
+
unsigned count= 0;
|
2369
|
+
|
2370
|
+
char return_key[MEMCACHED_MAX_KEY];
|
2371
|
+
size_t return_key_length;
|
2372
|
+
char *return_value;
|
2373
|
+
size_t return_value_length;
|
2374
|
+
|
2375
|
+
|
2376
|
+
key_length[0]= strlen("UDATA:edevil@sapo.pt");
|
2377
|
+
key_length[1]= strlen("fudge&*@#");
|
2378
|
+
key_length[2]= strlen("for^#@&$not");
|
2379
|
+
|
2380
|
+
|
2381
|
+
for (x= 0; x < 3; x++)
|
2382
|
+
{
|
2383
|
+
rc= memcached_set(memc, keys[x], key_length[x],
|
2384
|
+
keys[x], key_length[x],
|
2385
|
+
(time_t)50, (uint32_t)9);
|
2386
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2387
|
+
}
|
2388
|
+
|
2389
|
+
rc= memcached_mget(memc, keys, key_length, 3);
|
2390
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2391
|
+
|
2392
|
+
/* We need to empty the server before continueing test */
|
2393
|
+
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
|
2394
|
+
&return_value_length, &flags, &rc)) != NULL)
|
2395
|
+
{
|
2396
|
+
assert(return_value);
|
2397
|
+
free(return_value);
|
2398
|
+
count++;
|
2399
|
+
}
|
2400
|
+
assert(count == 3);
|
2401
|
+
|
2402
|
+
return 0;
|
2403
|
+
}
|
2404
|
+
|
2405
|
+
/* We are testing with aggressive timeout to get failures */
|
2406
|
+
static test_return user_supplied_bug10(memcached_st *memc)
|
2407
|
+
{
|
2408
|
+
const char *key= "foo";
|
2409
|
+
char *value;
|
2410
|
+
size_t value_length= 512;
|
2411
|
+
unsigned int x;
|
2412
|
+
size_t key_len= 3;
|
2413
|
+
memcached_return rc;
|
2414
|
+
unsigned int set= 1;
|
2415
|
+
memcached_st *mclone= memcached_clone(NULL, memc);
|
2416
|
+
int32_t timeout;
|
2417
|
+
|
2418
|
+
memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
|
2419
|
+
memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
|
2420
|
+
timeout= 2;
|
2421
|
+
memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT,
|
2422
|
+
(uint64_t)timeout);
|
2423
|
+
|
2424
|
+
value = (char*)malloc(value_length * sizeof(char));
|
2425
|
+
|
2426
|
+
for (x= 0; x < value_length; x++)
|
2427
|
+
value[x]= (char) (x % 127);
|
2428
|
+
|
2429
|
+
for (x= 1; x <= 100000; ++x)
|
2430
|
+
{
|
2431
|
+
rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
|
2432
|
+
|
2433
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE ||
|
2434
|
+
rc == MEMCACHED_BUFFERED || rc == MEMCACHED_TIMEOUT);
|
2435
|
+
|
2436
|
+
if (rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_TIMEOUT)
|
2437
|
+
x--;
|
2438
|
+
}
|
2439
|
+
|
2440
|
+
free(value);
|
2441
|
+
memcached_free(mclone);
|
2442
|
+
|
2443
|
+
return 0;
|
2444
|
+
}
|
2445
|
+
|
2446
|
+
/*
|
2447
|
+
We are looking failures in the async protocol
|
2448
|
+
*/
|
2449
|
+
static test_return user_supplied_bug11(memcached_st *memc)
|
2450
|
+
{
|
2451
|
+
const char *key= "foo";
|
2452
|
+
char *value;
|
2453
|
+
size_t value_length= 512;
|
2454
|
+
unsigned int x;
|
2455
|
+
size_t key_len= 3;
|
2456
|
+
memcached_return rc;
|
2457
|
+
unsigned int set= 1;
|
2458
|
+
int32_t timeout;
|
2459
|
+
memcached_st *mclone= memcached_clone(NULL, memc);
|
2460
|
+
|
2461
|
+
memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set);
|
2462
|
+
memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set);
|
2463
|
+
timeout= -1;
|
2464
|
+
memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT,
|
2465
|
+
(size_t)timeout);
|
2466
|
+
|
2467
|
+
timeout= (int32_t)memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
|
2468
|
+
|
2469
|
+
assert(timeout == -1);
|
2470
|
+
|
2471
|
+
value = (char*)malloc(value_length * sizeof(char));
|
2472
|
+
|
2473
|
+
for (x= 0; x < value_length; x++)
|
2474
|
+
value[x]= (char) (x % 127);
|
2475
|
+
|
2476
|
+
for (x= 1; x <= 100000; ++x)
|
2477
|
+
{
|
2478
|
+
rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
|
2479
|
+
}
|
2480
|
+
|
2481
|
+
free(value);
|
2482
|
+
memcached_free(mclone);
|
2483
|
+
|
2484
|
+
return 0;
|
2485
|
+
}
|
2486
|
+
|
2487
|
+
/*
|
2488
|
+
Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
|
2489
|
+
*/
|
2490
|
+
static test_return user_supplied_bug12(memcached_st *memc)
|
2491
|
+
{
|
2492
|
+
memcached_return rc;
|
2493
|
+
uint32_t flags;
|
2494
|
+
size_t value_length;
|
2495
|
+
char *value;
|
2496
|
+
uint64_t number_value;
|
2497
|
+
|
2498
|
+
value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
|
2499
|
+
&value_length, &flags, &rc);
|
2500
|
+
assert(value == NULL);
|
2501
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
2502
|
+
|
2503
|
+
rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
|
2504
|
+
1, &number_value);
|
2505
|
+
|
2506
|
+
assert(value == NULL);
|
2507
|
+
/* The binary protocol will set the key if it doesn't exist */
|
2508
|
+
if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1)
|
2509
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2510
|
+
else
|
2511
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
2512
|
+
|
2513
|
+
rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
|
2514
|
+
|
2515
|
+
value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
|
2516
|
+
&value_length, &flags, &rc);
|
2517
|
+
assert(value);
|
2518
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2519
|
+
free(value);
|
2520
|
+
|
2521
|
+
rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
|
2522
|
+
1, &number_value);
|
2523
|
+
assert(number_value == 2);
|
2524
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2525
|
+
|
2526
|
+
return 0;
|
2527
|
+
}
|
2528
|
+
|
2529
|
+
/*
|
2530
|
+
Bug found where command total one more than MEMCACHED_MAX_BUFFER
|
2531
|
+
set key34567890 0 0 8169 \r\n is sent followed by buffer of size 8169, followed by 8169
|
2532
|
+
*/
|
2533
|
+
static test_return user_supplied_bug13(memcached_st *memc)
|
2534
|
+
{
|
2535
|
+
char key[] = "key34567890";
|
2536
|
+
char *overflow;
|
2537
|
+
memcached_return rc;
|
2538
|
+
size_t overflowSize;
|
2539
|
+
|
2540
|
+
char commandFirst[]= "set key34567890 0 0 ";
|
2541
|
+
char commandLast[] = " \r\n"; /* first line of command sent to server */
|
2542
|
+
size_t commandLength;
|
2543
|
+
size_t testSize;
|
2544
|
+
|
2545
|
+
commandLength = strlen(commandFirst) + strlen(commandLast) + 4; /* 4 is number of characters in size, probably 8196 */
|
2546
|
+
|
2547
|
+
overflowSize = MEMCACHED_MAX_BUFFER - commandLength;
|
2548
|
+
|
2549
|
+
for (testSize= overflowSize - 1; testSize < overflowSize + 1; testSize++)
|
2550
|
+
{
|
2551
|
+
overflow= malloc(testSize);
|
2552
|
+
assert(overflow != NULL);
|
2553
|
+
|
2554
|
+
memset(overflow, 'x', testSize);
|
2555
|
+
rc= memcached_set(memc, key, strlen(key),
|
2556
|
+
overflow, testSize, 0, 0);
|
2557
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2558
|
+
free(overflow);
|
2559
|
+
}
|
2560
|
+
|
2561
|
+
return 0;
|
2562
|
+
}
|
2563
|
+
|
2564
|
+
|
2565
|
+
/*
|
2566
|
+
Test values of many different sizes
|
2567
|
+
Bug found where command total one more than MEMCACHED_MAX_BUFFER
|
2568
|
+
set key34567890 0 0 8169 \r\n
|
2569
|
+
is sent followed by buffer of size 8169, followed by 8169
|
2570
|
+
*/
|
2571
|
+
static test_return user_supplied_bug14(memcached_st *memc)
|
2572
|
+
{
|
2573
|
+
size_t setter= 1;
|
2574
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, setter);
|
2575
|
+
memcached_return rc;
|
2576
|
+
const char *key= "foo";
|
2577
|
+
char *value;
|
2578
|
+
size_t value_length= 18000;
|
2579
|
+
char *string;
|
2580
|
+
size_t string_length;
|
2581
|
+
uint32_t flags;
|
2582
|
+
unsigned int x;
|
2583
|
+
size_t current_length;
|
2584
|
+
|
2585
|
+
value = (char*)malloc(value_length);
|
2586
|
+
assert(value);
|
2587
|
+
|
2588
|
+
for (x= 0; x < value_length; x++)
|
2589
|
+
value[x] = (char) (x % 127);
|
2590
|
+
|
2591
|
+
for (current_length= 0; current_length < value_length; current_length++)
|
2592
|
+
{
|
2593
|
+
rc= memcached_set(memc, key, strlen(key),
|
2594
|
+
value, current_length,
|
2595
|
+
(time_t)0, (uint32_t)0);
|
2596
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
2597
|
+
|
2598
|
+
string= memcached_get(memc, key, strlen(key),
|
2599
|
+
&string_length, &flags, &rc);
|
2600
|
+
|
2601
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2602
|
+
assert(string_length == current_length);
|
2603
|
+
assert(!memcmp(string, value, string_length));
|
2604
|
+
|
2605
|
+
free(string);
|
2606
|
+
}
|
2607
|
+
|
2608
|
+
free(value);
|
2609
|
+
|
2610
|
+
return 0;
|
2611
|
+
}
|
2612
|
+
|
2613
|
+
/*
|
2614
|
+
Look for zero length value problems
|
2615
|
+
*/
|
2616
|
+
static test_return user_supplied_bug15(memcached_st *memc)
|
2617
|
+
{
|
2618
|
+
uint32_t x;
|
2619
|
+
memcached_return rc;
|
2620
|
+
const char *key= "mykey";
|
2621
|
+
char *value;
|
2622
|
+
size_t length;
|
2623
|
+
uint32_t flags;
|
2624
|
+
|
2625
|
+
for (x= 0; x < 2; x++)
|
2626
|
+
{
|
2627
|
+
rc= memcached_set(memc, key, strlen(key),
|
2628
|
+
NULL, 0,
|
2629
|
+
(time_t)0, (uint32_t)0);
|
2630
|
+
|
2631
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2632
|
+
|
2633
|
+
value= memcached_get(memc, key, strlen(key),
|
2634
|
+
&length, &flags, &rc);
|
2635
|
+
|
2636
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2637
|
+
assert(value == NULL);
|
2638
|
+
assert(length == 0);
|
2639
|
+
assert(flags == 0);
|
2640
|
+
|
2641
|
+
value= memcached_get(memc, key, strlen(key),
|
2642
|
+
&length, &flags, &rc);
|
2643
|
+
|
2644
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2645
|
+
assert(value == NULL);
|
2646
|
+
assert(length == 0);
|
2647
|
+
assert(flags == 0);
|
2648
|
+
}
|
2649
|
+
|
2650
|
+
return 0;
|
2651
|
+
}
|
2652
|
+
|
2653
|
+
/* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
|
2654
|
+
static test_return user_supplied_bug16(memcached_st *memc)
|
2655
|
+
{
|
2656
|
+
memcached_return rc;
|
2657
|
+
const char *key= "mykey";
|
2658
|
+
char *value;
|
2659
|
+
size_t length;
|
2660
|
+
uint32_t flags;
|
2661
|
+
|
2662
|
+
rc= memcached_set(memc, key, strlen(key),
|
2663
|
+
NULL, 0,
|
2664
|
+
(time_t)0, UINT32_MAX);
|
2665
|
+
|
2666
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2667
|
+
|
2668
|
+
value= memcached_get(memc, key, strlen(key),
|
2669
|
+
&length, &flags, &rc);
|
2670
|
+
|
2671
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2672
|
+
assert(value == NULL);
|
2673
|
+
assert(length == 0);
|
2674
|
+
assert(flags == UINT32_MAX);
|
2675
|
+
|
2676
|
+
return 0;
|
2677
|
+
}
|
2678
|
+
|
2679
|
+
#ifndef __sun
|
2680
|
+
/* Check the validity of chinese key*/
|
2681
|
+
static test_return user_supplied_bug17(memcached_st *memc)
|
2682
|
+
{
|
2683
|
+
memcached_return rc;
|
2684
|
+
const char *key= "豆瓣";
|
2685
|
+
const char *value="我们在炎热抑郁的夏天无法停止豆瓣";
|
2686
|
+
char *value2;
|
2687
|
+
size_t length;
|
2688
|
+
uint32_t flags;
|
2689
|
+
|
2690
|
+
rc= memcached_set(memc, key, strlen(key),
|
2691
|
+
value, strlen(value),
|
2692
|
+
(time_t)0, 0);
|
2693
|
+
|
2694
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2695
|
+
|
2696
|
+
value2= memcached_get(memc, key, strlen(key),
|
2697
|
+
&length, &flags, &rc);
|
2698
|
+
|
2699
|
+
assert(length==strlen(value));
|
2700
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2701
|
+
assert(memcmp(value, value2, length)==0);
|
2702
|
+
free(value2);
|
2703
|
+
|
2704
|
+
return 0;
|
2705
|
+
}
|
2706
|
+
#endif
|
2707
|
+
|
2708
|
+
/*
|
2709
|
+
From Andrei on IRC
|
2710
|
+
*/
|
2711
|
+
|
2712
|
+
static test_return user_supplied_bug19(memcached_st *memc)
|
2713
|
+
{
|
2714
|
+
memcached_st *m;
|
2715
|
+
memcached_server_st *s;
|
2716
|
+
memcached_return res;
|
2717
|
+
|
2718
|
+
(void)memc;
|
2719
|
+
|
2720
|
+
m= memcached_create(NULL);
|
2721
|
+
memcached_server_add_with_weight(m, "localhost", 11311, 100);
|
2722
|
+
memcached_server_add_with_weight(m, "localhost", 11312, 100);
|
2723
|
+
|
2724
|
+
s= memcached_server_by_key(m, "a", 1, &res);
|
2725
|
+
memcached_server_free(s);
|
2726
|
+
|
2727
|
+
memcached_free(m);
|
2728
|
+
|
2729
|
+
return 0;
|
2730
|
+
}
|
2731
|
+
|
2732
|
+
/* CAS test from Andei */
|
2733
|
+
static test_return user_supplied_bug20(memcached_st *memc)
|
2734
|
+
{
|
2735
|
+
memcached_return status;
|
2736
|
+
memcached_result_st *result, result_obj;
|
2737
|
+
const char *key = "abc";
|
2738
|
+
size_t key_len = strlen("abc");
|
2739
|
+
const char *value = "foobar";
|
2740
|
+
size_t value_len = strlen(value);
|
2741
|
+
|
2742
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 1);
|
2743
|
+
|
2744
|
+
status = memcached_set(memc, key, key_len, value, value_len, (time_t)0, (uint32_t)0);
|
2745
|
+
assert(status == MEMCACHED_SUCCESS);
|
2746
|
+
|
2747
|
+
status = memcached_mget(memc, &key, &key_len, 1);
|
2748
|
+
assert(status == MEMCACHED_SUCCESS);
|
2749
|
+
|
2750
|
+
result= memcached_result_create(memc, &result_obj);
|
2751
|
+
assert(result);
|
2752
|
+
|
2753
|
+
memcached_result_create(memc, &result_obj);
|
2754
|
+
result= memcached_fetch_result(memc, &result_obj, &status);
|
2755
|
+
|
2756
|
+
assert(result);
|
2757
|
+
assert(status == MEMCACHED_SUCCESS);
|
2758
|
+
|
2759
|
+
memcached_result_free(result);
|
2760
|
+
|
2761
|
+
return 0;
|
2762
|
+
}
|
2763
|
+
|
2764
|
+
#include "ketama_test_cases.h"
|
2765
|
+
static test_return user_supplied_bug18(memcached_st *trash)
|
2766
|
+
{
|
2767
|
+
memcached_return rc;
|
2768
|
+
uint64_t value;
|
2769
|
+
int x;
|
2770
|
+
memcached_server_st *server_pool;
|
2771
|
+
memcached_st *memc;
|
2772
|
+
|
2773
|
+
(void)trash;
|
2774
|
+
|
2775
|
+
memc= memcached_create(NULL);
|
2776
|
+
assert(memc);
|
2777
|
+
|
2778
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1);
|
2779
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2780
|
+
|
2781
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
|
2782
|
+
assert(value == 1);
|
2783
|
+
|
2784
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5);
|
2785
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2786
|
+
|
2787
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH);
|
2788
|
+
assert(value == MEMCACHED_HASH_MD5);
|
2789
|
+
|
2790
|
+
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");
|
2791
|
+
memcached_server_push(memc, server_pool);
|
2792
|
+
|
2793
|
+
/* verify that the server list was parsed okay. */
|
2794
|
+
assert(memc->number_of_hosts == 8);
|
2795
|
+
assert(strcmp(server_pool[0].hostname, "10.0.1.1") == 0);
|
2796
|
+
assert(server_pool[0].port == 11211);
|
2797
|
+
assert(server_pool[0].weight == 600);
|
2798
|
+
assert(strcmp(server_pool[2].hostname, "10.0.1.3") == 0);
|
2799
|
+
assert(server_pool[2].port == 11211);
|
2800
|
+
assert(server_pool[2].weight == 200);
|
2801
|
+
assert(strcmp(server_pool[7].hostname, "10.0.1.8") == 0);
|
2802
|
+
assert(server_pool[7].port == 11211);
|
2803
|
+
assert(server_pool[7].weight == 100);
|
2804
|
+
|
2805
|
+
/* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
|
2806
|
+
* us test the boundary wraparound.
|
2807
|
+
*/
|
2808
|
+
assert(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index);
|
2809
|
+
|
2810
|
+
/* verify the standard ketama set. */
|
2811
|
+
for (x= 0; x < 99; x++)
|
2812
|
+
{
|
2813
|
+
uint32_t server_idx = memcached_generate_hash(memc, test_cases[x].key, strlen(test_cases[x].key));
|
2814
|
+
char *hostname = memc->hosts[server_idx].hostname;
|
2815
|
+
assert(strcmp(hostname, test_cases[x].server) == 0);
|
2816
|
+
}
|
2817
|
+
|
2818
|
+
memcached_server_list_free(server_pool);
|
2819
|
+
memcached_free(memc);
|
2820
|
+
|
2821
|
+
return 0;
|
2822
|
+
}
|
2823
|
+
|
2824
|
+
static test_return auto_eject_hosts(memcached_st *trash)
|
2825
|
+
{
|
2826
|
+
(void) trash;
|
2827
|
+
int x;
|
2828
|
+
|
2829
|
+
memcached_return rc;
|
2830
|
+
memcached_st *memc= memcached_create(NULL);
|
2831
|
+
assert(memc);
|
2832
|
+
|
2833
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1);
|
2834
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2835
|
+
|
2836
|
+
uint64_t value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
|
2837
|
+
assert(value == 1);
|
2838
|
+
|
2839
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5);
|
2840
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2841
|
+
|
2842
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH);
|
2843
|
+
assert(value == MEMCACHED_HASH_MD5);
|
2844
|
+
|
2845
|
+
/* server should be removed when in delay */
|
2846
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, 1);
|
2847
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2848
|
+
|
2849
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS);
|
2850
|
+
assert(value == 1);
|
2851
|
+
|
2852
|
+
memcached_server_st *server_pool;
|
2853
|
+
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");
|
2854
|
+
memcached_server_push(memc, server_pool);
|
2855
|
+
|
2856
|
+
/* verify that the server list was parsed okay. */
|
2857
|
+
assert(memc->number_of_hosts == 8);
|
2858
|
+
assert(strcmp(server_pool[0].hostname, "10.0.1.1") == 0);
|
2859
|
+
assert(server_pool[0].port == 11211);
|
2860
|
+
assert(server_pool[0].weight == 600);
|
2861
|
+
assert(strcmp(server_pool[2].hostname, "10.0.1.3") == 0);
|
2862
|
+
assert(server_pool[2].port == 11211);
|
2863
|
+
assert(server_pool[2].weight == 200);
|
2864
|
+
assert(strcmp(server_pool[7].hostname, "10.0.1.8") == 0);
|
2865
|
+
assert(server_pool[7].port == 11211);
|
2866
|
+
assert(server_pool[7].weight == 100);
|
2867
|
+
|
2868
|
+
memc->hosts[2].next_retry = time(NULL) + 15;
|
2869
|
+
memc->next_distribution_rebuild= time(NULL) - 1;
|
2870
|
+
|
2871
|
+
for (x= 0; x < 99; x++)
|
2872
|
+
{
|
2873
|
+
uint32_t server_idx = memcached_generate_hash(memc, test_cases[x].key, strlen(test_cases[x].key));
|
2874
|
+
assert(server_idx != 2);
|
2875
|
+
}
|
2876
|
+
|
2877
|
+
/* and re-added when it's back. */
|
2878
|
+
memc->hosts[2].next_retry = time(NULL) - 1;
|
2879
|
+
memc->next_distribution_rebuild= time(NULL) - 1;
|
2880
|
+
run_distribution(memc);
|
2881
|
+
for (x= 0; x < 99; x++)
|
2882
|
+
{
|
2883
|
+
uint32_t server_idx = memcached_generate_hash(memc, test_cases[x].key, strlen(test_cases[x].key));
|
2884
|
+
char *hostname = memc->hosts[server_idx].hostname;
|
2885
|
+
assert(strcmp(hostname, test_cases[x].server) == 0);
|
2886
|
+
}
|
2887
|
+
|
2888
|
+
memcached_server_list_free(server_pool);
|
2889
|
+
memcached_free(memc);
|
2890
|
+
|
2891
|
+
return TEST_SUCCESS;
|
2892
|
+
}
|
2893
|
+
|
2894
|
+
static test_return result_static(memcached_st *memc)
|
2895
|
+
{
|
2896
|
+
memcached_result_st result;
|
2897
|
+
memcached_result_st *result_ptr;
|
2898
|
+
|
2899
|
+
result_ptr= memcached_result_create(memc, &result);
|
2900
|
+
assert(result.is_allocated == false);
|
2901
|
+
assert(result_ptr);
|
2902
|
+
memcached_result_free(&result);
|
2903
|
+
|
2904
|
+
return 0;
|
2905
|
+
}
|
2906
|
+
|
2907
|
+
static test_return result_alloc(memcached_st *memc)
|
2908
|
+
{
|
2909
|
+
memcached_result_st *result;
|
2910
|
+
|
2911
|
+
result= memcached_result_create(memc, NULL);
|
2912
|
+
assert(result);
|
2913
|
+
memcached_result_free(result);
|
2914
|
+
|
2915
|
+
return 0;
|
2916
|
+
}
|
2917
|
+
|
2918
|
+
static test_return string_static_null(memcached_st *memc)
|
2919
|
+
{
|
2920
|
+
memcached_string_st string;
|
2921
|
+
memcached_string_st *string_ptr;
|
2922
|
+
|
2923
|
+
string_ptr= memcached_string_create(memc, &string, 0);
|
2924
|
+
assert(string.is_allocated == false);
|
2925
|
+
assert(string_ptr);
|
2926
|
+
memcached_string_free(&string);
|
2927
|
+
|
2928
|
+
return 0;
|
2929
|
+
}
|
2930
|
+
|
2931
|
+
static test_return string_alloc_null(memcached_st *memc)
|
2932
|
+
{
|
2933
|
+
memcached_string_st *string;
|
2934
|
+
|
2935
|
+
string= memcached_string_create(memc, NULL, 0);
|
2936
|
+
assert(string);
|
2937
|
+
memcached_string_free(string);
|
2938
|
+
|
2939
|
+
return 0;
|
2940
|
+
}
|
2941
|
+
|
2942
|
+
static test_return string_alloc_with_size(memcached_st *memc)
|
2943
|
+
{
|
2944
|
+
memcached_string_st *string;
|
2945
|
+
|
2946
|
+
string= memcached_string_create(memc, NULL, 1024);
|
2947
|
+
assert(string);
|
2948
|
+
memcached_string_free(string);
|
2949
|
+
|
2950
|
+
return 0;
|
2951
|
+
}
|
2952
|
+
|
2953
|
+
static test_return string_alloc_with_size_toobig(memcached_st *memc)
|
2954
|
+
{
|
2955
|
+
memcached_string_st *string;
|
2956
|
+
|
2957
|
+
string= memcached_string_create(memc, NULL, SIZE_MAX);
|
2958
|
+
assert(string == NULL);
|
2959
|
+
|
2960
|
+
return 0;
|
2961
|
+
}
|
2962
|
+
|
2963
|
+
static test_return string_alloc_append(memcached_st *memc)
|
2964
|
+
{
|
2965
|
+
unsigned int x;
|
2966
|
+
char buffer[SMALL_STRING_LEN];
|
2967
|
+
memcached_string_st *string;
|
2968
|
+
|
2969
|
+
/* Ring the bell! */
|
2970
|
+
memset(buffer, 6, SMALL_STRING_LEN);
|
2971
|
+
|
2972
|
+
string= memcached_string_create(memc, NULL, 100);
|
2973
|
+
assert(string);
|
2974
|
+
|
2975
|
+
for (x= 0; x < 1024; x++)
|
2976
|
+
{
|
2977
|
+
memcached_return rc;
|
2978
|
+
rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
|
2979
|
+
assert(rc == MEMCACHED_SUCCESS);
|
2980
|
+
}
|
2981
|
+
memcached_string_free(string);
|
2982
|
+
|
2983
|
+
return 0;
|
2984
|
+
}
|
2985
|
+
|
2986
|
+
static test_return string_alloc_append_toobig(memcached_st *memc)
|
2987
|
+
{
|
2988
|
+
memcached_return rc;
|
2989
|
+
unsigned int x;
|
2990
|
+
char buffer[SMALL_STRING_LEN];
|
2991
|
+
memcached_string_st *string;
|
2992
|
+
|
2993
|
+
/* Ring the bell! */
|
2994
|
+
memset(buffer, 6, SMALL_STRING_LEN);
|
2995
|
+
|
2996
|
+
string= memcached_string_create(memc, NULL, 100);
|
2997
|
+
assert(string);
|
2998
|
+
|
2999
|
+
for (x= 0; x < 1024; x++)
|
3000
|
+
{
|
3001
|
+
rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
|
3002
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3003
|
+
}
|
3004
|
+
rc= memcached_string_append(string, buffer, SIZE_MAX);
|
3005
|
+
assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE);
|
3006
|
+
memcached_string_free(string);
|
3007
|
+
|
3008
|
+
return 0;
|
3009
|
+
}
|
3010
|
+
|
3011
|
+
static test_return cleanup_pairs(memcached_st *memc __attribute__((unused)))
|
3012
|
+
{
|
3013
|
+
pairs_free(global_pairs);
|
3014
|
+
|
3015
|
+
return 0;
|
3016
|
+
}
|
3017
|
+
|
3018
|
+
static test_return generate_pairs(memcached_st *memc __attribute__((unused)))
|
3019
|
+
{
|
3020
|
+
unsigned long long x;
|
3021
|
+
global_pairs= pairs_generate(GLOBAL_COUNT, 400);
|
3022
|
+
global_count= GLOBAL_COUNT;
|
3023
|
+
|
3024
|
+
for (x= 0; x < global_count; x++)
|
3025
|
+
{
|
3026
|
+
global_keys[x]= global_pairs[x].key;
|
3027
|
+
global_keys_length[x]= global_pairs[x].key_length;
|
3028
|
+
}
|
3029
|
+
|
3030
|
+
return 0;
|
3031
|
+
}
|
3032
|
+
|
3033
|
+
static test_return generate_large_pairs(memcached_st *memc __attribute__((unused)))
|
3034
|
+
{
|
3035
|
+
unsigned long long x;
|
3036
|
+
global_pairs= pairs_generate(GLOBAL2_COUNT, MEMCACHED_MAX_BUFFER+10);
|
3037
|
+
global_count= GLOBAL2_COUNT;
|
3038
|
+
|
3039
|
+
for (x= 0; x < global_count; x++)
|
3040
|
+
{
|
3041
|
+
global_keys[x]= global_pairs[x].key;
|
3042
|
+
global_keys_length[x]= global_pairs[x].key_length;
|
3043
|
+
}
|
3044
|
+
|
3045
|
+
return 0;
|
3046
|
+
}
|
3047
|
+
|
3048
|
+
static test_return generate_data(memcached_st *memc)
|
3049
|
+
{
|
3050
|
+
execute_set(memc, global_pairs, global_count);
|
3051
|
+
|
3052
|
+
return 0;
|
3053
|
+
}
|
3054
|
+
|
3055
|
+
static test_return generate_data_with_stats(memcached_st *memc)
|
3056
|
+
{
|
3057
|
+
memcached_stat_st *stat_p;
|
3058
|
+
memcached_return rc;
|
3059
|
+
uint32_t host_index= 0;
|
3060
|
+
execute_set(memc, global_pairs, global_count);
|
3061
|
+
|
3062
|
+
//TODO: hosts used size stats
|
3063
|
+
stat_p= memcached_stat(memc, NULL, &rc);
|
3064
|
+
assert(stat_p);
|
3065
|
+
|
3066
|
+
for (host_index= 0; host_index < SERVERS_TO_CREATE; host_index++)
|
3067
|
+
{
|
3068
|
+
/* This test was changes so that "make test" would work properlly */
|
3069
|
+
#ifdef DEBUG
|
3070
|
+
printf("\nserver %u|%s|%u bytes: %llu\n", host_index, (memc->hosts)[host_index].hostname, (memc->hosts)[host_index].port, (unsigned long long)(stat_p + host_index)->bytes);
|
3071
|
+
#endif
|
3072
|
+
assert((unsigned long long)(stat_p + host_index)->bytes);
|
3073
|
+
}
|
3074
|
+
|
3075
|
+
memcached_stat_free(NULL, stat_p);
|
3076
|
+
|
3077
|
+
return 0;
|
3078
|
+
}
|
3079
|
+
static test_return generate_buffer_data(memcached_st *memc)
|
3080
|
+
{
|
3081
|
+
size_t latch= 0;
|
3082
|
+
|
3083
|
+
latch= 1;
|
3084
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, latch);
|
3085
|
+
generate_data(memc);
|
3086
|
+
|
3087
|
+
return 0;
|
3088
|
+
}
|
3089
|
+
|
3090
|
+
static test_return get_read_count(memcached_st *memc)
|
3091
|
+
{
|
3092
|
+
unsigned int x;
|
3093
|
+
memcached_return rc;
|
3094
|
+
memcached_st *memc_clone;
|
3095
|
+
|
3096
|
+
memc_clone= memcached_clone(NULL, memc);
|
3097
|
+
assert(memc_clone);
|
3098
|
+
|
3099
|
+
memcached_server_add_with_weight(memc_clone, "localhost", 6666, 0);
|
3100
|
+
|
3101
|
+
{
|
3102
|
+
char *return_value;
|
3103
|
+
size_t return_value_length;
|
3104
|
+
uint32_t flags;
|
3105
|
+
uint32_t count;
|
3106
|
+
|
3107
|
+
for (x= count= 0; x < global_count; x++)
|
3108
|
+
{
|
3109
|
+
return_value= memcached_get(memc_clone, global_keys[x], global_keys_length[x],
|
3110
|
+
&return_value_length, &flags, &rc);
|
3111
|
+
if (rc == MEMCACHED_SUCCESS)
|
3112
|
+
{
|
3113
|
+
count++;
|
3114
|
+
if (return_value)
|
3115
|
+
free(return_value);
|
3116
|
+
}
|
3117
|
+
}
|
3118
|
+
fprintf(stderr, "\t%u -> %u", global_count, count);
|
3119
|
+
}
|
3120
|
+
|
3121
|
+
memcached_free(memc_clone);
|
3122
|
+
|
3123
|
+
return 0;
|
3124
|
+
}
|
3125
|
+
|
3126
|
+
static test_return get_read(memcached_st *memc)
|
3127
|
+
{
|
3128
|
+
unsigned int x;
|
3129
|
+
memcached_return rc;
|
3130
|
+
|
3131
|
+
{
|
3132
|
+
char *return_value;
|
3133
|
+
size_t return_value_length;
|
3134
|
+
uint32_t flags;
|
3135
|
+
|
3136
|
+
for (x= 0; x < global_count; x++)
|
3137
|
+
{
|
3138
|
+
return_value= memcached_get(memc, global_keys[x], global_keys_length[x],
|
3139
|
+
&return_value_length, &flags, &rc);
|
3140
|
+
/*
|
3141
|
+
assert(return_value);
|
3142
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3143
|
+
*/
|
3144
|
+
if (rc == MEMCACHED_SUCCESS && return_value)
|
3145
|
+
free(return_value);
|
3146
|
+
}
|
3147
|
+
}
|
3148
|
+
|
3149
|
+
return 0;
|
3150
|
+
}
|
3151
|
+
|
3152
|
+
static test_return mget_read(memcached_st *memc)
|
3153
|
+
{
|
3154
|
+
memcached_return rc;
|
3155
|
+
|
3156
|
+
rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
|
3157
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3158
|
+
/* Turn this into a help function */
|
3159
|
+
{
|
3160
|
+
char return_key[MEMCACHED_MAX_KEY];
|
3161
|
+
size_t return_key_length;
|
3162
|
+
char *return_value;
|
3163
|
+
size_t return_value_length;
|
3164
|
+
uint32_t flags;
|
3165
|
+
|
3166
|
+
while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
|
3167
|
+
&return_value_length, &flags, &rc)))
|
3168
|
+
{
|
3169
|
+
assert(return_value);
|
3170
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3171
|
+
free(return_value);
|
3172
|
+
}
|
3173
|
+
}
|
3174
|
+
|
3175
|
+
return 0;
|
3176
|
+
}
|
3177
|
+
|
3178
|
+
static test_return mget_read_result(memcached_st *memc)
|
3179
|
+
{
|
3180
|
+
memcached_return rc;
|
3181
|
+
|
3182
|
+
rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
|
3183
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3184
|
+
/* Turn this into a help function */
|
3185
|
+
{
|
3186
|
+
memcached_result_st results_obj;
|
3187
|
+
memcached_result_st *results;
|
3188
|
+
|
3189
|
+
results= memcached_result_create(memc, &results_obj);
|
3190
|
+
|
3191
|
+
while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
|
3192
|
+
{
|
3193
|
+
assert(results);
|
3194
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3195
|
+
}
|
3196
|
+
|
3197
|
+
memcached_result_free(&results_obj);
|
3198
|
+
}
|
3199
|
+
|
3200
|
+
return 0;
|
3201
|
+
}
|
3202
|
+
|
3203
|
+
static test_return mget_read_function(memcached_st *memc)
|
3204
|
+
{
|
3205
|
+
memcached_return rc;
|
3206
|
+
unsigned int counter;
|
3207
|
+
memcached_execute_function callbacks[1];
|
3208
|
+
|
3209
|
+
rc= memcached_mget(memc, global_keys, global_keys_length, global_count);
|
3210
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3211
|
+
|
3212
|
+
callbacks[0]= &callback_counter;
|
3213
|
+
counter= 0;
|
3214
|
+
rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
|
3215
|
+
|
3216
|
+
return 0;
|
3217
|
+
}
|
3218
|
+
|
3219
|
+
static test_return delete_generate(memcached_st *memc)
|
3220
|
+
{
|
3221
|
+
unsigned int x;
|
3222
|
+
|
3223
|
+
for (x= 0; x < global_count; x++)
|
3224
|
+
{
|
3225
|
+
(void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
|
3226
|
+
}
|
3227
|
+
|
3228
|
+
return 0;
|
3229
|
+
}
|
3230
|
+
|
3231
|
+
static test_return delete_buffer_generate(memcached_st *memc)
|
3232
|
+
{
|
3233
|
+
size_t latch= 0;
|
3234
|
+
unsigned int x;
|
3235
|
+
|
3236
|
+
latch= 1;
|
3237
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, latch);
|
3238
|
+
|
3239
|
+
for (x= 0; x < global_count; x++)
|
3240
|
+
{
|
3241
|
+
(void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
|
3242
|
+
}
|
3243
|
+
|
3244
|
+
return 0;
|
3245
|
+
}
|
3246
|
+
|
3247
|
+
static test_return add_host_test1(memcached_st *memc)
|
3248
|
+
{
|
3249
|
+
unsigned int x;
|
3250
|
+
memcached_return rc;
|
3251
|
+
char servername[]= "0.example.com";
|
3252
|
+
memcached_server_st *servers;
|
3253
|
+
|
3254
|
+
servers= memcached_server_list_append_with_weight(NULL, servername, 400, 0, &rc);
|
3255
|
+
assert(servers);
|
3256
|
+
assert(1 == memcached_server_list_count(servers));
|
3257
|
+
|
3258
|
+
for (x= 2; x < 20; x++)
|
3259
|
+
{
|
3260
|
+
char buffer[SMALL_STRING_LEN];
|
3261
|
+
|
3262
|
+
snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
|
3263
|
+
servers= memcached_server_list_append_with_weight(servers, buffer, 401, 0,
|
3264
|
+
&rc);
|
3265
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3266
|
+
assert(x == memcached_server_list_count(servers));
|
3267
|
+
}
|
3268
|
+
|
3269
|
+
rc= memcached_server_push(memc, servers);
|
3270
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3271
|
+
rc= memcached_server_push(memc, servers);
|
3272
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3273
|
+
|
3274
|
+
memcached_server_list_free(servers);
|
3275
|
+
|
3276
|
+
return 0;
|
3277
|
+
}
|
3278
|
+
|
3279
|
+
static memcached_return pre_nonblock(memcached_st *memc)
|
3280
|
+
{
|
3281
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
|
3282
|
+
|
3283
|
+
return MEMCACHED_SUCCESS;
|
3284
|
+
}
|
3285
|
+
|
3286
|
+
static memcached_return pre_nonblock_binary(memcached_st *memc)
|
3287
|
+
{
|
3288
|
+
memcached_return rc= MEMCACHED_FAILURE;
|
3289
|
+
memcached_st *memc_clone;
|
3290
|
+
|
3291
|
+
memc_clone= memcached_clone(NULL, memc);
|
3292
|
+
assert(memc_clone);
|
3293
|
+
// The memcached_version needs to be done on a clone, because the server
|
3294
|
+
// will not toggle protocol on an connection.
|
3295
|
+
memcached_version(memc_clone);
|
3296
|
+
|
3297
|
+
if (memc_clone->hosts[0].major_version >= 1 && memc_clone->hosts[0].minor_version > 2)
|
3298
|
+
{
|
3299
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
|
3300
|
+
rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
|
3301
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3302
|
+
assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1);
|
3303
|
+
}
|
3304
|
+
|
3305
|
+
memcached_free(memc_clone);
|
3306
|
+
return rc;
|
3307
|
+
}
|
3308
|
+
|
3309
|
+
static memcached_return pre_murmur(memcached_st *memc)
|
3310
|
+
{
|
3311
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MURMUR);
|
3312
|
+
|
3313
|
+
return MEMCACHED_SUCCESS;
|
3314
|
+
}
|
3315
|
+
|
3316
|
+
static memcached_return pre_jenkins(memcached_st *memc)
|
3317
|
+
{
|
3318
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_JENKINS);
|
3319
|
+
|
3320
|
+
return MEMCACHED_SUCCESS;
|
3321
|
+
}
|
3322
|
+
|
3323
|
+
|
3324
|
+
static memcached_return pre_md5(memcached_st *memc)
|
3325
|
+
{
|
3326
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_MD5);
|
3327
|
+
|
3328
|
+
return MEMCACHED_SUCCESS;
|
3329
|
+
}
|
3330
|
+
|
3331
|
+
static memcached_return pre_crc(memcached_st *memc)
|
3332
|
+
{
|
3333
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_CRC);
|
3334
|
+
|
3335
|
+
return MEMCACHED_SUCCESS;
|
3336
|
+
}
|
3337
|
+
|
3338
|
+
static memcached_return pre_hsieh(memcached_st *memc)
|
3339
|
+
{
|
3340
|
+
#ifdef HAVE_HSIEH_HASH
|
3341
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_HSIEH);
|
3342
|
+
return MEMCACHED_SUCCESS;
|
3343
|
+
#else
|
3344
|
+
(void) memc;
|
3345
|
+
return MEMCACHED_FAILURE;
|
3346
|
+
#endif
|
3347
|
+
}
|
3348
|
+
|
3349
|
+
static memcached_return pre_hash_fnv1_64(memcached_st *memc)
|
3350
|
+
{
|
3351
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1_64);
|
3352
|
+
|
3353
|
+
return MEMCACHED_SUCCESS;
|
3354
|
+
}
|
3355
|
+
|
3356
|
+
static memcached_return pre_hash_fnv1a_64(memcached_st *memc)
|
3357
|
+
{
|
3358
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_64);
|
3359
|
+
|
3360
|
+
return MEMCACHED_SUCCESS;
|
3361
|
+
}
|
3362
|
+
|
3363
|
+
static memcached_return pre_hash_fnv1_32(memcached_st *memc)
|
3364
|
+
{
|
3365
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1_32);
|
3366
|
+
|
3367
|
+
return MEMCACHED_SUCCESS;
|
3368
|
+
}
|
3369
|
+
|
3370
|
+
static memcached_return pre_hash_fnv1a_32(memcached_st *memc)
|
3371
|
+
{
|
3372
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, (uint64_t)MEMCACHED_HASH_FNV1A_32);
|
3373
|
+
|
3374
|
+
return MEMCACHED_SUCCESS;
|
3375
|
+
}
|
3376
|
+
|
3377
|
+
static memcached_return pre_behavior_ketama(memcached_st *memc)
|
3378
|
+
{
|
3379
|
+
memcached_return rc;
|
3380
|
+
uint64_t value;
|
3381
|
+
|
3382
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1);
|
3383
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3384
|
+
|
3385
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA);
|
3386
|
+
assert(value == 1);
|
3387
|
+
|
3388
|
+
return MEMCACHED_SUCCESS;
|
3389
|
+
}
|
3390
|
+
|
3391
|
+
static memcached_return pre_behavior_ketama_weighted(memcached_st *memc)
|
3392
|
+
{
|
3393
|
+
memcached_return rc;
|
3394
|
+
uint64_t value;
|
3395
|
+
|
3396
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1);
|
3397
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3398
|
+
|
3399
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
|
3400
|
+
assert(value == 1);
|
3401
|
+
|
3402
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5);
|
3403
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3404
|
+
|
3405
|
+
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_HASH);
|
3406
|
+
assert(value == MEMCACHED_HASH_MD5);
|
3407
|
+
return MEMCACHED_SUCCESS;
|
3408
|
+
}
|
3409
|
+
|
3410
|
+
static memcached_return pre_binary(memcached_st *memc)
|
3411
|
+
{
|
3412
|
+
memcached_return rc= MEMCACHED_FAILURE;
|
3413
|
+
memcached_st *memc_clone;
|
3414
|
+
|
3415
|
+
memc_clone= memcached_clone(NULL, memc);
|
3416
|
+
assert(memc_clone);
|
3417
|
+
// The memcached_version needs to be done on a clone, because the server
|
3418
|
+
// will not toggle protocol on an connection.
|
3419
|
+
memcached_version(memc_clone);
|
3420
|
+
|
3421
|
+
if (memc_clone->hosts[0].major_version >= 1 && memc_clone->hosts[0].minor_version > 2)
|
3422
|
+
{
|
3423
|
+
rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
|
3424
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3425
|
+
assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1);
|
3426
|
+
}
|
3427
|
+
|
3428
|
+
memcached_free(memc_clone);
|
3429
|
+
return rc;
|
3430
|
+
}
|
3431
|
+
|
3432
|
+
static void my_free(memcached_st *ptr __attribute__((unused)), void *mem)
|
3433
|
+
{
|
3434
|
+
free(mem);
|
3435
|
+
}
|
3436
|
+
|
3437
|
+
static void *my_malloc(memcached_st *ptr __attribute__((unused)), const size_t size)
|
3438
|
+
{
|
3439
|
+
void *ret= malloc(size);
|
3440
|
+
if (ret != NULL)
|
3441
|
+
memset(ret, 0xff, size);
|
3442
|
+
|
3443
|
+
return ret;
|
3444
|
+
}
|
3445
|
+
|
3446
|
+
static void *my_realloc(memcached_st *ptr __attribute__((unused)), void *mem, const size_t size)
|
3447
|
+
{
|
3448
|
+
return realloc(mem, size);
|
3449
|
+
}
|
3450
|
+
|
3451
|
+
static void *my_calloc(memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size)
|
3452
|
+
{
|
3453
|
+
return calloc(nelem, size);
|
3454
|
+
}
|
3455
|
+
|
3456
|
+
static memcached_return set_prefix(memcached_st *memc)
|
3457
|
+
{
|
3458
|
+
memcached_return rc;
|
3459
|
+
const char *key= "mine";
|
3460
|
+
char *value;
|
3461
|
+
|
3462
|
+
/* Make sure be default none exists */
|
3463
|
+
value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
|
3464
|
+
assert(rc == MEMCACHED_FAILURE);
|
3465
|
+
|
3466
|
+
/* Test a clean set */
|
3467
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
|
3468
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3469
|
+
|
3470
|
+
value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
|
3471
|
+
assert(memcmp(value, key, 4) == 0);
|
3472
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3473
|
+
|
3474
|
+
/* Test that we can turn it off */
|
3475
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
|
3476
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3477
|
+
|
3478
|
+
value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
|
3479
|
+
assert(rc == MEMCACHED_FAILURE);
|
3480
|
+
|
3481
|
+
/* Now setup for main test */
|
3482
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
|
3483
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3484
|
+
|
3485
|
+
value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
|
3486
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3487
|
+
assert(memcmp(value, key, 4) == 0);
|
3488
|
+
|
3489
|
+
/* Set to Zero, and then Set to something too large */
|
3490
|
+
{
|
3491
|
+
char long_key[255];
|
3492
|
+
memset(long_key, 0, 255);
|
3493
|
+
|
3494
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
|
3495
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3496
|
+
|
3497
|
+
value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
|
3498
|
+
assert(rc == MEMCACHED_FAILURE);
|
3499
|
+
assert(value == NULL);
|
3500
|
+
|
3501
|
+
/* Test a long key for failure */
|
3502
|
+
/* TODO, extend test to determine based on setting, what result should be */
|
3503
|
+
strcpy(long_key, "Thisismorethentheallottednumberofcharacters");
|
3504
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key);
|
3505
|
+
//assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
3506
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3507
|
+
|
3508
|
+
/* Now test a key with spaces (which will fail from long key, since bad key is not set) */
|
3509
|
+
strcpy(long_key, "This is more then the allotted number of characters");
|
3510
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key);
|
3511
|
+
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
3512
|
+
|
3513
|
+
/* Test for a bad prefix, but with a short key */
|
3514
|
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, 1);
|
3515
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3516
|
+
|
3517
|
+
strcpy(long_key, "dog cat");
|
3518
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key);
|
3519
|
+
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
|
3520
|
+
}
|
3521
|
+
|
3522
|
+
return MEMCACHED_SUCCESS;
|
3523
|
+
}
|
3524
|
+
|
3525
|
+
#ifdef MEMCACHED_ENABLE_DEPRECATED
|
3526
|
+
static memcached_return deprecated_set_memory_alloc(memcached_st *memc)
|
3527
|
+
{
|
3528
|
+
void *test_ptr= NULL;
|
3529
|
+
void *cb_ptr= NULL;
|
3530
|
+
{
|
3531
|
+
memcached_malloc_function malloc_cb=
|
3532
|
+
(memcached_malloc_function)my_malloc;
|
3533
|
+
cb_ptr= *(void **)&malloc_cb;
|
3534
|
+
memcached_return rc;
|
3535
|
+
|
3536
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, cb_ptr);
|
3537
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3538
|
+
test_ptr= memcached_callback_get(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &rc);
|
3539
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3540
|
+
assert(test_ptr == cb_ptr);
|
3541
|
+
}
|
3542
|
+
|
3543
|
+
{
|
3544
|
+
memcached_realloc_function realloc_cb=
|
3545
|
+
(memcached_realloc_function)my_realloc;
|
3546
|
+
cb_ptr= *(void **)&realloc_cb;
|
3547
|
+
memcached_return rc;
|
3548
|
+
|
3549
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, cb_ptr);
|
3550
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3551
|
+
test_ptr= memcached_callback_get(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &rc);
|
3552
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3553
|
+
assert(test_ptr == cb_ptr);
|
3554
|
+
}
|
3555
|
+
|
3556
|
+
{
|
3557
|
+
memcached_free_function free_cb=
|
3558
|
+
(memcached_free_function)my_free;
|
3559
|
+
cb_ptr= *(void **)&free_cb;
|
3560
|
+
memcached_return rc;
|
3561
|
+
|
3562
|
+
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, cb_ptr);
|
3563
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3564
|
+
test_ptr= memcached_callback_get(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, &rc);
|
3565
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3566
|
+
assert(test_ptr == cb_ptr);
|
3567
|
+
}
|
3568
|
+
return MEMCACHED_SUCCESS;
|
3569
|
+
}
|
3570
|
+
#endif
|
3571
|
+
|
3572
|
+
static memcached_return set_memory_alloc(memcached_st *memc)
|
3573
|
+
{
|
3574
|
+
memcached_return rc;
|
3575
|
+
rc= memcached_set_memory_allocators(memc, NULL, my_free,
|
3576
|
+
my_realloc, my_calloc);
|
3577
|
+
assert(rc == MEMCACHED_FAILURE);
|
3578
|
+
|
3579
|
+
rc= memcached_set_memory_allocators(memc, my_malloc, my_free,
|
3580
|
+
my_realloc, my_calloc);
|
3581
|
+
|
3582
|
+
memcached_malloc_function mem_malloc;
|
3583
|
+
memcached_free_function mem_free;
|
3584
|
+
memcached_realloc_function mem_realloc;
|
3585
|
+
memcached_calloc_function mem_calloc;
|
3586
|
+
memcached_get_memory_allocators(memc, &mem_malloc, &mem_free,
|
3587
|
+
&mem_realloc, &mem_calloc);
|
3588
|
+
|
3589
|
+
assert(mem_malloc == my_malloc);
|
3590
|
+
assert(mem_realloc == my_realloc);
|
3591
|
+
assert(mem_calloc == my_calloc);
|
3592
|
+
assert(mem_free == my_free);
|
3593
|
+
|
3594
|
+
return MEMCACHED_SUCCESS;
|
3595
|
+
}
|
3596
|
+
|
3597
|
+
static memcached_return enable_consistent(memcached_st *memc)
|
3598
|
+
{
|
3599
|
+
memcached_server_distribution value= MEMCACHED_DISTRIBUTION_CONSISTENT;
|
3600
|
+
memcached_hash hash;
|
3601
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
|
3602
|
+
if (pre_hsieh(memc) != MEMCACHED_SUCCESS)
|
3603
|
+
return MEMCACHED_FAILURE;
|
3604
|
+
|
3605
|
+
value= (memcached_server_distribution)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
|
3606
|
+
assert(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
|
3607
|
+
|
3608
|
+
hash= (memcached_hash)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
|
3609
|
+
assert(hash == MEMCACHED_HASH_HSIEH);
|
3610
|
+
|
3611
|
+
|
3612
|
+
return MEMCACHED_SUCCESS;
|
3613
|
+
}
|
3614
|
+
|
3615
|
+
static memcached_return enable_cas(memcached_st *memc)
|
3616
|
+
{
|
3617
|
+
unsigned int set= 1;
|
3618
|
+
|
3619
|
+
memcached_version(memc);
|
3620
|
+
|
3621
|
+
if ((memc->hosts[0].major_version >= 1 && (memc->hosts[0].minor_version == 2 && memc->hosts[0].micro_version >= 4))
|
3622
|
+
|| memc->hosts[0].minor_version > 2)
|
3623
|
+
{
|
3624
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
|
3625
|
+
|
3626
|
+
return MEMCACHED_SUCCESS;
|
3627
|
+
}
|
3628
|
+
|
3629
|
+
return MEMCACHED_FAILURE;
|
3630
|
+
}
|
3631
|
+
|
3632
|
+
static memcached_return check_for_1_2_3(memcached_st *memc)
|
3633
|
+
{
|
3634
|
+
memcached_version(memc);
|
3635
|
+
|
3636
|
+
if ((memc->hosts[0].major_version >= 1 && (memc->hosts[0].minor_version == 2 && memc->hosts[0].micro_version >= 4))
|
3637
|
+
|| memc->hosts[0].minor_version > 2)
|
3638
|
+
return MEMCACHED_SUCCESS;
|
3639
|
+
|
3640
|
+
return MEMCACHED_FAILURE;
|
3641
|
+
}
|
3642
|
+
|
3643
|
+
static memcached_return pre_unix_socket(memcached_st *memc)
|
3644
|
+
{
|
3645
|
+
memcached_return rc;
|
3646
|
+
struct stat buf;
|
3647
|
+
|
3648
|
+
memcached_server_list_free(memc->hosts);
|
3649
|
+
memc->hosts= NULL;
|
3650
|
+
memc->number_of_hosts= 0;
|
3651
|
+
|
3652
|
+
if (stat("/tmp/memcached.socket", &buf))
|
3653
|
+
return MEMCACHED_FAILURE;
|
3654
|
+
|
3655
|
+
rc= memcached_server_add_unix_socket_with_weight(memc, "/tmp/memcached.socket", 0);
|
3656
|
+
|
3657
|
+
return rc;
|
3658
|
+
}
|
3659
|
+
|
3660
|
+
static memcached_return pre_nodelay(memcached_st *memc)
|
3661
|
+
{
|
3662
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
|
3663
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 0);
|
3664
|
+
|
3665
|
+
return MEMCACHED_SUCCESS;
|
3666
|
+
}
|
3667
|
+
|
3668
|
+
static memcached_return pre_settimer(memcached_st *memc)
|
3669
|
+
{
|
3670
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 1000);
|
3671
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 1000);
|
3672
|
+
|
3673
|
+
return MEMCACHED_SUCCESS;
|
3674
|
+
}
|
3675
|
+
|
3676
|
+
static memcached_return poll_timeout(memcached_st *memc)
|
3677
|
+
{
|
3678
|
+
size_t timeout;
|
3679
|
+
|
3680
|
+
timeout= 100;
|
3681
|
+
|
3682
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout);
|
3683
|
+
|
3684
|
+
timeout= (size_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
|
3685
|
+
|
3686
|
+
assert(timeout == 100);
|
3687
|
+
|
3688
|
+
return MEMCACHED_SUCCESS;
|
3689
|
+
}
|
3690
|
+
|
3691
|
+
static test_return noreply_test(memcached_st *memc)
|
3692
|
+
{
|
3693
|
+
int count, x;
|
3694
|
+
uint32_t y;
|
3695
|
+
memcached_return ret;
|
3696
|
+
ret= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1);
|
3697
|
+
assert(ret == MEMCACHED_SUCCESS);
|
3698
|
+
ret= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
|
3699
|
+
assert(ret == MEMCACHED_SUCCESS);
|
3700
|
+
ret= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 1);
|
3701
|
+
assert(ret == MEMCACHED_SUCCESS);
|
3702
|
+
assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NOREPLY) == 1);
|
3703
|
+
assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS) == 1);
|
3704
|
+
assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS) == 1);
|
3705
|
+
|
3706
|
+
for (count=0; count < 5; ++count)
|
3707
|
+
{
|
3708
|
+
for (x=0; x < 100; ++x)
|
3709
|
+
{
|
3710
|
+
char key[10];
|
3711
|
+
size_t len= (size_t)sprintf(key, "%d", x);
|
3712
|
+
switch (count)
|
3713
|
+
{
|
3714
|
+
case 0:
|
3715
|
+
ret=memcached_add(memc, key, len, key, len, 0, 0);
|
3716
|
+
break;
|
3717
|
+
case 1:
|
3718
|
+
ret=memcached_replace(memc, key, len, key, len, 0, 0);
|
3719
|
+
break;
|
3720
|
+
case 2:
|
3721
|
+
ret=memcached_set(memc, key, len, key, len, 0, 0);
|
3722
|
+
break;
|
3723
|
+
case 3:
|
3724
|
+
ret=memcached_append(memc, key, len, key, len, 0, 0);
|
3725
|
+
break;
|
3726
|
+
case 4:
|
3727
|
+
ret=memcached_prepend(memc, key, len, key, len, 0, 0);
|
3728
|
+
break;
|
3729
|
+
default:
|
3730
|
+
assert(count);
|
3731
|
+
break;
|
3732
|
+
}
|
3733
|
+
assert(ret == MEMCACHED_SUCCESS || ret == MEMCACHED_BUFFERED);
|
3734
|
+
}
|
3735
|
+
|
3736
|
+
/*
|
3737
|
+
** NOTE: Don't ever do this in your code! this is not a supported use of the
|
3738
|
+
** API and is _ONLY_ done this way to verify that the library works the
|
3739
|
+
** way it is supposed to do!!!!
|
3740
|
+
*/
|
3741
|
+
int no_msg=0;
|
3742
|
+
for (y=0; x < memc->number_of_hosts; ++y)
|
3743
|
+
no_msg+=(int)(memc->hosts[y].cursor_active);
|
3744
|
+
|
3745
|
+
assert(no_msg == 0);
|
3746
|
+
assert(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
|
3747
|
+
|
3748
|
+
/*
|
3749
|
+
** Now validate that all items was set properly!
|
3750
|
+
*/
|
3751
|
+
for (x=0; x < 100; ++x)
|
3752
|
+
{
|
3753
|
+
char key[10];
|
3754
|
+
size_t len= (size_t)sprintf(key, "%d", x);
|
3755
|
+
size_t length;
|
3756
|
+
uint32_t flags;
|
3757
|
+
char* value=memcached_get(memc, key, strlen(key),
|
3758
|
+
&length, &flags, &ret);
|
3759
|
+
assert(ret == MEMCACHED_SUCCESS && value != NULL);
|
3760
|
+
switch (count)
|
3761
|
+
{
|
3762
|
+
case 0: /* FALLTHROUGH */
|
3763
|
+
case 1: /* FALLTHROUGH */
|
3764
|
+
case 2:
|
3765
|
+
assert(strncmp(value, key, len) == 0);
|
3766
|
+
assert(len == length);
|
3767
|
+
break;
|
3768
|
+
case 3:
|
3769
|
+
assert(length == len * 2);
|
3770
|
+
break;
|
3771
|
+
case 4:
|
3772
|
+
assert(length == len * 3);
|
3773
|
+
break;
|
3774
|
+
default:
|
3775
|
+
assert(count);
|
3776
|
+
break;
|
3777
|
+
}
|
3778
|
+
free(value);
|
3779
|
+
}
|
3780
|
+
}
|
3781
|
+
|
3782
|
+
/* Try setting an illegal cas value (should not return an error to
|
3783
|
+
* the caller (because we don't expect a return message from the server)
|
3784
|
+
*/
|
3785
|
+
const char* keys[]= {"0"};
|
3786
|
+
size_t lengths[]= {1};
|
3787
|
+
size_t length;
|
3788
|
+
uint32_t flags;
|
3789
|
+
memcached_result_st results_obj;
|
3790
|
+
memcached_result_st *results;
|
3791
|
+
ret= memcached_mget(memc, keys, lengths, 1);
|
3792
|
+
assert(ret == MEMCACHED_SUCCESS);
|
3793
|
+
|
3794
|
+
results= memcached_result_create(memc, &results_obj);
|
3795
|
+
assert(results);
|
3796
|
+
results= memcached_fetch_result(memc, &results_obj, &ret);
|
3797
|
+
assert(results);
|
3798
|
+
assert(ret == MEMCACHED_SUCCESS);
|
3799
|
+
uint64_t cas= memcached_result_cas(results);
|
3800
|
+
memcached_result_free(&results_obj);
|
3801
|
+
|
3802
|
+
ret= memcached_cas(memc, keys[0], lengths[0], keys[0], lengths[0], 0, 0, cas);
|
3803
|
+
assert(ret == MEMCACHED_SUCCESS);
|
3804
|
+
|
3805
|
+
/*
|
3806
|
+
* The item will have a new cas value, so try to set it again with the old
|
3807
|
+
* value. This should fail!
|
3808
|
+
*/
|
3809
|
+
ret= memcached_cas(memc, keys[0], lengths[0], keys[0], lengths[0], 0, 0, cas);
|
3810
|
+
assert(ret == MEMCACHED_SUCCESS);
|
3811
|
+
assert(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
|
3812
|
+
char* value=memcached_get(memc, keys[0], lengths[0], &length, &flags, &ret);
|
3813
|
+
assert(ret == MEMCACHED_SUCCESS && value != NULL);
|
3814
|
+
free(value);
|
3815
|
+
|
3816
|
+
return TEST_SUCCESS;
|
3817
|
+
}
|
3818
|
+
|
3819
|
+
static test_return analyzer_test(memcached_st *memc)
|
3820
|
+
{
|
3821
|
+
memcached_return rc;
|
3822
|
+
memcached_stat_st *memc_stat;
|
3823
|
+
memcached_analysis_st *report;
|
3824
|
+
|
3825
|
+
memc_stat= memcached_stat(memc, NULL, &rc);
|
3826
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3827
|
+
assert(memc_stat);
|
3828
|
+
|
3829
|
+
report= memcached_analyze(memc, memc_stat, &rc);
|
3830
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3831
|
+
assert(report);
|
3832
|
+
|
3833
|
+
free(report);
|
3834
|
+
memcached_stat_free(NULL, memc_stat);
|
3835
|
+
|
3836
|
+
return TEST_SUCCESS;
|
3837
|
+
}
|
3838
|
+
|
3839
|
+
/* Count the objects */
|
3840
|
+
static memcached_return callback_dump_counter(memcached_st *ptr __attribute__((unused)),
|
3841
|
+
const char *key __attribute__((unused)),
|
3842
|
+
size_t key_length __attribute__((unused)),
|
3843
|
+
void *context)
|
3844
|
+
{
|
3845
|
+
uint32_t *counter= (uint32_t *)context;
|
3846
|
+
|
3847
|
+
*counter= *counter + 1;
|
3848
|
+
|
3849
|
+
return MEMCACHED_SUCCESS;
|
3850
|
+
}
|
3851
|
+
|
3852
|
+
static test_return dump_test(memcached_st *memc)
|
3853
|
+
{
|
3854
|
+
memcached_return rc;
|
3855
|
+
uint32_t counter= 0;
|
3856
|
+
memcached_dump_func callbacks[1];
|
3857
|
+
test_return main_rc;
|
3858
|
+
|
3859
|
+
callbacks[0]= &callback_dump_counter;
|
3860
|
+
|
3861
|
+
/* No support for Binary protocol yet */
|
3862
|
+
if (memc->flags & MEM_BINARY_PROTOCOL)
|
3863
|
+
return TEST_SUCCESS;
|
3864
|
+
|
3865
|
+
main_rc= set_test3(memc);
|
3866
|
+
|
3867
|
+
assert (main_rc == TEST_SUCCESS);
|
3868
|
+
|
3869
|
+
rc= memcached_dump(memc, callbacks, (void *)&counter, 1);
|
3870
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3871
|
+
|
3872
|
+
/* We may have more then 32 if our previous flush has not completed */
|
3873
|
+
assert(counter >= 32);
|
3874
|
+
|
3875
|
+
return TEST_SUCCESS;
|
3876
|
+
}
|
3877
|
+
|
3878
|
+
#ifdef HAVE_LIBMEMCACHEDUTIL
|
3879
|
+
static void* connection_release(void *arg) {
|
3880
|
+
struct {
|
3881
|
+
memcached_pool_st* pool;
|
3882
|
+
memcached_st* mmc;
|
3883
|
+
} *resource= arg;
|
3884
|
+
|
3885
|
+
usleep(250);
|
3886
|
+
assert(memcached_pool_push(resource->pool, resource->mmc) == MEMCACHED_SUCCESS);
|
3887
|
+
return arg;
|
3888
|
+
}
|
3889
|
+
|
3890
|
+
static test_return connection_pool_test(memcached_st *memc)
|
3891
|
+
{
|
3892
|
+
memcached_pool_st* pool= memcached_pool_create(memc, 5, 10);
|
3893
|
+
assert(pool != NULL);
|
3894
|
+
memcached_st* mmc[10];
|
3895
|
+
memcached_return rc;
|
3896
|
+
|
3897
|
+
for (int x= 0; x < 10; ++x) {
|
3898
|
+
mmc[x]= memcached_pool_pop(pool, false, &rc);
|
3899
|
+
assert(mmc[x] != NULL);
|
3900
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3901
|
+
}
|
3902
|
+
|
3903
|
+
assert(memcached_pool_pop(pool, false, &rc) == NULL);
|
3904
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3905
|
+
|
3906
|
+
pthread_t tid;
|
3907
|
+
struct {
|
3908
|
+
memcached_pool_st* pool;
|
3909
|
+
memcached_st* mmc;
|
3910
|
+
} item= { .pool = pool, .mmc = mmc[9] };
|
3911
|
+
pthread_create(&tid, NULL, connection_release, &item);
|
3912
|
+
mmc[9]= memcached_pool_pop(pool, true, &rc);
|
3913
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3914
|
+
pthread_join(tid, NULL);
|
3915
|
+
assert(mmc[9] == item.mmc);
|
3916
|
+
const char *key= "key";
|
3917
|
+
size_t keylen= strlen(key);
|
3918
|
+
|
3919
|
+
// verify that I can do ops with all connections
|
3920
|
+
rc= memcached_set(mmc[0], key, keylen, "0", 1, 0, 0);
|
3921
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3922
|
+
|
3923
|
+
for (unsigned int x= 0; x < 10; ++x) {
|
3924
|
+
uint64_t number_value;
|
3925
|
+
rc= memcached_increment(mmc[x], key, keylen, 1, &number_value);
|
3926
|
+
assert(rc == MEMCACHED_SUCCESS);
|
3927
|
+
assert(number_value == (x+1));
|
3928
|
+
}
|
3929
|
+
|
3930
|
+
// Release them..
|
3931
|
+
for (int x= 0; x < 10; ++x)
|
3932
|
+
assert(memcached_pool_push(pool, mmc[x]) == MEMCACHED_SUCCESS);
|
3933
|
+
|
3934
|
+
assert(memcached_pool_destroy(pool) == memc);
|
3935
|
+
return TEST_SUCCESS;
|
3936
|
+
}
|
3937
|
+
#endif
|
3938
|
+
|
3939
|
+
|
3940
|
+
static void increment_request_id(uint16_t *id)
|
3941
|
+
{
|
3942
|
+
(*id)++;
|
3943
|
+
if ((*id & UDP_REQUEST_ID_THREAD_MASK) != 0)
|
3944
|
+
*id= 0;
|
3945
|
+
}
|
3946
|
+
|
3947
|
+
static uint16_t *get_udp_request_ids(memcached_st *memc)
|
3948
|
+
{
|
3949
|
+
uint16_t *ids= malloc(sizeof(uint16_t) * memc->number_of_hosts);
|
3950
|
+
assert(ids != NULL);
|
3951
|
+
unsigned int x;
|
3952
|
+
|
3953
|
+
for (x= 0; x < memc->number_of_hosts; x++)
|
3954
|
+
ids[x]= get_udp_datagram_request_id((struct udp_datagram_header_st *) memc->hosts[x].write_buffer);
|
3955
|
+
|
3956
|
+
return ids;
|
3957
|
+
}
|
3958
|
+
|
3959
|
+
static test_return post_udp_op_check(memcached_st *memc, uint16_t *expected_req_ids)
|
3960
|
+
{
|
3961
|
+
unsigned int x;
|
3962
|
+
memcached_server_st *cur_server = memc->hosts;
|
3963
|
+
uint16_t *cur_req_ids = get_udp_request_ids(memc);
|
3964
|
+
|
3965
|
+
for (x= 0; x < memc->number_of_hosts; x++)
|
3966
|
+
{
|
3967
|
+
assert(cur_server[x].cursor_active == 0);
|
3968
|
+
assert(cur_req_ids[x] == expected_req_ids[x]);
|
3969
|
+
}
|
3970
|
+
free(expected_req_ids);
|
3971
|
+
free(cur_req_ids);
|
3972
|
+
|
3973
|
+
return TEST_SUCCESS;
|
3974
|
+
}
|
3975
|
+
|
3976
|
+
/*
|
3977
|
+
** There is a little bit of a hack here, instead of removing
|
3978
|
+
** the servers, I just set num host to 0 and them add then new udp servers
|
3979
|
+
**/
|
3980
|
+
static memcached_return init_udp(memcached_st *memc)
|
3981
|
+
{
|
3982
|
+
memcached_version(memc);
|
3983
|
+
/* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
|
3984
|
+
if (memc->hosts[0].major_version != 1 || memc->hosts[0].minor_version != 2
|
3985
|
+
|| memc->hosts[0].micro_version < 6)
|
3986
|
+
return MEMCACHED_FAILURE;
|
3987
|
+
|
3988
|
+
uint32_t num_hosts= memc->number_of_hosts;
|
3989
|
+
unsigned int x= 0;
|
3990
|
+
memcached_server_st servers[num_hosts];
|
3991
|
+
memcpy(servers, memc->hosts, sizeof(memcached_server_st) * num_hosts);
|
3992
|
+
for (x= 0; x < num_hosts; x++)
|
3993
|
+
memcached_server_free(&memc->hosts[x]);
|
3994
|
+
|
3995
|
+
memc->number_of_hosts= 0;
|
3996
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1);
|
3997
|
+
for (x= 0; x < num_hosts; x++)
|
3998
|
+
{
|
3999
|
+
assert(memcached_server_add_udp(memc, servers[x].hostname, servers[x].port) == MEMCACHED_SUCCESS);
|
4000
|
+
assert(memc->hosts[x].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
|
4001
|
+
}
|
4002
|
+
|
4003
|
+
return MEMCACHED_SUCCESS;
|
4004
|
+
}
|
4005
|
+
|
4006
|
+
static memcached_return binary_init_udp(memcached_st *memc)
|
4007
|
+
{
|
4008
|
+
pre_binary(memc);
|
4009
|
+
return init_udp(memc);
|
4010
|
+
}
|
4011
|
+
|
4012
|
+
/* Make sure that I cant add a tcp server to a udp client */
|
4013
|
+
static test_return add_tcp_server_udp_client_test(memcached_st *memc)
|
4014
|
+
{
|
4015
|
+
memcached_server_st server;
|
4016
|
+
memcached_server_clone(&server, &memc->hosts[0]);
|
4017
|
+
assert(memcached_server_remove(&(memc->hosts[0])) == MEMCACHED_SUCCESS);
|
4018
|
+
assert(memcached_server_add(memc, server.hostname, server.port) == MEMCACHED_INVALID_HOST_PROTOCOL);
|
4019
|
+
return TEST_SUCCESS;
|
4020
|
+
}
|
4021
|
+
|
4022
|
+
/* Make sure that I cant add a udp server to a tcp client */
|
4023
|
+
static test_return add_udp_server_tcp_client_test(memcached_st *memc)
|
4024
|
+
{
|
4025
|
+
memcached_server_st server;
|
4026
|
+
memcached_server_clone(&server, &memc->hosts[0]);
|
4027
|
+
assert(memcached_server_remove(&(memc->hosts[0])) == MEMCACHED_SUCCESS);
|
4028
|
+
|
4029
|
+
memcached_st tcp_client;
|
4030
|
+
memcached_create(&tcp_client);
|
4031
|
+
assert(memcached_server_add_udp(&tcp_client, server.hostname, server.port) == MEMCACHED_INVALID_HOST_PROTOCOL);
|
4032
|
+
return TEST_SUCCESS;
|
4033
|
+
}
|
4034
|
+
|
4035
|
+
static test_return set_udp_behavior_test(memcached_st *memc)
|
4036
|
+
{
|
4037
|
+
|
4038
|
+
memcached_quit(memc);
|
4039
|
+
memc->number_of_hosts= 0;
|
4040
|
+
run_distribution(memc);
|
4041
|
+
assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1) == MEMCACHED_SUCCESS);
|
4042
|
+
assert(memc->flags & MEM_USE_UDP);
|
4043
|
+
assert(memc->flags & MEM_NOREPLY);;
|
4044
|
+
|
4045
|
+
assert(memc->number_of_hosts == 0);
|
4046
|
+
|
4047
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP,0);
|
4048
|
+
assert(!(memc->flags & MEM_USE_UDP));
|
4049
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY,0);
|
4050
|
+
assert(!(memc->flags & MEM_NOREPLY));
|
4051
|
+
return TEST_SUCCESS;
|
4052
|
+
}
|
4053
|
+
|
4054
|
+
static test_return udp_set_test(memcached_st *memc)
|
4055
|
+
{
|
4056
|
+
unsigned int x= 0;
|
4057
|
+
unsigned int num_iters= 1025; //request id rolls over at 1024
|
4058
|
+
for (x= 0; x < num_iters;x++)
|
4059
|
+
{
|
4060
|
+
memcached_return rc;
|
4061
|
+
const char *key= "foo";
|
4062
|
+
const char *value= "when we sanitize";
|
4063
|
+
uint16_t *expected_ids= get_udp_request_ids(memc);
|
4064
|
+
unsigned int server_key= memcached_generate_hash(memc,key,strlen(key));
|
4065
|
+
size_t init_offset= memc->hosts[server_key].write_buffer_offset;
|
4066
|
+
rc= memcached_set(memc, key, strlen(key),
|
4067
|
+
value, strlen(value),
|
4068
|
+
(time_t)0, (uint32_t)0);
|
4069
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
4070
|
+
/** NB, the check below assumes that if new write_ptr is less than
|
4071
|
+
* the original write_ptr that we have flushed. For large payloads, this
|
4072
|
+
* maybe an invalid assumption, but for the small payload we have it is OK
|
4073
|
+
*/
|
4074
|
+
if (rc == MEMCACHED_SUCCESS ||
|
4075
|
+
memc->hosts[server_key].write_buffer_offset < init_offset)
|
4076
|
+
increment_request_id(&expected_ids[server_key]);
|
4077
|
+
|
4078
|
+
if (rc == MEMCACHED_SUCCESS)
|
4079
|
+
{
|
4080
|
+
assert(memc->hosts[server_key].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
|
4081
|
+
}
|
4082
|
+
else
|
4083
|
+
{
|
4084
|
+
assert(memc->hosts[server_key].write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
|
4085
|
+
assert(memc->hosts[server_key].write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
|
4086
|
+
}
|
4087
|
+
assert(post_udp_op_check(memc,expected_ids) == TEST_SUCCESS);
|
4088
|
+
}
|
4089
|
+
return TEST_SUCCESS;
|
4090
|
+
}
|
4091
|
+
|
4092
|
+
static test_return udp_buffered_set_test(memcached_st *memc)
|
4093
|
+
{
|
4094
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
|
4095
|
+
return udp_set_test(memc);
|
4096
|
+
}
|
4097
|
+
|
4098
|
+
static test_return udp_set_too_big_test(memcached_st *memc)
|
4099
|
+
{
|
4100
|
+
memcached_return rc;
|
4101
|
+
const char *key= "bar";
|
4102
|
+
char value[MAX_UDP_DATAGRAM_LENGTH];
|
4103
|
+
uint16_t *expected_ids= get_udp_request_ids(memc);
|
4104
|
+
rc= memcached_set(memc, key, strlen(key),
|
4105
|
+
value, MAX_UDP_DATAGRAM_LENGTH,
|
4106
|
+
(time_t)0, (uint32_t)0);
|
4107
|
+
assert(rc == MEMCACHED_WRITE_FAILURE);
|
4108
|
+
return post_udp_op_check(memc,expected_ids);
|
4109
|
+
}
|
4110
|
+
|
4111
|
+
static test_return udp_delete_test(memcached_st *memc)
|
4112
|
+
{
|
4113
|
+
unsigned int x= 0;
|
4114
|
+
unsigned int num_iters= 1025; //request id rolls over at 1024
|
4115
|
+
for (x= 0; x < num_iters;x++)
|
4116
|
+
{
|
4117
|
+
memcached_return rc;
|
4118
|
+
const char *key= "foo";
|
4119
|
+
uint16_t *expected_ids=get_udp_request_ids(memc);
|
4120
|
+
unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
|
4121
|
+
size_t init_offset= memc->hosts[server_key].write_buffer_offset;
|
4122
|
+
rc= memcached_delete(memc, key, strlen(key), 0);
|
4123
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
4124
|
+
if (rc == MEMCACHED_SUCCESS || memc->hosts[server_key].write_buffer_offset < init_offset)
|
4125
|
+
increment_request_id(&expected_ids[server_key]);
|
4126
|
+
if (rc == MEMCACHED_SUCCESS)
|
4127
|
+
assert(memc->hosts[server_key].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
|
4128
|
+
else
|
4129
|
+
{
|
4130
|
+
assert(memc->hosts[server_key].write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
|
4131
|
+
assert(memc->hosts[server_key].write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
|
4132
|
+
}
|
4133
|
+
assert(post_udp_op_check(memc,expected_ids) == TEST_SUCCESS);
|
4134
|
+
}
|
4135
|
+
return TEST_SUCCESS;
|
4136
|
+
}
|
4137
|
+
|
4138
|
+
static test_return udp_buffered_delete_test(memcached_st *memc)
|
4139
|
+
{
|
4140
|
+
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
|
4141
|
+
return udp_delete_test(memc);
|
4142
|
+
}
|
4143
|
+
|
4144
|
+
static test_return udp_verbosity_test(memcached_st *memc)
|
4145
|
+
{
|
4146
|
+
memcached_return rc;
|
4147
|
+
uint16_t *expected_ids= get_udp_request_ids(memc);
|
4148
|
+
unsigned int x;
|
4149
|
+
for (x= 0; x < memc->number_of_hosts;x++)
|
4150
|
+
increment_request_id(&expected_ids[x]);
|
4151
|
+
|
4152
|
+
rc= memcached_verbosity(memc,3);
|
4153
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4154
|
+
return post_udp_op_check(memc,expected_ids);
|
4155
|
+
}
|
4156
|
+
|
4157
|
+
static test_return udp_quit_test(memcached_st *memc)
|
4158
|
+
{
|
4159
|
+
uint16_t *expected_ids= get_udp_request_ids(memc);
|
4160
|
+
memcached_quit(memc);
|
4161
|
+
return post_udp_op_check(memc, expected_ids);
|
4162
|
+
}
|
4163
|
+
|
4164
|
+
static test_return udp_flush_test(memcached_st *memc)
|
4165
|
+
{
|
4166
|
+
memcached_return rc;
|
4167
|
+
uint16_t *expected_ids= get_udp_request_ids(memc);
|
4168
|
+
unsigned int x;
|
4169
|
+
for (x= 0; x < memc->number_of_hosts;x++)
|
4170
|
+
increment_request_id(&expected_ids[x]);
|
4171
|
+
|
4172
|
+
rc= memcached_flush(memc,0);
|
4173
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4174
|
+
return post_udp_op_check(memc,expected_ids);
|
4175
|
+
}
|
4176
|
+
|
4177
|
+
static test_return udp_incr_test(memcached_st *memc)
|
4178
|
+
{
|
4179
|
+
memcached_return rc;
|
4180
|
+
const char *key= "incr";
|
4181
|
+
const char *value= "1";
|
4182
|
+
rc= memcached_set(memc, key, strlen(key),
|
4183
|
+
value, strlen(value),
|
4184
|
+
(time_t)0, (uint32_t)0);
|
4185
|
+
|
4186
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4187
|
+
uint16_t *expected_ids= get_udp_request_ids(memc);
|
4188
|
+
unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
|
4189
|
+
increment_request_id(&expected_ids[server_key]);
|
4190
|
+
uint64_t newvalue;
|
4191
|
+
rc= memcached_increment(memc, key, strlen(key), 1, &newvalue);
|
4192
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4193
|
+
return post_udp_op_check(memc, expected_ids);
|
4194
|
+
}
|
4195
|
+
|
4196
|
+
static test_return udp_decr_test(memcached_st *memc)
|
4197
|
+
{
|
4198
|
+
memcached_return rc;
|
4199
|
+
const char *key= "decr";
|
4200
|
+
const char *value= "1";
|
4201
|
+
rc= memcached_set(memc, key, strlen(key),
|
4202
|
+
value, strlen(value),
|
4203
|
+
(time_t)0, (uint32_t)0);
|
4204
|
+
|
4205
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4206
|
+
uint16_t *expected_ids= get_udp_request_ids(memc);
|
4207
|
+
unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
|
4208
|
+
increment_request_id(&expected_ids[server_key]);
|
4209
|
+
uint64_t newvalue;
|
4210
|
+
rc= memcached_decrement(memc, key, strlen(key), 1, &newvalue);
|
4211
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4212
|
+
return post_udp_op_check(memc, expected_ids);
|
4213
|
+
}
|
4214
|
+
|
4215
|
+
|
4216
|
+
static test_return udp_stat_test(memcached_st *memc)
|
4217
|
+
{
|
4218
|
+
memcached_stat_st * rv= NULL;
|
4219
|
+
memcached_return rc;
|
4220
|
+
char args[]= "";
|
4221
|
+
uint16_t *expected_ids = get_udp_request_ids(memc);
|
4222
|
+
rv = memcached_stat(memc, args, &rc);
|
4223
|
+
free(rv);
|
4224
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
4225
|
+
return post_udp_op_check(memc, expected_ids);
|
4226
|
+
}
|
4227
|
+
|
4228
|
+
static test_return udp_version_test(memcached_st *memc)
|
4229
|
+
{
|
4230
|
+
memcached_return rc;
|
4231
|
+
uint16_t *expected_ids = get_udp_request_ids(memc);
|
4232
|
+
rc = memcached_version(memc);
|
4233
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
4234
|
+
return post_udp_op_check(memc, expected_ids);
|
4235
|
+
}
|
4236
|
+
|
4237
|
+
static test_return udp_get_test(memcached_st *memc)
|
4238
|
+
{
|
4239
|
+
memcached_return rc;
|
4240
|
+
const char *key= "foo";
|
4241
|
+
size_t vlen;
|
4242
|
+
uint16_t *expected_ids = get_udp_request_ids(memc);
|
4243
|
+
char *val= memcached_get(memc, key, strlen(key), &vlen, (uint32_t)0, &rc);
|
4244
|
+
assert(rc == MEMCACHED_NOT_SUPPORTED);
|
4245
|
+
assert(val == NULL);
|
4246
|
+
return post_udp_op_check(memc, expected_ids);
|
4247
|
+
}
|
4248
|
+
|
4249
|
+
static test_return udp_mixed_io_test(memcached_st *memc)
|
4250
|
+
{
|
4251
|
+
test_st current_op;
|
4252
|
+
test_st mixed_io_ops [] ={
|
4253
|
+
{"udp_set_test", 0, udp_set_test},
|
4254
|
+
{"udp_set_too_big_test", 0, udp_set_too_big_test},
|
4255
|
+
{"udp_delete_test", 0, udp_delete_test},
|
4256
|
+
{"udp_verbosity_test", 0, udp_verbosity_test},
|
4257
|
+
{"udp_quit_test", 0, udp_quit_test},
|
4258
|
+
{"udp_flush_test", 0, udp_flush_test},
|
4259
|
+
{"udp_incr_test", 0, udp_incr_test},
|
4260
|
+
{"udp_decr_test", 0, udp_decr_test},
|
4261
|
+
{"udp_version_test", 0, udp_version_test}
|
4262
|
+
};
|
4263
|
+
unsigned int x= 0;
|
4264
|
+
for (x= 0; x < 500; x++)
|
4265
|
+
{
|
4266
|
+
current_op= mixed_io_ops[random() % 9];
|
4267
|
+
assert(current_op.function(memc) == TEST_SUCCESS);
|
4268
|
+
}
|
4269
|
+
return TEST_SUCCESS;
|
4270
|
+
}
|
4271
|
+
|
4272
|
+
static test_return hsieh_avaibility_test (memcached_st *memc)
|
4273
|
+
{
|
4274
|
+
memcached_return expected_rc= MEMCACHED_FAILURE;
|
4275
|
+
#ifdef HAVE_HSIEH_HASH
|
4276
|
+
expected_rc= MEMCACHED_SUCCESS;
|
4277
|
+
#endif
|
4278
|
+
memcached_return rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH,
|
4279
|
+
(uint64_t)MEMCACHED_HASH_HSIEH);
|
4280
|
+
assert(rc == expected_rc);
|
4281
|
+
return TEST_SUCCESS;
|
4282
|
+
}
|
4283
|
+
|
4284
|
+
static const char *list[]=
|
4285
|
+
{
|
4286
|
+
"apple",
|
4287
|
+
"beat",
|
4288
|
+
"carrot",
|
4289
|
+
"daikon",
|
4290
|
+
"eggplant",
|
4291
|
+
"flower",
|
4292
|
+
"green",
|
4293
|
+
"hide",
|
4294
|
+
"ick",
|
4295
|
+
"jack",
|
4296
|
+
"kick",
|
4297
|
+
"lime",
|
4298
|
+
"mushrooms",
|
4299
|
+
"nectarine",
|
4300
|
+
"orange",
|
4301
|
+
"peach",
|
4302
|
+
"quant",
|
4303
|
+
"ripen",
|
4304
|
+
"strawberry",
|
4305
|
+
"tang",
|
4306
|
+
"up",
|
4307
|
+
"volumne",
|
4308
|
+
"when",
|
4309
|
+
"yellow",
|
4310
|
+
"zip",
|
4311
|
+
NULL
|
4312
|
+
};
|
4313
|
+
|
4314
|
+
static test_return md5_run (memcached_st *memc __attribute__((unused)))
|
4315
|
+
{
|
4316
|
+
uint32_t x;
|
4317
|
+
const char **ptr;
|
4318
|
+
uint32_t values[]= { 3195025439U, 2556848621U, 3724893440U, 3332385401U,
|
4319
|
+
245758794U, 2550894432U, 121710495U, 3053817768U,
|
4320
|
+
1250994555U, 1862072655U, 2631955953U, 2951528551U,
|
4321
|
+
1451250070U, 2820856945U, 2060845566U, 3646985608U,
|
4322
|
+
2138080750U, 217675895U, 2230934345U, 1234361223U,
|
4323
|
+
3968582726U, 2455685270U, 1293568479U, 199067604U,
|
4324
|
+
2042482093U };
|
4325
|
+
|
4326
|
+
|
4327
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4328
|
+
{
|
4329
|
+
uint32_t hash_val;
|
4330
|
+
|
4331
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MD5);
|
4332
|
+
assert(values[x] == hash_val);
|
4333
|
+
}
|
4334
|
+
|
4335
|
+
return TEST_SUCCESS;
|
4336
|
+
}
|
4337
|
+
|
4338
|
+
static test_return crc_run (memcached_st *memc __attribute__((unused)))
|
4339
|
+
{
|
4340
|
+
uint32_t x;
|
4341
|
+
const char **ptr;
|
4342
|
+
uint32_t values[]= { 10542U, 22009U, 14526U, 19510U, 19432U, 10199U, 20634U,
|
4343
|
+
9369U, 11511U, 10362U, 7893U, 31289U, 11313U, 9354U,
|
4344
|
+
7621U, 30628U, 15218U, 25967U, 2695U, 9380U,
|
4345
|
+
17300U, 28156U, 9192U, 20484U, 16925U };
|
4346
|
+
|
4347
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4348
|
+
{
|
4349
|
+
uint32_t hash_val;
|
4350
|
+
|
4351
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_CRC);
|
4352
|
+
assert(values[x] == hash_val);
|
4353
|
+
}
|
4354
|
+
|
4355
|
+
return TEST_SUCCESS;
|
4356
|
+
}
|
4357
|
+
|
4358
|
+
static test_return fnv1_64_run (memcached_st *memc __attribute__((unused)))
|
4359
|
+
{
|
4360
|
+
uint32_t x;
|
4361
|
+
const char **ptr;
|
4362
|
+
uint32_t values[]= { 473199127U, 4148981457U, 3971873300U, 3257986707U,
|
4363
|
+
1722477987U, 2991193800U, 4147007314U, 3633179701U,
|
4364
|
+
1805162104U, 3503289120U, 3395702895U, 3325073042U,
|
4365
|
+
2345265314U, 3340346032U, 2722964135U, 1173398992U,
|
4366
|
+
2815549194U, 2562818319U, 224996066U, 2680194749U,
|
4367
|
+
3035305390U, 246890365U, 2395624193U, 4145193337U,
|
4368
|
+
1801941682U };
|
4369
|
+
|
4370
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4371
|
+
{
|
4372
|
+
uint32_t hash_val;
|
4373
|
+
|
4374
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_64);
|
4375
|
+
assert(values[x] == hash_val);
|
4376
|
+
}
|
4377
|
+
|
4378
|
+
return TEST_SUCCESS;
|
4379
|
+
}
|
4380
|
+
|
4381
|
+
static test_return fnv1a_64_run (memcached_st *memc __attribute__((unused)))
|
4382
|
+
{
|
4383
|
+
uint32_t x;
|
4384
|
+
const char **ptr;
|
4385
|
+
uint32_t values[]= { 1488911807U, 2500855813U, 1510099634U, 1390325195U,
|
4386
|
+
3647689787U, 3241528582U, 1669328060U, 2604311949U,
|
4387
|
+
734810122U, 1516407546U, 560948863U, 1767346780U,
|
4388
|
+
561034892U, 4156330026U, 3716417003U, 3475297030U,
|
4389
|
+
1518272172U, 227211583U, 3938128828U, 126112909U,
|
4390
|
+
3043416448U, 3131561933U, 1328739897U, 2455664041U,
|
4391
|
+
2272238452U };
|
4392
|
+
|
4393
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4394
|
+
{
|
4395
|
+
uint32_t hash_val;
|
4396
|
+
|
4397
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_64);
|
4398
|
+
assert(values[x] == hash_val);
|
4399
|
+
}
|
4400
|
+
|
4401
|
+
return TEST_SUCCESS;
|
4402
|
+
}
|
4403
|
+
|
4404
|
+
static test_return fnv1_32_run (memcached_st *memc __attribute__((unused)))
|
4405
|
+
{
|
4406
|
+
uint32_t x;
|
4407
|
+
const char **ptr;
|
4408
|
+
uint32_t values[]= { 67176023U, 1190179409U, 2043204404U, 3221866419U,
|
4409
|
+
2567703427U, 3787535528U, 4147287986U, 3500475733U,
|
4410
|
+
344481048U, 3865235296U, 2181839183U, 119581266U,
|
4411
|
+
510234242U, 4248244304U, 1362796839U, 103389328U,
|
4412
|
+
1449620010U, 182962511U, 3554262370U, 3206747549U,
|
4413
|
+
1551306158U, 4127558461U, 1889140833U, 2774173721U,
|
4414
|
+
1180552018U };
|
4415
|
+
|
4416
|
+
|
4417
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4418
|
+
{
|
4419
|
+
uint32_t hash_val;
|
4420
|
+
|
4421
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_32);
|
4422
|
+
assert(values[x] == hash_val);
|
4423
|
+
}
|
4424
|
+
|
4425
|
+
return TEST_SUCCESS;
|
4426
|
+
}
|
4427
|
+
|
4428
|
+
static test_return fnv1a_32_run (memcached_st *memc __attribute__((unused)))
|
4429
|
+
{
|
4430
|
+
uint32_t x;
|
4431
|
+
const char **ptr;
|
4432
|
+
uint32_t values[]= { 280767167U, 2421315013U, 3072375666U, 855001899U,
|
4433
|
+
459261019U, 3521085446U, 18738364U, 1625305005U,
|
4434
|
+
2162232970U, 777243802U, 3323728671U, 132336572U,
|
4435
|
+
3654473228U, 260679466U, 1169454059U, 2698319462U,
|
4436
|
+
1062177260U, 235516991U, 2218399068U, 405302637U,
|
4437
|
+
1128467232U, 3579622413U, 2138539289U, 96429129U,
|
4438
|
+
2877453236U };
|
4439
|
+
|
4440
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4441
|
+
{
|
4442
|
+
uint32_t hash_val;
|
4443
|
+
|
4444
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1A_32);
|
4445
|
+
assert(values[x] == hash_val);
|
4446
|
+
}
|
4447
|
+
|
4448
|
+
return TEST_SUCCESS;
|
4449
|
+
}
|
4450
|
+
|
4451
|
+
static test_return hsieh_run (memcached_st *memc __attribute__((unused)))
|
4452
|
+
{
|
4453
|
+
uint32_t x;
|
4454
|
+
const char **ptr;
|
4455
|
+
#ifdef HAVE_HSIEH_HASH
|
4456
|
+
uint32_t values[]= { 3738850110, 3636226060, 3821074029, 3489929160, 3485772682, 80540287,
|
4457
|
+
1805464076, 1895033657, 409795758, 979934958, 3634096985, 1284445480,
|
4458
|
+
2265380744, 707972988, 353823508, 1549198350, 1327930172, 9304163,
|
4459
|
+
4220749037, 2493964934, 2777873870, 2057831732, 1510213931, 2027828987,
|
4460
|
+
3395453351 };
|
4461
|
+
#else
|
4462
|
+
uint32_t values[]= { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
|
4463
|
+
#endif
|
4464
|
+
|
4465
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4466
|
+
{
|
4467
|
+
uint32_t hash_val;
|
4468
|
+
|
4469
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_HSIEH);
|
4470
|
+
assert(values[x] == hash_val);
|
4471
|
+
}
|
4472
|
+
|
4473
|
+
return TEST_SUCCESS;
|
4474
|
+
}
|
4475
|
+
|
4476
|
+
static test_return murmur_run (memcached_st *memc __attribute__((unused)))
|
4477
|
+
{
|
4478
|
+
uint32_t x;
|
4479
|
+
const char **ptr;
|
4480
|
+
uint32_t values[]= { 473199127U, 4148981457U, 3971873300U, 3257986707U,
|
4481
|
+
1722477987U, 2991193800U, 4147007314U, 3633179701U,
|
4482
|
+
1805162104U, 3503289120U, 3395702895U, 3325073042U,
|
4483
|
+
2345265314U, 3340346032U, 2722964135U, 1173398992U,
|
4484
|
+
2815549194U, 2562818319U, 224996066U, 2680194749U,
|
4485
|
+
3035305390U, 246890365U, 2395624193U, 4145193337U,
|
4486
|
+
1801941682U };
|
4487
|
+
|
4488
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4489
|
+
{
|
4490
|
+
uint32_t hash_val;
|
4491
|
+
|
4492
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_FNV1_64);
|
4493
|
+
assert(values[x] == hash_val);
|
4494
|
+
}
|
4495
|
+
|
4496
|
+
return TEST_SUCCESS;
|
4497
|
+
}
|
4498
|
+
|
4499
|
+
static test_return jenkins_run (memcached_st *memc __attribute__((unused)))
|
4500
|
+
{
|
4501
|
+
uint32_t x;
|
4502
|
+
const char **ptr;
|
4503
|
+
uint32_t values[]= { 1442444624U, 4253821186U, 1885058256U, 2120131735U,
|
4504
|
+
3261968576U, 3515188778U, 4232909173U, 4288625128U,
|
4505
|
+
1812047395U, 3689182164U, 2502979932U, 1214050606U,
|
4506
|
+
2415988847U, 1494268927U, 1025545760U, 3920481083U,
|
4507
|
+
4153263658U, 3824871822U, 3072759809U, 798622255U,
|
4508
|
+
3065432577U, 1453328165U, 2691550971U, 3408888387U,
|
4509
|
+
2629893356U };
|
4510
|
+
|
4511
|
+
|
4512
|
+
for (ptr= list, x= 0; *ptr; ptr++, x++)
|
4513
|
+
{
|
4514
|
+
uint32_t hash_val;
|
4515
|
+
|
4516
|
+
hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_JENKINS);
|
4517
|
+
assert(values[x] == hash_val);
|
4518
|
+
}
|
4519
|
+
|
4520
|
+
return TEST_SUCCESS;
|
4521
|
+
}
|
4522
|
+
|
4523
|
+
static memcached_return check_touch_capability(memcached_st *memc)
|
4524
|
+
{
|
4525
|
+
test_return test_rc= pre_binary(memc);
|
4526
|
+
|
4527
|
+
if (test_rc != TEST_SUCCESS)
|
4528
|
+
return MEMCACHED_PROTOCOL_ERROR;
|
4529
|
+
|
4530
|
+
const char *key= "touch_capability_key";
|
4531
|
+
const char *val= "touch_capability_val";
|
4532
|
+
memcached_return rc = memcached_touch(memc, key, strlen(key), 1);
|
4533
|
+
/* it should return NOTFOUND here if TOUCH is implemented */
|
4534
|
+
return (rc == MEMCACHED_NOTFOUND) ? MEMCACHED_SUCCESS : MEMCACHED_PROTOCOL_ERROR;
|
4535
|
+
}
|
4536
|
+
|
4537
|
+
static test_return test_memcached_touch(memcached_st *memc)
|
4538
|
+
{
|
4539
|
+
const char *key= "touchkey";
|
4540
|
+
const char *val= "touchval";
|
4541
|
+
size_t len;
|
4542
|
+
uint32_t flags;
|
4543
|
+
memcached_return rc;
|
4544
|
+
char *value;
|
4545
|
+
|
4546
|
+
value= memcached_get(memc, key, strlen(key), &len, &flags, &rc);
|
4547
|
+
assert(len == 0);
|
4548
|
+
assert(value == 0);
|
4549
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
4550
|
+
|
4551
|
+
rc= memcached_set(memc, key, strlen(key), val, strlen(val), 2, 0);
|
4552
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4553
|
+
|
4554
|
+
sleep(1);
|
4555
|
+
|
4556
|
+
value= memcached_get(memc, key, strlen(key), &len, &flags, &rc);
|
4557
|
+
assert(len == 8);
|
4558
|
+
assert(memcmp(value, val, len) == 0);
|
4559
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4560
|
+
|
4561
|
+
rc= memcached_touch(memc, key, strlen(key), 3);
|
4562
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4563
|
+
|
4564
|
+
sleep(2);
|
4565
|
+
|
4566
|
+
value= memcached_get(memc, key, strlen(key), &len, &flags, &rc);
|
4567
|
+
assert(len == 8);
|
4568
|
+
assert(memcmp(value, val, len) == 0);
|
4569
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4570
|
+
|
4571
|
+
sleep(2);
|
4572
|
+
|
4573
|
+
value= memcached_get(memc, key, strlen(key), &len, &flags, &rc);
|
4574
|
+
assert(len == 0);
|
4575
|
+
assert(value == 0);
|
4576
|
+
assert(rc == MEMCACHED_NOTFOUND);
|
4577
|
+
|
4578
|
+
return TEST_SUCCESS;
|
4579
|
+
}
|
4580
|
+
|
4581
|
+
static test_return test_memcached_touch_with_prefix(memcached_st *orig_memc)
|
4582
|
+
{
|
4583
|
+
const char *key= "touchkey";
|
4584
|
+
const char *val= "touchval";
|
4585
|
+
const char *prefix= "namespace:";
|
4586
|
+
memcached_return rc;
|
4587
|
+
memcached_st *memc= memcached_clone(NULL, orig_memc);
|
4588
|
+
|
4589
|
+
rc = memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)prefix);
|
4590
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4591
|
+
|
4592
|
+
rc= memcached_set(memc, key, strlen(key), val, strlen(val), 2, 0);
|
4593
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4594
|
+
|
4595
|
+
rc= memcached_touch(memc, key, strlen(key), 3);
|
4596
|
+
assert(rc == MEMCACHED_SUCCESS);
|
4597
|
+
|
4598
|
+
return TEST_SUCCESS;
|
4599
|
+
}
|
4600
|
+
|
4601
|
+
|
4602
|
+
test_st udp_setup_server_tests[] ={
|
4603
|
+
{"set_udp_behavior_test", 0, set_udp_behavior_test},
|
4604
|
+
{"add_tcp_server_udp_client_test", 0, add_tcp_server_udp_client_test},
|
4605
|
+
{"add_udp_server_tcp_client_test", 0, add_udp_server_tcp_client_test},
|
4606
|
+
{0, 0, 0}
|
4607
|
+
};
|
4608
|
+
|
4609
|
+
test_st upd_io_tests[] ={
|
4610
|
+
{"udp_set_test", 0, udp_set_test},
|
4611
|
+
{"udp_buffered_set_test", 0, udp_buffered_set_test},
|
4612
|
+
{"udp_set_too_big_test", 0, udp_set_too_big_test},
|
4613
|
+
{"udp_delete_test", 0, udp_delete_test},
|
4614
|
+
{"udp_buffered_delete_test", 0, udp_buffered_delete_test},
|
4615
|
+
{"udp_verbosity_test", 0, udp_verbosity_test},
|
4616
|
+
{"udp_quit_test", 0, udp_quit_test},
|
4617
|
+
{"udp_flush_test", 0, udp_flush_test},
|
4618
|
+
{"udp_incr_test", 0, udp_incr_test},
|
4619
|
+
{"udp_decr_test", 0, udp_decr_test},
|
4620
|
+
{"udp_stat_test", 0, udp_stat_test},
|
4621
|
+
{"udp_version_test", 0, udp_version_test},
|
4622
|
+
{"udp_get_test", 0, udp_get_test},
|
4623
|
+
{"udp_mixed_io_test", 0, udp_mixed_io_test},
|
4624
|
+
{0, 0, 0}
|
4625
|
+
};
|
4626
|
+
|
4627
|
+
/* Clean the server before beginning testing */
|
4628
|
+
test_st tests[] ={
|
4629
|
+
{"flush", 0, flush_test },
|
4630
|
+
{"init", 0, init_test },
|
4631
|
+
{"allocation", 0, allocation_test },
|
4632
|
+
{"server_list_null_test", 0, server_list_null_test},
|
4633
|
+
{"server_unsort", 0, server_unsort_test},
|
4634
|
+
{"server_sort", 0, server_sort_test},
|
4635
|
+
{"server_sort2", 0, server_sort2_test},
|
4636
|
+
{"clone_test", 0, clone_test },
|
4637
|
+
{"connection_test", 0, connection_test},
|
4638
|
+
{"callback_test", 0, callback_test},
|
4639
|
+
{"behavior_test", 0, behavior_test},
|
4640
|
+
{"userdata_test", 0, userdata_test},
|
4641
|
+
{"error", 0, error_test },
|
4642
|
+
{"set", 0, set_test },
|
4643
|
+
{"set2", 0, set_test2 },
|
4644
|
+
{"set3", 0, set_test3 },
|
4645
|
+
/* {"dump", 1, dump_test},*/
|
4646
|
+
{"add", 1, add_test },
|
4647
|
+
{"replace", 1, replace_test },
|
4648
|
+
{"delete", 1, delete_test },
|
4649
|
+
{"get", 1, get_test },
|
4650
|
+
{"get2", 0, get_test2 },
|
4651
|
+
{"get3", 0, get_test3 },
|
4652
|
+
{"get4", 0, get_test4 },
|
4653
|
+
{"partial mget", 0, get_test5 },
|
4654
|
+
{"get_miss_noop", 0, get_test6 },
|
4655
|
+
{"get_len", 1, get_len_test },
|
4656
|
+
{"get_len2", 0, get_len_test2 },
|
4657
|
+
{"get_len3", 0, get_len_test3 },
|
4658
|
+
{"stats_servername", 0, stats_servername_test },
|
4659
|
+
{"increment", 0, increment_test },
|
4660
|
+
{"increment_with_initial", 1, increment_with_initial_test },
|
4661
|
+
{"decrement", 0, decrement_test },
|
4662
|
+
{"decrement_with_initial", 1, decrement_with_initial_test },
|
4663
|
+
{"quit", 0, quit_test },
|
4664
|
+
{"mget", 1, mget_test },
|
4665
|
+
{"mget_result", 1, mget_result_test },
|
4666
|
+
{"mget_len_result", 1, mget_len_result_test },
|
4667
|
+
{"mget_result_alloc", 1, mget_result_alloc_test },
|
4668
|
+
{"mget_result_function", 1, mget_result_function },
|
4669
|
+
{"get_stats", 0, get_stats },
|
4670
|
+
{"add_host_test", 0, add_host_test },
|
4671
|
+
{"add_host_test_1", 0, add_host_test1 },
|
4672
|
+
{"get_stats_keys", 0, get_stats_keys },
|
4673
|
+
{"behavior_test", 0, get_stats_keys },
|
4674
|
+
{"callback_test", 0, get_stats_keys },
|
4675
|
+
{"version_string_test", 0, version_string_test},
|
4676
|
+
{"bad_key", 1, bad_key_test },
|
4677
|
+
{"memcached_server_cursor", 1, memcached_server_cursor_test },
|
4678
|
+
{"read_through", 1, read_through },
|
4679
|
+
{"delete_through", 1, delete_through },
|
4680
|
+
{"noreply", 1, noreply_test},
|
4681
|
+
{"analyzer", 1, analyzer_test},
|
4682
|
+
#ifdef HAVE_LIBMEMCACHEDUTIL
|
4683
|
+
{"connectionpool", 1, connection_pool_test },
|
4684
|
+
#endif
|
4685
|
+
{0, 0, 0}
|
4686
|
+
};
|
4687
|
+
|
4688
|
+
test_st async_tests[] ={
|
4689
|
+
{"add", 1, add_wrapper },
|
4690
|
+
{0, 0, 0}
|
4691
|
+
};
|
4692
|
+
|
4693
|
+
test_st string_tests[] ={
|
4694
|
+
{"string static with null", 0, string_static_null },
|
4695
|
+
{"string alloc with null", 0, string_alloc_null },
|
4696
|
+
{"string alloc with 1K", 0, string_alloc_with_size },
|
4697
|
+
{"string alloc with malloc failure", 0, string_alloc_with_size_toobig },
|
4698
|
+
{"string append", 0, string_alloc_append },
|
4699
|
+
{"string append failure (too big)", 0, string_alloc_append_toobig },
|
4700
|
+
{0, 0, 0}
|
4701
|
+
};
|
4702
|
+
|
4703
|
+
test_st result_tests[] ={
|
4704
|
+
{"result static", 0, result_static},
|
4705
|
+
{"result alloc", 0, result_alloc},
|
4706
|
+
{0, 0, 0}
|
4707
|
+
};
|
4708
|
+
|
4709
|
+
test_st version_1_2_3[] ={
|
4710
|
+
{"append", 0, append_test },
|
4711
|
+
{"prepend", 0, prepend_test },
|
4712
|
+
{"cas", 0, cas_test },
|
4713
|
+
{"cas2", 0, cas2_test },
|
4714
|
+
{"mget_len_no_cas", 0, mget_len_no_cas_test },
|
4715
|
+
{"mget_len_cas", 0, mget_len_cas_test },
|
4716
|
+
{"append_binary", 0, append_binary_test },
|
4717
|
+
{0, 0, 0}
|
4718
|
+
};
|
4719
|
+
|
4720
|
+
test_st user_tests[] ={
|
4721
|
+
{"user_supplied_bug1", 0, user_supplied_bug1 },
|
4722
|
+
{"user_supplied_bug2", 0, user_supplied_bug2 },
|
4723
|
+
{"user_supplied_bug3", 0, user_supplied_bug3 },
|
4724
|
+
{"user_supplied_bug4", 0, user_supplied_bug4 },
|
4725
|
+
{"user_supplied_bug5", 1, user_supplied_bug5 },
|
4726
|
+
{"user_supplied_bug6", 1, user_supplied_bug6 },
|
4727
|
+
{"user_supplied_bug7", 1, user_supplied_bug7 },
|
4728
|
+
{"user_supplied_bug8", 1, user_supplied_bug8 },
|
4729
|
+
{"user_supplied_bug9", 1, user_supplied_bug9 },
|
4730
|
+
{"user_supplied_bug10", 1, user_supplied_bug10 },
|
4731
|
+
{"user_supplied_bug11", 1, user_supplied_bug11 },
|
4732
|
+
{"user_supplied_bug12", 1, user_supplied_bug12 },
|
4733
|
+
{"user_supplied_bug13", 1, user_supplied_bug13 },
|
4734
|
+
{"user_supplied_bug14", 1, user_supplied_bug14 },
|
4735
|
+
{"user_supplied_bug15", 1, user_supplied_bug15 },
|
4736
|
+
{"user_supplied_bug16", 1, user_supplied_bug16 },
|
4737
|
+
#ifndef __sun
|
4738
|
+
/*
|
4739
|
+
** It seems to be something weird with the character sets..
|
4740
|
+
** value_fetch is unable to parse the value line (iscntrl "fails"), so I
|
4741
|
+
** guess I need to find out how this is supposed to work.. Perhaps I need
|
4742
|
+
** to run the test in a specific locale (I tried zh_CN.UTF-8 without success,
|
4743
|
+
** so just disable the code for now...).
|
4744
|
+
*/
|
4745
|
+
{"user_supplied_bug17", 1, user_supplied_bug17 },
|
4746
|
+
#endif
|
4747
|
+
{"user_supplied_bug18", 1, user_supplied_bug18 },
|
4748
|
+
{"user_supplied_bug19", 1, user_supplied_bug19 },
|
4749
|
+
{"user_supplied_bug20", 1, user_supplied_bug20 },
|
4750
|
+
{0, 0, 0}
|
4751
|
+
};
|
4752
|
+
|
4753
|
+
test_st generate_tests[] ={
|
4754
|
+
{"generate_pairs", 1, generate_pairs },
|
4755
|
+
{"generate_data", 1, generate_data },
|
4756
|
+
{"get_read", 0, get_read },
|
4757
|
+
{"delete_generate", 0, delete_generate },
|
4758
|
+
{"generate_buffer_data", 1, generate_buffer_data },
|
4759
|
+
{"delete_buffer", 0, delete_buffer_generate},
|
4760
|
+
{"generate_data", 1, generate_data },
|
4761
|
+
{"mget_read", 0, mget_read },
|
4762
|
+
{"mget_read_result", 0, mget_read_result },
|
4763
|
+
{"mget_read_function", 0, mget_read_function },
|
4764
|
+
{"cleanup", 1, cleanup_pairs },
|
4765
|
+
{"generate_large_pairs", 1, generate_large_pairs },
|
4766
|
+
{"generate_data", 1, generate_data },
|
4767
|
+
{"generate_buffer_data", 1, generate_buffer_data },
|
4768
|
+
{"cleanup", 1, cleanup_pairs },
|
4769
|
+
{0, 0, 0}
|
4770
|
+
};
|
4771
|
+
|
4772
|
+
test_st consistent_tests[] ={
|
4773
|
+
{"generate_pairs", 1, generate_pairs },
|
4774
|
+
{"generate_data", 1, generate_data },
|
4775
|
+
{"get_read", 0, get_read_count },
|
4776
|
+
{"cleanup", 1, cleanup_pairs },
|
4777
|
+
{0, 0, 0}
|
4778
|
+
};
|
4779
|
+
|
4780
|
+
test_st consistent_weighted_tests[] ={
|
4781
|
+
{"generate_pairs", 1, generate_pairs },
|
4782
|
+
{"generate_data", 1, generate_data_with_stats },
|
4783
|
+
{"get_read", 0, get_read_count },
|
4784
|
+
{"cleanup", 1, cleanup_pairs },
|
4785
|
+
{0, 0, 0}
|
4786
|
+
};
|
4787
|
+
|
4788
|
+
test_st hsieh_availability[] ={
|
4789
|
+
{"hsieh_avaibility_test",0,hsieh_avaibility_test},
|
4790
|
+
{0, 0, 0}
|
4791
|
+
};
|
4792
|
+
|
4793
|
+
test_st ketama_auto_eject_hosts[] ={
|
4794
|
+
{"auto_eject_hosts", 1, auto_eject_hosts },
|
4795
|
+
{0, 0, 0}
|
4796
|
+
};
|
4797
|
+
|
4798
|
+
test_st hash_tests[] ={
|
4799
|
+
{"md5", 0, md5_run },
|
4800
|
+
{"crc", 0, crc_run },
|
4801
|
+
{"fnv1_64", 0, fnv1_64_run },
|
4802
|
+
{"fnv1a_64", 0, fnv1a_64_run },
|
4803
|
+
{"fnv1_32", 0, fnv1_32_run },
|
4804
|
+
{"fnv1a_32", 0, fnv1a_32_run },
|
4805
|
+
{"hsieh", 0, hsieh_run },
|
4806
|
+
{"murmur", 0, murmur_run },
|
4807
|
+
{"jenkis", 0, jenkins_run },
|
4808
|
+
{0, 0, 0}
|
4809
|
+
};
|
4810
|
+
|
4811
|
+
test_st touch_tests[] ={
|
4812
|
+
{"memcached_touch", 1, test_memcached_touch},
|
4813
|
+
{"memcached_touch_with_prefix", 1, test_memcached_touch_with_prefix},
|
4814
|
+
{0, 0, 0}
|
4815
|
+
};
|
4816
|
+
|
4817
|
+
collection_st collection[] ={
|
4818
|
+
{"hsieh_availability",0,0,hsieh_availability},
|
4819
|
+
{"udp_setup", init_udp, 0, udp_setup_server_tests},
|
4820
|
+
{"udp_io", init_udp, 0, upd_io_tests},
|
4821
|
+
{"udp_binary_io", binary_init_udp, 0, upd_io_tests},
|
4822
|
+
{"block", 0, 0, tests},
|
4823
|
+
{"binary", pre_binary, 0, tests},
|
4824
|
+
{"nonblock", pre_nonblock, 0, tests},
|
4825
|
+
{"nodelay", pre_nodelay, 0, tests},
|
4826
|
+
{"settimer", pre_settimer, 0, tests},
|
4827
|
+
{"md5", pre_md5, 0, tests},
|
4828
|
+
{"crc", pre_crc, 0, tests},
|
4829
|
+
{"hsieh", pre_hsieh, 0, tests},
|
4830
|
+
{"jenkins", pre_jenkins, 0, tests},
|
4831
|
+
{"fnv1_64", pre_hash_fnv1_64, 0, tests},
|
4832
|
+
{"fnv1a_64", pre_hash_fnv1a_64, 0, tests},
|
4833
|
+
{"fnv1_32", pre_hash_fnv1_32, 0, tests},
|
4834
|
+
{"fnv1a_32", pre_hash_fnv1a_32, 0, tests},
|
4835
|
+
{"ketama", pre_behavior_ketama, 0, tests},
|
4836
|
+
{"ketama_auto_eject_hosts", pre_behavior_ketama, 0, ketama_auto_eject_hosts},
|
4837
|
+
{"unix_socket", pre_unix_socket, 0, tests},
|
4838
|
+
{"unix_socket_nodelay", pre_nodelay, 0, tests},
|
4839
|
+
{"poll_timeout", poll_timeout, 0, tests},
|
4840
|
+
{"gets", enable_cas, 0, tests},
|
4841
|
+
{"consistent", enable_consistent, 0, tests},
|
4842
|
+
#ifdef MEMCACHED_ENABLE_DEPRECATED
|
4843
|
+
{"deprecated_memory_allocators", deprecated_set_memory_alloc, 0, tests},
|
4844
|
+
#endif
|
4845
|
+
{"memory_allocators", set_memory_alloc, 0, tests},
|
4846
|
+
{"prefix", set_prefix, 0, tests},
|
4847
|
+
{"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
|
4848
|
+
{"string", 0, 0, string_tests},
|
4849
|
+
{"result", 0, 0, result_tests},
|
4850
|
+
{"async", pre_nonblock, 0, async_tests},
|
4851
|
+
{"async_binary", pre_nonblock_binary, 0, async_tests},
|
4852
|
+
{"user", 0, 0, user_tests},
|
4853
|
+
{"generate", 0, 0, generate_tests},
|
4854
|
+
{"generate_hsieh", pre_hsieh, 0, generate_tests},
|
4855
|
+
{"generate_ketama", pre_behavior_ketama, 0, generate_tests},
|
4856
|
+
{"generate_hsieh_consistent", enable_consistent, 0, generate_tests},
|
4857
|
+
{"generate_md5", pre_md5, 0, generate_tests},
|
4858
|
+
{"generate_murmur", pre_murmur, 0, generate_tests},
|
4859
|
+
{"generate_jenkins", pre_jenkins, 0, generate_tests},
|
4860
|
+
{"generate_nonblock", pre_nonblock, 0, generate_tests},
|
4861
|
+
{"consistent_not", 0, 0, consistent_tests},
|
4862
|
+
{"consistent_ketama", pre_behavior_ketama, 0, consistent_tests},
|
4863
|
+
{"consistent_ketama_weighted", pre_behavior_ketama_weighted, 0, consistent_weighted_tests},
|
4864
|
+
{"test_hashes", 0, 0, hash_tests},
|
4865
|
+
{"touch", check_touch_capability, 0, touch_tests},
|
4866
|
+
{0, 0, 0, 0}
|
4867
|
+
};
|
4868
|
+
|
4869
|
+
#define SERVERS_TO_CREATE 5
|
4870
|
+
|
4871
|
+
/* Prototypes for functions we will pass to test framework */
|
4872
|
+
void *world_create(void);
|
4873
|
+
void world_destroy(void *p);
|
4874
|
+
|
4875
|
+
void *world_create(void)
|
4876
|
+
{
|
4877
|
+
server_startup_st *construct;
|
4878
|
+
|
4879
|
+
construct= (server_startup_st *)malloc(sizeof(server_startup_st));
|
4880
|
+
memset(construct, 0, sizeof(server_startup_st));
|
4881
|
+
construct->count= SERVERS_TO_CREATE;
|
4882
|
+
construct->udp= 0;
|
4883
|
+
server_startup(construct);
|
4884
|
+
|
4885
|
+
return construct;
|
4886
|
+
}
|
4887
|
+
|
4888
|
+
|
4889
|
+
void world_destroy(void *p)
|
4890
|
+
{
|
4891
|
+
server_startup_st *construct= (server_startup_st *)p;
|
4892
|
+
memcached_server_st *servers= (memcached_server_st *)construct->servers;
|
4893
|
+
memcached_server_list_free(servers);
|
4894
|
+
|
4895
|
+
server_shutdown(construct);
|
4896
|
+
free(construct);
|
4897
|
+
}
|
4898
|
+
|
4899
|
+
void get_world(world_st *world)
|
4900
|
+
{
|
4901
|
+
world->collections= collection;
|
4902
|
+
world->create= world_create;
|
4903
|
+
world->destroy= world_destroy;
|
4904
|
+
}
|