Skip to content

Commit 9d8ed04

Browse files
committed
Merge branch 'master-test' into tmp
2 parents 3bde6e5 + fb9a572 commit 9d8ed04

File tree

11 files changed

+346
-68
lines changed

11 files changed

+346
-68
lines changed

Makefile.in

Lines changed: 75 additions & 9 deletions
Large diffs are not rendered by default.

libmemcached/instance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ memcached_instance_st* __instance_create_with(memcached_st *memc,
218218
uint32_t weight,
219219
const memcached_connection_t type);
220220

221+
LIBMEMCACHED_LOCAL
221222
memcached_return_t memcached_instance_push(memcached_st *ptr, const memcached_instance_st*, uint32_t);
222223

223224
void __instance_free(memcached_instance_st *);

libtest/dynamic_mode.cc

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,45 @@
1212
*/
1313

1414

15-
#include <config.h>
15+
#include <mem_config.h>
1616
#include<string.h>
1717
#include <libtest/common.h>
1818

1919
namespace libtest {
2020

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+
2146
void set_config(const char *config, uint16_t port, char *version)
2247
{
2348
int length = strlen(config) + strlen(version) + 2; //Add two for \r and \n
2449
char buffer[2000];
2550
sprintf(buffer, "\"config set cluster 0 %d\\r\\n%s\\r\\n%s\\r\\n\"", length, version, config);
2651
// 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);
2752
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);
2954
system(cmd);
3055
}
3156

@@ -166,7 +191,7 @@ namespace libtest {
166191
memcached_server_st *server = NULL;
167192
memcached_return rc;
168193
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);
170195
free(server);
171196
return TEST_SUCCESS;
172197
}

libtest/dynamic_mode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
namespace libtest {
1919

20+
/*
21+
* Check if the local memcached server process running on a specified port supports
22+
* Elasticache Auto Discovery -related comands.
23+
*/
24+
bool server_supports_dynamic_mode(uint16_t port);
25+
2026
void set_config(const char *config, uint16_t port, char *version);
2127

2228
test_return_t check_bad_config_with_no_newline(void *);

libtest/server_container.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ std::string server_startup_st::option_string() const
391391
return temp;
392392
}
393393

394-
/*
395394
void server_startup_st::set_config_for_dynamic_mode()
396395
{
397396
std::string buffer;
@@ -406,7 +405,7 @@ void server_startup_st::set_config_for_dynamic_mode()
406405
{
407406
Server *server = servers[i];
408407
buffer+= "localhost|127.0.0.1|";
409-
char port[6];
408+
char port[7]; // 5 digits (up to 65535) + 1 space + 1 null-terminator
410409
sprintf(port,"%d ", server->port());
411410
buffer += port;
412411
}
@@ -420,5 +419,5 @@ void server_startup_st::set_config_for_dynamic_mode()
420419
}
421420

422421
}
423-
*/
422+
424423
} // namespace libtest

libtest/server_container.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class server_startup_st
5454
std::string server_list;
5555
bool _socket;
5656
bool _sasl;
57+
memcached_client_mode _client_mode;
5758
std::string _username;
5859
std::string _password;
5960

@@ -115,6 +116,14 @@ class server_startup_st
115116
_password= password_arg;
116117
}
117118

119+
memcached_client_mode get_client_mode()
120+
{
121+
return _client_mode;
122+
}
123+
124+
void set_client_mode(memcached_client_mode client_mode) {
125+
_client_mode = client_mode;
126+
}
118127

119128
// Just remove everything after shutdown
120129
void clear();

libtest/unittest.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ test_st http_tests[] ={
11851185
{0, 0, 0}
11861186
};
11871187

1188-
/*
1188+
11891189
test_st dynamic_mode_tests[] = {
11901190
{"check_bad_config_with_no_newline", 0, check_bad_config_with_no_newline },
11911191
{"check_bad_config_with_missing_pipe", 0, check_bad_config_with_missing_pipe },
@@ -1204,7 +1204,7 @@ test_st dynamic_mode_tests[] = {
12041204
{"check_get_ipaddress", 0, check_get_ipaddress},
12051205
{0, 0, 0}
12061206
};
1207-
*/
1207+
12081208
collection_st collection[] ={
12091209
{"environment", 0, 0, environment_tests},
12101210
{"return values", 0, 0, tests_log},
@@ -1225,7 +1225,7 @@ collection_st collection[] ={
12251225
{"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
12261226
{"dns", check_for_VALGRIND, 0, dns_TESTS },
12271227
{"libtest::Timer", 0, 0, timer_TESTS },
1228-
// {"dynamic_mode_unit_tests", 0, 0, dynamic_mode_tests},
1228+
{"dynamic_mode", 0, 0, dynamic_mode_tests},
12291229
{0, 0, 0, 0}
12301230
};
12311231

0 commit comments

Comments
 (0)