2ea99ff2c05d2faf01e5892ca2adeeb7c61f8836
2 Sample test application.
16 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
17 #define TEST_SERVERS 1
19 long int timedif(struct timeval a
, struct timeval b
)
23 us
= a
.tv_usec
- b
.tv_usec
;
25 s
= a
.tv_sec
- b
.tv_sec
;
30 char *server_startup()
33 char server_string_buffer
[8096];
36 end_ptr
= server_string_buffer
;
38 for (x
= 0; x
< TEST_SERVERS
; x
++)
40 char buffer
[1024]; /* Nothing special for number */
43 sprintf(buffer
, "memcached -d -P /tmp/%umemc.pid -p %u", x
, x
+ TEST_PORT_BASE
);
45 count
= sprintf(end_ptr
, "localhost:%u,", x
+ TEST_PORT_BASE
);
50 return strdup(server_string_buffer
);
53 void server_shutdown(char *server_string
)
57 for (x
= 0; x
< TEST_SERVERS
; x
++)
59 char buffer
[1024]; /* Nothing special for number */
60 sprintf(buffer
, "cat /tmp/%umemc.pid | xargs kill", x
);
67 int main(int argc
, char *argv
[])
71 char *collection_to_run
= NULL
;
73 memcached_server_st
*servers
;
74 collection_st
*collection
;
77 collection
= gets_collections();
81 collection_to_run
= argv
[1];
86 if ((server_list
= getenv("MEMCACHED_SERVERS")))
88 printf("servers %s\n", server_list
);
89 servers
= memcached_servers_parse(server_list
);
94 server_list
= server_startup();
95 printf("servers %s\n", server_list
);
96 servers
= memcached_servers_parse(server_list
);
103 for (x
= 0; x
< memcached_server_list_count(servers
); x
++)
105 printf("\t%s : %u\n", servers
[x
].hostname
, servers
[x
].port
);
106 assert(servers
[x
].stack_responses
== 0);
107 assert(servers
[x
].fd
== -1);
108 assert(servers
[x
].cursor_active
== 0);
114 for (next
= collection
; next
->name
; next
++)
119 if (collection_to_run
&& strcmp(collection_to_run
, next
->name
))
122 fprintf(stderr
, "\n%s\n\n", next
->name
);
124 for (x
= 0; run
->name
; run
++)
126 if (wildcard
&& strcmp(wildcard
, run
->name
))
129 fprintf(stderr
, "Testing %s", run
->name
);
133 struct timeval start_time
, end_time
;
135 memc
= memcached_create(NULL
);
138 if (run
->requires_flush
)
139 memcached_flush(memc
, 0);
141 rc
= memcached_server_push(memc
, servers
);
142 assert(rc
== MEMCACHED_SUCCESS
);
145 for (loop
= 0; loop
< memcached_server_list_count(servers
); loop
++)
147 assert(memc
->hosts
[loop
].stack_responses
== 0);
148 assert(memc
->hosts
[loop
].fd
== -1);
149 assert(memc
->hosts
[loop
].cursor_active
== 0);
157 if (rc
!= MEMCACHED_SUCCESS
)
159 fprintf(stderr
, "\t\t\t\t\t [ skipping ]\n");
164 gettimeofday(&start_time
, NULL
);
165 failed
= run
->function(memc
);
166 gettimeofday(&end_time
, NULL
);
167 long int load_time
= timedif(end_time
, start_time
);
169 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ failed ]\n", load_time
/ 1000,
172 fprintf(stderr
, "\t\t\t\t\t %ld.%03ld [ ok ]\n", load_time
/ 1000,
176 (void)next
->post(memc
);
180 memcached_free(memc
);
184 fprintf(stderr
, "All tests completed successfully\n\n");
186 memcached_server_list_free(servers
);
188 server_shutdown(server_list
);