unittests/unittests
out
*.orig
+tests/memcapable
# includes append to these:
SUFFIXES =
.PHONY =
-PHONY =
TESTS =
CLEANFILES =
DISTCLEANFILES =
struct timeval next_time;
if (gettimeofday(&next_time, NULL) == 0)
+ {
ptr->next_retry= next_time.tv_sec + ptr->root->retry_timeout;
+ }
+ }
+
+ if (memcached_has_current_error(*ptr))
+ {
+ return memcached_server_error_return(ptr);
}
- if (timeout_error_occured)
+ if (timeout_error_occured and ptr->state < MEMCACHED_SERVER_STATE_IN_PROGRESS)
+ {
return memcached_set_error(*ptr, MEMCACHED_TIMEOUT, MEMCACHED_AT);
+ }
return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT); /* The last error should be from connect() */
}
return memc->error_messages->message;
}
-
bool memcached_has_current_error(memcached_st &memc)
{
if (memc.error_messages
return false;
}
+bool memcached_has_current_error(memcached_server_st& server)
+{
+ return memcached_has_current_error(*(server.root));
+}
+
memcached_return_t memcached_last_error(memcached_st *memc)
{
if (not memc)
memcached_return_t memcached_set_errno(memcached_server_st&, int local_errno, const char *at);
LIBMEMCACHED_LOCAL
-bool memcached_has_current_error(memcached_st &memc);
+bool memcached_has_current_error(memcached_st&);
+
+LIBMEMCACHED_LOCAL
+bool memcached_has_current_error(memcached_server_st&);
LIBMEMCACHED_LOCAL
void memcached_error_free(memcached_st&);
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
*error= memcached_response(server, buffer, sizeof(buffer), result);
- if (*error == MEMCACHED_SUCCESS)
+ if (*error == MEMCACHED_IN_PROGRESS)
+ {
+ continue;
+ }
+ else if (*error == MEMCACHED_SUCCESS)
{
result->count++;
return result;
self= _server_create(self, memc);
if (not self)
+ {
return NULL;
+ }
_server_init(self, const_cast<memcached_st *>(memc), hostname, port, weight, type);
unsigned int iferror= (*callback)(ptr, instance, context);
if (iferror)
+ {
continue;
+ }
}
return MEMCACHED_SUCCESS;
#pragma once
+#include <typeinfo>
+#include <libtest/strerror.h>
+#include <libmemcached/memcached.h>
+
namespace libtest {
template <class T_comparable, class T_hint>
{
if (__expected != __actual)
{
- libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"";
+ if (typeid(__expected) == typeid(memcached_return_t))
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected \""
+ << memcached_strerror(NULL, memcached_return_t(__expected))
+ << "\" got \""
+ << memcached_strerror(NULL, memcached_return_t(__actual)) << "\"";
+ }
+ else if (typeid(__expected) == typeid(test_return_t))
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected \""
+ << test_strerror(test_return_t(__expected))
+ << "\" got \""
+ << test_strerror(test_return_t(__actual)) << "\"";
+ }
+ else
+ {
+ libtest::stream::make_cerr(file, line, func) << "Expected \"" << __expected << "\" got \"" << __actual << "\"";
+ }
return false;
}
tests/var/run:
$(mkdir_p) tests/var/run
+.PHONY+= tests/var
+
libtest_unittest_CFLAGS=
libtest_unittest_LDADD= ${LIBTEST_LDADD}
arg_buffer << " -u root ";
}
+ arg_buffer << " -l 127.0.0.1 ";
+
for (int x= 1 ; x < argc ; x++)
{
arg_buffer << " " << argv[x] << " ";
using namespace libtest;
-#define SERVERS_TO_CREATE 5
-
#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
world->collection_shutdown= (test_callback_fn*)world_container_shutdown;
world->set_runner(&defualt_libmemcached_runner);
+ world->set_socket();
}
memc_ptr= memcached_create(NULL);
test_true(memc_ptr);
- memcached_increment(memc_ptr, memcached_literal_param("dead key"), 1, NULL);
+ memcached_increment(memc_ptr, test_literal_param("dead key"), 1, NULL);
test_true(memcached_last_error(memc_ptr) == MEMCACHED_NO_SERVERS);
- memcached_increment(memc_ptr, memcached_literal_param("dead key"), 1, NULL);
+ memcached_increment(memc_ptr, test_literal_param("dead key"), 1, NULL);
test_true(memcached_last_error(memc_ptr) == MEMCACHED_NO_SERVERS);
memcached_free(memc_ptr);
tests/string.h \
tests/virtual_buckets.h
-
-noinst_PROGRAMS+= \
- tests/atomsmasher \
- tests/cycle \
- tests/hash_plus \
- tests/testapp \
- tests/testhashkit \
- tests/testplus \
- tests/testudp
-
# Cycle should always run first
tests_cycle_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING)
tests_cycle_SOURCES= tests/cycle.cc
tests_cycle_DEPENDENCIES= $(TESTS_LDADDS)
tests_cycle_LDADD= $(tests_cycle_DEPENDENCIES)
check_PROGRAMS+= tests/cycle
+noinst_PROGRAMS+= tests/cycle
tests_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING)
libhashkit/libhashkit.la \
libmemcached/libmemcachedinternal.la
check_PROGRAMS+= tests/testapp
+noinst_PROGRAMS+= tests/testapp
tests_testplus_SOURCES= tests/plus.cpp
tests_testplus_CXXFLAGS = $(AM_CXXFLAGS) $(NO_EFF_CXX)
tests_testplus_DEPENDENCIES= $(TESTS_LDADDS)
tests_testplus_LDADD= $(tests_testplus_DEPENDENCIES) $(LIBSASL)
check_PROGRAMS+= tests/testplus
+noinst_PROGRAMS+= tests/testplus
tests_atomsmasher_SOURCES= \
tests/atomsmasher.cc \
clients/execute.cc
tests_atomsmasher_DEPENDENCIES= $(TESTS_LDADDS)
tests_atomsmasher_LDADD= $(tests_atomsmasher_DEPENDENCIES) $(LIBSASL)
+noinst_PROGRAMS+= tests/atomsmasher
tests_testudp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING)
tests_testudp_SOURCES= tests/mem_udp.cc
tests_testudp_DEPENDENCIES= $(TESTS_LDADDS)
tests_testudp_LDADD= $(tests_testudp_DEPENDENCIES) $(LIBSASL)
check_PROGRAMS+= tests/testudp
+noinst_PROGRAMS+= tests/testudp
tests_testhashkit_SOURCES = tests/hashkit_functions.cc
tests_testhashkit_DEPENDENCIES = libtest/libtest.la libhashkit/libhashkit.la $(TESTS_LDADDS)
tests_testhashkit_LDADD = $(tests_testhashkit_DEPENDENCIES)
check_PROGRAMS+= tests/testhashkit
+noinst_PROGRAMS+= tests/testhashkit
tests_hash_plus_SOURCES= tests/hash_plus.cc
tests_hash_plus_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX)
-tests_hash_plus_DEPENDENCIES= $(tests_testhashkit_DEPENDENCIES) $(TESTS_LDADDS)
+tests_hash_plus_DEPENDENCIES= $(tests_testhashkit_DEPENDENCIES)
tests_hash_plus_LDADD= $(tests_testhashkit_DEPENDENCIES)
check_PROGRAMS+= tests/hash_plus
+noinst_PROGRAMS+= tests/hash_plus
+
+tests_memcapable_SOURCES= tests/memcapable.cc
+tests_memcapable_CXXFLAGS= $(AM_CXXFLAGS) $(NO_EFF_CXX)
+tests_memcapable_DEPENDENCIES= libtest/libtest.la $(TESTS_LDADDS)
+tests_memcapable_LDADD= $(tests_memcapable_DEPENDENCIES)
+check_PROGRAMS+= tests/memcapable
+noinst_PROGRAMS+= tests/memcapable
test: check
-check-local: tests/var $(TEST_DOCS) memcapable
+check-local: tests/var $(TEST_DOCS)
@echo "Tests completed"
test-x: tests/var test-plus test-memcat test-memcp test-memrm test-memerror test-memdump test-memflush test-memstat
@echo "Tests completed"
-memcapable: clients/memcapable
- @@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
- @clients/memcapable -p 12555 || echo "Your memcached server does not support all commands"
- @cat tests/Xumemc.pid | xargs kill || echo "Failed to kill memcached server"
- @rm tests/Xumemc.pid
-
test-memcat: clients/memcat clients/memcp
@echo "Testing memcat"
@@MEMC_BINARY@ -d -u root -P `pwd`/tests/Xumemc.pid -p 12555
test-cycle: tests/var tests/cycle
@tests/cycle
+test-memcapable: tests/var tests/memcapable
+ @tests/memcapable
+
pahole-mem: tests/testapp
@$(PAHOLE_COMMAND) tests/testapp
valgrind-hashplus: tests/hash_plus
@$(VALGRIND_COMMAND) tests/hash_plus
-PHONY += valgrind
+.PHONY += valgrind
valgrind: valgrind-cycle valgrind-mem valgrind-udp valgrind-plus valgrind-hash valgrind-hashplus
helgrind-cycle: tests/cycle
.PHONY += helgrind
helgrind: helgrind-cycle helgrind-mem helgrind-udp helgrind-plus helgrind-hash helgrind-hashplus
-PHONY += cachegrind
+.PHONY += cachegrind
CLEANFILES += tests/cachegrind.out
cachegrind:
rm -f tests/cachegrind.out.*
$(LIBTOOL) --mode=execute valgrind --tool=cachegrind --cachegrind-out-file=tests/cachegrind.out.%p --branch-sim=yes tests/testapp
cg_annotate tests/cachegrind.out.* --auto=yes > tests/cachegrind.out
-PHONY += callgrind
+.PHONY += callgrind
CLEANFILES += tests/callgrind.out
callgrind:
rm -f tests/callgrind.out.*
static test_return_t set_test(memcached_st *memc)
{
memcached_return_t rc= memcached_set(memc,
- memcached_literal_param("foo"),
- memcached_literal_param("when we sanitize"),
+ test_literal_param("foo"),
+ test_literal_param("when we sanitize"),
time_t(0), (uint32_t)0);
test_true_got(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc));
memcached_return_t rc;
while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
{
+ if (rc == MEMCACHED_IN_PROGRESS)
+ {
+ continue;
+ }
+
test_true(results);
test_compare(MEMCACHED_SUCCESS, rc);
}
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
test_compare(MEMCACHED_SUCCESS,
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1));
- test_compare(1UL, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
+ test_compare(uint64_t(1), memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
}
else
{
test_compare(MEMCACHED_SUCCESS,
memcached_set(mmc[0], key, keylen, "0", 1, 0, 0));
- for (size_t x= 0; x < POOL_SIZE; ++x)
+ for (uint64_t x= 0; x < POOL_SIZE; ++x)
{
uint64_t number_value;
test_compare(MEMCACHED_SUCCESS,
test_compare(MEMCACHED_SUCCESS,
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1));
- test_compare(1UL, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
+ test_compare(uint64_t(1), memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
test_compare(MEMCACHED_SUCCESS, memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA));
test_compare(MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA, memcached_behavior_get_distribution(memc));
test_false(value);
test_zero(length);
- test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(memc, rc));
+ test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
memcached_free(memc);
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Test memcapable
+ *
+ * Copyright (C) 2011 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 <config.h>
+
+#include <libtest/test.hpp>
+#include <libmemcached/memcached.h>
+
+using namespace libtest;
+
+#ifndef __INTEL_COMPILER
+#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
+
+static std::string executable;
+
+static test_return_t help_test(void *)
+{
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
+ const char *args[]= { buffer, "--help", 0 };
+
+ test_success(exec_cmdline(executable, args));
+ return TEST_SUCCESS;
+}
+
+static test_return_t ascii_test(void *)
+{
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
+ const char *args[]= { buffer, " -a ", 0 };
+
+ test_success(exec_cmdline(executable, args));
+ return TEST_SUCCESS;
+}
+
+static test_return_t binary_test(void *)
+{
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
+ const char *args[]= { buffer, " -b ", 0 };
+
+ test_success(exec_cmdline(executable, args));
+ return TEST_SUCCESS;
+}
+
+test_st memcapable_tests[] ={
+ {"--help", 0, help_test},
+ {"-a, ascii", 0, ascii_test},
+ {"-b, binary", 0, binary_test},
+ {0, 0, 0}
+};
+
+collection_st collection[] ={
+ {"memcapable", 0, 0, memcapable_tests },
+ {0, 0, 0, 0}
+};
+
+static void *world_create(server_startup_st& servers, test_return_t& error)
+{
+ const char *argv[1]= { "memcapable" };
+ if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv))
+ {
+ error= TEST_FAILURE;
+ }
+
+ return &servers;
+}
+
+
+void get_world(Framework *world)
+{
+ executable= "./clients/memcapable";
+ world->collections= collection;
+ world->_create= world_create;
+}
+
memcached_increment(memc,
test_literal_param("number"),
1, &new_number));
- test_compare(1UL, new_number);
+ test_compare(uint64_t(1), new_number);
test_compare(MEMCACHED_SUCCESS,
memcached_increment(memc,
test_literal_param("number"),
1, &new_number));
- test_compare(2UL, new_number);
+ test_compare(uint64_t(2), new_number);
memcached_st *clone= memcached_clone(NULL, memc);
memcached_increment(clone,
test_literal_param("number"),
1, &new_number));
- test_compare(11UL, new_number);
+ test_compare(uint64_t(11), new_number);
test_compare(MEMCACHED_SUCCESS,
memcached_increment(memc,
test_literal_param("number"),
1, &new_number));
- test_compare(3UL, new_number);
+ test_compare(uint64_t(3), new_number);
memcached_free(clone);
memcached_return_t rc;
char buffer[BUFSIZ];
- rc= libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer));
- test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+ test_compare(MEMCACHED_SUCCESS,
+ libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer)));
rc= libmemcached_check_configuration(test_literal_param("--dude=localhost"), buffer, sizeof(buffer));
test_false_with(rc == MEMCACHED_SUCCESS, buffer);
return TEST_SKIPPED;
char buffer[BUFSIZ];
- memcached_return_t rc;
- rc= libmemcached_check_configuration(test_literal_param("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer));
- test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+ test_compare(MEMCACHED_SUCCESS,
+ libmemcached_check_configuration(test_literal_param("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer)));
return TEST_SUCCESS;
}
test_return_t test_end_keyword(memcached_st*)
{
char buffer[BUFSIZ];
- memcached_return_t rc;
- rc= libmemcached_check_configuration(test_literal_param("--server=localhost END bad keywords"), buffer, sizeof(buffer));
- test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+ test_compare(MEMCACHED_SUCCESS,
+ libmemcached_check_configuration(test_literal_param("--server=localhost END bad keywords"), buffer, sizeof(buffer)));
return TEST_SUCCESS;
}
test_return_t test_reset_keyword(memcached_st*)
{
char buffer[BUFSIZ];
- memcached_return_t rc;
- rc= libmemcached_check_configuration(test_literal_param("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer));
- test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+ test_compare(MEMCACHED_SUCCESS,
+ libmemcached_check_configuration(test_literal_param("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer)));
return TEST_SUCCESS;
}
return TEST_SKIPPED;
{ // Test the connect-timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE
- memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=0"));
+ memcached_st *memc= memcached(test_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=0"));
test_true(memc);
test_zero(memc->connect_timeout);
test_compare(MEMCACHED_DEFAULT_TIMEOUT, memc->poll_timeout);
memcached_return_t rc;
size_t value_len;
- char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc);
+ char *value= memcached_get(memc, test_literal_param("test"), &value_len, NULL, &rc);
test_false(value);
test_zero(value_len);
- test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc));
+ test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
memcached_free(memc);
}
return TEST_SKIPPED;
{ // Test the poll timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE
- memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0"));
+ memcached_st *memc= memcached(test_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0"));
test_true(memc);
test_compare(MEMCACHED_DEFAULT_CONNECT_TIMEOUT, memc->connect_timeout);
test_zero(memc->poll_timeout);
memcached_return_t rc;
size_t value_len;
- char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc);
+ char *value= memcached_get(memc, test_literal_param("test"), &value_len, NULL, &rc);
test_false(value);
test_zero(value_len);
- test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc));
+ test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
memcached_free(memc);
}
test_compare(int_inc_value, int_ret_value);
test_true(mcach.increment(key, 1, &int_ret_value));
- test_compare(2UL, int_ret_value);
+ test_compare(uint64_t(2), int_ret_value);
test_true(mcach.increment(key, 1, &int_ret_value));
- test_compare(3UL, int_ret_value);
+ test_compare(uint64_t(3), int_ret_value);
test_true(mcach.increment(key, 5, &int_ret_value));
- test_compare(8UL, int_ret_value);
+ test_compare(uint64_t(8), int_ret_value);
return TEST_SUCCESS;
}
// Make one copy
test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc_replicated, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 1UL));
- test_compare(1UL, memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS));
+ test_compare(uint64_t(1), memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS));
test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc_not_replicate, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0UL));
- test_compare(0UL, memcached_behavior_get(memc_not_replicate, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS));
+ test_compare(uint64_t(0), memcached_behavior_get(memc_not_replicate, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS));
for (size_t x= 0; x < test_array_length(keys); ++x)
{