#endif
LIBMEMCACHED_API
- const char *memcached_last_error_message(memcached_st *);
+ const char *memcached_last_error_message(const memcached_st *);
LIBMEMCACHED_API
void memcached_error_print(const memcached_st *);
LIBMEMCACHED_API
- memcached_return_t memcached_last_error(memcached_st *);
+ memcached_return_t memcached_last_error(const memcached_st *);
LIBMEMCACHED_API
- int memcached_last_error_errno(memcached_st *);
+ int memcached_last_error_errno(const memcached_st *);
LIBMEMCACHED_API
- const char *memcached_server_error(memcached_server_instance_st ptr);
+ const char *memcached_server_error(const memcached_server_instance_st ptr);
LIBMEMCACHED_API
- memcached_return_t memcached_server_error_return(memcached_server_instance_st ptr);
+ memcached_return_t memcached_server_error_return(const memcached_server_instance_st ptr);
#ifdef __cplusplus
} // extern "C"
*
* Libmemcached library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* Copyright (C) 2010 Brian Aker All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#endif
LIBMEMCACHED_API
-const char *memcached_strerror(memcached_st *ptr, memcached_return_t rc);
+const char *memcached_strerror(const memcached_st *ptr, memcached_return_t rc);
#ifdef __cplusplus
}
uint32_t read;
uint32_t write;
uint32_t timeouts;
+ size_t _bytes_read;
} io_wait_count;
uint8_t major_version; // Default definition of UINT8_MAX means that it has not been set.
uint8_t micro_version; // ditto, and note that this is the third, not second version bit
static void _set(memcached_server_st& server, memcached_st& memc)
{
- if (server.error_messages && server.error_messages->query_id != server.root->query_id)
+ if (server.error_messages and server.error_messages->query_id != server.root->query_id)
{
memcached_error_free(server);
}
return memcached_set_error(memc, MEMCACHED_PARSE_ERROR, at, buffer, length);
}
+static inline size_t append_host_to_string(memcached_server_st& self, char* buffer, const size_t buffer_length)
+{
+ size_t size= 0;
+ switch (self.type)
+ {
+ case MEMCACHED_CONNECTION_TCP:
+ case MEMCACHED_CONNECTION_UDP:
+ size+= snprintf(buffer, buffer_length, " host: %s:%d",
+ self.hostname, int(self.port));
+ break;
+
+ case MEMCACHED_CONNECTION_UNIX_SOCKET:
+ size+= snprintf(buffer, buffer_length, " socket: %s",
+ self.hostname);
+ break;
+ }
+
+ return size;
+}
+
memcached_return_t memcached_set_error(memcached_server_st& self, memcached_return_t rc, const char *at, memcached_string_t& str)
{
assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client");
}
char hostname_port_message[MAX_ERROR_LENGTH];
- int size;
+ char* hostname_port_message_ptr= hostname_port_message;
+ int size= 0;
if (str.size)
{
- size= snprintf(hostname_port_message, sizeof(hostname_port_message), "%.*s, host: %s:%d",
- memcached_string_printf(str),
- self.hostname, int(self.port));
- }
- else
- {
- size= snprintf(hostname_port_message, sizeof(hostname_port_message), "host: %s:%d",
- self.hostname, int(self.port));
+ size= snprintf(hostname_port_message_ptr, sizeof(hostname_port_message), "%.*s, ",
+ memcached_string_printf(str));
+ hostname_port_message_ptr+= size;
}
+ size+= append_host_to_string(self, hostname_port_message_ptr, sizeof(hostname_port_message) -size);
+
memcached_string_t error_host= { hostname_port_message, size };
assert(self.root);
}
char hostname_port[NI_MAXHOST +NI_MAXSERV + sizeof("host : ")];
- int size= snprintf(hostname_port, sizeof(hostname_port), "host: %s:%d", self.hostname, int(self.port));
+ size_t size= append_host_to_string(self, hostname_port, sizeof(hostname_port));
memcached_string_t error_host= { hostname_port, size};
}
char hostname_port_message[MAX_ERROR_LENGTH];
- int size;
+ char* hostname_port_message_ptr= hostname_port_message;
+ size_t size= 0;
if (str.size)
{
- size= snprintf(hostname_port_message, sizeof(hostname_port_message), "%.*s, host: %s:%d",
- memcached_string_printf(str),
- self.hostname, int(self.port));
- }
- else
- {
- size= snprintf(hostname_port_message, sizeof(hostname_port_message), "host: %s:%d",
- self.hostname, int(self.port));
+ size= snprintf(hostname_port_message_ptr, sizeof(hostname_port_message), "%.*s, ", memcached_string_printf(str));
}
+ size+= append_host_to_string(self, hostname_port_message_ptr, sizeof(hostname_port_message) -size);
memcached_string_t error_host= { hostname_port_message, size };
}
char hostname_port_message[MAX_ERROR_LENGTH];
- int size = snprintf(hostname_port_message, sizeof(hostname_port_message), "host: %s:%d",
- self.hostname, int(self.port));
+ size_t size= append_host_to_string(self, hostname_port_message, sizeof(hostname_port_message));
memcached_string_t error_host= { hostname_port_message, size };
self.error_messages= NULL;
}
-const char *memcached_last_error_message(memcached_st *memc)
+const char *memcached_last_error_message(const memcached_st *memc)
{
if (memc == NULL)
{
return memcached_has_current_error(*(server.root));
}
-memcached_return_t memcached_last_error(memcached_st *memc)
+memcached_return_t memcached_last_error(const memcached_st *memc)
{
if (memc == NULL)
{
return memc->error_messages->rc;
}
-int memcached_last_error_errno(memcached_st *memc)
+int memcached_last_error_errno(const memcached_st *memc)
{
if (memc == NULL)
{
return memc->error_messages->local_errno;
}
-const char *memcached_server_error(memcached_server_instance_st server)
+const char *memcached_server_error(const memcached_server_instance_st server)
{
if (server == NULL)
{
for blocking I/O we do not return 0 and for non-blocking case
it will return EGAIN if data is not immediatly available.
*/
- WATCHPOINT_STRING("We had a zero length recv()");
memcached_quit_server(ptr, true);
nread= -1;
return memcached_set_error(*ptr, MEMCACHED_CONNECTION_FAILURE, MEMCACHED_AT,
memcached_literal_param("::rec() returned zero, server has disconnected"));
}
+ ptr->io_wait_count._bytes_read+= data_read;
} while (data_read <= 0);
- ptr->io_bytes_sent = 0;
+ ptr->io_bytes_sent= 0;
ptr->read_data_length= (size_t) data_read;
ptr->read_buffer_length= (size_t) data_read;
ptr->read_ptr= ptr->read_buffer;
self->io_wait_count.read= 0;
self->io_wait_count.write= 0;
self->io_wait_count.timeouts= 0;
+ self->io_wait_count._bytes_read= 0;
self->major_version= UINT8_MAX;
self->micro_version= UINT8_MAX;
self->minor_version= UINT8_MAX;
{
WATCHPOINT_ASSERT(self);
if (self == NULL)
+ {
return 0;
+ }
return self->port;
}
{
WATCHPOINT_ASSERT(self);
if (self == NULL)
+ {
return 0;
+ }
return self->cursor_active;
}
#include <libmemcached/common.h>
-const char *memcached_strerror(memcached_st *, memcached_return_t rc)
+const char *memcached_strerror(const memcached_st *, memcached_return_t rc)
{
switch (rc)
{
output << memcached_strerror(NULL, arg);
return output;
}
+
+static inline std::ostream& operator<<(std::ostream& output, const memcached_st &arg)
+{
+ output << " query_id: " << memcached_query_id(&arg);
+ output << " error: " << memcached_last_error_message(&arg);
+ return output;
+}
catch (libtest::fatal &e)
{
Error << "Fatal exception was thrown: " << e.what();
+ stream::cerr(__FILE__, __LINE__, __func__) << e.what();
_failed++;
throw;
}
strncpy(_mesg, last_error, sizeof(_mesg));
- snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, int(_line), last_error, _func);
+ snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func);
}
static bool _disabled= false;
_counter++;
}
-disconnected::disconnected(const char *file, int line, const char *func, const char *instance, const in_port_t port, const char *format, ...) :
+disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg,
+ const char *instance, const in_port_t port,
+ const char *format, ...) :
+ std::runtime_error(func_arg),
_port(port),
- std::runtime_error(func)
+ _line(line_arg),
+ _file(file_arg),
+ _func(func_arg)
{
strncpy(_instance, instance, sizeof(_instance));
va_list args;
(void)vsnprintf(last_error, sizeof(last_error), format, args);
va_end(args);
- snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", file, int(line), last_error, func);
+ snprintf(_error_message, sizeof(_error_message), "%s:%d FATAL:%s (%s)", _file, _line, last_error, _func);
}
} // namespace libtest
static uint32_t disabled_counter();
static void increment_disabled_counter();
+ int line()
+ {
+ return _line;
+ }
+
+ const char* file()
+ {
+ return _file;
+ }
+
+ const char* func()
+ {
+ return _func;
+ }
+
private:
char _error_message[BUFSIZ];
in_port_t _port;
char _instance[1024];
+ int _line;
+ const char* _file;
+ const char* _func;
};
{
std::stringstream arg_buffer;
- if (getenv("PWD"))
+ if (getenv("PWD") and strcmp(MEMCACHED_BINARY, "memcached/memcached") == 0)
{
arg_buffer << getenv("PWD");
arg_buffer << "/";
}
arg_buffer << MEMCACHED_BINARY;
+ std::cout << "Value: " << arg_buffer.str() << std::endl;
if (access(arg_buffer.str().c_str(), X_OK) == 0)
{
return true;
}
+ std::cout << "Access was not 0 : " << strerror(errno) << std::endl;
}
return false;
break;
case TEST_SKIPPED:
- Out << "SKIP " << argv[0];
return EXIT_SKIP;
case TEST_FAILURE:
#define test_compare_got(__expected, __actual, __hint) \
do \
{ \
- if (not libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint))) \
+ if (libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint)) == false) \
{ \
libtest::create_core(); \
return TEST_FAILURE; \
#pragma once
-#include <tests/libmemcached-1.0/memcached_get.h>
+#include "tests/libmemcached-1.0/memcached_get.h"
/* Clean the server before beginning testing */
{"memcached_set()", false, (test_callback_fn*)set_test },
{"memcached_set() 2", false, (test_callback_fn*)set_test2 },
{"memcached_set() 3", false, (test_callback_fn*)set_test3 },
+ {"memcached_add(SUCCESS)", true, (test_callback_fn*)memcached_add_SUCCESS_TEST },
{"add", true, (test_callback_fn*)add_test },
{"memcached_fetch_result(MEMCACHED_NOTFOUND)", true, (test_callback_fn*)memcached_fetch_result_NOT_FOUND },
{"replace", true, (test_callback_fn*)replace_test },
};
test_st libmemcachedutil_tests[] ={
- {"libmemcached_util_ping()", true, (test_callback_fn*)ping_test },
+ {"libmemcached_util_ping()", true, (test_callback_fn*)libmemcached_util_ping_TEST },
{"libmemcached_util_getpid()", true, (test_callback_fn*)getpid_test },
{"libmemcached_util_getpid(MEMCACHED_CONNECTION_FAILURE)", true, (test_callback_fn*)getpid_connection_failure_test },
{0, 0, 0}
return TEST_SUCCESS;
}
+/*
+ Set the value, then quit to make sure it is flushed.
+ Come back in and test that add fails.
+*/
+test_return_t memcached_add_SUCCESS_TEST(memcached_st *memc)
+{
+ memcached_return_t rc;
+ test_null(memcached_get(memc, test_literal_param(__func__), NULL, NULL, &rc));
+ test_compare(MEMCACHED_NOTFOUND, rc);
+
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_add(memc,
+ test_literal_param(__func__),
+ test_literal_param("try something else"),
+ time_t(0), uint32_t(0)));
+
+ return TEST_SUCCESS;
+}
+
/*
Set the value, then quit to make sure it is flushed.
Come back in and test that add fails.
*/
test_return_t add_test(memcached_st *memc)
{
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- test_literal_param("when we sanitize"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc,
+ test_literal_param(__func__),
+ test_literal_param("when we sanitize"),
+ time_t(0), uint32_t(0)));
memcached_quit(memc);
- test_compare_hint(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) ? MEMCACHED_DATA_EXISTS : MEMCACHED_NOTSTORED,
- memcached_add(memc,
- test_literal_param(__func__),
- test_literal_param("try something else"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ size_t value_length;
+ uint32_t flags;
+ memcached_return_t rc;
+ char *check_value= memcached_get(memc,
+ test_literal_param(__func__),
+ &value_length, &flags, &rc);
+ test_memcmp(check_value, "when we sanitize", strlen("when we sanitize"));
+ test_compare(test_literal_param_size("when we sanitize"), value_length);
+ test_compare(MEMCACHED_SUCCESS, rc);
+ free(check_value);
+
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) ? MEMCACHED_DATA_EXISTS : MEMCACHED_NOTSTORED,
+ memcached_add(memc,
+ test_literal_param(__func__),
+ test_literal_param("try something else"),
+ time_t(0), uint32_t(0)));
return TEST_SUCCESS;
}
#endif
for (uint32_t x= 0; x < max; x++)
+ {
add_test(memc);
+ }
return TEST_SUCCESS;
}
test_return_t replace_test(memcached_st *memc)
{
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- test_literal_param("when we sanitize"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc,
+ test_literal_param(__func__),
+ test_literal_param("when we sanitize"),
+ time_t(0), uint32_t(0)));
- test_compare_hint(MEMCACHED_SUCCESS,
- memcached_replace(memc,
- test_literal_param(__func__),
- test_literal_param("first we insert some data"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_replace(memc,
+ test_literal_param(__func__),
+ test_literal_param("first we insert some data"),
+ time_t(0), uint32_t(0)));
return TEST_SUCCESS;
}
test_return_t delete_test(memcached_st *memc)
{
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- test_literal_param("when we sanitize"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc,
+ test_literal_param(__func__),
+ test_literal_param("when we sanitize"),
+ time_t(0), uint32_t(0)));
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_delete(memc,
- test_literal_param(__func__),
- time_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_delete(memc,
+ test_literal_param(__func__),
+ time_t(0)));
return TEST_SUCCESS;
}
{
for (uint32_t x= 0; x < 10; x++)
{
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param("foo"),
- test_literal_param("train in the brain"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc,
+ test_literal_param("foo"),
+ test_literal_param("train in the brain"),
+ time_t(0), uint32_t(0)));
}
return TEST_SUCCESS;
snprintf(key, sizeof(key), "foo%u", x);
uint64_t query_id= memcached_query_id(memc);
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc, key, strlen(key),
- &value[0], value.size(),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc, key, strlen(key),
+ &value[0], value.size(),
+ time_t(0), uint32_t(0)));
test_compare(query_id +1, memcached_query_id(memc));
}
test_literal_param(__func__),
test_literal_param("3"),
time_t(0), uint32_t(0)));
+
// Make sure we flush the value we just set
test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc));
{
const char *value= "sanford and sun";
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- value, strlen(value),
- (time_t)10, (uint32_t)3),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc,
+ test_literal_param(__func__),
+ value, strlen(value),
+ time_t(10), uint32_t(3)));
memcached_quit(memc);
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- value, strlen(value),
- (time_t)50, (uint32_t)9),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc,
+ test_literal_param(__func__),
+ value, strlen(value),
+ time_t(50), uint32_t(9)));
return TEST_SUCCESS;
}
size_t key_length[]= {5, 3, 4};
memcached_result_st results_obj;
- memcached_result_st *results;
-
- results= memcached_result_create(memc, &results_obj);
+ memcached_result_st *results= memcached_result_create(memc, &results_obj);
test_true(results);
test_true(&results_obj == results);
const char *keys= "036790384900";
size_t key_length= strlen(keys);
- test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length,
- insert_data, VALUE_SIZE_BUG5,
- time_t(0), 245U),
- memcached_last_error_message(memc));
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length,
+ insert_data, VALUE_SIZE_BUG5,
+ time_t(0), 245U));
memcached_return_t rc;
size_t value_length;
char *value2= memcached_get(memc, key, strlen(key),
&length, &flags, &rc);
- test_true(length==strlen(value));
+ test_compare(length, strlen(value));
test_compare(MEMCACHED_SUCCESS, rc);
test_memcmp(value, value2, length);
free(value2);
return TEST_SUCCESS;
}
-test_return_t ping_test(memcached_st *memc)
+static memcached_return_t ping_each_server(const memcached_st*,
+ const memcached_server_st *instance,
+ void*)
{
+ // Test both the version that returns a code, and the one that does not.
memcached_return_t rc;
- memcached_server_instance_st instance=
- memcached_server_instance_by_position(memc, 0);
+ if (libmemcached_util_ping(memcached_server_name(instance),
+ memcached_server_port(instance), &rc) == false)
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s:%d %s", memcached_server_name(instance),
+ memcached_server_port(instance), memcached_strerror(NULL, rc));
+ }
- // Test both the version that returns a code, and the one that does not.
- test_true(libmemcached_util_ping(memcached_server_name(instance),
- memcached_server_port(instance), NULL));
+ if (libmemcached_util_ping(memcached_server_name(instance),
+ memcached_server_port(instance), NULL) == false)
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s:%d", memcached_server_name(instance), memcached_server_port(instance));
+ }
- test_true(libmemcached_util_ping(memcached_server_name(instance),
- memcached_server_port(instance), &rc));
+ return MEMCACHED_SUCCESS;
+}
- test_compare(MEMCACHED_SUCCESS, rc);
+test_return_t libmemcached_util_ping_TEST(memcached_st *memc)
+{
+ memcached_server_fn callbacks[1]= { ping_each_server };
+ memcached_server_cursor(memc, callbacks, NULL, 1);
return TEST_SUCCESS;
}
test_return_t _user_supplied_bug21(memcached_st* memc, size_t key_count);
test_return_t add_host_test(memcached_st *memc);
test_return_t add_host_test1(memcached_st *memc);
+test_return_t memcached_add_SUCCESS_TEST(memcached_st*);
test_return_t add_test(memcached_st *memc);
test_return_t add_wrapper(memcached_st *memc);
test_return_t allocation_test(memcached_st *not_used);
test_return_t noreply_test(memcached_st *memc);
test_return_t one_at_a_time_run (memcached_st *);
test_return_t output_ketama_weighted_keys(memcached_st *);
-test_return_t ping_test(memcached_st *memc);
+test_return_t libmemcached_util_ping_TEST(memcached_st*);
test_return_t prepend_test(memcached_st *memc);
test_return_t quit_test(memcached_st *memc);
test_return_t read_through(memcached_st *memc);
uint32_t flags;
size_t rlen;
- test_compare_hint(return_value_based_on_buffering(memc),
+ test_compare(return_value_based_on_buffering(memc),
memcached_set(memc, keys[0], lengths[0],
keys[0], lengths[0],
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ time_t(0), uint32_t(0)));
test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys)));
memcached_result_st results_obj;