tests/testhashkit
tests/testplus
tests/testudp
+unittests/unittests
0.41
* Added --file for memcat.
* Added limemcached_ping() to libmemcached_util
+ * Bugfix for some cases where connect would have issues with timeout.
+ * Wrong value for errno given as error on an IO failure inside of poll.
+ * Bug fix for issue where multiple interfaces with bad DNS were not being caught.
0.40 Thu Apr 22 19:01:25 PDT 2010
* Placed retry logic in for busted resolvers
include libmemcached/include.am
include clients/include.am
include libhashkit/include.am
+include unittests/include.am
include tests/include.am
include example/include.am
include support/include.am
Return the number of rows set.
*/
-#include "libmemcached/common.h"
-
+#include "config.h"
#include "execute.h"
unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of)
rc= memcached_mget_execute(memc, keys, key_length,
(size_t)number_of, callbacks, &retrieved, 1);
- likely (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND ||
+ if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND ||
rc == MEMCACHED_BUFFERED || rc == MEMCACHED_END)
{
rc= memcached_fetch_execute(memc, callbacks, (void *)&retrieved, 1);
- unlikely (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND &&
- rc != MEMCACHED_END)
+ if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTFOUND && rc != MEMCACHED_END)
{
fprintf(stderr, "Failed to execute mget: %s\n",
memcached_strerror(memc, rc));
#ifndef CLIENTS_EXECUTE_H
#define CLIENTS_EXECUTE_H
+
+#include <stdio.h>
+
#include "libmemcached/memcached.h"
#include "generator.h"
*
*/
-#include "libmemcached/common.h"
+#include "config.h"
#include <stdio.h>
#include <stdlib.h>
*
*/
-#include "libmemcached/common.h"
+#include "config.h"
+
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
*
*/
-#include "libmemcached/common.h"
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
/* Check for various possible errors */
- if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
+ if ((errno == ERANGE && (val == INTMAX_MAX || val == INTMAX_MIN))
|| (errno != 0 && val == 0))
{
*error= true;
*
*/
-#include "libmemcached/common.h"
+#include "config.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
* Summary:
*
*/
+#include "config.h"
-#include "libmemcached/common.h"
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
* Summary:
*
*/
+#include "config.h"
-#include "libmemcached/common.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
* Summary:
*
*/
+#include "config.h"
-#include "libmemcached/common.h"
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
* Brian Aker
* Toru Maesaka
*/
+#include "config.h"
-#include "libmemcached/common.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
* Summary:
*
*/
+#include "config.h"
-#include "libmemcached/common.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <getopt.h>
#include <libmemcached/memcached.h>
+#include "libmemcached/watchpoint.h"
#include "client_options.h"
#if TIME_WITH_SYS_TIME
ptr->server_failure_limit= (uint32_t)data;
break;
case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL:
+ memcached_quit(ptr); // We need t shutdown all of the connections to make sure we do the correct protocol
if (data)
{
ptr->flags.verify_key= false;
typedef enum {
MEM_NOT= -1,
MEM_FALSE= false,
- MEM_TRUE= true,
+ MEM_TRUE= true
} memcached_ternary_t;
+/* LibMemcached
+ * Copyright (C) 2006-2010 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ *
+ * Summary: Server IO, Not public!
+ *
+ */
+
#include "common.h"
#include <netdb.h>
#include <poll.h>
#include <sys/time.h>
#include <time.h>
+static memcached_return_t connect_poll(memcached_server_st *ptr)
+{
+ struct pollfd fds[1];
+ fds[0].fd = ptr->fd;
+ fds[0].events = POLLOUT;
+
+ int timeout= ptr->root->connect_timeout;
+ if (ptr->root->flags.no_block == true)
+ timeout= -1;
+
+ int error;
+ size_t loop_max= 5;
+
+ while (--loop_max) // Should only loop on cases of ERESTART or EINTR
+ {
+ error= poll(fds, 1, timeout);
+
+ switch (error)
+ {
+ case 1:
+ {
+ int err;
+ socklen_t len= sizeof (err);
+ (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
+
+ // We check the value to see what happened wth the socket.
+ if (err == 0)
+ {
+ return MEMCACHED_SUCCESS;
+ }
+ else
+ {
+ ptr->cached_errno= errno;
+
+ return MEMCACHED_ERRNO;
+ }
+ }
+ case 0:
+ return MEMCACHED_TIMEOUT;
+ default: // A real error occurred and we need to completely bail
+ WATCHPOINT_ERRNO(errno);
+ switch (errno)
+ {
+#ifdef TARGET_OS_LINUX
+ case ERESTART:
+#endif
+ case EINTR:
+ continue;
+ default:
+ if (fds[0].revents & POLLERR)
+ {
+ int err;
+ socklen_t len= sizeof (err);
+ (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
+ ptr->cached_errno= (err == 0) ? errno : err;
+ }
+ else
+ {
+ ptr->cached_errno= errno;
+ }
+
+ (void)close(ptr->fd);
+ ptr->fd= -1;
+
+ return MEMCACHED_ERRNO;
+ }
+ }
+ WATCHPOINT_ASSERT(0); // Programming error
+ }
+
+ // This should only be possible from ERESTART or EINTR;
+ ptr->cached_errno= errno;
+
+ return MEMCACHED_ERRNO;
+}
+
static memcached_return_t set_hostinfo(memcached_server_st *server)
{
struct addrinfo *ai;
{
struct sockaddr_un servAddr;
- if (ptr->fd == -1)
+ WATCHPOINT_ASSERT(ptr->fd == -1);
+
+ if ((ptr->fd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
- if ((ptr->fd= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
- {
- ptr->cached_errno= errno;
- return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
- }
+ ptr->cached_errno= errno;
+ return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
+ }
- memset(&servAddr, 0, sizeof (struct sockaddr_un));
- servAddr.sun_family= AF_UNIX;
- strcpy(servAddr.sun_path, ptr->hostname); /* Copy filename */
+ memset(&servAddr, 0, sizeof (struct sockaddr_un));
+ servAddr.sun_family= AF_UNIX;
+ strcpy(servAddr.sun_path, ptr->hostname); /* Copy filename */
test_connect:
- if (connect(ptr->fd,
- (struct sockaddr *)&servAddr,
- sizeof(servAddr)) < 0)
+ if (connect(ptr->fd,
+ (struct sockaddr *)&servAddr,
+ sizeof(servAddr)) < 0)
+ {
+ switch (errno)
{
- switch (errno)
- {
- case EINPROGRESS:
- case EALREADY:
- case EINTR:
- goto test_connect;
- case EISCONN: /* We were spinning waiting on connect */
- break;
- default:
- WATCHPOINT_ERRNO(errno);
- ptr->cached_errno= errno;
- return MEMCACHED_ERRNO;
- }
+ case EINPROGRESS:
+ case EALREADY:
+ case EINTR:
+ goto test_connect;
+ case EISCONN: /* We were spinning waiting on connect */
+ break;
+ default:
+ WATCHPOINT_ERRNO(errno);
+ ptr->cached_errno= errno;
+ return MEMCACHED_ERRNO;
}
}
static memcached_return_t network_connect(memcached_server_st *ptr)
{
- if (ptr->fd == -1)
+ bool timeout_error_occured= false;
+
+
+ WATCHPOINT_ASSERT(ptr->fd == -1);
+ WATCHPOINT_ASSERT(ptr->cursor_active == 0);
+
+ if (! ptr->options.sockaddr_inited || (!(ptr->root->flags.use_cache_lookups)))
{
- struct addrinfo *use;
+ memcached_return_t rc;
- WATCHPOINT_ASSERT(ptr->cursor_active == 0);
+ rc= set_hostinfo(ptr);
+ if (rc != MEMCACHED_SUCCESS)
+ return rc;
+ ptr->options.sockaddr_inited= true;
+ }
- if (! ptr->options.sockaddr_inited ||
- (!(ptr->root->flags.use_cache_lookups)))
+ struct addrinfo *use= ptr->address_info;
+ /* Create the socket */
+ while (use != NULL)
+ {
+ /* Memcache server does not support IPV6 in udp mode, so skip if not ipv4 */
+ if (ptr->type == MEMCACHED_CONNECTION_UDP && use->ai_family != AF_INET)
{
- memcached_return_t rc;
-
- rc= set_hostinfo(ptr);
- if (rc != MEMCACHED_SUCCESS)
- return rc;
- ptr->options.sockaddr_inited= true;
+ use= use->ai_next;
+ continue;
}
- use= ptr->address_info;
- /* Create the socket */
- while (use != NULL)
+ if ((ptr->fd= socket(use->ai_family,
+ use->ai_socktype,
+ use->ai_protocol)) < 0)
{
- /* Memcache server does not support IPV6 in udp mode, so skip if not ipv4 */
- if (ptr->type == MEMCACHED_CONNECTION_UDP && use->ai_family != AF_INET)
- {
- use= use->ai_next;
- continue;
- }
-
- if ((ptr->fd= socket(use->ai_family,
- use->ai_socktype,
- use->ai_protocol)) < 0)
- {
- ptr->cached_errno= errno;
- WATCHPOINT_ERRNO(errno);
- return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
- }
-
- (void)set_socket_options(ptr);
+ ptr->cached_errno= errno;
+ WATCHPOINT_ERRNO(errno);
+ return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
+ }
- /* connect to server */
- if ((connect(ptr->fd, use->ai_addr, use->ai_addrlen) == -1))
- {
- ptr->cached_errno= errno;
- if (errno == EINPROGRESS || /* nonblocking mode - first return, */
- errno == EALREADY) /* nonblocking mode - subsequent returns */
- {
- struct pollfd fds[1];
- fds[0].fd = ptr->fd;
- fds[0].events = POLLOUT;
-
- int timeout= ptr->root->connect_timeout;
- if (ptr->root->flags.no_block == true)
- timeout= -1;
-
- size_t loop_max= 5;
- while (--loop_max)
- {
- int error= poll(fds, 1, timeout);
-
- switch (error)
- {
- case 1:
- loop_max= 1;
- break;
- case 0:
- if (loop_max==1)
- return MEMCACHED_TIMEOUT;
- continue;
- // A real error occurred and we need to completely bail
- default:
- WATCHPOINT_ERRNO(errno);
- switch (errno)
- {
-#ifdef TARGET_OS_LINUX
- case ERESTART:
-#endif
- case EINTR:
- continue;
- default:
- if (fds[0].revents & POLLERR)
- {
- int err;
- socklen_t len= sizeof (err);
- (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
- ptr->cached_errno= (err == 0) ? errno : err;
- }
-
- (void)close(ptr->fd);
- ptr->fd= -1;
-
- break;
- }
- }
- }
- }
- else if (errno == EISCONN) /* we are connected :-) */
- {
- break;
- }
- else if (errno != EINTR)
- {
- (void)close(ptr->fd);
- ptr->fd= -1;
- break;
- }
- }
+ (void)set_socket_options(ptr);
-#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
- if (ptr->fd != -1 && ptr->root->sasl && ptr->root->sasl->callbacks)
- {
- memcached_return rc= memcached_sasl_authenticate_connection(ptr);
- if (rc != MEMCACHED_SUCCESS)
- {
- (void)close(ptr->fd);
- ptr->fd= -1;
+ /* connect to server */
+ if ((connect(ptr->fd, use->ai_addr, use->ai_addrlen) > -1))
+ {
+ break; // Success
+ }
- return rc;
- }
- }
-#endif
+ /* An error occurred */
+ ptr->cached_errno= errno;
+ if (errno == EINPROGRESS || /* nonblocking mode - first return, */
+ errno == EALREADY) /* nonblocking mode - subsequent returns */
+ {
+ memcached_return_t rc;
+ rc= connect_poll(ptr);
+ if (rc == MEMCACHED_TIMEOUT)
+ timeout_error_occured= true;
- if (ptr->fd != -1)
- {
- return MEMCACHED_SUCCESS;
- }
- use = use->ai_next;
+ if (rc == MEMCACHED_SUCCESS)
+ break;
+ }
+ else if (errno == EISCONN) /* we are connected :-) */
+ {
+ break;
}
+ else if (errno == EINTR) // Special case, we retry ai_addr
+ {
+ (void)close(ptr->fd);
+ ptr->fd= -1;
+ continue;
+ }
+
+ (void)close(ptr->fd);
+ ptr->fd= -1;
+ use= use->ai_next;
}
if (ptr->fd == -1)
ptr->next_retry= next_time.tv_sec + ptr->root->retry_timeout;
}
- if (ptr->cached_errno == 0)
+ if (timeout_error_occured)
return MEMCACHED_TIMEOUT;
return MEMCACHED_ERRNO; /* The last error should be from connect() */
memcached_return_t memcached_connect(memcached_server_write_instance_st ptr)
{
memcached_return_t rc= MEMCACHED_NO_SERVERS;
+
+ if (ptr->fd > -1)
+ return MEMCACHED_SUCCESS;
+
LIBMEMCACHED_MEMCACHED_CONNECT_START();
/* both retry_timeout and server_failure_limit must be set in order to delay retrying a server on error. */
case MEMCACHED_CONNECTION_UDP:
case MEMCACHED_CONNECTION_TCP:
rc= network_connect(ptr);
+#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+ if (ptr->fd != -1 && ptr->root->sasl && ptr->root->sasl->callbacks)
+ {
+ rc= memcached_sasl_authenticate_connection(ptr);
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ (void)close(ptr->fd);
+ ptr->fd= -1;
+ }
+ }
+#endif
break;
case MEMCACHED_CONNECTION_UNIX_SOCKET:
rc= unix_socket_connect(ptr);
if (ptr->flags.binary_protocol)
{
- likely (!expiration)
+ likely (! expiration)
{
rc= binary_delete(ptr, server_key, key, key_length, to_write);
}
if DTRACE_NEEDS_OBJECTS
libmemcached_libmemcached_la_SOURCES += libmemcached/libmemcached_probes.d
libmemcached_libmemcached_la_DEPENDENCIES += libmemcached/libmemcached_probes.o
+CLEANFILES+= libmemcached/libmemcached_probes.o
endif
SUFFIXES+= .d
libmemcached/dtrace_probes.h: libmemcached/libmemcached_probes.d
$(DTRACE) $(DTRACEFLAGS) -h -o libmemcached/dtrace_probes.h -s ${top_srcdir}/libmemcached/libmemcached_probes.d
-libmemcached/libmemcached_probes.o: libmemcached/libmemcached_probes.d ${libmemcached_libmemcached_OBJECTS} config.h
+libmemcached/libmemcached_probes.o: libmemcached/libmemcached_probes.d ${libmemcached_libmemcached_la_OBJECTS} config.h
.d.o:
$(DTRACE) $(DTRACEFLAGS) -o libmemcached/libmemcached_probes.o -G -s ${top_srcdir}/libmemcached/libmemcached_probes.d `grep '^pic_object' ${top_builddir}/libmemcached/*.lo | cut -f 2 -d\' | sed "s/^/${top_builddir}\//"`
timeout= -1;
size_t loop_max= 5;
- while (--loop_max)
+ while (--loop_max) // While loop is for ERESTART or EINTR
{
error= poll(&fds, 1, timeout);
switch (error)
{
- case 1:
+ case 1: // Success!
WATCHPOINT_IF_LABELED_NUMBER(read_or_write && loop_max < 4, "read() times we had to loop, decremented down from 5", loop_max);
WATCHPOINT_IF_LABELED_NUMBER(!read_or_write && loop_max < 4, "write() times we had to loop, decremented down from 5", loop_max);
return MEMCACHED_SUCCESS;
- case 0:
+ case 0: // Timeout occured, we let the while() loop do its thing.
return MEMCACHED_TIMEOUT;
default:
WATCHPOINT_ERRNO(errno);
+ switch (errno)
{
- switch (errno)
- {
#ifdef TARGET_OS_LINUX
- case ERESTART:
+ case ERESTART:
#endif
- case EINTR:
- continue;
- default:
- ptr->cached_errno= error;
- memcached_quit_server(ptr, true);
-
- return MEMCACHED_FAILURE;
+ case EINTR:
+ break;
+ default:
+ if (fds.revents & POLLERR)
+ {
+ int err;
+ socklen_t len= sizeof (err);
+ (void)getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &err, &len);
+ ptr->cached_errno= (err == 0) ? errno : err;
}
+ else
+ {
+ ptr->cached_errno= errno;
+ }
+ memcached_quit_server(ptr, true);
+
+ return MEMCACHED_FAILURE;
}
}
}
- if (loop_max == 0 && error == 0)
- return MEMCACHED_TIMEOUT;
-
/* Imposssible for anything other then -1 */
WATCHPOINT_ASSERT(error == -1);
- ptr->cached_errno= error;
+ ptr->cached_errno= errno;
memcached_quit_server(ptr, true);
return MEMCACHED_FAILURE;
struct local_context
{
uint8_t major_version;
- uint8_t micro_version;
uint8_t minor_version;
+ uint8_t micro_version;
bool truth;
};
struct local_context *check= (struct local_context *)context;
if (instance->major_version >= check->major_version &&
- instance->micro_version >= check->micro_version &&
- instance->minor_version >= check->minor_version)
+ instance->minor_version >= check->minor_version &&
+ instance->micro_version >= check->micro_version )
{
return MEMCACHED_SUCCESS;
}
bool libmemcached_util_version_check(memcached_st *memc,
uint8_t major_version,
- uint8_t micro_version,
- uint8_t minor_version)
+ uint8_t minor_version,
+ uint8_t micro_version)
{
memcached_server_fn callbacks[1];
memcached_version(memc);
- struct local_context check= { .major_version= major_version, .micro_version= micro_version, .minor_version= minor_version, .truth= true };
+ struct local_context check= { .major_version= major_version, .minor_version= minor_version, .micro_version= micro_version, .truth= true };
callbacks[0]= check_server_version;
memcached_server_cursor(memc, callbacks, (void *)&check, 1);
LIBMEMCACHED_API
bool libmemcached_util_version_check(memcached_st *memc,
uint8_t major_version,
- uint8_t micro_version,
- uint8_t minor_version);
+ uint8_t minor_version,
+ uint8_t micro_version);
#ifdef __cplusplus
}
m4_if(PW_LESS_WARNINGS,[no],[
BASE_WARNINGS_FULL="-Wformat=2 ${W_CONVERSION} -Wstrict-aliasing"
CC_WARNINGS_FULL="-Wswitch-default -Wswitch-enum -Wwrite-strings"
- CXX_WARNINGS_FULL="-Weffc++ -Wold-style-cast"
+ CXX_WARNINGS_FULL="-Wold-style-cast"
NO_OLD_STYLE_CAST="-Wno-old-style-cast"
NO_EFF_CXX="-Wno-effc++"
],[
/*
Sample test application.
*/
-#include "libmemcached/common.h"
+#include "config.h"
+
+#include "libmemcached/memcached.h"
+#include "libmemcached/watchpoint.h"
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include "../clients/generator.h"
#include "../clients/execute.h"
-#ifndef INT64_MAX
-#define INT64_MAX LONG_MAX
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX INT_MAX
-#endif
-
-
#include "test.h"
/* Number of items generated for tests */
* the COPYING file in the parent directory for full text.
*/
+#include "config.h"
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
PAHOLE_COMMAND= $(LIBTOOL) --mode=execute pahole
-if HAVE_LIBGTEST
-check_PROGRAMS += tests/unittests
-endif
-
if BUILD_LIBMEMCACHEDUTIL
TESTS_LDADDS+= libmemcached/libmemcachedutil.la
endif
noinst_LTLIBRARIES+= tests/libtest.la
tests_libtest_la_SOURCES= tests/test.c
-tests_unittests_SOURCES= \
- tests/main.cc
-tests_unittests_LDADD= \
- tests/libserver.la \
- libmemcached/libmemcachedinternal.la \
- ${TESTS_LDADDS} ${LTLIBGTEST}
-
tests_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING)
tests_testapp_SOURCES= tests/mem_functions.c
tests_testapp_DEPENDENCIES= \
+ $(BUILT_SOURCES) \
clients/libgenexec.la \
tests/libserver.la \
tests/libtest.la \
tests_memplus_DEPENDENCIES = tests/libtest.la tests/libserver.la libmemcached/libmemcached.la
tests_memplus_LDADD = $(tests_memplus_DEPENDENCIES)
-test: test-docs test-mem test-hash memcapable
+test: unittests-run test-docs test-mem test-hash memcapable
echo "Tests completed"
test-x: test-docs test-plus test-mem test-hash memcapable test-memcat test-memcp test-memrm test-memerror test-memdump test-memflush test-memstat
+++ /dev/null
-/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- *
- * Copyright (C) 2010 Monty Taylor
- *
- * All rights reserved.
- *
- * Use and distribution licensed under the BSD license. See
- * the COPYING file in the parent directory for full text.
- */
-
-#include "config.h"
-
-#include <gtest/gtest.h>
-
-
-int main(int argc, char **argv)
-{
- ::testing::InitGoogleTest(&argc, argv);
- return RUN_ALL_TESTS();
-}
Sample test application.
*/
-#include "libmemcached/common.h"
+#include "config.h"
#include <assert.h>
#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>
#include <time.h>
+
+#include "libmemcached/common.h"
+
#include "server.h"
#include "clients/generator.h"
#include "clients/execute.h"
-#ifndef INT64_MAX
-#define INT64_MAX LONG_MAX
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX INT_MAX
-#endif
-
+#define SMALL_STRING_LEN 1024
#include "test.h"
+
#ifdef HAVE_LIBMEMCACHEDUTIL
#include <pthread.h>
#include "libmemcached/memcached_util.h"
*/
static test_return_t add_wrapper(memcached_st *memc)
{
- unsigned int x;
unsigned int max= 10000;
#ifdef __sun
max= 10;
max= 10;
#endif
- for (x= 0; x < max; x++)
+ for (uint32_t x= 0; x < max; x++)
add_test(memc);
return TEST_SUCCESS;
// will not toggle protocol on an connection.
memcached_version(memc_clone);
- if (libmemcached_util_version_check(memc_clone, 1, 2, 0))
+ if (libmemcached_util_version_check(memc_clone, 1, 3, 0))
{
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
static test_return_t pre_binary(memcached_st *memc)
{
memcached_return_t rc= MEMCACHED_FAILURE;
- memcached_st *memc_clone;
- memc_clone= memcached_clone(NULL, memc);
- test_true(memc_clone);
- // The memcached_version needs to be done on a clone, because the server
- // will not toggle protocol on an connection.
- memcached_version(memc_clone);
-
- if (libmemcached_util_version_check(memc_clone, 1, 2, 0))
+ if (libmemcached_util_version_check(memc, 1, 3, 0))
{
rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
test_true(rc == MEMCACHED_SUCCESS);
test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1);
}
- memcached_free(memc_clone);
-
return rc == MEMCACHED_SUCCESS ? TEST_SUCCESS : TEST_SKIPPED;
}
memcached_version(memc);
// We only use one binary when we test, so this should be just fine.
- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version, instance->minor_version);
+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version, instance->micro_version);
test_true(if_successful == true);
- if (instance->minor_version > 0)
- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version, instance->minor_version -1);
- else if (instance->micro_version > 0)
- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version - 1, instance->minor_version);
+ if (instance->micro_version > 0)
+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version, instance->micro_version -1);
+ else if (instance->minor_version > 0)
+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version - 1, instance->micro_version);
else if (instance->major_version > 0)
- if_successful= libmemcached_util_version_check(memc, instance->major_version -1, instance->micro_version, instance->minor_version);
+ if_successful= libmemcached_util_version_check(memc, instance->major_version -1, instance->minor_version, instance->micro_version);
test_true(if_successful == true);
- if (instance->minor_version > 0)
- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version, instance->minor_version +1);
- else if (instance->micro_version > 0)
- if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->micro_version +1, instance->minor_version);
+ if (instance->micro_version > 0)
+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version, instance->micro_version +1);
+ else if (instance->minor_version > 0)
+ if_successful= libmemcached_util_version_check(memc, instance->major_version, instance->minor_version +1, instance->micro_version);
else if (instance->major_version > 0)
- if_successful= libmemcached_util_version_check(memc, instance->major_version +1, instance->micro_version, instance->minor_version);
+ if_successful= libmemcached_util_version_check(memc, instance->major_version +1, instance->minor_version, instance->micro_version);
test_true(if_successful == false);
We are testing the error condition when we connect to a server via memcached_get()
but find that the server is not available.
*/
-static test_return_t memcached_get_MEMCACHED_SOME_ERRORS(memcached_st *memc)
+static test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *memc)
{
(void)memc;
memcached_st *tl_memc_h;
// Create a handle.
tl_memc_h= memcached_create(NULL);
- servers= memcached_servers_parse("localhost:9898"); // This server should not exist
+ servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
memcached_server_push(tl_memc_h, servers);
memcached_server_list_free(servers);
}
test_true(len == 0);
- test_true(rc == MEMCACHED_SOME_ERRORS);
+ test_true(rc == MEMCACHED_ERRNO);
return TEST_SUCCESS;
}
We are testing the error condition when we connect to a server via memcached_get_by_key()
but find that the server is not available.
*/
-static test_return_t memcached_get_by_key_MEMCACHED_SOME_ERRORS(memcached_st *memc)
+static test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *memc)
{
(void)memc;
memcached_st *tl_memc_h;
// Create a handle.
tl_memc_h= memcached_create(NULL);
- servers= memcached_servers_parse("localhost:9898"); // This server should not exist
+ servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
memcached_server_push(tl_memc_h, servers);
memcached_server_list_free(servers);
}
test_true(len == 0);
- test_true(rc == MEMCACHED_SOME_ERRORS);
+ test_true(rc == MEMCACHED_ERRNO);
return TEST_SUCCESS;
}
static test_return_t regression_bug_463297(memcached_st *memc)
{
- memcached_st *memc_clone= memcached_clone(NULL, memc);
- test_true(memc_clone != NULL);
- test_true(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
+ memcached_st *memc_clone= memcached_clone(NULL, memc);
+ test_true(memc_clone != NULL);
+ test_true(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
+ memcached_server_instance_st instance=
+ memcached_server_instance_by_position(memc_clone, 0);
- if (libmemcached_util_version_check(memc_clone, 1, 1, 2))
+ if (instance->major_version > 1 ||
+ (instance->major_version == 1 &&
+ instance->minor_version > 2))
{
- /* Binary protocol doesn't support deferred delete */
- memcached_st *bin_clone= memcached_clone(NULL, memc);
- test_true(bin_clone != NULL);
- test_true(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS);
- test_true(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
- memcached_free(bin_clone);
+ /* Binary protocol doesn't support deferred delete */
+ memcached_st *bin_clone= memcached_clone(NULL, memc);
+ test_true(bin_clone != NULL);
+ test_true(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS);
+ test_true(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
+ memcached_free(bin_clone);
- memcached_quit(memc_clone);
+ memcached_quit(memc_clone);
- /* If we know the server version, deferred delete should fail
- * with invalid arguments */
- test_true(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
+ /* If we know the server version, deferred delete should fail
+ * with invalid arguments */
+ test_true(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
- /* If we don't know the server version, we should get a protocol error */
- memcached_return_t rc= memcached_delete(memc, "foo", 3, 1);
+ /* If we don't know the server version, we should get a protocol error */
+ memcached_return_t rc= memcached_delete(memc, "foo", 3, 1);
- /* but there is a bug in some of the memcached servers (1.4) that treats
- * the counter as noreply so it doesn't send the proper error message
- */
- test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
+ /* but there is a bug in some of the memcached servers (1.4) that treats
+ * the counter as noreply so it doesn't send the proper error message
+ */
+ test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
- /* And buffered mode should be disabled and we should get protocol error */
- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS);
- rc= memcached_delete(memc, "foo", 3, 1);
- test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
+ /* And buffered mode should be disabled and we should get protocol error */
+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS);
+ rc= memcached_delete(memc, "foo", 3, 1);
+ test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
- /* Same goes for noreply... */
- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS);
- rc= memcached_delete(memc, "foo", 3, 1);
- test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
+ /* Same goes for noreply... */
+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS);
+ rc= memcached_delete(memc, "foo", 3, 1);
+ test_true(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
- /* but a normal request should go through (and be buffered) */
- test_true((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED);
- test_true(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
+ /* but a normal request should go through (and be buffered) */
+ test_true((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED);
+ test_true(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS);
- /* unbuffered noreply should be success */
- test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS);
- /* unbuffered with reply should be not found... */
- test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS);
- test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND);
+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS);
+ /* unbuffered noreply should be success */
+ test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS);
+ /* unbuffered with reply should be not found... */
+ test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS);
+ test_true(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND);
}
memcached_free(memc_clone);
/* Clean the server before beginning testing */
test_st tests[] ={
+ {"util_version", 1, (test_callback_fn)util_version_test },
{"flush", 0, (test_callback_fn)flush_test },
{"init", 0, (test_callback_fn)init_test },
{"allocation", 0, (test_callback_fn)allocation_test },
#ifdef HAVE_LIBMEMCACHEDUTIL
{"connectionpool", 1, (test_callback_fn)connection_pool_test },
{"ping", 1, (test_callback_fn)ping_test },
- {"util_version", 1, (test_callback_fn)util_version_test },
#endif
{"test_get_last_disconnect", 1, (test_callback_fn)test_get_last_disconnect},
{"verbosity", 1, (test_callback_fn)test_verbosity},
};
test_st error_conditions[] ={
- {"memcached_get_MEMCACHED_SOME_ERRORS", 0, (test_callback_fn)memcached_get_MEMCACHED_SOME_ERRORS },
+ {"memcached_get_MEMCACHED_ERRNO", 0, (test_callback_fn)memcached_get_MEMCACHED_ERRNO },
{"memcached_get_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_MEMCACHED_NOTFOUND },
- {"memcached_get_by_key_MEMCACHED_SOME_ERRORS", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_SOME_ERRORS },
+ {"memcached_get_by_key_MEMCACHED_ERRNO", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_ERRNO },
{"memcached_get_by_key_MEMCACHED_NOTFOUND", 0, (test_callback_fn)memcached_get_by_key_MEMCACHED_NOTFOUND },
{0, 0, (test_callback_fn)0}
};
Sample test application.
*/
+#include "config.h"
+
#include "libmemcached/common.h"
#include <assert.h>
#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "server.h"
-#ifndef INT64_MAX
-#define INT64_MAX LONG_MAX
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX INT_MAX
-#endif
-
-
#include "test.h"
#define SERVERS_TO_CREATE 5
*
*/
+#include "config.h"
+
#include <stdio.h>
#include <string.h>
#include "server.h"
/*
Sample test application.
*/
+
+#include "config.h"
+
#include <assert.h>
#include <stdlib.h>
#include <string.h>
--- /dev/null
+# vim:ft=automake
+# included from Top Level Makefile.am
+# All paths should be given relative to the root
+
+if HAVE_LIBGTEST
+UNITTEST_PROGRAM= unittests/unittests
+
+noinst_PROGRAMS += $(UNITTEST_PROGRAM)
+
+unittests_unittests_SOURCES= \
+ unittests/strings.cc \
+ unittests/main.cc
+unittests_unittests_LDADD= \
+ tests/libserver.la \
+ libmemcached/libmemcachedinternal.la \
+ ${TESTS_LDADDS} ${LTLIBGTEST}
+endif
+
+# Shorthand
+unit: unittests-run
+
+unittests-run: $(UNITTEST_PROGRAM)
+ $(UNITTEST_PROGRAM)
--- /dev/null
+/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Copyright (C) 2010 Monty Taylor
+ *
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ */
+
+#include "config.h"
+
+#include <gtest/gtest.h>
+
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+/* libMemcached
+ * Copyright (C) 2010 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license. See
+ * the COPYING file in the parent directory for full text.
+ */
+
+#include "config.h"
+
+#include <gtest/gtest.h>
+
+#include <libmemcached/common.h>
+
+TEST(memcached_string_st, memcached_create_static)
+{
+ memcached_string_st string;
+ memcached_string_st *string_ptr;
+
+ memcached_st *memc= memcached_create(NULL);
+ string_ptr= memcached_string_create(memc, &string, 0);
+ ASSERT_TRUE(string.options.is_initialized);
+ ASSERT_TRUE(string_ptr);
+
+ /* The following two better be the same! */
+ ASSERT_FALSE(memcached_is_allocated(string_ptr));
+ ASSERT_FALSE(memcached_is_allocated(&string));
+ EXPECT_EQ(&string, string_ptr);
+
+ ASSERT_TRUE(string.options.is_initialized);
+ ASSERT_TRUE(memcached_is_initialized(&string));
+ memcached_string_free(&string);
+ ASSERT_FALSE(memcached_is_initialized(&string));
+
+ memcached_free(memc);
+}
+
+TEST(memcached_string_st, memcached_create_null)
+{
+ memcached_string_st *string;
+ memcached_st *memc= memcached_create(NULL);
+
+ string= memcached_string_create(memc, NULL, 0);
+ ASSERT_TRUE(string);
+ ASSERT_TRUE(memcached_is_allocated(string));
+ ASSERT_TRUE(memcached_is_initialized(string));
+ memcached_string_free(string);
+
+ memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_with_size)
+{
+ memcached_string_st *string;
+ memcached_st *memc= memcached_create(NULL);
+
+ string= memcached_string_create(memc, NULL, 1024);
+ ASSERT_TRUE(string);
+ ASSERT_TRUE(memcached_is_allocated(string));
+ ASSERT_TRUE(memcached_is_initialized(string));
+ memcached_string_free(string);
+
+ memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_with_size_toobig)
+{
+ memcached_st *memc= memcached_create(NULL);
+ memcached_string_st *string;
+
+ string= memcached_string_create(memc, NULL, SIZE_MAX);
+ ASSERT_FALSE(string);
+
+ memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_append)
+{
+ char buffer[SMALL_STRING_LEN];
+ memcached_string_st *string;
+
+ memcached_st *memc= memcached_create(NULL);
+
+ /* Ring the bell! */
+ memset(buffer, 6, SMALL_STRING_LEN);
+
+ string= memcached_string_create(memc, NULL, 100);
+ ASSERT_TRUE(string);
+ ASSERT_TRUE(memcached_is_allocated(string));
+ ASSERT_TRUE(memcached_is_initialized(string));
+
+ for (uint32_t x= 0; x < 1024; x++)
+ {
+ memcached_return_t rc;
+ rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
+ EXPECT_EQ(rc, MEMCACHED_SUCCESS);
+ }
+ ASSERT_TRUE(memcached_is_allocated(string));
+ memcached_string_free(string);
+
+ memcached_free(memc);
+}
+
+TEST(memcached_string_st, string_alloc_append_toobig)
+{
+ memcached_return_t rc;
+ char buffer[SMALL_STRING_LEN];
+ memcached_string_st *string;
+
+ memcached_st *memc= memcached_create(NULL);
+
+ /* Ring the bell! */
+ memset(buffer, 6, SMALL_STRING_LEN);
+
+ string= memcached_string_create(memc, NULL, 100);
+ ASSERT_TRUE(string);
+ ASSERT_TRUE(memcached_is_allocated(string));
+ ASSERT_TRUE(memcached_is_initialized(string));
+
+ for (uint32_t x= 0; x < 1024; x++)
+ {
+ rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
+ EXPECT_EQ(rc, MEMCACHED_SUCCESS);
+ }
+ rc= memcached_string_append(string, buffer, SIZE_MAX);
+ EXPECT_EQ(rc, MEMCACHED_MEMORY_ALLOCATION_FAILURE);
+ ASSERT_TRUE(memcached_is_allocated(string));
+ memcached_string_free(string);
+
+ memcached_free(memc);
+}