*
*/
-#include <config.h>
-#include <libtest/test.hpp>
+#include "mem_config.h"
+#include "libtest/test.hpp"
#if defined(HAVE_LIBUUID) && HAVE_LIBUUID
-#include <uuid/uuid.h>
+# include <uuid/uuid.h>
#endif
/*
Test cases
*/
-#include <libmemcached-1.0/memcached.h>
-#include <libmemcached/is.h>
-#include <libmemcached/server_instance.h>
+#include "libmemcached-1.0/memcached.h"
+#include "libmemcached/is.h"
+#include "libmemcached/server_instance.h"
-#include <libhashkit-1.0/hashkit.h>
+#include "libhashkit-1.0/hashkit.h"
+
+#include "libtest/memcached.hpp"
-#include <cassert>
#include <cerrno>
#include <memory>
#include <pthread.h>
#include <iostream>
-#include <libtest/server.h>
+#include "libtest/server.h"
-#include "clients/generator.h"
+#include "bin/generator.h"
#define SMALL_STRING_LEN 1024
-#include <libtest/test.hpp>
+#include "libtest/test.hpp"
using namespace libtest;
-#include <libmemcached/util.h>
+#include "libmemcachedutil-1.0/util.h"
#include "tests/hash_results.h"
#include "tests/libmemcached-1.0/setup_and_teardowns.h"
#include "tests/print.h"
#include "tests/debug.h"
+#include "tests/memc.hpp"
#define UUID_STRING_MAXLENGTH 36
-struct keys_st {
-public:
- keys_st(size_t arg)
- {
- init(arg, UUID_STRING_MAXLENGTH);
- }
-
- keys_st(size_t arg, size_t padding)
- {
- init(arg, padding);
- }
-
- void init(size_t arg, size_t padding)
- {
- _lengths.resize(arg);
- _keys.resize(arg);
-
- for (size_t x= 0; x < _keys.size(); x++)
- {
- libtest::vchar_t key_buffer;
- key_buffer.resize(padding +1);
- memset(&key_buffer[0], 'x', padding);
-
- if (HAVE_LIBUUID)
- {
-#if defined(HAVE_LIBUUID) && HAVE_LIBUUID
- uuid_t out;
- uuid_generate(out);
-
- uuid_unparse(out, &key_buffer[0]);
- _keys[x]= strdup(&key_buffer[0]);
- (_keys[x])[UUID_STRING_MAXLENGTH]= 'x';
-#endif
- }
- else // We just use a number and pad the string if UUID is not available
- {
- char int_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
- int key_length= snprintf(int_buffer, sizeof(int_buffer), "%u", uint32_t(x));
- memcpy(&key_buffer[0], int_buffer, key_length);
- _keys[x]= strdup(&key_buffer[0]);
- }
- _lengths[x]= padding;
- }
- }
-
- ~keys_st()
- {
- for (libtest::vchar_ptr_t::iterator iter= _keys.begin();
- iter != _keys.end();
- iter++)
- {
- ::free(*iter);
- }
- }
-
- libtest::vchar_ptr_t::iterator begin()
- {
- return _keys.begin();
- }
-
- libtest::vchar_ptr_t::iterator end()
- {
- return _keys.end();
- }
+#include "tests/keys.hpp"
- size_t size() const
- {
- return _keys.size();
- }
-
- std::vector<size_t>& lengths()
- {
- return _lengths;
- }
-
- libtest::vchar_ptr_t& keys()
- {
- return _keys;
- }
-
- size_t* lengths_ptr()
- {
- return &_lengths[0];
- }
-
- char** keys_ptr()
- {
- return &_keys[0];
- }
-
- char* key_at(size_t arg)
- {
- return _keys[arg];
- }
-
- size_t length_at(size_t arg)
- {
- return _lengths[arg];
- }
-
-private:
- libtest::vchar_ptr_t _keys;
- std::vector<size_t> _lengths;
-};
-
-static memcached_return_t return_value_based_on_buffering(memcached_st *memc)
-{
- if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS))
- {
- return MEMCACHED_BUFFERED;
- }
-
- return MEMCACHED_SUCCESS;
-}
+#include "libmemcached/instance.hpp"
static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options)
{
* I only want to hit _one_ server so I know the number of requests I'm
* sending in the pipeline.
*/
- memcached_server_instance_st instance= memcached_server_instance_by_position(original_memc, 0);
+ const memcached_instance_st * instance= memcached_server_instance_by_position(original_memc, 0);
char server_string[1024];
int server_string_length;
in_port_t test_ports[TEST_PORT_COUNT];
static memcached_return_t server_display_function(const memcached_st *ptr,
- const memcached_server_st *server,
+ const memcached_instance_st * server,
void *context)
{
/* Do Nothing */
size_t bigger= *((size_t *)(context));
(void)ptr;
- assert(bigger <= memcached_server_port(server));
+ fatal_assert(bigger <= memcached_server_port(server));
*((size_t *)(context))= memcached_server_port(server);
return MEMCACHED_SUCCESS;
}
static memcached_return_t dump_server_information(const memcached_st *ptr,
- const memcached_server_st *instance,
+ const memcached_instance_st * instance,
void *context)
{
/* Do Nothing */
size_t bigger= 0; /* Prime the value for the test_true in server_display_function */
memcached_server_fn callbacks[1];
memcached_st *local_memc;
- memcached_server_instance_st instance;
+ const memcached_instance_st * instance;
(void)ptr;
local_memc= memcached_create(NULL);
}
static memcached_return_t server_display_unsort_function(const memcached_st*,
- const memcached_server_st *server,
+ const memcached_instance_st * server,
void *context)
{
/* Do Nothing */
uint32_t x= *((uint32_t *)(context));
- if (! (test_ports[x] == server->port))
+ if (! (test_ports[x] == memcached_server_port(server)))
{
- fprintf(stderr, "%lu -> %lu\n", (unsigned long)test_ports[x], (unsigned long)server->port);
+ fprintf(stderr, "%lu -> %lu\n", (unsigned long)test_ports[x], (unsigned long)memcached_server_port(server));
return MEMCACHED_FAILURE;
}
test_true(memc_clone->flags.buffer_requests == memc->flags.buffer_requests);
test_true(memc_clone->flags.use_sort_hosts == memc->flags.use_sort_hosts);
test_true(memc_clone->flags.verify_key == memc->flags.verify_key);
- test_true(memc_clone->ketama.weighted == memc->ketama.weighted);
+ test_true(memc_clone->ketama.weighted_ == memc->ketama.weighted_);
test_true(memc_clone->flags.binary_protocol == memc->flags.binary_protocol);
test_true(memc_clone->flags.hash_with_namespace == memc->flags.hash_with_namespace);
test_true(memc_clone->flags.reply == memc->flags.reply);
test_true(memc_clone->retry_timeout == memc->retry_timeout);
test_true(memc_clone->send_size == memc->send_size);
test_true(memc_clone->server_failure_limit == memc->server_failure_limit);
+ test_true(memc_clone->server_timeout_limit == memc->server_timeout_limit);
test_true(memc_clone->snd_timeout == memc->snd_timeout);
test_true(memc_clone->user_data == memc->user_data);
{
test_true(libmemcached_string_behavior(memcached_behavior_t(x)));
}
- test_compare(37, int(MEMCACHED_BEHAVIOR_MAX));
+ test_compare(38, int(MEMCACHED_BEHAVIOR_MAX));
return TEST_SUCCESS;
}
4159057246U, 3425930182U, 2593724503U, 1868899624U,
1769812374U, 2302537950U, 1110330676U, 3365377466U,
1336171666U, 3021258493U, 2334992265U, 3861994737U,
- 3582734124U, 3365377466U };
+ 3582734124U, 3889811103, 3365377466U };
// You have updated the memcache_error messages but not updated docs/tests.
for (int rc= int(MEMCACHED_SUCCESS); rc < int(MEMCACHED_MAXIMUM_RETURN); ++rc)
}
test_compare(values[rc], hash_val);
}
- test_compare(49, int(MEMCACHED_MAXIMUM_RETURN));
+ test_compare(50, int(MEMCACHED_MAXIMUM_RETURN));
return TEST_SUCCESS;
}
test_literal_param("foo"),
test_literal_param("when we sanitize"),
time_t(0), (uint32_t)0);
- test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc));
+ test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
return TEST_SUCCESS;
}
test_compare(value_length, sizeof(uint32_t) * count);
test_compare(MEMCACHED_SUCCESS, rc);
- for (uint32_t counter= count, *ptr= value; counter; counter--)
+ for (uint32_t counter= uint32_t(count), *ptr= value; counter; counter--)
{
test_compare(*ptr, store_list[count - counter]);
ptr++;
for (libtest::vchar_ptr_t::iterator iter= keys.begin();
iter != keys.end();
- iter++)
+ ++iter)
{
- test_compare(MEMCACHED_SUCCESS,
- memcached_set(memc,
- (*iter), 36,
- NULL, 0,
- time_t(0), uint32_t(0)));
+ test_compare_hint(MEMCACHED_SUCCESS,
+ memcached_set(memc,
+ (*iter), 36,
+ NULL, 0,
+ time_t(0), uint32_t(0)),
+ memcached_last_error_message(memc));
}
for (ptrdiff_t loop= 0; loop < 20; loop++)
{
result_count++;
}
- test_compare(keys.size(), result_count);
+ test_true(keys.size() >= result_count);
}
else
{
- int which_key= random() %keys.size();
+ int which_key= random() % int(keys.size());
size_t value_length;
uint32_t flags;
memcached_return_t rc;
char *out_value= memcached_get(memc, keys.key_at(which_key), keys.length_at(which_key),
&value_length, &flags, &rc);
- test_compare(MEMCACHED_SUCCESS, rc);
+ if (rc == MEMCACHED_NOTFOUND)
+ { } // It is possible that the value has been purged.
+ else
+ {
+ test_compare(MEMCACHED_SUCCESS, rc);
+ }
test_null(out_value);
test_zero(value_length);
test_zero(flags);
test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0));
- test_skip(true, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true));
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true));
test_compare(MEMCACHED_SUCCESS,
memcached_set(memc,
return TEST_SUCCESS;
}
+/*
+ Set the value, then quit to make sure it is flushed.
+ Come back in and test that add fails.
+*/
+test_return_t memcached_add_SUCCESS_TEST(memcached_st *memc)
+{
+ memcached_return_t rc;
+ test_null(memcached_get(memc, test_literal_param(__func__), NULL, NULL, &rc));
+ test_compare(MEMCACHED_NOTFOUND, rc);
+
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_add(memc,
+ test_literal_param(__func__),
+ test_literal_param("try something else"),
+ time_t(0), uint32_t(0)));
+
+ return TEST_SUCCESS;
+}
+
+test_return_t regression_1067242_TEST(memcached_st *memc)
+{
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc,
+ test_literal_param(__func__),
+ test_literal_param("-2"),
+ 0, 0));
+
+ memcached_return_t rc;
+ char* value;
+ test_true((value= memcached_get(memc, test_literal_param(__func__), NULL, NULL, &rc)));
+ test_compare(MEMCACHED_SUCCESS, rc);
+ free(value);
+
+ for (size_t x= 0; x < 10; x++)
+ {
+ uint64_t new_number;
+ test_compare(MEMCACHED_CLIENT_ERROR,
+ memcached_increment(memc,
+ test_literal_param(__func__), 1, &new_number));
+ test_compare(MEMCACHED_CLIENT_ERROR, memcached_last_error(memc));
+ test_true((value= memcached_get(memc, test_literal_param(__func__), NULL, NULL, &rc)));
+ test_compare(MEMCACHED_SUCCESS, rc);
+ free(value);
+ }
+
+ return TEST_SUCCESS;
+}
+
/*
Set the value, then quit to make sure it is flushed.
Come back in and test that add fails.
*/
test_return_t add_test(memcached_st *memc)
{
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- test_literal_param("when we sanitize"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc,
+ test_literal_param(__func__),
+ test_literal_param("when we sanitize"),
+ time_t(0), uint32_t(0)));
memcached_quit(memc);
- test_compare_hint(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) ? MEMCACHED_DATA_EXISTS : MEMCACHED_NOTSTORED,
- memcached_add(memc,
- test_literal_param(__func__),
- test_literal_param("try something else"),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ size_t value_length;
+ uint32_t flags;
+ memcached_return_t rc;
+ char *check_value= memcached_get(memc,
+ test_literal_param(__func__),
+ &value_length, &flags, &rc);
+ test_memcmp(check_value, "when we sanitize", strlen("when we sanitize"));
+ test_compare(test_literal_param_size("when we sanitize"), value_length);
+ test_compare(MEMCACHED_SUCCESS, rc);
+ free(check_value);
+
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) ? MEMCACHED_DATA_EXISTS : MEMCACHED_NOTSTORED,
+ memcached_add(memc,
+ test_literal_param(__func__),
+ test_literal_param("try something else"),
+ time_t(0), uint32_t(0)));
return TEST_SUCCESS;
}
#endif
for (uint32_t x= 0; x < max; x++)
+ {
add_test(memc);
+ }
return TEST_SUCCESS;
}
test_literal_param("when we sanitize"),
time_t(0), uint32_t(0)));
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_delete(memc,
- test_literal_param(__func__),
- time_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_delete(memc,
+ test_literal_param(__func__),
+ time_t(0)));
return TEST_SUCCESS;
}
}
static memcached_return_t server_function(const memcached_st *,
- const memcached_server_st *,
+ const memcached_instance_st *,
void *)
{
/* Do Nothing */
test_compare(MEMCACHED_SUCCESS,
memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, true));
test_compare(query_id, memcached_query_id(memc_clone)); // We should not increase the query_id for memcached_behavior_set()
+ ASSERT_TRUE(memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY));
/* All keys are valid in the binary protocol (except for length) */
if (memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == false)
size_t string_length;
char *string= memcached_get(memc_clone, key, strlen(key),
&string_length, &flags, &rc);
- test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc));
+ test_compare(MEMCACHED_NOTFOUND, rc);
test_zero(string_length);
test_false(string);
}
}
#define READ_THROUGH_VALUE "set for me"
-static memcached_return_t read_through_trigger(memcached_st *memc,
- char *key,
- size_t key_length,
+static memcached_return_t read_through_trigger(memcached_st *, // memc
+ char *, // key
+ size_t, // key_length,
memcached_result_st *result)
{
- (void)memc;(void)key;(void)key_length;
return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE));
}
&string_length, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
- test_compare(string_length, sizeof(READ_THROUGH_VALUE) -1);
- test_true(string[sizeof(READ_THROUGH_VALUE) -1] == 0);
+ test_compare(sizeof(READ_THROUGH_VALUE) -1, string_length);
+ test_compare(0, string[sizeof(READ_THROUGH_VALUE) -1]);
test_strcmp(READ_THROUGH_VALUE, string);
free(string);
return TEST_SUCCESS;
}
-test_return_t get_test(memcached_st *memc)
-{
- uint64_t query_id= memcached_query_id(memc);
- memcached_return_t rc= memcached_delete(memc,
- test_literal_param(__func__),
- time_t(0));
- test_true_hint(rc == MEMCACHED_BUFFERED or rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc));
- test_compare(query_id +1, memcached_query_id(memc));
-
- size_t string_length;
- uint32_t flags;
- char *string= memcached_get(memc,
- test_literal_param(__func__),
- &string_length, &flags, &rc);
-
- test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_last_error_message(memc));
- test_false(string_length);
- test_false(string);
-
- return TEST_SUCCESS;
-}
-
-test_return_t get_test2(memcached_st *memc)
-{
- const char *value= "when we sanitize";
-
- uint64_t query_id= memcached_query_id(memc);
- test_compare(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- value, strlen(value),
- time_t(0), uint32_t(0)));
- test_compare(query_id +1, memcached_query_id(memc));
-
- query_id= memcached_query_id(memc);
- test_true(query_id);
-
- uint32_t flags;
- size_t string_length;
- memcached_return_t rc;
- char *string= memcached_get(memc,
- test_literal_param(__func__),
- &string_length, &flags, &rc);
- test_compare(query_id +1, memcached_query_id(memc));
-
- test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
- test_compare_got(MEMCACHED_SUCCESS, memcached_last_error(memc), memcached_last_error_message(memc));
- test_true(string);
- test_compare(strlen(value), string_length);
- test_memcmp(string, value, string_length);
-
- free(string);
-
- return TEST_SUCCESS;
-}
-
test_return_t set_test2(memcached_st *memc)
{
for (uint32_t x= 0; x < 10; x++)
snprintf(key, sizeof(key), "foo%u", x);
uint64_t query_id= memcached_query_id(memc);
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc, key, strlen(key),
- &value[0], value.size(),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
+ test_compare(return_value_based_on_buffering(memc),
+ memcached_set(memc, key, strlen(key),
+ &value[0], value.size(),
+ time_t(0), uint32_t(0)));
test_compare(query_id +1, memcached_query_id(memc));
}
return TEST_SUCCESS;
}
-test_return_t get_test3(memcached_st *memc)
-{
- size_t value_length= 8191;
-
- libtest::vchar_t value;
- value.reserve(value_length);
- for (uint32_t x= 0; x < value_length; x++)
- {
- value.push_back(char(x % 127));
- }
-
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- &value[0], value.size(),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
-
- size_t string_length;
- uint32_t flags;
- memcached_return_t rc;
- char *string= memcached_get(memc,
- test_literal_param(__func__),
- &string_length, &flags, &rc);
-
- test_compare(MEMCACHED_SUCCESS, rc);
- test_true(string);
- test_compare(value.size(), string_length);
- test_memcmp(string, &value[0], string_length);
-
- free(string);
-
- return TEST_SUCCESS;
-}
-
-test_return_t get_test4(memcached_st *memc)
-{
- size_t value_length= 8191;
-
- libtest::vchar_t value;
- value.reserve(value_length);
- for (uint32_t x= 0; x < value_length; x++)
- {
- value.push_back(char(x % 127));
- }
-
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc,
- test_literal_param(__func__),
- &value[0], value.size(),
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
-
- for (uint32_t x= 0; x < 10; x++)
- {
- uint32_t flags;
- size_t string_length;
- memcached_return_t rc;
- char *string= memcached_get(memc,
- test_literal_param(__func__),
- &string_length, &flags, &rc);
-
- test_compare(MEMCACHED_SUCCESS, rc);
- test_true(string);
- test_compare(value.size(), string_length);
- test_memcmp(string, &value[0], string_length);
- free(string);
- }
-
- return TEST_SUCCESS;
-}
-
-/*
- * This test verifies that memcached_read_one_response doesn't try to
- * dereference a NIL-pointer if you issue a multi-get and don't read out all
- * responses before you execute a storage command.
- */
-test_return_t get_test5(memcached_st *memc)
-{
- /*
- ** Request the same key twice, to ensure that we hash to the same server
- ** (so that we have multiple response values queued up) ;-)
- */
- const char *keys[]= { "key", "key" };
- size_t lengths[]= { 3, 3 };
- uint32_t flags;
- size_t rlen;
-
- test_compare_hint(return_value_based_on_buffering(memc),
- memcached_set(memc, keys[0], lengths[0],
- keys[0], lengths[0],
- time_t(0), uint32_t(0)),
- memcached_last_error_message(memc));
- test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys)));
-
- memcached_result_st results_obj;
- memcached_result_st *results= memcached_result_create(memc, &results_obj);
- test_true(results);
-
- memcached_return_t rc;
- results= memcached_fetch_result(memc, &results_obj, &rc);
- test_true(results);
-
- memcached_result_free(&results_obj);
-
- /* Don't read out the second result, but issue a set instead.. */
- test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[0], lengths[0], keys[0], lengths[0], 0, 0));
-
- char *val= memcached_get_by_key(memc, keys[0], lengths[0], "yek", 3,
- &rlen, &flags, &rc);
- test_false(val);
- test_compare(MEMCACHED_NOTFOUND, rc);
- val= memcached_get(memc, keys[0], lengths[0], &rlen, &flags, &rc);
- test_true(val);
- test_compare(MEMCACHED_SUCCESS, rc);
- free(val);
-
- return TEST_SUCCESS;
-}
-
test_return_t mget_end(memcached_st *memc)
{
const char *keys[]= { "foo", "foo2" };
test_return_t stats_servername_test(memcached_st *memc)
{
memcached_stat_st memc_stat;
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc, 0);
if (LIBMEMCACHED_WITH_SASL_SUPPORT and memcached_get_sasl_callbacks(memc))
return TEST_SUCCESS;
}
-test_return_t increment_with_initial_test(memcached_st *memc)
+static test_return_t __increment_with_initial_test(memcached_st *memc, uint64_t initial)
{
- test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
-
uint64_t new_number;
- uint64_t initial= 0;
test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc));
- test_compare(MEMCACHED_SUCCESS,
- memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number));
- test_compare(new_number, initial);
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL))
+ {
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number));
+ test_compare(new_number, initial);
- test_compare(MEMCACHED_SUCCESS,
- memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number));
- test_compare(new_number, (initial +1));
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number));
+ test_compare(new_number, (initial +1));
+ }
+ else
+ {
+ test_compare(MEMCACHED_INVALID_ARGUMENTS,
+ memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number));
+ }
return TEST_SUCCESS;
}
+test_return_t increment_with_initial_test(memcached_st *memc)
+{
+ return __increment_with_initial_test(memc, 0);
+}
+
+test_return_t increment_with_initial_999_test(memcached_st *memc)
+{
+ return __increment_with_initial_test(memc, 999);
+}
+
test_return_t decrement_test(memcached_st *memc)
{
test_compare(return_value_based_on_buffering(memc),
test_literal_param(__func__),
test_literal_param("3"),
time_t(0), uint32_t(0)));
+
// Make sure we flush the value we just set
test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc));
return TEST_SUCCESS;
}
-test_return_t decrement_with_initial_test(memcached_st *memc)
+static test_return_t __decrement_with_initial_test(memcached_st *memc, uint64_t initial)
{
test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
- uint64_t initial= 3;
-
test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc));
uint64_t new_number;
return TEST_SUCCESS;
}
+test_return_t decrement_with_initial_test(memcached_st *memc)
+{
+ return __decrement_with_initial_test(memc, 3);
+}
+
+test_return_t decrement_with_initial_999_test(memcached_st *memc)
+{
+ return __decrement_with_initial_test(memc, 999);
+}
+
test_return_t increment_by_key_test(memcached_st *memc)
{
const char *master_key= "foo";
test_return_t increment_with_initial_by_key_test(memcached_st *memc)
{
- test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
-
uint64_t new_number;
const char *master_key= "foo";
const char *key= "number";
uint64_t initial= 0;
- test_compare(MEMCACHED_SUCCESS,
- memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key),
- key, strlen(key),
- 1, initial, 0, &new_number));
- test_compare(new_number, initial);
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL))
+ {
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key),
+ key, strlen(key),
+ 1, initial, 0, &new_number));
+ test_compare(new_number, initial);
- test_compare(MEMCACHED_SUCCESS,
- memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key),
- key, strlen(key),
- 1, initial, 0, &new_number));
- test_compare(new_number, (initial +1));
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key),
+ key, strlen(key),
+ 1, initial, 0, &new_number));
+ test_compare(new_number, (initial +1));
+ }
+ else
+ {
+ test_compare(MEMCACHED_INVALID_ARGUMENTS,
+ memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key),
+ key, strlen(key),
+ 1, initial, 0, &new_number));
+ }
return TEST_SUCCESS;
}
uint64_t new_number;
uint64_t initial= 3;
- test_compare(MEMCACHED_SUCCESS,
- memcached_decrement_with_initial_by_key(memc,
- test_literal_param("foo"),
- test_literal_param("number"),
- 1, initial, 0, &new_number));
- test_compare(new_number, initial);
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL))
+ {
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_decrement_with_initial_by_key(memc,
+ test_literal_param("foo"),
+ test_literal_param("number"),
+ 1, initial, 0, &new_number));
+ test_compare(new_number, initial);
- test_compare(MEMCACHED_SUCCESS,
- memcached_decrement_with_initial_by_key(memc,
- test_literal_param("foo"),
- test_literal_param("number"),
- 1, initial, 0, &new_number));
- test_compare(new_number, (initial - 1));
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_decrement_with_initial_by_key(memc,
+ test_literal_param("foo"),
+ test_literal_param("number"),
+ 1, initial, 0, &new_number));
+ test_compare(new_number, (initial - 1));
+ }
+ else
+ {
+ test_compare(MEMCACHED_INVALID_ARGUMENTS,
+ memcached_decrement_with_initial_by_key(memc,
+ test_literal_param("foo"),
+ test_literal_param("number"),
+ 1, initial, 0, &new_number));
+ }
return TEST_SUCCESS;
}
memcached_set(memc,
test_literal_param(__func__),
value, strlen(value),
- (time_t)10, (uint32_t)3));
+ time_t(10), uint32_t(3)));
memcached_quit(memc);
test_compare(return_value_based_on_buffering(memc),
memcached_set(memc,
test_literal_param(__func__),
value, strlen(value),
- (time_t)50, (uint32_t)9));
+ time_t(50), uint32_t(9)));
return TEST_SUCCESS;
}
size_t key_length[]= {5, 3, 4};
memcached_result_st results_obj;
- memcached_result_st *results;
-
- results= memcached_result_create(memc, &results_obj);
+ memcached_result_st *results= memcached_result_create(memc, &results_obj);
test_true(results);
test_true(&results_obj == results);
while ((results= memcached_fetch_result(memc, &results_obj, &rc))) { test_true(false); /* We should never see a value returned */ };
test_false(results);
- test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc));
+ test_compare(MEMCACHED_NOTFOUND, rc);
for (uint32_t x= 0; x < 3; x++)
{
rc= memcached_set(memc, keys[x], key_length[x],
keys[x], key_length[x],
(time_t)50, (uint32_t)9);
- test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc));
+ test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
}
test_compare(MEMCACHED_SUCCESS,
test_true(results);
}
test_false(results);
- test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc));
+ test_compare(MEMCACHED_NOTFOUND, rc);
for (uint32_t x= 0; x < 3; x++)
{
rc= memcached_set(memc, keys[x], key_length[x],
keys[x], key_length[x],
(time_t)50, (uint32_t)9);
- test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc));
+ test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
}
test_compare(MEMCACHED_SUCCESS,
rc= memcached_set(memc, keys[x], key_length[x],
keys[x], key_length[x],
(time_t)50, (uint32_t)9);
- test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc));
+ test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
}
test_compare(MEMCACHED_SUCCESS,
memcached_mget(memc, keys, key_length, 3));
keys.key_at(x), keys.length_at(x),
blob, sizeof(blob),
0, 0);
- test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED,
- memcached_strerror(NULL, rc));
+ ASSERT_TRUE_(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, "Returned %s", memcached_strerror(NULL, rc));
+ test_compare(query_id +1, memcached_query_id(memc));
+ }
+
+ /* Try to get all of them with a large multiget */
+ size_t counter= 0;
+ memcached_execute_fn callbacks[]= { &callback_counter };
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_mget_execute(memc,
+ keys.keys_ptr(), keys.lengths_ptr(),
+ keys.size(), callbacks, &counter, 1));
+
+ {
+ uint64_t query_id= memcached_query_id(memc);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_fetch_execute(memc, callbacks, (void *)&counter, 1));
+ test_compare(query_id, memcached_query_id(memc));
+
+ /* Verify that we got all of the items */
+ test_compare(keys.size(), counter);
+ }
+
+ memcached_free(memc);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH_TEST(memcached_st *original_memc)
+{
+ test_skip(true, memcached_behavior_get(original_memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
+
+ memcached_st *memc= create_single_instance_memcached(original_memc, "--BINARY-PROTOCOL");
+ test_true(memc);
+
+ test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH, 8));
+
+ keys_st keys(20480);
+
+ /* First add all of the items.. */
+ char blob[1024] = {0};
+
+ for (size_t x= 0; x < keys.size(); ++x)
+ {
+ uint64_t query_id= memcached_query_id(memc);
+ memcached_return_t rc= memcached_add(memc,
+ keys.key_at(x), keys.length_at(x),
+ blob, sizeof(blob),
+ 0, 0);
+ test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
test_compare(query_id +1, memcached_query_id(memc));
}
}
#define REGRESSION_BINARY_VS_BLOCK_COUNT 20480
-static pairs_st *global_pairs;
+static pairs_st *global_pairs= NULL;
test_return_t key_setup(memcached_st *memc)
{
test_return_t key_teardown(memcached_st *)
{
pairs_free(global_pairs);
+ global_pairs= NULL;
return TEST_SUCCESS;
}
/* First add all of the items.. */
for (ptrdiff_t x= 0; x < REGRESSION_BINARY_VS_BLOCK_COUNT; ++x)
{
- char blob[1024] = {0};
+ libtest::vchar_t blob;
+ libtest::vchar::make(blob, 1024);
- memcached_return_t rc= memcached_add_by_key(memc, "bob", 3, global_pairs[x].key, global_pairs[x].key_length, blob, sizeof(blob), 0, 0);
- test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE, memcached_strerror(NULL, rc));
+ memcached_return_t rc= memcached_add_by_key(memc,
+ test_literal_param("bob"),
+ global_pairs[x].key, global_pairs[x].key_length,
+ &blob[0], blob.size(),
+ time_t(0), uint32_t(0));
+ if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
+ {
+ Error << memcached_last_error_message(memc);
+ return TEST_SKIPPED;
+ }
+ test_compare(MEMCACHED_SUCCESS,*memc);
+ test_compare(MEMCACHED_SUCCESS, rc);
}
return TEST_SUCCESS;
test_return_t binary_add_regression(memcached_st *memc)
{
test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, true));
- test_return_t rc= block_add_regression(memc);
-
- return rc;
+ return block_add_regression(memc);
}
test_return_t get_stats_keys(memcached_st *memc)
return TEST_SUCCESS;
}
+test_return_t regression_1048945_TEST(memcached_st*)
+{
+ memcached_return status;
+
+ memcached_server_st* list= memcached_server_list_append_with_weight(NULL, "a", 11211, 0, &status);
+ test_compare(status, MEMCACHED_SUCCESS);
+
+ list= memcached_server_list_append_with_weight(list, "b", 11211, 0, &status);
+ test_compare(status, MEMCACHED_SUCCESS);
+
+ list= memcached_server_list_append_with_weight(list, "c", 11211, 0, &status);
+ test_compare(status, MEMCACHED_SUCCESS);
+
+ memcached_st* memc= memcached_create(NULL);
+
+ status= memcached_server_push(memc, list);
+ memcached_server_list_free(list);
+ test_compare(status, MEMCACHED_SUCCESS);
+
+ const memcached_instance_st * server= memcached_server_by_key(memc, test_literal_param(__func__), &status);
+ test_true(server);
+ test_compare(status, MEMCACHED_SUCCESS);
+
+ memcached_free(memc);
+
+ return TEST_SUCCESS;
+}
+
test_return_t memcached_fetch_result_NOT_FOUND(memcached_st *memc)
{
memcached_return_t rc;
memcached_result_st *result= memcached_fetch_result(memc, NULL, &rc);
test_null(result);
- test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc));
+ test_compare(MEMCACHED_NOTFOUND, rc);
memcached_result_free(result);
count++;
}
test_zero(count);
- test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc));
+ test_compare(MEMCACHED_NOTFOUND, rc);
for (uint32_t x= 0; x < test_array_length(keys); x++)
{
const char *keys= "036790384900";
size_t key_length= strlen(keys);
- test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length,
- insert_data, VALUE_SIZE_BUG5,
- time_t(0), 245U),
- memcached_last_error_message(memc));
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length,
+ insert_data, VALUE_SIZE_BUG5,
+ time_t(0), 245U));
memcached_return_t rc;
size_t value_length;
&value[0], value.size(),
0, 0);
- test_true_got((rc == MEMCACHED_SUCCESS or rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_BUFFERED or rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_CONNECTION_FAILURE
- or rc == MEMCACHED_SERVER_TEMPORARILY_DISABLED),
- memcached_strerror(NULL, rc));
+ test_true((rc == MEMCACHED_SUCCESS or rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_BUFFERED or rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_CONNECTION_FAILURE
+ or rc == MEMCACHED_SERVER_TEMPORARILY_DISABLED));
if (rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_TIMEOUT)
{
*/
test_return_t user_supplied_bug11(memcached_st *memc)
{
- memcached_st *mclone= memcached_clone(NULL, memc);
-
- memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, true);
- memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, true);
- memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, size_t(-1));
+ (void)memc;
+#ifndef __APPLE__
+ test::Memc mclone(memc);
- test_compare(-1, int32_t(memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT)));
+ memcached_behavior_set(&mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, true);
+ memcached_behavior_set(&mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, true);
+ memcached_behavior_set(&mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, size_t(-1));
+ test_compare(-1, int32_t(memcached_behavior_get(&mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT)));
libtest::vchar_t value;
value.reserve(512);
for (unsigned int x= 1; x <= 100000; ++x)
{
- memcached_return_t rc= memcached_set(mclone, test_literal_param("foo"), &value[0], value.size(), 0, 0);
+ memcached_return_t rc= memcached_set(&mclone, test_literal_param("foo"), &value[0], value.size(), 0, 0);
(void)rc;
}
- memcached_free(mclone);
+#endif
return TEST_SUCCESS;
}
memcached_return_t rc= memcached_set(memc, test_literal_param("foo"),
&value[0], current_length,
(time_t)0, (uint32_t)0);
- test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
+ ASSERT_TRUE_(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, "Instead got %s", memcached_strerror(NULL, rc));
size_t string_length;
uint32_t flags;
test_compare(string_length, current_length);
char buffer[1024];
snprintf(buffer, sizeof(buffer), "%u", uint32_t(string_length));
- test_memcmp_hint(string, &value[0], string_length, buffer);
+ test_memcmp(string, &value[0], string_length);
free(string);
}
/* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
test_return_t user_supplied_bug16(memcached_st *memc)
{
- test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("mykey"),
- NULL, 0,
- (time_t)0, UINT32_MAX),
- memcached_last_error_message(memc));
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("mykey"),
+ NULL, 0,
+ (time_t)0, UINT32_MAX));
size_t length;
char *value2= memcached_get(memc, key, strlen(key),
&length, &flags, &rc);
- test_true(length==strlen(value));
+ test_compare(length, strlen(value));
test_compare(MEMCACHED_SUCCESS, rc);
test_memcmp(value, value2, length);
free(value2);
memcached_st *memc= memcached(test_literal_param("--server=localhost:11311/?100 --server=localhost:11312/?100"));
- const memcached_server_st *server= memcached_server_by_key(memc, "a", 1, &res);
+ const memcached_instance_st * server= memcached_server_by_key(memc, "a", 1, &res);
test_true(server);
memcached_free(memc);
*/
/* sighandler_t function that always asserts false */
-static void fail(int)
+static __attribute__((noreturn)) void fail(int)
{
- assert(0);
+ fatal_assert(0);
}
return TEST_SUCCESS;
}
+test_return_t comparison_operator_memcached_st_and__memcached_return_t_TEST(memcached_st *)
+{
+ test::Memc memc_;
+
+ memcached_st *memc= &memc_;
+
+ ASSERT_EQ(memc, MEMCACHED_SUCCESS);
+ test_compare(memc, MEMCACHED_SUCCESS);
+
+ ASSERT_NEQ(memc, MEMCACHED_FAILURE);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t ketama_TEST(memcached_st *)
+{
+ test::Memc memc("--server=10.0.1.1:11211 --server=10.0.1.2:11211");
+
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_behavior_set(&memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, true));
+
+ test_compare(memcached_behavior_get(&memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED), uint64_t(1));
+
+ test_compare(memcached_behavior_set(&memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, MEMCACHED_HASH_MD5), MEMCACHED_SUCCESS);
+
+ test_compare(memcached_hash_t(memcached_behavior_get(&memc, MEMCACHED_BEHAVIOR_KETAMA_HASH)), MEMCACHED_HASH_MD5);
+
+ test_compare(memcached_behavior_set_distribution(&memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY), MEMCACHED_SUCCESS);
+
+
+ return TEST_SUCCESS;
+}
+
test_return_t output_ketama_weighted_keys(memcached_st *)
{
memcached_st *memc= memcached_create(NULL);
char *hostname = memc->hosts[server_idx].hostname;
in_port_t port = memc->hosts[server_idx].port;
fprintf(fp, "key %s is on host /%s:%u\n", key, hostname, port);
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc, host_index);
}
fclose(fp);
const char *key= "mine";
char *value;
- /* Make sure be default none exists */
+ /* Make sure by default none exists */
value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
test_null(value);
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
test_true(value);
- test_memcmp(value, key, 4);
+ test_memcmp(value, key, strlen(key));
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
/* Test that we can turn it off */
value= (char *)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
test_true(value);
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
- test_memcmp(value, key, 4);
+ test_memcmp(value, key, strlen(key));
/* Set to Zero, and then Set to something too large */
{
test_compare(MEMCACHED_SUCCESS,
memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, NULL));
- value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
- test_null(value);
- test_compare(MEMCACHED_SUCCESS, rc);
+ ASSERT_NULL_(memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc), "Setting namespace to NULL did not work");
/* Test a long key for failure */
/* TODO, extend test to determine based on setting, what result should be */
{
memcached_return_t rc;
const char *key= "mine";
- char *value;
// Make sure we default to a null namespace
- value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
- test_null(value);
+ char* value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
+ ASSERT_NULL_(value, "memc had a value for namespace when none should exist");
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
/* Test a clean set */
memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, (void *)key));
value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
- test_true(value);
- test_memcmp(value, key, 4);
+ ASSERT_TRUE(value);
+ test_memcmp(value, key, strlen(key));
test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
return TEST_SUCCESS;
test_return_t enable_consistent_crc(memcached_st *memc)
{
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT));
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT));
+
test_return_t rc;
- memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT;
- memcached_hash_t hash;
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
if ((rc= pre_crc(memc)) != TEST_SUCCESS)
+ {
return rc;
+ }
- value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
- test_true(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
-
- hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT));
- if (hash != MEMCACHED_HASH_CRC)
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_CRC)
+ {
return TEST_SKIPPED;
+ }
return TEST_SUCCESS;
}
test_return_t enable_consistent_hsieh(memcached_st *memc)
{
test_return_t rc;
- memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT;
- memcached_hash_t hash;
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT);
if ((rc= pre_hsieh(memc)) != TEST_SUCCESS)
{
return rc;
}
- value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
- test_true(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
-
- hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION), uint64_t(MEMCACHED_DISTRIBUTION_CONSISTENT));
- if (hash != MEMCACHED_HASH_HSIEH)
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH) != MEMCACHED_HASH_HSIEH)
+ {
return TEST_SKIPPED;
-
+ }
return TEST_SUCCESS;
}
test_return_t enable_cas(memcached_st *memc)
{
- unsigned int set= 1;
-
if (libmemcached_util_version_check(memc, 1, 2, 4))
{
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true);
return TEST_SUCCESS;
}
{
memcached_version(memc);
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc, 0);
if ((instance->major_version >= 1 && (instance->minor_version == 2 && instance->micro_version >= 4))
for (size_t x= 0; x < 100; ++x)
{
char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
- int check_length= (size_t)snprintf(key, sizeof(key), "%lu", (unsigned long)x);
+ int check_length= snprintf(key, sizeof(key), "%lu", (unsigned long)x);
test_false((size_t)check_length >= sizeof(key) || check_length < 0);
size_t len= (size_t)check_length;
int no_msg=0;
for (uint32_t x= 0; x < memcached_server_count(memc); ++x)
{
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc, x);
no_msg+=(int)(instance->cursor_active);
}
{
char key[10];
- int check_length= (size_t)snprintf(key, sizeof(key), "%lu", (unsigned long)x);
+ int check_length= snprintf(key, sizeof(key), "%lu", (unsigned long)x);
test_false((size_t)check_length >= sizeof(key) || check_length < 0);
uint32_t flags;
char* value=memcached_get(memc, key, strlen(key),
&length, &flags, &ret);
- test_true_got(ret == MEMCACHED_SUCCESS && value != NULL, memcached_strerror(NULL, ret));
+ // For the moment we will just go to the next key
+ if (MEMCACHED_TIMEOUT == ret)
+ {
+ continue;
+ }
+ test_true(ret == MEMCACHED_SUCCESS and value != NULL);
switch (count)
{
case 0: /* FALLTHROUGH */
test_return_t util_version_test(memcached_st *memc)
{
- test_compare_hint(MEMCACHED_SUCCESS, memcached_version(memc), memcached_last_error_message(memc));
+ test_compare(memcached_version(memc), MEMCACHED_SUCCESS);
test_true(libmemcached_util_version_check(memc, 0, 0, 0));
bool if_successful= libmemcached_util_version_check(memc, 9, 9, 9);
}
test_true(if_successful == false);
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc, 0);
memcached_version(memc);
{
test_skip(memc->servers[0].type, MEMCACHED_CONNECTION_TCP);
memcached_return_t rc;
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc, 0);
// Test both the version that returns a code, and the one that does not.
test_return_t getpid_test(memcached_st *memc)
{
memcached_return_t rc;
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc, 0);
// Test both the version that returns a code, and the one that does not.
return TEST_SUCCESS;
}
-test_return_t ping_test(memcached_st *memc)
+static memcached_return_t ping_each_server(const memcached_st*,
+ const memcached_instance_st * instance,
+ void*)
{
+ // Test both the version that returns a code, and the one that does not.
memcached_return_t rc;
- memcached_server_instance_st instance=
- memcached_server_instance_by_position(memc, 0);
+ if (libmemcached_util_ping(memcached_server_name(instance),
+ memcached_server_port(instance), &rc) == false)
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s:%d %s", memcached_server_name(instance),
+ memcached_server_port(instance), memcached_strerror(NULL, rc));
+ }
- // Test both the version that returns a code, and the one that does not.
- test_true(libmemcached_util_ping(memcached_server_name(instance),
- memcached_server_port(instance), NULL));
+ if (libmemcached_util_ping(memcached_server_name(instance),
+ memcached_server_port(instance), NULL) == false)
+ {
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s:%d", memcached_server_name(instance), memcached_server_port(instance));
+ }
- test_true(libmemcached_util_ping(memcached_server_name(instance),
- memcached_server_port(instance), &rc));
+ return MEMCACHED_SUCCESS;
+}
- test_compare(MEMCACHED_SUCCESS, rc);
+test_return_t libmemcached_util_ping_TEST(memcached_st *memc)
+{
+ memcached_server_fn callbacks[1]= { ping_each_server };
+ memcached_server_cursor(memc, callbacks, NULL, 1);
return TEST_SUCCESS;
}
#endif
}
+test_return_t murmur3_TEST(hashkit_st *)
+{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR3));
+
+#ifdef WORDS_BIGENDIAN
+ (void)murmur3_values;
+ return TEST_SKIPPED;
+#else
+ uint32_t x;
+ const char **ptr;
+
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ test_compare(murmur3_values[x],
+ memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_MURMUR3));
+ }
+
+ return TEST_SUCCESS;
+#endif
+}
+
test_return_t jenkins_run (memcached_st *)
{
uint32_t x;
for (uint32_t x= 0; x < 250; ++x)
{
- char key[250];
+ char key[251];
size_t len= (size_t)snprintf(key, sizeof(key), "%0250u", x);
memcached_return_t rc= memcached_delete(memc, key, len, 0);
char error_buffer[2048]= { 0 };
// Delete, and then delete again to look for not found
{
- char key[250];
+ char key[251];
size_t len= snprintf(key, sizeof(key), "%037u", 251U);
memcached_return_t rc= memcached_delete(memc, key, len, 0);
test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
* This is to verify correct behavior in the library. Fake that two servers
* are dead..
*/
- memcached_server_instance_st instance_one= memcached_server_instance_by_position(memc, 0);
- memcached_server_instance_st instance_two= memcached_server_instance_by_position(memc, 2);
- in_port_t port0= instance_one->port;
- in_port_t port2= instance_two->port;
+ const memcached_instance_st * instance_one= memcached_server_instance_by_position(memc, 0);
+ const memcached_instance_st * instance_two= memcached_server_instance_by_position(memc, 2);
+ in_port_t port0= instance_one->port();
+ in_port_t port2= instance_two->port();
- ((memcached_server_write_instance_st)instance_one)->port= 0;
- ((memcached_server_write_instance_st)instance_two)->port= 0;
+ ((memcached_server_write_instance_st)instance_one)->port(0);
+ ((memcached_server_write_instance_st)instance_two)->port(0);
test_compare(MEMCACHED_SUCCESS,
memcached_mget(memc,
test_compare(counter, keys.size());
/* restore the memc handle */
- ((memcached_server_write_instance_st)instance_one)->port= port0;
- ((memcached_server_write_instance_st)instance_two)->port= port2;
+ ((memcached_server_write_instance_st)instance_one)->port(port0);
+ ((memcached_server_write_instance_st)instance_two)->port(port2);
memcached_quit(memc);
}
memcached_quit(memc);
- ((memcached_server_write_instance_st)instance_one)->port= 0;
- ((memcached_server_write_instance_st)instance_two)->port= 0;
+ ((memcached_server_write_instance_st)instance_one)->port(0);
+ ((memcached_server_write_instance_st)instance_two)->port(0);
/* now retry the command, this time we should have cache misses */
test_compare(MEMCACHED_SUCCESS,
test_compare(counter, (unsigned int)(keys.size() >> 1));
/* restore the memc handle */
- ((memcached_server_write_instance_st)instance_one)->port= port0;
- ((memcached_server_write_instance_st)instance_two)->port= port2;
+ ((memcached_server_write_instance_st)instance_one)->port(port0);
+ ((memcached_server_write_instance_st)instance_two)->port(port2);
return TEST_SUCCESS;
}
test_true(memc_clone);
test_true(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
- memcached_server_instance_st instance=
+ const memcached_instance_st * instance=
memcached_server_instance_by_position(memc_clone, 0);
if (instance->major_version > 1 ||
test_return_t test_get_last_disconnect(memcached_st *memc)
{
memcached_return_t rc;
- memcached_server_instance_st disconnected_server;
+ const memcached_instance_st * disconnected_server;
/* With the working set of server */
const char *key= "marmotte";
memcached_return_t ret= memcached_set(memc, msg, strlen(msg), NULL, 0, (time_t)0, (uint32_t)0);
test_true_got((ret == MEMCACHED_CONNECTION_FAILURE or ret == MEMCACHED_SERVER_TEMPORARILY_DISABLED), memcached_last_error_message(memc));
- memcached_server_instance_st disconnected_server= memcached_server_get_last_disconnect(memc);
+ const memcached_instance_st * disconnected_server= memcached_server_get_last_disconnect(memc);
test_true(disconnected_server);
test_strcmp("localhost", memcached_server_name(disconnected_server));
test_true(memcached_server_port(disconnected_server) >= 8888 and memcached_server_port(disconnected_server) <= 8892);
test_return_t test_verbosity(memcached_st *memc)
{
- memcached_verbosity(memc, 3);
+ test_compare(MEMCACHED_SUCCESS, memcached_verbosity(memc, 0));
return TEST_SUCCESS;
}
-static memcached_return_t stat_printer(memcached_server_instance_st server,
+static memcached_return_t stat_printer(const memcached_instance_st * server,
const char *key, size_t key_length,
const char *value, size_t value_length,
void *context)
test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
- memcached_server_instance_st instance= memcached_server_instance_by_position(memc, 0);
+ const memcached_instance_st * instance= memcached_server_instance_by_position(memc, 0);
/* The test is to see that the memcached_quit doesn't increase the
* the server failure conter, so let's ensure that it is zero
/* Put a retry timeout to effectively activate failure_limit effect */
test_compare(MEMCACHED_SUCCESS,
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, true));
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1));
/* change behavior that triggers memcached_quit()*/
test_compare(MEMCACHED_SUCCESS,
return TEST_SUCCESS;
}
+test_return_t regression_996813_TEST(memcached_st *)
+{
+ memcached_st* memc= memcached_create(NULL);
+
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA));
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 1));
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1));
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1));
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, 1));
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 300));
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 30));
+
+ // We will never connect to these servers
+ in_port_t base_port= 11211;
+ for (size_t x= 0; x < 17; x++)
+ {
+ test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "10.2.3.4", base_port +x));
+ }
+ test_compare(6U, memcached_generate_hash(memc, test_literal_param("SZ6hu0SHweFmpwpc0w2R")));
+ test_compare(1U, memcached_generate_hash(memc, test_literal_param("SQCK9eiCf53YxHWnYA.o")));
+ test_compare(9U, memcached_generate_hash(memc, test_literal_param("SUSDkGXuuZC9t9VhMwa.")));
+ test_compare(0U, memcached_generate_hash(memc, test_literal_param("SnnqnJARfaCNT679iAF_")));
+
+ memcached_free(memc);
+
+ return TEST_SUCCESS;
+}
+
/*
* Test that ensures mget_execute does not end into recursive calls that finally fails
return TEST_SUCCESS;
}
+test_return_t regression_1021819_TEST(memcached_st *original)
+{
+ memcached_st *memc= memcached_clone(NULL, original);
+ test_true(memc);
+
+ test_compare(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 2000000), MEMCACHED_SUCCESS);
+ test_compare(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 3000000), MEMCACHED_SUCCESS);
+
+ memcached_return_t rc;
+
+ memcached_get(memc,
+ test_literal_param(__func__),
+ NULL, NULL, &rc);
+
+ test_compare(rc, MEMCACHED_NOTFOUND);
+
+ memcached_free(memc);
+
+ return TEST_SUCCESS;
+}
+
test_return_t regression_bug_583031(memcached_st *)
{
memcached_st *memc= memcached_create(NULL);
test_true(memc);
- test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "10.2.3.4", 11211));
+ test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "10.2.251.4", 11211));
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 1000);
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 3000);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1000);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 1000);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 1000);
test_false(value);
test_zero(length);
- test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
+ test_compare(MEMCACHED_TIMEOUT, memc);
memcached_free(memc);
return TEST_SUCCESS;
}
+test_return_t regression_bug_1251482(memcached_st*)
+{
+ test::Memc memc("--server=localhost:5");
+
+ memcached_behavior_set(&memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 0);
+
+ for (size_t x= 0; x < 5; ++x)
+ {
+ size_t value_length;
+ memcached_return_t rc;
+ char *value= memcached_get(&memc,
+ test_literal_param(__func__),
+ &value_length, NULL, &rc);
+
+ test_false(value);
+ test_compare(0LLU, value_length);
+ if (x) {
+ test_ne_compare(MEMCACHED_SUCCESS, rc);
+ } else {
+ test_compare(MEMCACHED_CONNECTION_FAILURE, rc);
+ }
+ }
+
+ return TEST_SUCCESS;
+}
+
+test_return_t regression_1009493_TEST(memcached_st*)
+{
+ memcached_st* memc= memcached_create(NULL);
+ test_true(memc);
+ test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, true));
+
+ memcached_st* clone= memcached_clone(NULL, memc);
+ test_true(clone);
+
+ test_compare(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED),
+ memcached_behavior_get(clone, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED));
+
+ memcached_free(memc);
+ memcached_free(clone);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t regression_994772_TEST(memcached_st* memc)
+{
+ test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1));
+
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_set(memc,
+ test_literal_param(__func__), // Key
+ test_literal_param(__func__), // Value
+ time_t(0), uint32_t(0)));
+
+ const char *keys[] = { __func__ };
+ size_t key_length[]= { strlen(__func__) };
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_mget(memc, keys, key_length, 1));
+
+ memcached_return_t rc;
+ memcached_result_st *results= memcached_fetch_result(memc, NULL, &rc);
+ test_true(results);
+ test_compare(MEMCACHED_SUCCESS, rc);
+
+ test_strcmp(__func__, memcached_result_value(results));
+ uint64_t cas_value= memcached_result_cas(results);
+ test_true(cas_value);
+
+ char* take_value= memcached_result_take_value(results);
+ test_strcmp(__func__, take_value);
+ free(take_value);
+
+ memcached_result_free(results);
+
+ // Bad cas value, sanity check
+ test_true(cas_value != 9999);
+ test_compare(MEMCACHED_END,
+ memcached_cas(memc,
+ test_literal_param(__func__), // Key
+ test_literal_param(__FILE__), // Value
+ time_t(0), uint32_t(0), 9999));
+
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc,
+ "different", strlen("different"), // Key
+ test_literal_param(__FILE__), // Value
+ time_t(0), uint32_t(0)));
+
+ return TEST_SUCCESS;
+}
test_return_t regression_bug_854604(memcached_st *)
{
return TEST_SUCCESS;
}
-static void memcached_die(memcached_st* mc, memcached_return error, const char* what, uint32_t it)
+static void die_message(memcached_st* mc, memcached_return error, const char* what, uint32_t it)
{
fprintf(stderr, "Iteration #%u: ", it);
rc= memcached_behavior_set(mc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
if (rc != MEMCACHED_SUCCESS)
{
- memcached_die(mc, rc, "memcached_behavior_set", x);
+ die_message(mc, rc, "memcached_behavior_set", x);
}
rc= memcached_behavior_set(mc, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, 1);
if (rc != MEMCACHED_SUCCESS)
{
- memcached_die(mc, rc, "memcached_behavior_set", x);
+ die_message(mc, rc, "memcached_behavior_set", x);
}
rc= memcached_server_add(mc, remote_server, 0);
if (rc != MEMCACHED_SUCCESS)
{
- memcached_die(mc, rc, "memcached_server_add", x);
+ die_message(mc, rc, "memcached_server_add", x);
}
const char *set_key= "akey";
&get_value_flags, &rc);
if (rc != MEMCACHED_SUCCESS)
{
- memcached_die(mc, rc, "memcached_get", x);
+ die_message(mc, rc, "memcached_get", x);
}
else
{
);
if (rc != MEMCACHED_SUCCESS)
{
- memcached_die(mc, rc, "memcached_set", x);
+ die_message(mc, rc, "memcached_set", x);
}
}
memcached_st *memc= create_single_instance_memcached(original_memc, 0);
test_true(memc);
- memcached_server_instance_st instance= memcached_server_instance_by_position(memc, 0);
+ const memcached_instance_st * instance= memcached_server_instance_by_position(memc, 0);
pid_t pid;
test_true((pid= libmemcached_util_getpid(memcached_server_name(instance),
0, 0));
test_true_got(kill(pid, SIGHUP) == 0, strerror(errno));
- test_compare(MEMCACHED_SUCCESS,
- memcached_set(memc,
- test_literal_param(__func__), // Keys
- test_literal_param(__func__), // Values
- 0, 0));
+ memcached_return_t ret= memcached_set(memc,
+ test_literal_param(__func__), // Keys
+ test_literal_param(__func__), // Values
+ 0, 0);
+ if (ret == MEMCACHED_ERRNO) {
+ test_compare(EPIPE, memcached_last_error_errno(memc));
+ } else {
+ test_compare(MEMCACHED_CONNECTION_FAILURE, ret);
+ }
memcached_free(memc);