From ecc7382f48857cb22e74ffa9496f9a31e956bde3 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 24 Jun 2011 12:25:01 -0700 Subject: [PATCH] Update docs, and syncronize libtest. --- docs/{ => bin}/memaslap.rst | 2 +- docs/{ => bin}/memcapable.rst | 7 +- docs/{ => bin}/memcat.rst | 10 +- docs/{ => bin}/memcp.rst | 2 +- docs/{ => bin}/memdump.rst | 2 +- docs/{ => bin}/memerror.rst | 2 +- docs/{ => bin}/memflush.rst | 2 +- docs/{ => bin}/memrm.rst | 2 +- docs/{ => bin}/memslap.rst | 3 +- docs/{ => bin}/memstat.rst | 2 +- docs/conf.py.in | 25 ++- docs/index.rst | 30 ++-- docs/libmemcached/memcached_fetch.rst | 66 ++++++++ docs/libmemcached/memcached_return_t.rst | 103 ++++++------ docs/libmemcached_configuration.rst | 5 +- docs/memcached_behavior.rst | 95 +++++------ docs/memcached_callback.rst | 41 ++--- docs/memcached_create.rst | 14 +- docs/memcached_get.rst | 51 +++--- docs/memcached_pool.rst | 47 ++---- libtest/callbacks.h | 21 +++ libtest/collection.h | 19 +++ libtest/common.h | 50 ++++++ libtest/core.h | 11 ++ libtest/error.h | 18 +++ libtest/failed.h | 1 - libtest/framework.cc | 57 +++++++ libtest/framework.h | 137 ++++++++++++++++ libtest/get.h | 22 +++ libtest/include.am | 13 +- libtest/runner.h | 19 +++ libtest/stats.h | 30 ++++ libtest/strerror.h | 14 ++ libtest/test.cc | 168 +++++++------------- libtest/test.h | 192 ++--------------------- libtest/test.hpp | 46 ++++++ tests/atomsmasher.cc | 18 +-- tests/basic.cc | 4 +- tests/deprecated.cc | 2 +- tests/error_conditions.cc | 4 +- tests/error_conditions.h | 2 - tests/hash_plus.cc | 16 +- tests/hashkit_functions.cc | 8 +- tests/libmemcached_world.h | 4 +- tests/mem_functions.cc | 18 +-- tests/mem_udp.cc | 18 +-- tests/parser.cc | 6 +- tests/parser.h | 2 - tests/plus.cpp | 18 +-- tests/pool.cc | 4 +- tests/pool.h | 2 - tests/print.cc | 2 +- tests/replication.cc | 2 +- tests/string.cc | 3 + tests/string.h | 2 - tests/virtual_buckets.cc | 1 + tests/virtual_buckets.h | 2 - 57 files changed, 875 insertions(+), 592 deletions(-) rename docs/{ => bin}/memaslap.rst (99%) rename docs/{ => bin}/memcapable.rst (92%) rename docs/{ => bin}/memcat.rst (93%) rename docs/{ => bin}/memcp.rst (97%) rename docs/{ => bin}/memdump.rst (97%) rename docs/{ => bin}/memerror.rst (95%) rename docs/{ => bin}/memflush.rst (97%) rename docs/{ => bin}/memrm.rst (97%) rename docs/{ => bin}/memslap.rst (97%) rename docs/{ => bin}/memstat.rst (97%) create mode 100644 docs/libmemcached/memcached_fetch.rst create mode 100644 libtest/callbacks.h create mode 100644 libtest/collection.h create mode 100644 libtest/common.h create mode 100644 libtest/core.h create mode 100644 libtest/error.h create mode 100644 libtest/framework.cc create mode 100644 libtest/framework.h create mode 100644 libtest/get.h create mode 100644 libtest/runner.h create mode 100644 libtest/stats.h create mode 100644 libtest/strerror.h create mode 100644 libtest/test.hpp diff --git a/docs/memaslap.rst b/docs/bin/memaslap.rst similarity index 99% rename from docs/memaslap.rst rename to docs/bin/memaslap.rst index 3f9e62dd..b69bb3f8 100644 --- a/docs/memaslap.rst +++ b/docs/bin/memaslap.rst @@ -7,7 +7,7 @@ memaslap - Load testing and benchmarking a server SYNOPSIS -------- -:program:: `memaslap` +memaslap [options] .. program:: memaslap diff --git a/docs/memcapable.rst b/docs/bin/memcapable.rst similarity index 92% rename from docs/memcapable.rst rename to docs/bin/memcapable.rst index 28988046..0e4f33e3 100644 --- a/docs/memcapable.rst +++ b/docs/bin/memcapable.rst @@ -2,16 +2,11 @@ memcapable - Checking a Memcached server capibilities and compatibility ======================================================================= -.. index:: object: memcached_st - -Check the server for compatibility and capabilities - - -------- SYNOPSIS -------- -:program:`memcapable` +memcapable [options] .. program:: memcapable diff --git a/docs/memcat.rst b/docs/bin/memcat.rst similarity index 93% rename from docs/memcat.rst rename to docs/bin/memcat.rst index 5c102207..b8612a92 100644 --- a/docs/memcat.rst +++ b/docs/bin/memcat.rst @@ -3,15 +3,15 @@ memcat - "cat" data from a server ================================= -Copy a set of keys to stdout - -------- SYNOPSIS -------- +memcat [options] key + +Copy a set of keys to stdout -:program:`memcat` .. program:: memcat @@ -34,7 +34,7 @@ OPTIONS You can specify servers via the option: -.. option:: --servers +.. cmdoption:: --servers or via the environment variable: @@ -42,7 +42,7 @@ or via the environment variable: For a full list of operations run the tool with the option: -.. option:: --help +.. cmdoption:: --help ---- diff --git a/docs/memcp.rst b/docs/bin/memcp.rst similarity index 97% rename from docs/memcp.rst rename to docs/bin/memcp.rst index 1ae45114..a85eed8b 100644 --- a/docs/memcp.rst +++ b/docs/bin/memcp.rst @@ -10,7 +10,7 @@ Copies files to a collection of memcached servers SYNOPSIS -------- -:program: `memcp` +memcp [options] [file] [server] .. program:: memcp diff --git a/docs/memdump.rst b/docs/bin/memdump.rst similarity index 97% rename from docs/memdump.rst rename to docs/bin/memdump.rst index ab7bd02e..6a8e12da 100644 --- a/docs/memdump.rst +++ b/docs/bin/memdump.rst @@ -10,7 +10,7 @@ Dump a list of keys from a server. SYNOPSIS -------- -:program: `memdump` +memdump [options] .. program:: memdump diff --git a/docs/memerror.rst b/docs/bin/memerror.rst similarity index 95% rename from docs/memerror.rst rename to docs/bin/memerror.rst index aa298993..53fc09c4 100644 --- a/docs/memerror.rst +++ b/docs/bin/memerror.rst @@ -10,7 +10,7 @@ Translates a memcached error code into a string SYNOPSIS -------- -:program: `memerror` +memerror [options] [error code] .. program:: memerror diff --git a/docs/memflush.rst b/docs/bin/memflush.rst similarity index 97% rename from docs/memflush.rst rename to docs/bin/memflush.rst index d2cb644f..a2b9894d 100644 --- a/docs/memflush.rst +++ b/docs/bin/memflush.rst @@ -10,7 +10,7 @@ Reset a server or list of servers SYNOPSIS -------- -:program: `memflush` +memflush [options] .. program:: memflush diff --git a/docs/memrm.rst b/docs/bin/memrm.rst similarity index 97% rename from docs/memrm.rst rename to docs/bin/memrm.rst index 7b34b029..d395b364 100644 --- a/docs/memrm.rst +++ b/docs/bin/memrm.rst @@ -10,7 +10,7 @@ memrm - Remove a key(s) from a collection of memcached servers SYNOPSIS -------- -:program: `memrm` +memrm [options] [key] .. program:: memrm diff --git a/docs/memslap.rst b/docs/bin/memslap.rst similarity index 97% rename from docs/memslap.rst rename to docs/bin/memslap.rst index c99abd77..fbaa5fe3 100644 --- a/docs/memslap.rst +++ b/docs/bin/memslap.rst @@ -7,8 +7,7 @@ memslap - Load testing and benchmarking a server SYNOPSIS -------- - -:program: `memslap` +memslap [options] .. program:: memslap diff --git a/docs/memstat.rst b/docs/bin/memstat.rst similarity index 97% rename from docs/memstat.rst rename to docs/bin/memstat.rst index 550c346f..3bbec8f8 100644 --- a/docs/memstat.rst +++ b/docs/bin/memstat.rst @@ -10,7 +10,7 @@ memstat - Display the operating status of a single or group of memcached servers SYNOPSIS -------- -:program: `memstat` +memstat [options] .. program:: memstat diff --git a/docs/conf.py.in b/docs/conf.py.in index a6a1dfb7..44f3f420 100644 --- a/docs/conf.py.in +++ b/docs/conf.py.in @@ -269,7 +269,7 @@ man_pages = [ ('memcached_flush_buffers', 'memcached_flush_buffers', u'libmemcached Documentation', [u'Brian Aker'], 3), ('memcached_generate_hash_value', 'memcached_generate_hash', u'Generating hash values directly', [u'Brian Aker'], 3), ('memcached_generate_hash_value', 'memcached_generate_hash_value', u'Generating hash values directly', [u'Brian Aker'], 3), - ('memcached_get', 'memcached_fetch', u'Retrieving data from the server', [u'Brian Aker'], 3), + ('libmemcached/memcached_fetch', 'memcached_fetch', u'Retrieving data from the server', [u'Brian Aker'], 3), ('memcached_get', 'memcached_fetch_execute', u'Retrieving data from the server', [u'Brian Aker'], 3), ('memcached_get', 'memcached_fetch_result', u'Retrieving data from the server', [u'Brian Aker'], 3), ('memcached_get', 'memcached_get', u'Retrieving data from the server', [u'Brian Aker'], 3), @@ -338,18 +338,13 @@ man_pages = [ ('memcached_verbosity', 'memcached_verbosity', u'libmemcached Documentation', [u'Brian Aker'], 3), ('memcached_version', 'memcached_lib_version', u'libmemcached Documentation', [u'Brian Aker'], 3), ('memcached_version', 'memcached_version', u'libmemcached Documentation', [u'Brian Aker'], 3), - ('memcapable', 'memcapable', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memcapable', 'memcapable', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memcat', 'memcat', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memcat', 'memcat', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memcp', 'memcp', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memcp', 'memcp', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memdump', 'memdump', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memdump', 'memdump', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memerror', 'memerror', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memerror', 'memerror', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memflush', 'memflush', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memrm', 'memrm', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memslap', 'memslap', u'libmemcached Documentation', [u'Brian Aker'], 1), - ('memstat', 'memstat', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memcapable', 'memcapable', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memcat', 'memcat', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memcp', 'memcp', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memdump', 'memdump', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memerror', 'memerror', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memflush', 'memflush', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memrm', 'memrm', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memslap', 'memslap', u'libmemcached Documentation', [u'Brian Aker'], 1), + ('bin/memstat', 'memstat', u'libmemcached Documentation', [u'Brian Aker'], 1), ] diff --git a/docs/index.rst b/docs/index.rst index 77b50600..57e2671d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -62,6 +62,16 @@ Advanced Topics memcached_verbosity memcached_version + +#################### +Deprecated Functions +#################### + +.. toctree:: + :titlesonly: + + libmemcached/memcached_fetch + ################# Platform Specific ################# @@ -98,16 +108,16 @@ Client Applications .. toctree:: :maxdepth: 1 - memcapable - memcat - memcp - memdump - memerror - memflush - memrm - memslap - memaslap - memstat + bin/memcapable + bin/memcat + bin/memcp + bin/memdump + bin/memerror + bin/memflush + bin/memrm + bin/memslap + bin/memaslap + bin/memstat ---------- Libhashkit diff --git a/docs/libmemcached/memcached_fetch.rst b/docs/libmemcached/memcached_fetch.rst new file mode 100644 index 00000000..9d995101 --- /dev/null +++ b/docs/libmemcached/memcached_fetch.rst @@ -0,0 +1,66 @@ +================= +memcached_fetch() +================= + +.. index:: object: memcached_st + +-------- +SYNOPSIS +-------- + + +#include + +.. c:function:: char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error) + + .. deprecated:: 0.50 + Use :c:func:`memcached_fetch_result()` instead. + +Compile and link with -lmemcached + + +----------- +DESCRIPTION +----------- + +:c:func:`memcached_fetch()` is used to fetch an individual value from the server. :c:func:`memcached_mget()` must always be called before using this method. +You must pass in a key and its length to fetch the object. You must supply +three pointer variables which will give you the state of the returned +object. A :c:type:`uint32_t` pointer to contain whatever flags you stored with the value, a :c:type:`size_t` pointer which will be filled with size of of the +object, and a :c:type:`memcached_return_t` pointer to hold any error. The +object will be returned upon success and NULL will be returned on failure. :c:type:`MEMCACHD_END` is returned by the \*error value when all objects that have been found are returned. The final value upon :c:type:`MEMCACHED_END` is null. + +Values returned by :c:func:`memcached_fetch()` must be freed by the caller. + +All of the above functions are not tested when the +:c:type:`MEMCACHED_BEHAVIOR_USE_UDP` has been set. Executing any of these +functions with this behavior on will result in :c:type:`MEMCACHED_NOT_SUPPORTED` being returned, or for those functions which do not return a :c:type:`memcached_return_t`, the error function parameter will be set to :c:type:`MEMCACHED_NOT_SUPPORTED`. + + +------ +RETURN +------ + +:c:func:`memcached_fetch()` sets error to +to :c:type:`MEMCACHED_END` upon successful conclusion. +:c:type:`MEMCACHED_NOTFOUND` will be return if no keys at all were found. + +:c:type:`MEMCACHED_KEY_TOO_BIG` is set to error whenever :c::func:`memcached_fetch()` was used +and the key was set larger then :c:type:`MEMCACHED_MAX_KEY`, which was the largest +key allowed for the original memcached ascii server. + + +---- +HOME +---- + +To find out more information please check: +`http://libmemcached.org/ `_ + + +-------- +SEE ALSO +-------- + +:manpage:`memcached(1)` :manpage:`libmemcached(3)` :manpage:`memcached_strerror(3)` :manpage:`memcached_fetch_result(3)` + diff --git a/docs/libmemcached/memcached_return_t.rst b/docs/libmemcached/memcached_return_t.rst index 3663c6df..40f6f96f 100644 --- a/docs/libmemcached/memcached_return_t.rst +++ b/docs/libmemcached/memcached_return_t.rst @@ -25,105 +25,110 @@ SYNOPSIS :c:func:`memcached_failure()` return true if any value other then :c:type:`MEMCACHED_SUCCESS` was provided. +Libmemcached return types: +++++++++++++++++++++++++++ -.. c:type:: MEMCACHED_SUCCESS, +.. c:type:: MEMCACHED_SUCCESS Success -.. c:type:: MEMCACHED_FAILURE, +.. c:type:: MEMCACHED_FAILURE -.. c:type:: MEMCACHED_HOST_LOOKUP_FAILURE, // getaddrinfo() only +.. c:type:: MEMCACHED_HOST_LOOKUP_FAILURE -.. c:type:: MEMCACHED_CONNECTION_FAILURE, // DEPRECATED +.. c:type:: MEMCACHED_CONNECTION_FAILURE -.. c:type:: MEMCACHED_CONNECTION_BIND_FAILURE, // DEPRECATED +.. c:type:: MEMCACHED_CONNECTION_BIND_FAILURE +.. deprecated:: <0.30 -.. c:type:: MEMCACHED_WRITE_FAILURE, +.. c:type:: MEMCACHED_WRITE_FAILURE -.. c:type:: MEMCACHED_READ_FAILURE, +.. c:type:: MEMCACHED_READ_FAILURE -.. c:type:: MEMCACHED_UNKNOWN_READ_FAILURE, +.. c:type:: MEMCACHED_UNKNOWN_READ_FAILURE -.. c:type:: MEMCACHED_PROTOCOL_ERROR, +.. c:type:: MEMCACHED_PROTOCOL_ERROR -.. c:type:: MEMCACHED_CLIENT_ERROR, +.. c:type:: MEMCACHED_CLIENT_ERROR -.. c:type:: MEMCACHED_SERVER_ERROR, +.. c:type:: MEMCACHED_SERVER_ERROR -.. c:type:: MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE, // DEPRECATED +.. c:type:: MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE +.. deprecated:: <0.30 -.. c:type:: MEMCACHED_DATA_EXISTS, +.. c:type:: MEMCACHED_DATA_EXISTS -.. c:type:: MEMCACHED_DATA_DOES_NOT_EXIST, +.. c:type:: MEMCACHED_DATA_DOES_NOT_EXIST -.. c:type:: MEMCACHED_NOTSTORED, +.. c:type:: MEMCACHED_NOTSTORED -.. c:type:: MEMCACHED_STORED, +.. c:type:: MEMCACHED_STORED -.. c:type:: MEMCACHED_NOTFOUND, +.. c:type:: MEMCACHED_NOTFOUND -.. c:type:: MEMCACHED_MEMORY_ALLOCATION_FAILURE, +.. c:type:: MEMCACHED_MEMORY_ALLOCATION_FAILURE -.. c:type:: MEMCACHED_PARTIAL_READ, +.. c:type:: MEMCACHED_PARTIAL_READ -.. c:type:: MEMCACHED_SOME_ERRORS, +.. c:type:: MEMCACHED_SOME_ERRORS -.. c:type:: MEMCACHED_NO_SERVERS, +.. c:type:: MEMCACHED_NO_SERVERS -.. c:type:: MEMCACHED_END, +.. c:type:: MEMCACHED_END -.. c:type:: MEMCACHED_DELETED, +.. c:type:: MEMCACHED_DELETED -.. c:type:: MEMCACHED_VALUE, +.. c:type:: MEMCACHED_VALUE -.. c:type:: MEMCACHED_STAT, +.. c:type:: MEMCACHED_STAT -.. c:type:: MEMCACHED_ITEM, +.. c:type:: MEMCACHED_ITEM -.. c:type:: MEMCACHED_ERRNO, +.. c:type:: MEMCACHED_ERRNO -.. c:type:: MEMCACHED_FAIL_UNIX_SOCKET, // DEPRECATED +.. c:type:: MEMCACHED_FAIL_UNIX_SOCKET +.. deprecated:: <0.30 -.. c:type:: MEMCACHED_NOT_SUPPORTED, +.. c:type:: MEMCACHED_NOT_SUPPORTED -.. c:type:: MEMCACHED_NO_KEY_PROVIDED, /* Deprecated. Use MEMCACHED_BAD_KEY_PROVIDED! */ +.. c:type:: MEMCACHED_NO_KEY_PROVIDED +.. deprecated:: <0.30 + Use :c:type:`MEMCACHED_BAD_KEY_PROVIDED` instead. -.. c:type:: MEMCACHED_FETCH_NOTFINISHED, +.. c:type:: MEMCACHED_FETCH_NOTFINISHED -.. c:type:: MEMCACHED_TIMEOUT, +.. c:type:: MEMCACHED_TIMEOUT -Connection to server timed out. + Connection to server timed out. -.. c:type:: MEMCACHED_BUFFERED, +.. c:type:: MEMCACHED_BUFFERED -.. c:type:: MEMCACHED_BAD_KEY_PROVIDED, +.. c:type:: MEMCACHED_BAD_KEY_PROVIDED -.. c:type:: MEMCACHED_INVALID_HOST_PROTOCOL, +.. c:type:: MEMCACHED_INVALID_HOST_PROTOCOL -.. c:type:: MEMCACHED_SERVER_MARKED_DEAD, +.. c:type:: MEMCACHED_SERVER_MARKED_DEAD -.. c:type:: MEMCACHED_UNKNOWN_STAT_KEY, +.. c:type:: MEMCACHED_UNKNOWN_STAT_KEY -.. c:type:: MEMCACHED_E2BIG, +.. c:type:: MEMCACHED_E2BIG -.. c:type:: MEMCACHED_INVALID_ARGUMENTS, +.. c:type:: MEMCACHED_INVALID_ARGUMENTS -.. c:type:: MEMCACHED_KEY_TOO_BIG, +.. c:type:: MEMCACHED_KEY_TOO_BIG -.. c:type:: MEMCACHED_AUTH_PROBLEM, +.. c:type:: MEMCACHED_AUTH_PROBLEM -.. c:type:: MEMCACHED_AUTH_FAILURE, +.. c:type:: MEMCACHED_AUTH_FAILURE -.. c:type:: MEMCACHED_AUTH_CONTINUE, +.. c:type:: MEMCACHED_AUTH_CONTINUE -.. c:type:: MEMCACHED_PARSE_ERROR, +.. c:type:: MEMCACHED_PARSE_ERROR -.. c:type:: MEMCACHED_PARSE_USER_ERROR, +.. c:type:: MEMCACHED_PARSE_USER_ERROR -.. c:type:: MEMCACHED_DEPRECATED, - -.. c:type:: MEMCACHED_MAXIMUM_RETURN /* Always add new error code before */ +.. c:type:: MEMCACHED_DEPRECATED -------- SEE ALSO diff --git a/docs/libmemcached_configuration.rst b/docs/libmemcached_configuration.rst index 74902aab..4cfec4a8 100644 --- a/docs/libmemcached_configuration.rst +++ b/docs/libmemcached_configuration.rst @@ -2,7 +2,7 @@ Configuring Libmemcached ======================== -.. index:: object: memcached_st +.. highlightlang:: c -------- SYNOPSIS @@ -17,13 +17,12 @@ SYNOPSIS Compile and link with -lmemcached - ----------- DESCRIPTION ----------- Libmemcached implements a custom language for configuring and modifying -servers. By passing in an option string you can generate a memcached_st object +servers. By passing in an option string you can generate a ``memcached_st`` object that you can use in your application directly. .. describe:: --SERVER=:/? diff --git a/docs/memcached_behavior.rst b/docs/memcached_behavior.rst index f7acb297..59ec4839 100644 --- a/docs/memcached_behavior.rst +++ b/docs/memcached_behavior.rst @@ -39,7 +39,7 @@ on or off options you just need to pass in a value of 1. Calls to :c:func:`memcached_behavior_set()` will flush and reset all connections. -.. c:var:: MEMCACHED_BEHAVIOR_USE_UDP +.. c:type:: MEMCACHED_BEHAVIOR_USE_UDP Causes :manpage:`libmemcached(3)` to use the UDP transport when communicating with a memcached server. Not all I/O operations are testsed @@ -58,18 +58,18 @@ not been enabled. -.. c:var:: MEMCACHED_BEHAVIOR_NO_BLOCK +.. c:type:: MEMCACHED_BEHAVIOR_NO_BLOCK Causes :manpage:`libmemcached(3)` to use asychronous IO. This is the fastest transport available for storage functions. -.. c:var:: MEMCACHED_BEHAVIOR_SND_TIMEOUT +.. c:type:: MEMCACHED_BEHAVIOR_SND_TIMEOUT This sets the microsecond behavior of the socket against the SO_SNDTIMEO flag. In cases where you cannot use non-blocking IO this will allow you to still have timeouts on the sending of data. -.. c:var:: MEMCACHED_BEHAVIOR_RCV_TIMEOUT +.. c:type:: MEMCACHED_BEHAVIOR_RCV_TIMEOUT This sets the microsecond behavior of the socket against the SO_RCVTIMEO flag. @@ -77,14 +77,14 @@ In cases where you cannot use non-blocking IO this will allow you to still have -.. c:var:: MEMCACHED_BEHAVIOR_TCP_NODELAY +.. c:type:: MEMCACHED_BEHAVIOR_TCP_NODELAY Turns on the no-delay feature for connecting sockets (may be faster in some environments). -.. c:var:: MEMCACHED_BEHAVIOR_HASH +.. c:type:: MEMCACHED_BEHAVIOR_HASH Makes the default hashing algorithm for keys use MD5. The value can be set to either :c:type:`MEMCACHED_HASH_DEFAULT`, :c:type:`MEMCACHED_HASH_MD5`, :c:type:`MEMCACHED_HASH_CRC`, :c:type:`MEMCACHED_HASH_FNV1_64`, :c:type:`MEMCACHED_HASH_FNV1A_64`, :c:type:`MEMCACHED_HASH_FNV1_32`, :c:type:`MEMCACHED_HASH_FNV1A_32`, :c:type:`MEMCACHED_HASH_JENKINS`, :c:type:`MEMCACHED_HASH_HSIEH`, and :c:type:`MEMCACHED_HASH_MURMUR`. @@ -95,162 +95,167 @@ Support for :c:type:`MEMCACHED_HASH_HSIEH` is a compile time option that is disa -.. c:var:: MEMCACHED_BEHAVIOR_DISTRIBUTION +.. c:type:: MEMCACHED_BEHAVIOR_DISTRIBUTION Using this you can enable different means of distributing values to servers. The default method is MEMCACHED_DISTRIBUTION_MODULA. You can enable consistent hashing by setting MEMCACHED_DISTRIBUTION_CONSISTENT. Consistent hashing delivers better distribution and allows servers to be added to the cluster with minimal cache losses. Currently MEMCACHED_DISTRIBUTION_CONSISTENT is an alias for the value MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA. -.. c:var:: MEMCACHED_BEHAVIOR_CACHE_LOOKUPS +.. c:type:: MEMCACHED_BEHAVIOR_CACHE_LOOKUPS +.. deprecated:: 0.46(?) + DNS lookups are now always cached until an error occurs with the server. -DEPRECATED. Memcached can cache named lookups so that DNS lookups are made only once. + Memcached can cache named lookups so that DNS lookups are made only once. -.. c:var:: MEMCACHED_BEHAVIOR_SUPPORT_CAS +.. c:type:: MEMCACHED_BEHAVIOR_SUPPORT_CAS Support CAS operations (this is not enabled by default at this point in the server since it imposes a slight performance penalty). -.. c:var:: MEMCACHED_BEHAVIOR_KETAMA +.. c:type:: MEMCACHED_BEHAVIOR_KETAMA Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA and the hash to MEMCACHED_HASH_MD5. -.. c:var:: MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED +.. c:type:: MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED + + Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA with the weighted tests. and the hash to MEMCACHED_HASH_MD5. -Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA with the weighted tests. and the hash to MEMCACHED_HASH_MD5. - -.. c:var:: MEMCACHED_BEHAVIOR_KETAMA_HASH +.. c:type:: MEMCACHED_BEHAVIOR_KETAMA_HASH Sets the hashing algorithm for host mapping on continuum. The value can be set to either MEMCACHED_HASH_DEFAULT, MEMCACHED_HASH_MD5, MEMCACHED_HASH_CRC, MEMCACHED_HASH_FNV1_64, MEMCACHED_HASH_FNV1A_64, MEMCACHED_HASH_FNV1_32, and MEMCACHED_HASH_FNV1A_32. -.. c:var:: MEMCACHED_BEHAVIOR_KETAMA_COMPAT +.. c:type:: MEMCACHED_BEHAVIOR_KETAMA_COMPAT Sets the compatibility mode. The value can be set to either MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED (this is the default) or MEMCACHED_KETAMA_COMPAT_SPY to be compatible with the SPY Memcached client for Java. -.. c:var:: MEMCACHED_BEHAVIOR_POLL_TIMEOUT +.. c:type:: MEMCACHED_BEHAVIOR_POLL_TIMEOUT Modify the timeout value that is used by poll(). The default value is -1. An signed int pointer must be passed to memcached_behavior_set() to change this value. For memcached_behavior_get() a signed int value will be cast and returned as the unsigned long long. -.. c:var:: MEMCACHED_BEHAVIOR_USER_DATA - -DEPRECATED +.. c:type:: MEMCACHED_BEHAVIOR_USER_DATA +.. deprecated:: < 0.30 -.. c:var:: MEMCACHED_BEHAVIOR_BUFFER_REQUESTS +.. c:type:: MEMCACHED_BEHAVIOR_BUFFER_REQUESTS Enabling buffered IO causes commands to "buffer" instead of being sent. Any action that gets data causes this buffer to be be sent to the remote connection. Quiting the connection or closing down the connection will also cause the buffered data to be pushed to the remote connection. -.. c:var:: MEMCACHED_BEHAVIOR_VERIFY_KEY +.. c:type:: MEMCACHED_BEHAVIOR_VERIFY_KEY Enabling this will cause :manpage:`libmemcached(3)` to test all keys to verify that they are valid keys. -.. c:var:: MEMCACHED_BEHAVIOR_SORT_HOSTS +.. c:type:: MEMCACHED_BEHAVIOR_SORT_HOSTS Enabling this will cause hosts that are added to be placed in the host list in sorted order. This will defeat consisten hashing. -.. c:var:: MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT +.. c:type:: MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT In non-blocking mode this changes the value of the timeout during socket connection. -.. c:var:: MEMCACHED_BEHAVIOR_BINARY_PROTOCOL +.. c:type:: MEMCACHED_BEHAVIOR_BINARY_PROTOCOL Enable the use of the binary protocol. Please note that you cannot toggle this flag on an open connection. -.. c:var:: MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT +.. c:type:: MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT Set this value to enable the server be removed after continuous MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT times connection failure. -.. c:var:: MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK +.. c:type:: MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK Set this value to tune the number of messages that may be sent before libmemcached should start to automatically drain the input queue. Setting this value to high, may cause libmemcached to deadlock (trying to send data, but the send will block because the input buffer in the kernel is full). -.. c:var:: MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK +.. c:type:: MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK Set this value to tune the number of bytes that may be sent before libmemcached should start to automatically drain the input queue (need at least 10 IO requests sent without reading the input buffer). Setting this value to high, may cause libmemcached to deadlock (trying to send data, but the send will block because the input buffer in the kernel is full). -.. c:var:: MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH +.. c:type:: MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH The binary protocol works a bit different than the textual protocol in that a multiget is implemented as a pipe of single get-operations which are sent to the server in a chunk. If you are using large multigets from your application, you may improve the latency of the gets by setting this value so you send out the first chunk of requests when you hit the specified limit. It allows the servers to start processing the requests to send the data back while the rest of the requests are created and sent to the server. -.. c:var:: MEMCACHED_BEHAVIOR_NOREPLY +.. c:type:: MEMCACHED_BEHAVIOR_NOREPLY Set this value to specify that you really don't care about the result from your storage commands (set, add, replace, append, prepend). -.. c:var:: MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS +.. c:type:: MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS If you just want "a poor mans HA", you may specify the numbers of replicas libmemcached should store of each item (on different servers). This replication does not dedicate certain memcached servers to store the replicas in, but instead it will store the replicas together with all of the other objects (on the 'n' next servers specified in your server list). -.. c:var:: MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ +.. c:type:: MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ Allows randomizing the replica reads starting point. Normally the read is done from primary server and in case of miss the read is done from primary + 1, then primary + 2 all the way to 'n' replicas. If this option is set on the starting point of the replica reads is randomized between the servers. This allows distributing read load to multiple servers with the expense of more write traffic. -.. c:var:: MEMCACHED_BEHAVIOR_CORK +.. c:type:: MEMCACHED_BEHAVIOR_CORK This open has been deprecated with the behavior now built and used appropriately on selected platforms. -.. c:var:: MEMCACHED_BEHAVIOR_KEEPALIVE +.. c:type:: MEMCACHED_BEHAVIOR_KEEPALIVE Enable TCP_KEEPALIVE behavior. -.. c:var:: MEMCACHED_BEHAVIOR_KEEPALIVE_IDLE +.. c:type:: MEMCACHED_BEHAVIOR_KEEPALIVE_IDLE Specify time, in seconds, to mark a connection as idle. This is only available as an option Linux. -.. c:var:: MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE +.. c:type:: MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE Find the current size of SO_SNDBUF. A value of 0 means either an error occured or no hosts were available. It is safe to assume system default if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error. -.. c:var:: MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE +.. c:type:: MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE Find the current size of SO_RCVBUF. A value of 0 means either an error occured or no hosts were available. It is safe to assume system default if this occurs. If an error occurs you can checked the last cached errno statement to find the specific error. -.. c:var:: MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT +.. c:type:: MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT +.. deprecated:: 0.48 + See :c:type:`MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS` -DEPRECATED, please see MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS. This number of times a host can have an error before it is disabled. + This number of times a host can have an error before it is disabled. -.. c:var:: MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS +.. c:type:: MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS +.. deprecated:: 0.48 + See :c:type:`MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS` -DEPRECATED, please see MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS. If enabled any hosts which have been flagged as disabled will be removed from the list of servers in the memcached_st structure. This must be used in combination with MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT. + If enabled any hosts which have been flagged as disabled will be removed from the list of servers in the memcached_st structure. This must be used in combination with MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT. -.. c:var:: MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS +.. c:type:: MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS -If enabled any hosts which have been flagged as disabled will be removed from the list of servers in the memcached_st structure. + If enabled any hosts which have been flagged as disabled will be removed from the list of servers in the memcached_st structure. -.. c:var:: MEMCACHED_BEHAVIOR_RETRY_TIMEOUT +.. c:type:: MEMCACHED_BEHAVIOR_RETRY_TIMEOUT When enabled a host which is problematic will only be checked for usage based on the amount of time set by this behavior. -.. c:var:: MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY +.. c:type:: MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY When enabled the prefix key will be added to the key when determining server by hash. diff --git a/docs/memcached_callback.rst b/docs/memcached_callback.rst index 3cdd5adb..e5723d90 100644 --- a/docs/memcached_callback.rst +++ b/docs/memcached_callback.rst @@ -40,21 +40,19 @@ You can use :c:type:`MEMCACHED_CALLBACK_USER_DATA` to provide custom context if required for any of the callbacks. -.. c:var:: MEMCACHED_CALLBACK_CLEANUP_FUNCTION +.. c:type:: MEMCACHED_CALLBACK_CLEANUP_FUNCTION When :c:func:`memcached_delete()` is called this function will be excuted. At the point of its execution all connections are closed. -.. c:var:: MEMCACHED_CALLBACK_CLONE_FUNCTION +.. c:type:: MEMCACHED_CALLBACK_CLONE_FUNCTION When :c:func:`memcached_delete()` is called this function will be excuted. At the point of its execution all connections are closed. - - -.. c:var:: MEMCACHED_CALLBACK_PREFIX_KEY +.. c:type:: MEMCACHED_CALLBACK_PREFIX_KEY You can set a value which will be used to create a domain for your keys. The value specified here will be prefixed to each of your keys. The value can @@ -67,34 +65,25 @@ a key which is too long, :c:type:`MEMCACHED_BAD_KEY_PROVIDED` will be returned. If you set a value with the value being NULL then the prefix key is disabled. - -.. c:var:: MEMCACHED_CALLBACK_USER_DATA +.. c:type:: MEMCACHED_CALLBACK_USER_DATA This allows you to store a pointer to a specifc piece of data. This can be retrieved from inside of :c:func:`memcached_fetch_execute()`. Cloning a :c:type:`memcached_st` will copy the pointer to the clone. +.. c:type:: MEMCACHED_CALLBACK_MALLOC_FUNCTION +.. deprecated:: <0.32 + Use :c:type:`memcached_set_memory_allocators` instead. - -.. c:var:: MEMCACHED_CALLBACK_MALLOC_FUNCTION - -DEPRECATED: use :c:type:`memcached_set_memory_allocators` instead. - - - -.. c:var:: MEMCACHED_CALLBACK_REALLOC_FUNCTION - -DEPRECATED: use :c:type:`memcached_set_memory_allocators` instead. +.. c:type:: MEMCACHED_CALLBACK_REALLOC_FUNCTION +.. deprecated:: <0.32 + Use :c:type:`memcached_set_memory_allocators` instead. +.. c:type:: MEMCACHED_CALLBACK_FREE_FUNCTION +.. deprecated:: <0.32 + Use :c:type:`memcached_set_memory_allocators` instead. - -.. c:var:: MEMCACHED_CALLBACK_FREE_FUNCTION - -DEPRECATED: use :c:type:`memcached_set_memory_allocators` instead. - - - -.. c:var:: MEMCACHED_CALLBACK_GET_FAILURE +.. c:type:: MEMCACHED_CALLBACK_GET_FAILURE This function implements the read through cache behavior. On failure of retrieval this callback will be called. @@ -113,7 +102,7 @@ The prototype for this is: -.. c:var:: MEMCACHED_CALLBACK_DELETE_TRIGGER +.. c:type:: MEMCACHED_CALLBACK_DELETE_TRIGGER This function implements a trigger upon successful deletion of a key. The memcached_st structure will need to be cloned in order to make use of it. diff --git a/docs/memcached_create.rst b/docs/memcached_create.rst index 782b1a06..8e1d30f5 100644 --- a/docs/memcached_create.rst +++ b/docs/memcached_create.rst @@ -2,21 +2,21 @@ Creating and destroying a memcached_st ====================================== -.. index:: object: memcached_st - -------- SYNOPSIS -------- #include + +.. c:type:: memcachd_st + +.. c:function:: memcached_st* memcached_create(memcached_st *ptr) -.. c:function:: memcached_st *memcached_create (memcached_st *ptr); - -.. c:function:: void memcached_free (memcached_st *ptr); +.. c:function:: void memcached_free(memcached_st *ptr) -.. c:function:: memcached_st *memcached_clone (memcached_st *destination, memcached_st *source); +.. c:function:: memcached_st* memcached_clone(memcached_st *destination, memcached_st *source) -.. c:function:: void memcached_servers_reset(memcached_st); +.. c:function:: void memcached_servers_reset(memcached_st) Compile and link with -lmemcached diff --git a/docs/memcached_get.rst b/docs/memcached_get.rst index d3f5806f..4285b3ae 100644 --- a/docs/memcached_get.rst +++ b/docs/memcached_get.rst @@ -11,23 +11,21 @@ SYNOPSIS #include -.. c:function:: memcached_result_st * memcached_fetch_result (memcached_st *ptr, memcached_result_st *result, memcached_return_t *error); +.. c:function:: memcached_result_st * memcached_fetch_result (memcached_st *ptr, memcached_result_st *result, memcached_return_t *error) -.. c:function:: char * memcached_get (memcached_st *ptr, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error); +.. c:function:: char * memcached_get (memcached_st *ptr, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error) -.. c:function:: memcached_return_t memcached_mget (memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys); +.. c:function:: memcached_return_t memcached_mget (memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys) -.. c:function:: char * memcached_get_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error); +.. c:function:: char * memcached_get_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char *key, size_t key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error) -.. c:function:: memcached_return_t memcached_mget_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys); +.. c:function:: memcached_return_t memcached_mget_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys) -.. c:function:: char * memcached_fetch (memcached_st *ptr, char *key, size_t *key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error); +.. c:function:: memcached_return_t memcached_fetch_execute (memcached_st *ptr, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks) -.. c:function:: memcached_return_t memcached_fetch_execute (memcached_st *ptr, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks); +.. c:function:: memcached_return_t memcached_mget_execute (memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks) -.. c:function:: memcached_return_t memcached_mget_execute (memcached_st *ptr, const char * const *keys, const size_t *key_length, size_t number_of_keys, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks); - -.. c:function:: memcached_return_t memcached_mget_execute_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks); +.. c:function:: memcached_return_t memcached_mget_execute_by_key (memcached_st *ptr, const char *group_key, size_t group_key_length, const char * const *keys, const size_t *key_length, size_t number_of_keys, memcached_execute_fn *callback, void *context, uint32_t number_of_callbacks) Compile and link with -lmemcached @@ -47,23 +45,19 @@ object returned by :c:func:`memcached_get()` must be released by the caller application. :c:func:`memcached_mget()` is used to select multiple keys at once. For -multiple key operations it is always faster to use this function. This function always works asynchronously. :c:func:`memcached_fetch()` is then used to -retrieve any keys found. No error is given on keys that are not found. You -must call either :c:func:`memcached_fetch()` or -:c:func:`memcached_fetch_result()` after a successful call to -:c:func:`memcached_mget()`. You should continue to call these functions until -they return NULL (aka no more values). If you need to quit in the middle of a -:c:func:`memcached_get()` call, execute a :c:func:`memcached_quit()`. After you do this, you can issue new queries against the server. - -:c:func:`memcached_fetch()` is used to fetch an individual value from the server. :c:func:`memcached_mget()` must always be called before using this method. +multiple key operations it is always faster to use this function. This function always works asynchronously. + +To retrieve data after a successful execution of :c:func:`memcached_mget()`, you will need to +call :c:func:`memcached_fetch_result()`. You should continue to call this function until +it returns a NULL (i.e. no more values). If you need to quit in the middle of a +:c:func:`memcached_mget()` call, you can execute a :c:func:`memcached_quit()`, those this is not required. + +:c:func:`memcached_fetch_result()` is used to fetch an individual value from the server. :c:func:`memcached_mget()` must always be called before using this method. You must pass in a key and its length to fetch the object. You must supply three pointer variables which will give you the state of the returned object. A :c:type:`uint32_t` pointer to contain whatever flags you stored with the value, a :c:type:`size_t` pointer which will be filled with size of of the object, and a :c:type:`memcached_return_t` pointer to hold any error. The object will be returned upon success and NULL will be returned on failure. :c:type:`MEMCACHD_END` is returned by the \*error value when all objects that have been found are returned. The final value upon :c:type:`MEMCACHED_END` is null. -Values returned by :c:func:`memcached_fetch()` must be freed by the caller. -:c:func:`memcached_fetch()` will be DEPRECATED in the near future, -c:func:`memcached_fetch_result()` should be used instead. :c:func:`memcached_fetch_result()` is used to return a :c:type:`memcached_result_st` structure from a memcached server. The result object is forward compatible with changes to the server. For more information please refer to the @@ -105,8 +99,9 @@ RETURN ------ -All objects returned must be freed by the calling application. -:c:func:`memcached_get()` and :c:func:`memcached_fetch()` will return NULL on +All objects retrieved via :c:func:`memcached_get()` or :c:func:`memcached_get_by_key()` must be freed with :manpage:`free(3)`. + +:c:func:`memcached_get()` will return NULL on error. You must look at the value of error to determine what the actual error was. @@ -114,15 +109,10 @@ was. all keys were successful. :c:type:`MEMCACHED_NOTFOUND` will be return if no keys at all were found. -:c:func:`memcached_fetch()` and :c:func:`memcached_fetch_result()` set error +:c:func:`memcached_fetch_result()` sets error to :c:type:`MEMCACHED_END` upon successful conclusion. :c:type:`MEMCACHED_NOTFOUND` will be return if no keys at all were found. -:c:type:`MEMCACHED_KEY_TOO_BIG` is set to error whenever :c::func:`memcached_fetch()` was used -and the key was set larger then :c:type:`MEMCACHED_MAX_KEY`, which was the largest -key allowed for the original memcached ascii server. - - ---- HOME ---- @@ -132,7 +122,6 @@ To find out more information please check: `http://libmemcached.org/ `_ - -------- SEE ALSO -------- diff --git a/docs/memcached_pool.rst b/docs/memcached_pool.rst index 38d2b3a7..7dcc707a 100644 --- a/docs/memcached_pool.rst +++ b/docs/memcached_pool.rst @@ -2,25 +2,25 @@ Working with memcached pools ============================ -.. index:: object: memcached_pool_st - -------- SYNOPSIS -------- #include -.. c:function:: memcached_pool_st *memcached_pool(const char *option_string, size_t option_string_length); +.. c:type:: memcached_pool_st -.. c:function:: memcached_pool_st * memcached_pool_create(memcached_st* mmc, int initial, int max); DEPRECATED - -.. c:function:: memcached_st * memcached_pool_destroy(memcached_pool_st* pool); +.. c:function:: memcached_pool_st* memcached_pool(const char *option_string, size_t option_string_length) + +.. c:function:: memcached_pool_st* memcached_pool_create(memcached_st* mmc, int initial, int max) +.. deprecated:: 0.46 + Use :c:func:`memcached_pool()` instead. -.. c:function:: memcached_st * memcached_pool_pop (memcached_pool_st* pool, bool block, memcached_return_t *rc); +.. c:function:: memcached_st* memcached_pool_destroy(memcached_pool_st* pool) -.. c:function:: memcached_return_t memcached_pool_push(memcached_pool_st* pool, memcached_st *mmc); +.. c:function:: memcached_st* memcached_pool_pop (memcached_pool_st* pool, bool block, memcached_return_t *rc) -.. c:function:: memcached_st *memcached_create (memcached_st *ptr); +.. c:function:: memcached_return_t memcached_pool_push(memcached_pool_st* pool, memcached_st *mmc) .. c:function:: memcached_return_t memcached_pool_behavior_set(memcached_pool_st *pool, memcached_behavior_t flag, uint64_t data) @@ -36,19 +36,7 @@ DESCRIPTION :c:func:`memcached_pool()` is used to create a connection pool of objects you may use to remove the overhead of using memcached_clone for short lived -:c:type:`memcached_st` objects. Please see :manpage:`libmemcached_configuration` for details on the format of the configuration string. - -DEPRECATED :c:func:`memcached_pool_create()` is used to create a connection pool of objects you may use to remove the overhead of using -:c:type:`memcached_clone` for short lived :c:type:`memcached_st` objects. -The mmc argument should be an initialised :c:type:`memcached_st` structure, -and a successfull invocation of :c:type:`memcached_pool_create` takes full -ownership of the variable (until it is released by -:c:type:`memcached_pool_destroy`). The :c:type:`initial` argument specifies -the initial size of the connection pool, and the :c:type:`max` argument -specifies the maximum size the connection pool should grow to. Please note -that the library will allocate a fixed size buffer scaled to the max size of -the connection pool, so you should not pass MAXINT or some other large -number here. +:c:type:`memcached_st` objects. Please see :doc:`libmemcached_configuration` for details on the format of the configuration string. :c:func:`memcached_pool_destroy()` is used to destroy the connection pool created with :c:func:`memcached_pool_create()` and release all allocated @@ -62,23 +50,16 @@ to exceed the maximum size. :c:func:`memcached_pool_push()` is used to return a connection structure back to the pool. -:c:func:`memcached_pool_behavior_set()` and :c:func:`memcached_pool_behagior_get()` is used to get/set behavior flags on all connections in the pool. +:c:func:`memcached_pool_behavior_get()` and :c:func:`memcached_pool_behavior_set()` is used to get/set behavior flags on all connections in the pool. ------ RETURN ------ +:c:func:`memcached_pool_destroy()` returns the pointer (and ownership) to the :c:type:`memcached_st` structure used to create the pool. If connections are in use it returns NULL. -:c:func:`memcached_pool_create()` returns a pointer to the newly created -:c:type:`memcached_pool_st` structure. On an allocation failure, it returns -NULL. - -:c:func:`memcached_pool_destroy()` returns the pointer (and ownership) to the -:c:type:`memcached_st` structure used to create the pool. If connections are in -use it returns NULL. - -:c:func:`memcached_pool_pop()` returns a pointer to a :c:type:`memcached_st structure` from the pool (or NULL if an allocation cannot be satisfied). +:c:func:`memcached_pool_pop()` returns a pointer to a :c:type:`memcached_st` structure from the pool (or NULL if an allocation cannot be satisfied). :c:func:`memcached_pool_push()` returns :c:type:`MEMCACHED_SUCCESS` upon success. @@ -108,4 +89,4 @@ Trond Norbye, SEE ALSO -------- -:manpage:`memcached(1)` :manpage:`libmemcached(3)` :manpage:`memcached_strerror(3)` +:manpage:`memcached(1)` :manpage:`libmemcached(3)` :manpage:`memcached_strerror(3)` :manpage:`libmemcached_configuration(3)` diff --git a/libtest/callbacks.h b/libtest/callbacks.h new file mode 100644 index 00000000..ea7ae182 --- /dev/null +++ b/libtest/callbacks.h @@ -0,0 +1,21 @@ +/* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void* (test_callback_create_fn)(enum test_return_t*); +typedef enum test_return_t (test_callback_fn)(void *); +typedef enum test_return_t (test_callback_runner_fn)(test_callback_fn*, void *); +typedef enum test_return_t (test_callback_error_fn)(const enum test_return_t, void *); + +#ifdef __cplusplus +} +#endif + diff --git a/libtest/collection.h b/libtest/collection.h new file mode 100644 index 00000000..e8f8f62c --- /dev/null +++ b/libtest/collection.h @@ -0,0 +1,19 @@ +/* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + +/** + A structure which describes a collection of test cases. +*/ +struct collection_st { + const char *name; + test_callback_fn *pre; + test_callback_fn *post; + struct test_st *tests; +}; + + diff --git a/libtest/common.h b/libtest/common.h new file mode 100644 index 00000000..9b00f6de --- /dev/null +++ b/libtest/common.h @@ -0,0 +1,50 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * uTest + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ All + * rights reserved. + * + * 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. + * + */ + +/* + Common include file for libmemached +*/ + +#pragma once + +#include + +#include +#include +#include + +#include diff --git a/libtest/core.h b/libtest/core.h new file mode 100644 index 00000000..2b62161b --- /dev/null +++ b/libtest/core.h @@ -0,0 +1,11 @@ +/* + * uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + +LIBTEST_API +void create_core(void); diff --git a/libtest/error.h b/libtest/error.h new file mode 100644 index 00000000..c4a3a702 --- /dev/null +++ b/libtest/error.h @@ -0,0 +1,18 @@ +/* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + +enum test_return_t { + TEST_SUCCESS= 0, /* Backwards compatibility */ + TEST_FAILURE, + TEST_MEMORY_ALLOCATION_FAILURE, + TEST_SKIPPED, + TEST_FATAL // Collection should not be continued +}; + + +#define test_failed(__test_return_t) ((__test_return_t) != TEST_SUCCESS) diff --git a/libtest/failed.h b/libtest/failed.h index 16d1aecc..a4b2cacc 100644 --- a/libtest/failed.h +++ b/libtest/failed.h @@ -36,7 +36,6 @@ */ #pragma once -#include #ifdef __cplusplus extern "C" { diff --git a/libtest/framework.cc b/libtest/framework.cc new file mode 100644 index 00000000..ff67f20b --- /dev/null +++ b/libtest/framework.cc @@ -0,0 +1,57 @@ +/* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#include + +test_return_t Framework::destroy(void* arg) +{ + if (_destroy) + { + return _destroy(arg); + } + + return TEST_SUCCESS; +} + +test_return_t Framework::Item::flush(void* arg, test_st* run) +{ + if (run->requires_flush and _flush) + { + return _flush(arg); + } + + return TEST_SUCCESS; +} + +test_return_t Framework::on_error(const test_return_t rc, void* arg) +{ + if (_on_error and test_failed(_on_error(rc, arg))) + { + return TEST_FAILURE; + } + + return TEST_SUCCESS; +} + +test_return_t Framework::startup(void* arg) +{ + if (collection_startup) + { + return collection_startup(arg); + } + + return TEST_SUCCESS; +} + +test_return_t Framework::Item::startup(void* arg) +{ + if (_startup) + { + return _startup(arg); + } + + return TEST_SUCCESS; +} diff --git a/libtest/framework.h b/libtest/framework.h new file mode 100644 index 00000000..7a58cbee --- /dev/null +++ b/libtest/framework.h @@ -0,0 +1,137 @@ +/* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + +/** + Framework is the structure which is passed to the test implementation to be filled. + This must be implemented in order for the test framework to load the tests. We call + get_world() in order to fill this structure. +*/ + +struct Framework { + collection_st *collections; + + /* These methods are called outside of any collection call. */ + test_callback_create_fn *_create; + test_callback_fn *_destroy; + + void* create(test_return_t* arg) + { + if (_create) + { + return _create(arg); + } + + return NULL; + } + + test_return_t destroy(void*); + + /* This is called a the beginning of any collection run. */ + test_callback_fn *collection_startup; + + test_return_t startup(void*); + + /* This is called a the end of any collection run. */ + test_callback_fn *collection_shutdown; + + test_return_t shutdown(void* arg) + { + if (collection_shutdown) + { + return collection_shutdown(arg); + } + + return TEST_SUCCESS; + } + + /** + These are run before/after the test. If implemented. Their execution is not controlled + by the test. + */ + struct Item { + /* This is called a the beginning of any run. */ + test_callback_fn *_startup; + + test_return_t startup(void*); + + /* + This called on a test if the test requires a flush call (the bool is + from test_st) + */ + test_callback_fn *_flush; + + /* + Run before and after the runnner is executed. + */ + test_callback_fn *pre_run; + test_callback_fn *post_run; + + Item() : + _startup(NULL), + _flush(NULL), + pre_run(NULL), + post_run(NULL) + { } + + test_return_t flush(void* arg, test_st* run); + + void set_pre(test_callback_fn *arg) + { + pre_run= arg; + } + + void set_post(test_callback_fn *arg) + { + pre_run= arg; + } + + test_return_t pre(void *arg) + { + if (pre_run) + { + return pre_run(arg); + } + + return TEST_SUCCESS; + } + + test_return_t post(void *arg) + { + if (post_run) + { + return post_run(arg); + } + + return TEST_SUCCESS; + } + + } item; + + /** + If an error occurs during the test, this is called. + */ + test_callback_error_fn *_on_error; + + test_return_t on_error(const enum test_return_t, void *); + + /** + Runner represents the callers for the tests. If not implemented we will use + a set of default implementations. + */ + Runner *runner; + + Framework(); + + virtual ~Framework() + { } + + Framework(const Framework&); + +private: + Framework& operator=(const Framework&); +}; diff --git a/libtest/get.h b/libtest/get.h new file mode 100644 index 00000000..2cd9dec8 --- /dev/null +++ b/libtest/get.h @@ -0,0 +1,22 @@ +/* + * uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + + /* How we make all of this work :) */ + LIBTEST_API + void get_world(Framework *world); + +#ifdef __cplusplus +} +#endif + + diff --git a/libtest/include.am b/libtest/include.am index a7a795fd..610521a7 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -16,8 +16,18 @@ CLEANFILES+= \ tests/var/tmp/* noinst_HEADERS+= \ + libtest/callbacks.h \ + libtest/collection.h \ + libtest/common.h \ + libtest/core.h \ + libtest/error.h \ libtest/failed.h \ + libtest/framework.h \ + libtest/get.h \ + libtest/runner.h \ libtest/server.h \ + libtest/stats.h \ + libtest/strerror.h \ libtest/test.h \ libtest/visibility.h @@ -26,8 +36,9 @@ libtest_libserver_la_SOURCES= libtest/server.c noinst_LTLIBRARIES+= libtest/libtest.la libtest_libtest_la_SOURCES=\ + libtest/framework.cc \ libtest/test.cc -libtest_libtest_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} +libtest_libtest_la_CFLAGS= ${AM_CFLAGS} ${NO_CONVERSION} -DBUILDING_LIBTEST libtest_libtest_la_CPPFLAGS= ${AM_CPPFLAGS} tests/var: tests/var/log tests/var/tmp diff --git a/libtest/runner.h b/libtest/runner.h new file mode 100644 index 00000000..8678c4c0 --- /dev/null +++ b/libtest/runner.h @@ -0,0 +1,19 @@ +/* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + + +/** + Structure which houses the actual callers for the test cases contained in + the collections. +*/ +struct Runner { + test_callback_runner_fn *pre; + test_callback_runner_fn *run; + test_callback_runner_fn *post; +}; + diff --git a/libtest/stats.h b/libtest/stats.h new file mode 100644 index 00000000..29be06c6 --- /dev/null +++ b/libtest/stats.h @@ -0,0 +1,30 @@ +/* uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once +struct Stats { + int32_t collection_success; + int32_t collection_skipped; + int32_t collection_failed; + int32_t collection_total; + + uint32_t success; + uint32_t skipped; + uint32_t failed; + uint32_t total; + + Stats() : + collection_success(0), + collection_skipped(0), + collection_failed(0), + collection_total(0), + success(0), + skipped(0), + failed(0), + total(0) + { } +}; + diff --git a/libtest/strerror.h b/libtest/strerror.h new file mode 100644 index 00000000..2d6e6536 --- /dev/null +++ b/libtest/strerror.h @@ -0,0 +1,14 @@ +/* + * uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +#pragma once + +/** + @note Friendly print function for errors. +*/ +LIBTEST_API +const char *test_strerror(test_return_t code); diff --git a/libtest/test.cc b/libtest/test.cc index 2c57d206..ee743983 100644 --- a/libtest/test.cc +++ b/libtest/test.cc @@ -8,28 +8,40 @@ */ -#include +#include -#include -#include -#include -#include +#include +#include +#include #include #include #include #include #include -#include +#include #include #include -#include +#include #ifndef __INTEL_COMPILER #pragma GCC diagnostic ignored "-Wold-style-cast" #endif -static void world_stats_print(world_stats_st *stats) +static in_port_t global_port= 0; + +in_port_t default_port() +{ + assert(global_port); + return global_port; +} + +void set_default_port(in_port_t port) +{ + global_port= port; +} + +static void stats_print(Stats *stats) { std::cout << "\tTotal Collections\t\t\t\t" << stats->collection_total << std::endl; std::cout << "\tFailed Collections\t\t\t\t" << stats->collection_failed << std::endl; @@ -58,19 +70,21 @@ const char *test_strerror(test_return_t code) switch (code) { case TEST_SUCCESS: return "ok"; + case TEST_FAILURE: return "failed"; - case TEST_FATAL: - return "failed"; + case TEST_MEMORY_ALLOCATION_FAILURE: return "memory allocation"; + case TEST_SKIPPED: return "skipped"; - case TEST_MAXIMUM_RETURN: - default: - std::cerr << "Unknown return value." << std::endl; - abort(); + + case TEST_FATAL: + break; } + + return "failed"; } void create_core(void) @@ -94,12 +108,14 @@ void create_core(void) static test_return_t _runner_default(test_callback_fn func, void *p) { if (func) + { return func(p); + } return TEST_SUCCESS; } -static world_runner_st defualt_runners= { +static Runner defualt_runners= { _runner_default, _runner_default, _runner_default @@ -112,29 +128,23 @@ static test_return_t _default_callback(void *p) return TEST_SUCCESS; } -static collection_st *init_world(world_st *world) +Framework::Framework() : + collections(NULL), + _create(NULL), + _destroy(NULL), + collection_startup(_default_callback), + collection_shutdown(_default_callback), + _on_error(NULL), + runner(&defualt_runners) { - if (world->runner == NULL) - { - world->runner= &defualt_runners; - } - - if (world->collection_startup == NULL) - world->collection_startup= _default_callback; - - if (world->collection_shutdown == NULL) - world->collection_shutdown= _default_callback; - - return world->collections; } int main(int argc, char *argv[]) { - world_st world; - void *world_ptr; + Framework world; - world_stats_st stats; + Stats stats; get_world(&world); @@ -143,20 +153,11 @@ int main(int argc, char *argv[]) world.runner= &defualt_runners; } - collection_st *collection= init_world(&world); - - if (world.create) + test_return_t error; + void *world_ptr= world.create(&error); + if (test_failed(error)) { - test_return_t error; - world_ptr= world.create(&error); - if (error != TEST_SUCCESS) - { - return EXIT_FAILURE; - } - } - else - { - world_ptr= NULL; + return EXIT_FAILURE; } char *collection_to_run= NULL; @@ -180,7 +181,7 @@ int main(int argc, char *argv[]) wildcard= argv[2]; } - for (collection_st *next= collection; next->name; next++) + for (collection_st *next= world.collections; next->name; next++) { test_return_t collection_rc= TEST_SUCCESS; bool failed= false; @@ -191,7 +192,7 @@ int main(int argc, char *argv[]) stats.collection_total++; - collection_rc= world.collection_startup(world_ptr); + collection_rc= world.startup(world_ptr); if (collection_rc == TEST_SUCCESS and next->pre) { @@ -216,10 +217,7 @@ int main(int argc, char *argv[]) goto cleanup; case TEST_MEMORY_ALLOCATION_FAILURE: - case TEST_MAXIMUM_RETURN: - default: - assert(0); - break; + test_assert(0, "Allocation failure, or unknown return"); } for (test_st *run= next->tests; run->name; run++) @@ -234,53 +232,21 @@ int main(int argc, char *argv[]) std::cerr << "\tTesting " << run->name; - if (world.run_startup) - { - world.run_startup(world_ptr); - } + world.item.startup(world_ptr); - if (run->requires_flush && world.flush) - { - world.flush(world_ptr); - } - - if (world.pre_run) - { - world.pre_run(world_ptr); - } + world.item.flush(world_ptr, run); + world.item.pre(world_ptr); test_return_t return_code; { // Runner Code -#if 0 - if (next->pre and world.runner->pre) - { - return_code= world.runner->pre(next->pre, world_ptr); - - if (return_code != TEST_SUCCESS) - { - goto error; - } - } -#endif - gettimeofday(&start_time, NULL); return_code= world.runner->run(run->test_fn, world_ptr); gettimeofday(&end_time, NULL); load_time= timedif(end_time, start_time); - -#if 0 - if (next->post && world.runner->post) - { - (void) world.runner->post(next->post, world_ptr); - } -#endif } - if (world.post_run) - { - world.post_run(world_ptr); - } + world.item.post(world_ptr); stats.total++; @@ -305,22 +271,15 @@ int main(int argc, char *argv[]) break; case TEST_MEMORY_ALLOCATION_FAILURE: - case TEST_MAXIMUM_RETURN: - default: - break; - abort(); + test_assert(0, "Memory Allocation Error"); } std::cerr << "[ " << test_strerror(return_code) << " ]" << std::endl; - if (world.on_error) + if (test_failed(world.on_error(return_code, world_ptr))) { - test_return_t rc= world.on_error(return_code, world_ptr); - - if (rc != TEST_SUCCESS) - break; + break; } - } if (next->post && world.runner->post) @@ -334,10 +293,7 @@ int main(int argc, char *argv[]) } cleanup: - if (world.collection_shutdown) - { - world.collection_shutdown(world_ptr); - } + world.shutdown(world_ptr); } if (stats.collection_failed || stats.collection_skipped) @@ -352,18 +308,12 @@ cleanup: std::cout << std::endl << std::endl << "All tests completed successfully." << std::endl << std::endl; } - if (world.destroy) + if (test_failed(world.destroy(world_ptr))) { - test_return_t error= world.destroy(world_ptr); - - if (error != TEST_SUCCESS) - { - std::cerr << "Failure during shutdown." << std::endl; - stats.failed++; // We do this to make our exit code return EXIT_FAILURE - } + stats.failed++; // We do this to make our exit code return EXIT_FAILURE } - world_stats_print(&stats); + stats_print(&stats); return stats.failed == 0 ? 0 : 1; } diff --git a/libtest/test.h b/libtest/test.h index d6d7d787..c36572ea 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -1,46 +1,12 @@ -/* uTest - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* + * uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ * * Use and distribution licensed under the BSD license. See * the COPYING file in the parent directory for full text. */ -/* - Structures for generic tests. -*/ - -#include -#include -#include -#include -#include - #pragma once -enum test_return_t { - TEST_SUCCESS= 0, /* Backwards compatibility */ - TEST_FAILURE, - TEST_MEMORY_ALLOCATION_FAILURE, - TEST_SKIPPED, - TEST_FATAL, // Collection should not be continued - TEST_MAXIMUM_RETURN /* Always add new error code before */ -}; - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void* (test_callback_create_fn)(enum test_return_t*); -typedef enum test_return_t (test_callback_fn)(void *); -typedef enum test_return_t (test_callback_runner_fn)(test_callback_fn*, void *); -typedef enum test_return_t (test_callback_error_fn)(const enum test_return_t, void *); - -#ifdef __cplusplus -} -#endif - /** A structure describing the test case. */ @@ -50,142 +16,10 @@ struct test_st { test_callback_fn *test_fn; }; - -/** - A structure which describes a collection of test cases. -*/ -struct collection_st { - const char *name; - test_callback_fn *pre; - test_callback_fn *post; - struct test_st *tests; -}; - - -/** - Structure which houses the actual callers for the test cases contained in - the collections. -*/ -struct world_runner_st { - test_callback_runner_fn *pre; - test_callback_runner_fn *run; - test_callback_runner_fn *post; -}; - - -/** - world_st is the structure which is passed to the test implementation to be filled. - This must be implemented in order for the test framework to load the tests. We call - get_world() in order to fill this structure. -*/ - -struct world_st { - collection_st *collections; - - /* These methods are called outside of any collection call. */ - test_callback_create_fn *create; - test_callback_fn *destroy; - - /* This is called a the beginning of any collection run. */ - test_callback_fn *collection_startup; - - /* This is called a the end of any collection run. */ - test_callback_fn *collection_shutdown; - - /* This is called a the beginning of any run. */ - test_callback_fn *run_startup; - - /* This called on a test if the test requires a flush call (the bool is from test_st) */ - test_callback_fn *flush; - - /** - These are run before/after the test. If implemented. Their execution is not controlled - by the test. - */ - test_callback_fn *pre_run; - test_callback_fn *post_run; - - /** - If an error occurs during the test, this is called. - */ - test_callback_error_fn *on_error; - - /** - Runner represents the callers for the tests. If not implemented we will use - a set of default implementations. - */ - world_runner_st *runner; - - world_st() : - collections(NULL), - create(NULL), - destroy(NULL), - collection_startup(NULL), - collection_shutdown(NULL), - run_startup(NULL), - flush(NULL), - pre_run(NULL), - post_run(NULL), - on_error(NULL), - runner(NULL) - { } - - virtual ~world_st() - { } - -private: - world_st(const world_st&); - world_st& operator=(const world_st&); -}; - - - -/** - @note world_stats_st is a simple structure for tracking test successes. -*/ -struct world_stats_st { - int32_t collection_success; - int32_t collection_skipped; - int32_t collection_failed; - int32_t collection_total; - - uint32_t success; - uint32_t skipped; - uint32_t failed; - uint32_t total; - - world_stats_st() : - collection_success(0), - collection_skipped(0), - collection_failed(0), - collection_total(0), - success(0), - skipped(0), - failed(0), - total(0) - { } -}; - #define TEST_STRINGIFY(x) #x #define TEST_TOSTRING(x) TEST_STRINGIFY(x) #define TEST_AT __FILE__ ":" TEST_TOSTRING(__LINE__) -#ifdef __cplusplus -extern "C" { -#endif - -/* How we make all of this work :) */ -LIBTEST_API -void get_world(world_st *world); - -LIBTEST_INTERNAL_API -void create_core(void); - -/** - @note Friendly print function for errors. -*/ -LIBTEST_INTERNAL_API -const char *test_strerror(test_return_t code); #define test_assert_errno(A) \ do \ @@ -199,6 +33,17 @@ do \ } \ } while (0) +#define test_assert(A, B) \ +do \ +{ \ + if ((A)) { \ + fprintf(stderr, "\nAssertion, %s(%s), failed at %s:%d: ", (B), #A, __FILE__, __LINE__);\ + fprintf(stderr, "\n"); \ + create_core(); \ + assert((A)); \ + } \ +} while (0) + #define test_truth(A) \ do \ { \ @@ -315,14 +160,3 @@ do \ } \ } while (0) -#ifdef __cplusplus -} -#endif - -#ifdef __cplusplus -#define test_literal_param(X) (X), (static_cast((sizeof(X) - 1))) -#else -#define test_literal_param(X) (X), ((size_t)((sizeof(X) - 1))) -#endif - -#define test_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0) diff --git a/libtest/test.hpp b/libtest/test.hpp new file mode 100644 index 00000000..5953f82c --- /dev/null +++ b/libtest/test.hpp @@ -0,0 +1,46 @@ +/* uTest + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + */ + +/* + Structures for generic tests. +*/ + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#pragma once + +LIBTEST_API + in_port_t default_port(); + +LIBTEST_API + void set_default_port(in_port_t port); + +#ifdef __cplusplus +#define test_literal_param(X) (X), (static_cast((sizeof(X) - 1))) +#else +#define test_literal_param(X) (X), ((size_t)((sizeof(X) - 1))) +#endif + +#define test_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0) diff --git a/tests/atomsmasher.cc b/tests/atomsmasher.cc index ffde3877..a525b95e 100644 --- a/tests/atomsmasher.cc +++ b/tests/atomsmasher.cc @@ -30,7 +30,7 @@ #include #include -#include +#include /* Number of items generated for tests */ #define GLOBAL_COUNT 100000 @@ -276,18 +276,18 @@ collection_st collection[] ={ #include "libmemcached_world.h" -void get_world(world_st *world) +void get_world(Framework *world) { world->collections= collection; - world->create= (test_callback_create_fn*)world_create; - world->destroy= (test_callback_fn*)world_destroy; + world->_create= (test_callback_create_fn*)world_create; + world->_destroy= (test_callback_fn*)world_destroy; - world->run_startup= (test_callback_fn*)world_test_startup; - world->flush= (test_callback_fn*)world_flush; - world->pre_run= (test_callback_fn*)world_pre_run; - world->post_run= (test_callback_fn*)world_post_run; - world->on_error= (test_callback_error_fn*)world_on_error; + world->item._startup= (test_callback_fn*)world_test_startup; + world->item._flush= (test_callback_fn*)world_flush; + world->item.set_pre((test_callback_fn*)world_pre_run); + world->item.set_post((test_callback_fn*)world_post_run); + world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; world->collection_shutdown= (test_callback_fn*)world_container_shutdown; diff --git a/tests/basic.cc b/tests/basic.cc index 85e96591..8f57e4c5 100644 --- a/tests/basic.cc +++ b/tests/basic.cc @@ -37,7 +37,9 @@ #include #include -#include + +#include + #include "tests/basic.h" #include diff --git a/tests/deprecated.cc b/tests/deprecated.cc index 03cfdaaa..eebc7d06 100644 --- a/tests/deprecated.cc +++ b/tests/deprecated.cc @@ -39,7 +39,7 @@ #include -#include +#include #include #include diff --git a/tests/error_conditions.cc b/tests/error_conditions.cc index 50a64da5..09a01eb4 100644 --- a/tests/error_conditions.cc +++ b/tests/error_conditions.cc @@ -41,7 +41,9 @@ #include #include -#include + +#include + #include test_return_t memcached_increment_MEMCACHED_NO_SERVERS(memcached_st *) diff --git a/tests/error_conditions.h b/tests/error_conditions.h index 1bfa9ed2..54991973 100644 --- a/tests/error_conditions.h +++ b/tests/error_conditions.h @@ -37,8 +37,6 @@ #pragma once -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/tests/hash_plus.cc b/tests/hash_plus.cc index 987d7971..e3130786 100644 --- a/tests/hash_plus.cc +++ b/tests/hash_plus.cc @@ -4,7 +4,7 @@ #include -#include +#include #include #include @@ -93,7 +93,7 @@ static test_return_t set_function_test(void *) { hashkit_return_t rc= hashk.set_function(*algo); - test_true(rc == HASHKIT_SUCCESS); + test_compare(HASHKIT_SUCCESS, rc); uint32_t *list; switch (*algo) @@ -101,30 +101,38 @@ static test_return_t set_function_test(void *) case HASHKIT_HASH_DEFAULT: list= one_at_a_time_values; break; + case HASHKIT_HASH_MD5: list= md5_values; break; + case HASHKIT_HASH_CRC: list= crc_values; break; + case HASHKIT_HASH_FNV1_64: list= fnv1_64_values; break; + case HASHKIT_HASH_FNV1A_64: list= fnv1a_64_values; break; + case HASHKIT_HASH_FNV1_32: list= fnv1_32_values; break; + case HASHKIT_HASH_FNV1A_32: list= fnv1a_32_values; break; + case HASHKIT_HASH_HSIEH: #ifndef HAVE_HSIEH_HASH continue; #endif list= hsieh_values; break; + case HASHKIT_HASH_MURMUR: #ifdef WORDS_BIGENDIAN continue; @@ -134,9 +142,11 @@ static test_return_t set_function_test(void *) #endif list= murmur_values; break; + case HASHKIT_HASH_JENKINS: list= jenkins_values; break; + case HASHKIT_HASH_CUSTOM: case HASHKIT_HASH_MAX: default: @@ -211,7 +221,7 @@ collection_st collection[] ={ {0, 0, 0, 0} }; -void get_world(world_st *world) +void get_world(Framework *world) { world->collections= collection; } diff --git a/tests/hashkit_functions.cc b/tests/hashkit_functions.cc index 461faaed..98396df5 100644 --- a/tests/hashkit_functions.cc +++ b/tests/hashkit_functions.cc @@ -44,7 +44,7 @@ #include -#include +#include #include "hash_results.h" @@ -613,9 +613,9 @@ test_return_t world_destroy(hashkit_st *hashk) return TEST_SUCCESS; } -void get_world(world_st *world) +void get_world(Framework *world) { world->collections= collection; - world->create= (test_callback_create_fn*)world_create; - world->destroy= (test_callback_fn*)world_destroy; + world->_create= (test_callback_create_fn*)world_create; + world->_destroy= (test_callback_fn*)world_destroy; } diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 36136c6e..fc0b6ae8 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -188,7 +188,7 @@ static test_return_t _post_runner_default(libmemcached_test_callback_fn func, li #ifdef __cplusplus -static world_runner_st defualt_libmemcached_runner= { +static Runner defualt_libmemcached_runner= { reinterpret_cast(_pre_runner_default), reinterpret_cast(_runner_default), reinterpret_cast(_post_runner_default) @@ -196,7 +196,7 @@ static world_runner_st defualt_libmemcached_runner= { #else -static world_runner_st defualt_libmemcached_runner= { +static Runner defualt_libmemcached_runner= { (test_callback_runner_fn)_pre_runner_default, (test_callback_runner_fn)_runner_default, (test_callback_runner_fn)_post_runner_default diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index bc29f2c0..c1bb70fe 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -63,7 +63,7 @@ #define SMALL_STRING_LEN 1024 -#include +#include #include "tests/deprecated.h" #include "tests/parser.h" #include "tests/pool.h" @@ -6507,18 +6507,18 @@ collection_st collection[] ={ #include "tests/libmemcached_world.h" -void get_world(world_st *world) +void get_world(Framework *world) { world->collections= collection; - world->create= (test_callback_create_fn*)world_create; - world->destroy= (test_callback_fn*)world_destroy; + world->_create= (test_callback_create_fn*)world_create; + world->_destroy= (test_callback_fn*)world_destroy; - world->run_startup= (test_callback_fn*)world_test_startup; - world->flush= (test_callback_fn*)world_flush; - world->pre_run= (test_callback_fn*)world_pre_run; - world->post_run= (test_callback_fn*)world_post_run; - world->on_error= (test_callback_error_fn*)world_on_error; + world->item._startup= (test_callback_fn*)world_test_startup; + world->item._flush= (test_callback_fn*)world_flush; + world->item.set_pre((test_callback_fn*)world_pre_run); + world->item.set_post((test_callback_fn*)world_post_run); + world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; world->collection_shutdown= (test_callback_fn*)world_container_shutdown; diff --git a/tests/mem_udp.cc b/tests/mem_udp.cc index 650134ad..8153e8ef 100644 --- a/tests/mem_udp.cc +++ b/tests/mem_udp.cc @@ -27,7 +27,7 @@ #include #include -#include +#include #define SERVERS_TO_CREATE 5 @@ -491,18 +491,18 @@ collection_st collection[] ={ #include "libmemcached_world.h" -void get_world(world_st *world) +void get_world(Framework *world) { world->collections= collection; - world->create= (test_callback_create_fn*)world_create; - world->destroy= (test_callback_fn*)world_destroy; + world->_create= (test_callback_create_fn*)world_create; + world->_destroy= (test_callback_fn*)world_destroy; - world->run_startup= (test_callback_fn*)world_test_startup; - world->flush= (test_callback_fn*)world_flush; - world->pre_run= (test_callback_fn*)world_pre_run; - world->post_run= (test_callback_fn*)world_post_run; - world->on_error= (test_callback_error_fn*)world_on_error; + world->item._startup= (test_callback_fn*)world_test_startup; + world->item._flush= (test_callback_fn*)world_flush; + world->item.set_pre((test_callback_fn*)world_pre_run); + world->item.set_post((test_callback_fn*)world_post_run); + world->_on_error= (test_callback_error_fn*)world_on_error; world->collection_startup= (test_callback_fn*)world_container_startup; world->collection_shutdown= (test_callback_fn*)world_container_shutdown; diff --git a/tests/parser.cc b/tests/parser.cc index e18fd01c..ad602048 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -43,13 +43,15 @@ #include #include +#include + #define BUILDING_LIBMEMCACHED // !NEVER use common.h, always use memcached.h in your own apps #include #include -#include "tests/parser.h" -#include "tests/print.h" +#include +#include enum scanner_type_t { diff --git a/tests/parser.h b/tests/parser.h index 15d57a64..dac1a691 100644 --- a/tests/parser.h +++ b/tests/parser.h @@ -37,8 +37,6 @@ #pragma once -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/tests/plus.cpp b/tests/plus.cpp index efb705a7..f67fcf27 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -14,7 +14,7 @@ #include -#include +#include #include #include @@ -220,18 +220,18 @@ collection_st collection[] ={ #include "libmemcached_world.h" -void get_world(world_st *world) +void get_world(Framework *world) { world->collections= collection; - world->create= reinterpret_cast(world_create); - world->destroy= reinterpret_cast(world_destroy); + world->_create= reinterpret_cast(world_create); + world->_destroy= reinterpret_cast(world_destroy); - world->run_startup= reinterpret_cast(world_test_startup); - world->flush= reinterpret_cast(world_flush); - world->pre_run= reinterpret_cast(world_pre_run); - world->post_run= reinterpret_cast(world_post_run); - world->on_error= reinterpret_cast(world_on_error); + world->item._startup= reinterpret_cast(world_test_startup); + world->item._flush= reinterpret_cast(world_flush); + world->item.set_pre(reinterpret_cast(world_pre_run)); + world->item.set_post(reinterpret_cast(world_post_run)); + world->_on_error= reinterpret_cast(world_on_error); world->collection_startup= reinterpret_cast(world_container_startup); world->collection_shutdown= reinterpret_cast(world_container_shutdown); diff --git a/tests/pool.cc b/tests/pool.cc index ed5016f0..9e1d94f7 100644 --- a/tests/pool.cc +++ b/tests/pool.cc @@ -37,10 +37,12 @@ #include +#include + #include #include #include -#include +#include #include #include diff --git a/tests/pool.h b/tests/pool.h index 45bb14da..ff4d47c7 100644 --- a/tests/pool.h +++ b/tests/pool.h @@ -37,8 +37,6 @@ #pragma once -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/tests/print.cc b/tests/print.cc index 570ab0f0..b3c8d066 100644 --- a/tests/print.cc +++ b/tests/print.cc @@ -40,7 +40,7 @@ #include #include -#include +#include #include "tests/print.h" diff --git a/tests/replication.cc b/tests/replication.cc index 92d68066..3e4476c5 100644 --- a/tests/replication.cc +++ b/tests/replication.cc @@ -37,7 +37,7 @@ #include -#include +#include #include "libmemcached/common.h" #include diff --git a/tests/string.cc b/tests/string.cc index 5c6175f8..4048d91c 100644 --- a/tests/string.cc +++ b/tests/string.cc @@ -38,6 +38,9 @@ #define BUILDING_LIBMEMCACHED #include + +#include + #include #include diff --git a/tests/string.h b/tests/string.h index eebd0c11..12f06109 100644 --- a/tests/string.h +++ b/tests/string.h @@ -37,8 +37,6 @@ #pragma once -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/tests/virtual_buckets.cc b/tests/virtual_buckets.cc index 308fa1d8..1714600e 100644 --- a/tests/virtual_buckets.cc +++ b/tests/virtual_buckets.cc @@ -37,6 +37,7 @@ #include +#include #include #include diff --git a/tests/virtual_buckets.h b/tests/virtual_buckets.h index 054ec492..dee47694 100644 --- a/tests/virtual_buckets.h +++ b/tests/virtual_buckets.h @@ -37,8 +37,6 @@ #pragma once -#include - struct memcached_st; #ifdef __cplusplus -- 2.30.2