|
12 | 12 | */
|
13 | 13 |
|
14 | 14 |
|
15 |
| -#include <config.h> |
| 15 | +#include <mem_config.h> |
16 | 16 | #include<string.h>
|
17 | 17 | #include <libtest/common.h>
|
18 | 18 |
|
19 | 19 | namespace libtest {
|
20 | 20 |
|
| 21 | + /* |
| 22 | + * This is the only available option to implement this because as of now both 'version' command |
| 23 | + * of HTTP API and '-V' command-line option return only X.Y.Z version without any information as |
| 24 | + * to whether it is plain open source or AWS Elasticache flavor of the engine. |
| 25 | + */ |
| 26 | + bool server_supports_dynamic_mode(uint16_t port) { |
| 27 | + char cmd[100]; |
| 28 | + FILE *fp; |
| 29 | + sprintf(cmd, "echo -n -e \"config get cluster\\r\\n\" | nc localhost %d", port); |
| 30 | + if ((fp = popen(cmd, "r")) == NULL) { |
| 31 | + // likely memcached (server) binary not present on the system |
| 32 | + return false; |
| 33 | + } |
| 34 | + char buf[100]; |
| 35 | + bool result = true; |
| 36 | + if (fgets(buf, 100, fp) == NULL || strcmp(buf, "ERROR\r\n") == 0) { |
| 37 | + result = false; |
| 38 | + } |
| 39 | + if(pclose(fp)) { |
| 40 | + fprintf(stderr, "pclose() exited with error"); |
| 41 | + } |
| 42 | + return result; |
| 43 | + } |
| 44 | + |
| 45 | + |
21 | 46 | void set_config(const char *config, uint16_t port, char *version)
|
22 | 47 | {
|
23 | 48 | int length = strlen(config) + strlen(version) + 2; //Add two for \r and \n
|
24 | 49 | char buffer[2000];
|
25 | 50 | sprintf(buffer, "\"config set cluster 0 %d\\r\\n%s\\r\\n%s\\r\\n\"", length, version, config);
|
26 | 51 | // To run for memcached 1.4.5, switch to this: sprintf(buffer, "\"set AmazonElastiCache:cluster 0 0 %d\\r\\n%s\\r\\n%s\\r\\n\"", length, version, config);
|
27 | 52 | char cmd[2500];
|
28 |
| - sprintf(cmd, "echo -n -e %s | nc localhost %d", buffer, port); |
| 53 | + sprintf(cmd, "echo -n -e %s | nc localhost %d >/dev/null", buffer, port); |
29 | 54 | system(cmd);
|
30 | 55 | }
|
31 | 56 |
|
@@ -166,7 +191,7 @@ namespace libtest {
|
166 | 191 | memcached_server_st *server = NULL;
|
167 | 192 | memcached_return rc;
|
168 | 193 | server= memcached_server_list_append_with_ipaddress(server, "localhost", "10.61.120.162", 11211, &rc);
|
169 |
| - test_true(strcmp(memcached_server_ipaddress(server), "10.61.120.162") == 0); |
| 194 | + test_true(strcmp(server->ipaddress, "10.61.120.162") == 0); |
170 | 195 | free(server);
|
171 | 196 | return TEST_SUCCESS;
|
172 | 197 | }
|
|
0 commit comments