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,118 @@
|
|
1
|
+
/*
|
2
|
+
Startup, and shutdown the memcached servers.
|
3
|
+
*/
|
4
|
+
|
5
|
+
#define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
|
6
|
+
|
7
|
+
#include "config.h"
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <string.h>
|
12
|
+
#include <time.h>
|
13
|
+
#include <assert.h>
|
14
|
+
#include <signal.h>
|
15
|
+
#include <libmemcached/memcached.h>
|
16
|
+
#include <unistd.h>
|
17
|
+
#include "server.h"
|
18
|
+
|
19
|
+
void server_startup(server_startup_st *construct)
|
20
|
+
{
|
21
|
+
unsigned int x;
|
22
|
+
|
23
|
+
if ((construct->server_list= getenv("MEMCACHED_SERVERS")))
|
24
|
+
{
|
25
|
+
printf("servers %s\n", construct->server_list);
|
26
|
+
construct->servers= memcached_servers_parse(construct->server_list);
|
27
|
+
construct->server_list= NULL;
|
28
|
+
construct->count= 0;
|
29
|
+
}
|
30
|
+
else
|
31
|
+
{
|
32
|
+
{
|
33
|
+
char server_string_buffer[8096];
|
34
|
+
char *end_ptr;
|
35
|
+
end_ptr= server_string_buffer;
|
36
|
+
|
37
|
+
for (x= 0; x < construct->count; x++)
|
38
|
+
{
|
39
|
+
char buffer[1024]; /* Nothing special for number */
|
40
|
+
int count;
|
41
|
+
int status;
|
42
|
+
|
43
|
+
sprintf(buffer, "/tmp/%umemc.pid", x);
|
44
|
+
if (access(buffer, F_OK) == 0)
|
45
|
+
{
|
46
|
+
FILE *fp= fopen(buffer, "r");
|
47
|
+
remove(buffer);
|
48
|
+
|
49
|
+
if (fp != NULL)
|
50
|
+
{
|
51
|
+
if (fgets(buffer, sizeof(buffer), fp) != NULL)
|
52
|
+
{
|
53
|
+
pid_t pid = (pid_t)atol(buffer);
|
54
|
+
if (pid != 0)
|
55
|
+
kill(pid, SIGTERM);
|
56
|
+
}
|
57
|
+
|
58
|
+
fclose(fp);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
if (x == 0)
|
63
|
+
{
|
64
|
+
sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u -m 128",
|
65
|
+
MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
|
66
|
+
}
|
67
|
+
else
|
68
|
+
{
|
69
|
+
sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u",
|
70
|
+
MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE);
|
71
|
+
}
|
72
|
+
fprintf(stderr, "STARTING SERVER: %s\n", buffer);
|
73
|
+
status= system(buffer);
|
74
|
+
count= sprintf(end_ptr, "localhost:%u,", x + TEST_PORT_BASE);
|
75
|
+
end_ptr+= count;
|
76
|
+
}
|
77
|
+
*end_ptr= 0;
|
78
|
+
|
79
|
+
construct->server_list= strdup(server_string_buffer);
|
80
|
+
}
|
81
|
+
printf("servers %s\n", construct->server_list);
|
82
|
+
construct->servers= memcached_servers_parse(construct->server_list);
|
83
|
+
}
|
84
|
+
|
85
|
+
assert(construct->servers);
|
86
|
+
|
87
|
+
srandom((unsigned int)time(NULL));
|
88
|
+
|
89
|
+
for (x= 0; x < memcached_server_list_count(construct->servers); x++)
|
90
|
+
{
|
91
|
+
printf("\t%s : %u\n", construct->servers[x].hostname, construct->servers[x].port);
|
92
|
+
assert(construct->servers[x].fd == -1);
|
93
|
+
assert(construct->servers[x].cursor_active == 0);
|
94
|
+
}
|
95
|
+
|
96
|
+
printf("\n");
|
97
|
+
}
|
98
|
+
|
99
|
+
void server_shutdown(server_startup_st *construct)
|
100
|
+
{
|
101
|
+
unsigned int x;
|
102
|
+
|
103
|
+
if (construct->server_list)
|
104
|
+
{
|
105
|
+
for (x= 0; x < construct->count; x++)
|
106
|
+
{
|
107
|
+
char buffer[1024]; /* Nothing special for number */
|
108
|
+
sprintf(buffer, "cat /tmp/%umemc.pid | xargs kill", x);
|
109
|
+
/* We have to check the return value of this or the compiler will yell */
|
110
|
+
int sys_ret= system(buffer);
|
111
|
+
assert(sys_ret != -1);
|
112
|
+
sprintf(buffer, "/tmp/%umemc.pid", x);
|
113
|
+
unlink(buffer);
|
114
|
+
}
|
115
|
+
|
116
|
+
free(construct->server_list);
|
117
|
+
}
|
118
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
Server startup and shutdown functions.
|
3
|
+
*/
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#include <libmemcached/memcached.h>
|
9
|
+
|
10
|
+
typedef struct server_startup_st server_startup_st;
|
11
|
+
|
12
|
+
struct server_startup_st
|
13
|
+
{
|
14
|
+
uint8_t count;
|
15
|
+
uint8_t udp;
|
16
|
+
memcached_server_st *servers;
|
17
|
+
char *server_list;
|
18
|
+
};
|
19
|
+
|
20
|
+
void server_startup(server_startup_st *construct);
|
21
|
+
void server_shutdown(server_startup_st *construct);
|
22
|
+
|
23
|
+
#ifdef __cplusplus
|
24
|
+
}
|
25
|
+
#endif
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#include <stdio.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include "server.h"
|
4
|
+
|
5
|
+
int main(void)
|
6
|
+
{
|
7
|
+
server_startup_st construct;
|
8
|
+
|
9
|
+
memset(&construct, 0, sizeof(server_startup_st));
|
10
|
+
|
11
|
+
construct.count= 4;
|
12
|
+
|
13
|
+
server_startup(&construct);
|
14
|
+
|
15
|
+
return 0;
|
16
|
+
}
|
@@ -0,0 +1,137 @@
|
|
1
|
+
/*
|
2
|
+
Sample test application.
|
3
|
+
*/
|
4
|
+
#include <assert.h>
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <string.h>
|
7
|
+
#include <sys/time.h>
|
8
|
+
#include <sys/types.h>
|
9
|
+
#include <sys/stat.h>
|
10
|
+
#include <unistd.h>
|
11
|
+
#include <time.h>
|
12
|
+
#include <fnmatch.h>
|
13
|
+
#include "server.h"
|
14
|
+
|
15
|
+
#include "test.h"
|
16
|
+
|
17
|
+
static long int timedif(struct timeval a, struct timeval b)
|
18
|
+
{
|
19
|
+
register int us, s;
|
20
|
+
|
21
|
+
us = (int)(a.tv_usec - b.tv_usec);
|
22
|
+
us /= 1000;
|
23
|
+
s = (int)(a.tv_sec - b.tv_sec);
|
24
|
+
s *= 1000;
|
25
|
+
return s + us;
|
26
|
+
}
|
27
|
+
|
28
|
+
int main(int argc, char *argv[])
|
29
|
+
{
|
30
|
+
unsigned int x;
|
31
|
+
char *collection_to_run= NULL;
|
32
|
+
char *wildcard= NULL;
|
33
|
+
server_startup_st *startup_ptr;
|
34
|
+
memcached_server_st *servers;
|
35
|
+
world_st world;
|
36
|
+
collection_st *collection;
|
37
|
+
collection_st *next;
|
38
|
+
uint8_t failed;
|
39
|
+
void *world_ptr;
|
40
|
+
|
41
|
+
memset(&world, 0, sizeof(world_st));
|
42
|
+
get_world(&world);
|
43
|
+
collection= world.collections;
|
44
|
+
|
45
|
+
if (world.create)
|
46
|
+
world_ptr= world.create();
|
47
|
+
else
|
48
|
+
world_ptr= NULL;
|
49
|
+
|
50
|
+
startup_ptr= (server_startup_st *)world_ptr;
|
51
|
+
servers= (memcached_server_st *)startup_ptr->servers;
|
52
|
+
|
53
|
+
if (argc > 1)
|
54
|
+
collection_to_run= argv[1];
|
55
|
+
|
56
|
+
if (argc == 3)
|
57
|
+
wildcard= argv[2];
|
58
|
+
|
59
|
+
for (next= collection; next->name; next++)
|
60
|
+
{
|
61
|
+
test_st *run;
|
62
|
+
|
63
|
+
run= next->tests;
|
64
|
+
if (collection_to_run && fnmatch(collection_to_run, next->name, 0))
|
65
|
+
continue;
|
66
|
+
|
67
|
+
fprintf(stderr, "\n%s\n\n", next->name);
|
68
|
+
|
69
|
+
for (x= 0; run->name; run++)
|
70
|
+
{
|
71
|
+
unsigned int loop;
|
72
|
+
memcached_st *memc;
|
73
|
+
memcached_return rc;
|
74
|
+
struct timeval start_time, end_time;
|
75
|
+
long int load_time;
|
76
|
+
|
77
|
+
if (wildcard && fnmatch(wildcard, run->name, 0))
|
78
|
+
continue;
|
79
|
+
|
80
|
+
fprintf(stderr, "Testing %s", run->name);
|
81
|
+
|
82
|
+
memc= memcached_create(NULL);
|
83
|
+
assert(memc);
|
84
|
+
|
85
|
+
rc= memcached_server_push(memc, servers);
|
86
|
+
assert(rc == MEMCACHED_SUCCESS);
|
87
|
+
|
88
|
+
if (run->requires_flush)
|
89
|
+
{
|
90
|
+
memcached_flush(memc, 0);
|
91
|
+
memcached_quit(memc);
|
92
|
+
}
|
93
|
+
|
94
|
+
for (loop= 0; loop < memcached_server_list_count(servers); loop++)
|
95
|
+
{
|
96
|
+
assert(memc->hosts[loop].fd == -1);
|
97
|
+
assert(memc->hosts[loop].cursor_active == 0);
|
98
|
+
}
|
99
|
+
|
100
|
+
if (next->pre)
|
101
|
+
{
|
102
|
+
rc= next->pre(memc);
|
103
|
+
|
104
|
+
if (rc != MEMCACHED_SUCCESS)
|
105
|
+
{
|
106
|
+
fprintf(stderr, "\t\t\t\t\t [ skipping ]\n");
|
107
|
+
goto error;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
gettimeofday(&start_time, NULL);
|
112
|
+
failed= run->function(memc);
|
113
|
+
gettimeofday(&end_time, NULL);
|
114
|
+
load_time= timedif(end_time, start_time);
|
115
|
+
if (failed)
|
116
|
+
fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ failed ]\n", load_time / 1000,
|
117
|
+
load_time % 1000);
|
118
|
+
else
|
119
|
+
fprintf(stderr, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time / 1000,
|
120
|
+
load_time % 1000);
|
121
|
+
|
122
|
+
if (next->post)
|
123
|
+
(void)next->post(memc);
|
124
|
+
|
125
|
+
assert(memc);
|
126
|
+
error:
|
127
|
+
memcached_free(memc);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
fprintf(stderr, "All tests completed successfully\n\n");
|
132
|
+
|
133
|
+
if (world.destroy)
|
134
|
+
world.destroy(world_ptr);
|
135
|
+
|
136
|
+
return 0;
|
137
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
Structures for generic tests.
|
3
|
+
*/
|
4
|
+
#ifdef __cplusplus
|
5
|
+
extern "C" {
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#include <libmemcached/memcached.h>
|
9
|
+
#include <stdio.h>
|
10
|
+
|
11
|
+
typedef struct world_st world_st;
|
12
|
+
typedef struct collection_st collection_st;
|
13
|
+
typedef struct test_st test_st;
|
14
|
+
|
15
|
+
typedef enum {
|
16
|
+
TEST_SUCCESS= 0, /* Backwards compatibility */
|
17
|
+
TEST_FAILURE,
|
18
|
+
TEST_MEMORY_ALLOCATION_FAILURE,
|
19
|
+
TEST_MAXIMUM_RETURN /* Always add new error code before */
|
20
|
+
} test_return;
|
21
|
+
|
22
|
+
struct test_st {
|
23
|
+
const char *name;
|
24
|
+
unsigned int requires_flush;
|
25
|
+
test_return (*function)(memcached_st *memc);
|
26
|
+
};
|
27
|
+
|
28
|
+
struct collection_st {
|
29
|
+
const char *name;
|
30
|
+
memcached_return (*pre)(memcached_st *memc);
|
31
|
+
memcached_return (*post)(memcached_st *memc);
|
32
|
+
test_st *tests;
|
33
|
+
};
|
34
|
+
|
35
|
+
struct world_st {
|
36
|
+
collection_st *collections;
|
37
|
+
void *(*create)(void);
|
38
|
+
void (*destroy)(void *collection_object);
|
39
|
+
};
|
40
|
+
|
41
|
+
/* How we make all of this work :) */
|
42
|
+
void get_world(world_st *world);
|
43
|
+
|
44
|
+
#ifdef __cplusplus
|
45
|
+
}
|
46
|
+
#endif
|
@@ -0,0 +1,76 @@
|
|
1
|
+
/*
|
2
|
+
Sample test application.
|
3
|
+
*/
|
4
|
+
#include <assert.h>
|
5
|
+
#include <libmemcached/memcached.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <sys/time.h>
|
10
|
+
#include <sys/types.h>
|
11
|
+
#include <sys/stat.h>
|
12
|
+
#include <unistd.h>
|
13
|
+
#include <time.h>
|
14
|
+
#include "test.h"
|
15
|
+
#include "server.h"
|
16
|
+
|
17
|
+
/* Prototypes */
|
18
|
+
test_return set_test(memcached_st *memc);
|
19
|
+
void *world_create(void);
|
20
|
+
void world_destroy(void *p);
|
21
|
+
|
22
|
+
test_return set_test(memcached_st *memc)
|
23
|
+
{
|
24
|
+
memcached_return rc;
|
25
|
+
const char *key= "foo";
|
26
|
+
const char *value= "when we sanitize";
|
27
|
+
|
28
|
+
rc= memcached_set(memc, key, strlen(key),
|
29
|
+
value, strlen(value),
|
30
|
+
(time_t)0, (uint32_t)0);
|
31
|
+
assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
|
32
|
+
|
33
|
+
return TEST_SUCCESS;
|
34
|
+
}
|
35
|
+
|
36
|
+
test_st tests[] ={
|
37
|
+
{"set", 1, set_test },
|
38
|
+
{0, 0, 0}
|
39
|
+
};
|
40
|
+
|
41
|
+
collection_st collection[] ={
|
42
|
+
{"udp", 0, 0, tests},
|
43
|
+
{0, 0, 0, 0}
|
44
|
+
};
|
45
|
+
|
46
|
+
#define SERVERS_TO_CREATE 1
|
47
|
+
|
48
|
+
void *world_create(void)
|
49
|
+
{
|
50
|
+
server_startup_st *construct;
|
51
|
+
|
52
|
+
construct= (server_startup_st *)malloc(sizeof(server_startup_st));
|
53
|
+
memset(construct, 0, sizeof(server_startup_st));
|
54
|
+
construct->count= SERVERS_TO_CREATE;
|
55
|
+
construct->udp= 1;
|
56
|
+
server_startup(construct);
|
57
|
+
|
58
|
+
return construct;
|
59
|
+
}
|
60
|
+
|
61
|
+
void world_destroy(void *p)
|
62
|
+
{
|
63
|
+
server_startup_st *construct= (server_startup_st *)p;
|
64
|
+
memcached_server_st *servers= (memcached_server_st *)construct->servers;
|
65
|
+
memcached_server_list_free(servers);
|
66
|
+
|
67
|
+
server_shutdown(construct);
|
68
|
+
free(construct);
|
69
|
+
}
|
70
|
+
|
71
|
+
void get_world(world_st *world)
|
72
|
+
{
|
73
|
+
world->collections= collection;
|
74
|
+
world->create= world_create;
|
75
|
+
world->destroy= world_destroy;
|
76
|
+
}
|
data/ext/rlibmemcached.i
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
%module rlibmemcached
|
2
|
+
%{
|
3
|
+
#include <libmemcached/visibility.h>
|
4
|
+
#include <libmemcached/memcached.h>
|
5
|
+
#include <libmemcached/memcached_exist.h>
|
6
|
+
%}
|
7
|
+
|
8
|
+
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) memcached_st;
|
9
|
+
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) memcached_server_st;
|
10
|
+
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) memcached_stat_st;
|
11
|
+
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) memcached_string_st;
|
12
|
+
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) memcached_result_st;
|
13
|
+
|
14
|
+
%include "typemaps.i"
|
15
|
+
%include "libmemcached/visibility.h"
|
16
|
+
|
17
|
+
//// Memory management
|
18
|
+
|
19
|
+
// Register libmemcached's struct free function to prevent memory leaks
|
20
|
+
%freefunc memcached_st "memcached_free";
|
21
|
+
%freefunc memcached_stat_st "memcached_stat_free";
|
22
|
+
%freefunc memcached_server_st "memcached_server_free";
|
23
|
+
|
24
|
+
// Register which functions generate new objects
|
25
|
+
%newobject memcached_create;
|
26
|
+
%newobject memcached_clone;
|
27
|
+
%newobject memcached_stat_get_value;
|
28
|
+
// %newobject memcached_stat;
|
29
|
+
|
30
|
+
// %trackobjects; // Doesn't fix any interesting leaks
|
31
|
+
|
32
|
+
//// Input maps
|
33
|
+
|
34
|
+
%apply unsigned short { uint8_t };
|
35
|
+
%apply unsigned int { uint16_t };
|
36
|
+
%apply unsigned int { uint32_t server_failure_counter };
|
37
|
+
%apply unsigned int { uint32_t user_spec_len };
|
38
|
+
%apply unsigned long { uint32_t flags, uint32_t offset, uint32_t weight, time_t expiration };
|
39
|
+
%apply unsigned long long { uint64_t data, uint64_t cas };
|
40
|
+
|
41
|
+
// Array of strings map for multiget
|
42
|
+
%typemap(in) (const char **keys, size_t *key_length, size_t number_of_keys) {
|
43
|
+
unsigned int i;
|
44
|
+
VALUE str;
|
45
|
+
Check_Type($input, T_ARRAY);
|
46
|
+
$3 = (unsigned int) RARRAY_LEN($input);
|
47
|
+
$2 = (size_t *) malloc(($3+1)*sizeof(size_t));
|
48
|
+
$1 = (char **) malloc(($3+1)*sizeof(char *));
|
49
|
+
for(i = 0; i < $3; i ++) {
|
50
|
+
str = rb_string_value(&RARRAY_PTR($input)[i]);
|
51
|
+
$1[i] = RSTRING_PTR(str);
|
52
|
+
$2[i] = RSTRING_LEN(str);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
%typemap(freearg) (const char **keys, size_t *key_length, size_t number_of_keys) {
|
57
|
+
free($1);
|
58
|
+
free($2);
|
59
|
+
}
|
60
|
+
|
61
|
+
// Generic strings
|
62
|
+
%typemap(in) (const char *str, size_t len) {
|
63
|
+
VALUE str;
|
64
|
+
str = rb_string_value(&$input);
|
65
|
+
$1 = RSTRING_PTR(str);
|
66
|
+
$2 = RSTRING_LEN(str);
|
67
|
+
};
|
68
|
+
|
69
|
+
// Void type strings without lengths for prefix_key callback
|
70
|
+
%typemap(in) (void *data) {
|
71
|
+
VALUE str;
|
72
|
+
str = rb_string_value(&$input);
|
73
|
+
if (RSTRING_LEN(str) == 0) {
|
74
|
+
$1 = NULL;
|
75
|
+
} else {
|
76
|
+
$1 = RSTRING_PTR(str);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
%apply (const char *str, size_t len) {
|
81
|
+
(const char *namespace, size_t namespace_length),
|
82
|
+
(const char *key, size_t key_length),
|
83
|
+
(const char *value, size_t value_length)
|
84
|
+
};
|
85
|
+
|
86
|
+
// Key strings with same master key
|
87
|
+
// This will have to go if people actually want to set the master key separately
|
88
|
+
%typemap(in) (const char *master_key, size_t master_key_length, const char *key, size_t key_length) {
|
89
|
+
VALUE str;
|
90
|
+
str = rb_string_value(&$input);
|
91
|
+
$3 = $1 = RSTRING_PTR(str);
|
92
|
+
$4 = $2 = RSTRING_LEN(str);
|
93
|
+
};
|
94
|
+
|
95
|
+
//// Output maps
|
96
|
+
|
97
|
+
%apply unsigned short *OUTPUT {memcached_return *error}
|
98
|
+
%apply unsigned int *OUTPUT {uint32_t *flags}
|
99
|
+
%apply size_t *OUTPUT {size_t *value_length}
|
100
|
+
%apply unsigned long long *OUTPUT {uint64_t *value}
|
101
|
+
|
102
|
+
// Uint64
|
103
|
+
%typemap(out) (uint64_t) {
|
104
|
+
$result = ULL2NUM($1);
|
105
|
+
};
|
106
|
+
|
107
|
+
// Uint32
|
108
|
+
%typemap(out) (uint32_t) {
|
109
|
+
$result = UINT2NUM($1);
|
110
|
+
};
|
111
|
+
|
112
|
+
// String for memcached_fetch
|
113
|
+
%typemap(in, numinputs=0) (char *key, size_t *key_length) {
|
114
|
+
char string[256];
|
115
|
+
size_t length = 0;
|
116
|
+
$1 = string;
|
117
|
+
$2 = &length;
|
118
|
+
};
|
119
|
+
|
120
|
+
// Strings with lengths
|
121
|
+
%typemap(argout) (char *key, size_t *key_length) {
|
122
|
+
rb_ary_push($result, rb_str_new($1, *$2));
|
123
|
+
}
|
124
|
+
|
125
|
+
// Array of strings
|
126
|
+
// Only used by memcached_stat_get_keys() and not performance-critical
|
127
|
+
%typemap(out) (char **) {
|
128
|
+
int i;
|
129
|
+
VALUE ary = rb_ary_new();
|
130
|
+
$result = rb_ary_new();
|
131
|
+
|
132
|
+
for(i=0; $1[i] != NULL; i++) {
|
133
|
+
rb_ary_store(ary, i, rb_str_new2($1[i]));
|
134
|
+
}
|
135
|
+
rb_ary_push($result, ary);
|
136
|
+
free($1);
|
137
|
+
};
|
138
|
+
|
139
|
+
//// SWIG includes, for functions, constants, and structs
|
140
|
+
|
141
|
+
%include "libmemcached/visibility.h"
|
142
|
+
%include "libmemcached/memcached.h"
|
143
|
+
%include "libmemcached/memcached_constants.h"
|
144
|
+
%include "libmemcached/memcached_get.h"
|
145
|
+
%include "libmemcached/memcached_storage.h"
|
146
|
+
%include "libmemcached/memcached_result.h"
|
147
|
+
%include "libmemcached/memcached_server.h"
|
148
|
+
%include "libmemcached/memcached_sasl.h"
|
149
|
+
%include "libmemcached/memcached_touch.h"
|
150
|
+
%include "libmemcached/memcached_exist.h"
|
151
|
+
|
152
|
+
//// Custom C functions
|
153
|
+
|
154
|
+
VALUE rb_str_new_by_ref(char *ptr, long len);
|
155
|
+
%{
|
156
|
+
VALUE rb_str_new_by_ref(char *ptr, long len)
|
157
|
+
{
|
158
|
+
#ifdef OBJSETUP
|
159
|
+
NEWOBJ(str, struct RString);
|
160
|
+
OBJSETUP(str, rb_cString, T_STRING);
|
161
|
+
#ifdef RSTRING_NOEMBED
|
162
|
+
/* Ruby 1.9 */
|
163
|
+
str->as.heap.ptr = ptr;
|
164
|
+
str->as.heap.len = len;
|
165
|
+
str->as.heap.aux.capa = len + 1;
|
166
|
+
// Set STR_NOEMBED
|
167
|
+
FL_SET(str, FL_USER1);
|
168
|
+
#else
|
169
|
+
/* Ruby 1.8 */
|
170
|
+
str->ptr = ptr;
|
171
|
+
str->len = len;
|
172
|
+
str->aux.capa = 0;
|
173
|
+
#endif
|
174
|
+
#else
|
175
|
+
/* Rubinius, JRuby */
|
176
|
+
VALUE str = rb_str_new(ptr, len);
|
177
|
+
free(ptr);
|
178
|
+
#endif
|
179
|
+
return (VALUE)str;
|
180
|
+
}
|
181
|
+
%}
|
182
|
+
|
183
|
+
//// Manual wrappers
|
184
|
+
|
185
|
+
// Single get
|
186
|
+
VALUE memcached_get_rvalue(memcached_st *ptr, const char *key, size_t key_length, uint32_t *flags, memcached_return *error);
|
187
|
+
%{
|
188
|
+
VALUE memcached_get_rvalue(memcached_st *ptr, const char *key, size_t key_length, uint32_t *flags, memcached_return *error) {
|
189
|
+
size_t value_length = 0;
|
190
|
+
char *value = memcached_get(ptr, key, key_length, &value_length, flags, error);
|
191
|
+
return rb_str_new_by_ref(value, value_length);
|
192
|
+
};
|
193
|
+
%}
|
194
|
+
|
195
|
+
VALUE memcached_get_len_rvalue(memcached_st *ptr, const char *key, size_t key_length, uint32_t user_spec_len, uint32_t *flags, memcached_return *error);
|
196
|
+
%{
|
197
|
+
VALUE memcached_get_len_rvalue(memcached_st *ptr, const char *key, size_t key_length, uint32_t user_spec_len, uint32_t *flags, memcached_return *error) {
|
198
|
+
size_t value_length = 0;
|
199
|
+
char *value = memcached_get_len(ptr, key, key_length, user_spec_len, &value_length, flags, error);
|
200
|
+
return rb_str_new_by_ref(value, value_length);
|
201
|
+
};
|
202
|
+
%}
|
203
|
+
|
204
|
+
VALUE memcached_get_from_last_rvalue(memcached_st *ptr, const char *key, size_t key_length, uint32_t *flags, memcached_return *error);
|
205
|
+
%{
|
206
|
+
VALUE memcached_get_from_last_rvalue(memcached_st *ptr, const char *key, size_t key_length, uint32_t *flags, memcached_return *error) {
|
207
|
+
size_t value_length = 0;
|
208
|
+
char *value = memcached_get_from_last(ptr, key, key_length, &value_length, flags, error);
|
209
|
+
return rb_str_new_by_ref(value, value_length);
|
210
|
+
};
|
211
|
+
%}
|
212
|
+
|
213
|
+
// Multi get
|
214
|
+
VALUE memcached_fetch_rvalue(memcached_st *ptr, char *key, size_t *key_length, uint32_t *flags, memcached_return *error);
|
215
|
+
%{
|
216
|
+
VALUE memcached_fetch_rvalue(memcached_st *ptr, char *key, size_t *key_length, uint32_t *flags, memcached_return *error) {
|
217
|
+
size_t value_length = 0;
|
218
|
+
VALUE ary = rb_ary_new();
|
219
|
+
*key_length = 0;
|
220
|
+
if (error) *error = MEMCACHED_TIMEOUT; // timeouts leave error uninitialized
|
221
|
+
char *value = memcached_fetch(ptr, key, key_length, &value_length, flags, error);
|
222
|
+
VALUE str = rb_str_new_by_ref(value, value_length);
|
223
|
+
rb_ary_push(ary, str);
|
224
|
+
return ary;
|
225
|
+
};
|
226
|
+
%}
|
227
|
+
|
228
|
+
// Ruby isn't aware that the pointer is an array... there is probably a better way to do this
|
229
|
+
memcached_server_st *memcached_select_server_at(memcached_st *in_ptr, int index);
|
230
|
+
%{
|
231
|
+
memcached_server_st *memcached_select_server_at(memcached_st *in_ptr, int index) {
|
232
|
+
return &(in_ptr->hosts[index]);
|
233
|
+
};
|
234
|
+
%}
|
235
|
+
|
236
|
+
// Same, but for stats
|
237
|
+
memcached_stat_st *memcached_select_stat_at(memcached_st *in_ptr, memcached_stat_st *stat_ptr, int index);
|
238
|
+
%{
|
239
|
+
memcached_stat_st *memcached_select_stat_at(memcached_st *in_ptr, memcached_stat_st *stat_ptr, int index) {
|
240
|
+
return &(stat_ptr[index]);
|
241
|
+
};
|
242
|
+
%}
|
243
|
+
|
244
|
+
// Wrap only hash function
|
245
|
+
// Uint32
|
246
|
+
VALUE memcached_generate_hash_rvalue(const char *key, size_t key_length, memcached_hash hash_algorithm);
|
247
|
+
%{
|
248
|
+
VALUE memcached_generate_hash_rvalue(const char *key, size_t key_length,memcached_hash hash_algorithm) {
|
249
|
+
return UINT2NUM(memcached_generate_hash_value(key, key_length, hash_algorithm));
|
250
|
+
};
|
251
|
+
%}
|
252
|
+
|
253
|
+
// Initialization for SASL
|
254
|
+
%init %{
|
255
|
+
if (sasl_client_init(NULL) != SASL_OK) {
|
256
|
+
fprintf(stderr, "Failed to initialized SASL.\n");
|
257
|
+
}
|
258
|
+
%}
|