int main(int argc, char *argv[])
{
- memcached_st *memc;
char *string;
size_t string_length;
uint32_t flags;
memcached_return_t rc;
- memcached_server_st *servers;
int return_code= EXIT_SUCCESS;
options_parse(argc, argv);
initialize_sockets();
- if (!opt_servers)
+ if (opt_servers == NULL)
{
char *temp;
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
std::cerr << "No servers provied" << std::endl;
exit(EXIT_FAILURE);
}
}
- memc= memcached_create(NULL);
- process_hash_option(memc, opt_hash);
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
- servers= memcached_servers_parse(opt_servers);
+ memcached_st* memc= memcached_create(NULL);
+ process_hash_option(memc, opt_hash);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
case '?':
/* getopt_long already printed an error message. */
- exit(1);
+ exit(EXIT_FAILURE);
default:
abort();
}
{
opt_servers= strdup(temp);
}
- else
+ else if (argc >= 1 and argv[--argc])
+ {
+ opt_servers= strdup(argv[--argc]);
+ }
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
exit(EXIT_FAILURE);
}
}
- memcached_server_st *servers;
- if (opt_servers)
- {
- servers= memcached_servers_parse(opt_servers);
- }
- else
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
{
- servers= memcached_servers_parse(argv[--argc]);
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
}
memcached_server_push(memc, servers);
options_parse(argc, argv);
- memcached_st *memc= memcached_create(NULL);
- process_hash_option(memc, opt_hash);
-
if (opt_servers == NULL)
{
char *temp;
{
opt_servers= strdup(temp);
}
- else
+ else if (argc >= 1 and argv[--argc])
+ {
+ opt_servers= strdup(argv[--argc]);
+ }
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
exit(EXIT_FAILURE);
}
}
- memcached_server_st *servers;
- if (opt_servers)
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
{
- servers= memcached_servers_parse(opt_servers);
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
}
- else
+
+ memcached_st *memc= memcached_create(NULL);
+ if (memc == NULL)
{
- servers= memcached_servers_parse(argv[--argc]);
+ std::cerr << "Could not allocate a memcached_st structure.\n" << std::endl;
+ return EXIT_FAILURE;
}
+ process_hash_option(memc, opt_hash);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
int main(int argc, char *argv[])
{
- memcached_st *memc;
- memcached_server_st *servers;
-
options_parse(argc, argv);
initialize_sockets();
- if (opt_servers == 0)
+ if (opt_servers == NULL)
{
char *temp;
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
- return EXIT_FAILURE;
+ exit(EXIT_FAILURE);
}
}
- memc= memcached_create(NULL);
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ memcached_st* memc= memcached_create(NULL);
process_hash_option(memc, opt_hash);
- servers= memcached_servers_parse(opt_servers);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == false)
{
std::cerr << "No Servers provided" << std::endl;
exit(EXIT_FAILURE);
}
}
- memcached_st *memc= memcached_create(NULL);
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
- memcached_server_st *servers= memcached_servers_parse(opt_servers);
+ memcached_st *memc= memcached_create(NULL);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
exit(EXIT_FAILURE);
int exit_code= EXIT_SUCCESS;
memcached_server_st *servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ exit_code= EXIT_FAILURE;
+ }
+ else
{
for (uint32_t x= 0; x < memcached_server_list_count(servers); x++)
{
const char *hostname= servers[x].hostname;
in_port_t port= servers[x].port;
+ if (opt_verbose)
+ {
+ std::cout << "Trying to ping " << hostname << ":" << port << std::endl;
+ }
+
if (libmemcached_util_ping2(hostname, port, opt_username, opt_passwd, &instance_rc) == false)
{
std::cerr << "Failed to ping " << hostname << ":" << port << " " << memcached_strerror(NULL, instance_rc) << std::endl;
int main(int argc, char *argv[])
{
- memcached_st *memc;
- memcached_server_st *servers;
-
options_parse(argc, argv);
initialize_sockets();
- if (opt_servers == 0)
+ if (opt_servers == NULL)
{
char *temp;
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
- return EXIT_FAILURE;
+ exit(EXIT_FAILURE);
}
}
- memc= memcached_create(NULL);
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ memcached_st* memc= memcached_create(NULL);
process_hash_option(memc, opt_hash);
- servers= memcached_servers_parse(opt_servers);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
- fprintf(stderr, "No Servers provided\n");
- return EXIT_FAILURE;
+ std::cerr << "No Servers provided" << std::endl;
+ exit(EXIT_FAILURE);
}
}
memcached_server_st *servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
pthread_mutex_init(&sleeper_mutex, NULL);
pthread_cond_init(&sleep_threshhold, NULL);
options_parse(argc, argv);
initialize_sockets();
- if (opt_servers == false)
+ if (opt_servers == NULL)
{
char *temp;
if ((temp= getenv("MEMCACHED_SERVERS")))
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
return EXIT_FAILURE;
}
}
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
+
+ if (opt_servers)
+ {
+ free(opt_servers);
+ }
+
memcached_st *memc= memcached_create(NULL);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, opt_binary);
- memcached_server_st *servers= memcached_servers_parse(opt_servers);
- free(opt_servers);
-
memcached_return_t rc= memcached_server_push(memc, servers);
memcached_server_list_free(servers);
uint32_t num_of_tests= 32;
const char *test_key= "libmemcached_test_key";
- memcached_st **servers;
- servers= static_cast<memcached_st**>(malloc(sizeof(memcached_st*) * server_count));
- if (not servers)
+ memcached_st **servers= static_cast<memcached_st**>(malloc(sizeof(memcached_st*) * server_count));
+ if (servers == NULL)
{
fprintf(stderr, "Failed to allocate memory\n");
return;
{
fprintf(stderr, "Failed to memcached_create()\n");
if (x > 0)
+ {
memcached_free(servers[0]);
+ }
x--;
for (; x > 0; x--)
+ {
memcached_free(servers[x]);
+ }
free(servers);
+
return;
}
memcached_server_add(servers[x],
size_t vlen;
char *val= memcached_get(servers[x], test_key, strlen(test_key),
&vlen, &flags, &rc);
- if (rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_SUCCESS)
+ if (rc != MEMCACHED_NOTFOUND and rc != MEMCACHED_SUCCESS)
+ {
break;
+ }
free(val);
}
gettimeofday(&end_time, NULL);
printf("\n");
for (uint32_t x= 0; x < server_count; x++)
+ {
memcached_free(servers[x]);
+ }
free(servers);
free(analyze_mode);
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
- return EXIT_FAILURE;
+ exit(EXIT_FAILURE);
}
}
+ memcached_server_st* servers= memcached_servers_parse(opt_servers);
+ if (servers == NULL or memcached_server_list_count(servers) == 0)
+ {
+ std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+ return EXIT_FAILURE;
+ }
+
memcached_st *memc= memcached_create(NULL);
process_hash_option(memc, opt_hash);
- memcached_server_st *servers= memcached_servers_parse(opt_servers);
-
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
memcached_return_t rc;
if (opt_hash == NULL)
+ {
return;
+ }
set= MEMCACHED_HASH_DEFAULT; /* Just here to solve warning */
if (!strcasecmp(opt_hash, "CRC"))
check_PROGRAMS+= tests/memcat
noinst_PROGRAMS+= tests/memcat
+tests_memping_SOURCES= tests/memping.cc
+tests_memping_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX)
+EXTRA_tests_memping_DEPENDENCIES= clients/memping
+tests_memping_LDADD= libtest/libtest.la $(TESTS_LDADDS)
+check_PROGRAMS+= tests/memping
+noinst_PROGRAMS+= tests/memping
+
tests_memerror_SOURCES= tests/memerror.cc
tests_memerror_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX)
EXTRA_tests_memerror_DEPENDENCIES= clients/memerror
test-memtouch: tests/memtouch
tests/memtouch
+test-memping: tests/memping
+ tests/memping
+
valgrind-memerror: tests/memerror
@$(VALGRIND_COMMAND) tests/memerror
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Test memping
+ *
+ * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+
+/*
+ Test that we are cycling the servers we are creating during testing.
+*/
+
+#include <mem_config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached-1.0/memcached.h>
+
+using namespace libtest;
+
+#ifndef __INTEL_COMPILER
+#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
+
+static std::string executable("clients/memping");
+
+static test_return_t help_test(void *)
+{
+ const char *args[]= { "--help", 0 };
+
+ test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t ping_TEST(void *)
+{
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "--server=localhost:%d", int(default_port()));
+ const char *args[]= { buffer, 0 };
+
+ test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t NOT_FOUND_TEST(void *)
+{
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "--server=nonexist.libmemcached.org:%d", int(default_port()));
+ const char *args[]= { buffer, 0 };
+
+ test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
+
+ return TEST_SUCCESS;
+}
+
+test_st memping_TESTS[] ={
+ {"--help", true, help_test },
+ {"ping(FOUND)", true, ping_TEST },
+ {"ping(NOT_FOUND)", true, NOT_FOUND_TEST },
+ {0, 0, 0}
+};
+
+collection_st collection[] ={
+ {"memping", 0, 0, memping_TESTS },
+ {0, 0, 0, 0}
+};
+
+static void *world_create(server_startup_st& servers, test_return_t& error)
+{
+ if (libtest::has_memcached() == false)
+ {
+ error= TEST_SKIPPED;
+ return NULL;
+ }
+
+ if (server_startup(servers, "memcached", libtest::default_port(), NULL) == false)
+ {
+ error= TEST_FAILURE;
+ }
+
+ return &servers;
+}
+
+
+void get_world(libtest::Framework* world)
+{
+ world->collections(collection);
+ world->create(world_create);
+}
+
+