Skip to content

Commit

Permalink
Merge branch 'master-test' into tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
malyeyev-AMZN committed Feb 11, 2017
2 parents 3bde6e5 + fb9a572 commit 9d8ed04
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 68 deletions.
84 changes: 75 additions & 9 deletions Makefile.in

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions libmemcached/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ memcached_instance_st* __instance_create_with(memcached_st *memc,
uint32_t weight,
const memcached_connection_t type);

LIBMEMCACHED_LOCAL
memcached_return_t memcached_instance_push(memcached_st *ptr, const memcached_instance_st*, uint32_t);

void __instance_free(memcached_instance_st *);
31 changes: 28 additions & 3 deletions libtest/dynamic_mode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,45 @@
*/


#include <config.h>
#include <mem_config.h>
#include<string.h>
#include <libtest/common.h>

namespace libtest {

/*
* This is the only available option to implement this because as of now both 'version' command
* of HTTP API and '-V' command-line option return only X.Y.Z version without any information as
* to whether it is plain open source or AWS Elasticache flavor of the engine.
*/
bool server_supports_dynamic_mode(uint16_t port) {
char cmd[100];
FILE *fp;
sprintf(cmd, "echo -n -e \"config get cluster\\r\\n\" | nc localhost %d", port);
if ((fp = popen(cmd, "r")) == NULL) {
// likely memcached (server) binary not present on the system
return false;
}
char buf[100];
bool result = true;
if (fgets(buf, 100, fp) == NULL || strcmp(buf, "ERROR\r\n") == 0) {
result = false;
}
if(pclose(fp)) {
fprintf(stderr, "pclose() exited with error");
}
return result;
}


void set_config(const char *config, uint16_t port, char *version)
{
int length = strlen(config) + strlen(version) + 2; //Add two for \r and \n
char buffer[2000];
sprintf(buffer, "\"config set cluster 0 %d\\r\\n%s\\r\\n%s\\r\\n\"", length, version, config);
// 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);
char cmd[2500];
sprintf(cmd, "echo -n -e %s | nc localhost %d", buffer, port);
sprintf(cmd, "echo -n -e %s | nc localhost %d >/dev/null", buffer, port);
system(cmd);
}

Expand Down Expand Up @@ -166,7 +191,7 @@ namespace libtest {
memcached_server_st *server = NULL;
memcached_return rc;
server= memcached_server_list_append_with_ipaddress(server, "localhost", "10.61.120.162", 11211, &rc);
test_true(strcmp(memcached_server_ipaddress(server), "10.61.120.162") == 0);
test_true(strcmp(server->ipaddress, "10.61.120.162") == 0);
free(server);
return TEST_SUCCESS;
}
Expand Down
6 changes: 6 additions & 0 deletions libtest/dynamic_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

namespace libtest {

/*
* Check if the local memcached server process running on a specified port supports
* Elasticache Auto Discovery -related comands.
*/
bool server_supports_dynamic_mode(uint16_t port);

void set_config(const char *config, uint16_t port, char *version);

test_return_t check_bad_config_with_no_newline(void *);
Expand Down
5 changes: 2 additions & 3 deletions libtest/server_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ std::string server_startup_st::option_string() const
return temp;
}

/*
void server_startup_st::set_config_for_dynamic_mode()
{
std::string buffer;
Expand All @@ -406,7 +405,7 @@ void server_startup_st::set_config_for_dynamic_mode()
{
Server *server = servers[i];
buffer+= "localhost|127.0.0.1|";
char port[6];
char port[7]; // 5 digits (up to 65535) + 1 space + 1 null-terminator
sprintf(port,"%d ", server->port());
buffer += port;
}
Expand All @@ -420,5 +419,5 @@ void server_startup_st::set_config_for_dynamic_mode()
}

}
*/

} // namespace libtest
9 changes: 9 additions & 0 deletions libtest/server_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class server_startup_st
std::string server_list;
bool _socket;
bool _sasl;
memcached_client_mode _client_mode;
std::string _username;
std::string _password;

Expand Down Expand Up @@ -115,6 +116,14 @@ class server_startup_st
_password= password_arg;
}

memcached_client_mode get_client_mode()
{
return _client_mode;
}

void set_client_mode(memcached_client_mode client_mode) {
_client_mode = client_mode;
}

// Just remove everything after shutdown
void clear();
Expand Down
6 changes: 3 additions & 3 deletions libtest/unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ test_st http_tests[] ={
{0, 0, 0}
};

/*

test_st dynamic_mode_tests[] = {
{"check_bad_config_with_no_newline", 0, check_bad_config_with_no_newline },
{"check_bad_config_with_missing_pipe", 0, check_bad_config_with_missing_pipe },
Expand All @@ -1204,7 +1204,7 @@ test_st dynamic_mode_tests[] = {
{"check_get_ipaddress", 0, check_get_ipaddress},
{0, 0, 0}
};
*/

collection_st collection[] ={
{"environment", 0, 0, environment_tests},
{"return values", 0, 0, tests_log},
Expand All @@ -1225,7 +1225,7 @@ collection_st collection[] ={
{"create_tmpfile()", 0, 0, create_tmpfile_TESTS },
{"dns", check_for_VALGRIND, 0, dns_TESTS },
{"libtest::Timer", 0, 0, timer_TESTS },
// {"dynamic_mode_unit_tests", 0, 0, dynamic_mode_tests},
{"dynamic_mode", 0, 0, dynamic_mode_tests},
{0, 0, 0, 0}
};

Expand Down
Loading

0 comments on commit 9d8ed04

Please sign in to comment.