memc_clone= memcached_clone(NULL, memc);
test_true(memc_clone);
- test_true(memc_clone->call_free == memc->call_free);
- test_true(memc_clone->call_malloc == memc->call_malloc);
- test_true(memc_clone->call_realloc == memc->call_realloc);
- test_true(memc_clone->call_calloc == memc->call_calloc);
+ { // Test allocators
+ test_true(memc_clone->allocators.free == memc->allocators.free);
+ test_true(memc_clone->allocators.malloc == memc->allocators.malloc);
+ test_true(memc_clone->allocators.realloc == memc->allocators.realloc);
+ test_true(memc_clone->allocators.calloc == memc->allocators.calloc);
+ }
+
test_true(memc_clone->connect_timeout == memc->connect_timeout);
test_true(memc_clone->delete_trigger == memc->delete_trigger);
test_true(memc_clone->distribution == memc->distribution);
test_true(memc_clone->flags.randomize_replica_read == memc->flags.randomize_replica_read);
}
test_true(memc_clone->get_key_failure == memc->get_key_failure);
- test_true(memc_clone->hash == memc->hash);
- test_true(memc_clone->distribution_hash == memc->distribution_hash);
+ test_true(hashkit_compare(&memc_clone->hashkit, &memc->hashkit));
+ test_true(hashkit_compare(&memc_clone->distribution_hashkit, &memc->distribution_hashkit));
test_true(memc_clone->io_bytes_watermark == memc->io_bytes_watermark);
test_true(memc_clone->io_msg_watermark == memc->io_msg_watermark);
test_true(memc_clone->io_key_prefetch == memc->io_key_prefetch);
4269430871U, 610793021U, 527273862U, 1437122909U,
2300930706U, 2943759320U, 674306647U, 2400528935U,
54481931U, 4186304426U, 1741088401U, 2979625118U,
- 4159057246U, 3425930182U, 2593724503U};
+ 4159057246U, 3425930182U, 2593724503U, 1868899624U};
// You have updated the memcache_error messages but not updated docs/tests.
- test_true(MEMCACHED_MAXIMUM_RETURN == 39);
+ test_true(MEMCACHED_MAXIMUM_RETURN == 40);
for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
{
uint32_t hash_val;
const char *msg= memcached_strerror(memc, rc);
hash_val= memcached_generate_hash_value(msg, strlen(msg),
MEMCACHED_HASH_JENKINS);
+ if (values[rc] != hash_val)
+ {
+ fprintf(stderr, "\n\nYou have updated memcached_return_t without updating the error_test\n");
+ fprintf(stderr, "%u, %s, (%u)\n\n", (uint32_t)rc, memcached_strerror(memc, rc), hash_val);
+ }
test_true(values[rc] == hash_val);
}
results= memcached_fetch_result(memc, &results_obj, &rc);
test_true(results);
- test_true(results->cas);
+ test_true(results->item_cas);
test_true(rc == MEMCACHED_SUCCESS);
test_true(memcached_result_cas(results));
static test_return_t get_stats(memcached_st *memc)
{
- unsigned int x;
char **stat_list;
char **ptr;
memcached_return_t rc;
test_true(rc == MEMCACHED_SUCCESS);
test_true(memc_stat);
- for (x= 0; x < memcached_server_count(memc); x++)
+ for (uint32_t x= 0; x < memcached_server_count(memc); x++)
{
stat_list= memcached_stat_get_keys(memc, memc_stat+x, &rc);
test_true(rc == MEMCACHED_SUCCESS);
{
memcached_return_t rc;
bool set= true;
+
rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CORK, set);
+#ifdef __APPLE__
+ return TEST_SKIPPED;
+#endif
+
if (rc == MEMCACHED_SUCCESS)
return TEST_SUCCESS;
rc= pre_cork(memc);
+#ifdef __APPLE__
+ return TEST_SKIPPED;
+#endif
+
if (rc != TEST_SUCCESS)
return rc;
}
-static void my_free(const memcached_st *ptr __attribute__((unused)), void *mem)
+static void my_free(const memcached_st *ptr __attribute__((unused)), void *mem, void *context)
{
+ (void) context;
#ifdef HARD_MALLOC_TESTS
void *real_ptr= (mem == NULL) ? mem : (void*)((caddr_t)mem - 8);
free(real_ptr);
}
-static void *my_malloc(const memcached_st *ptr __attribute__((unused)), const size_t size)
+static void *my_malloc(const memcached_st *ptr __attribute__((unused)), const size_t size, void *context)
{
+ (void)context;
#ifdef HARD_MALLOC_TESTS
void *ret= malloc(size + 8);
if (ret != NULL)
}
-static void *my_realloc(const memcached_st *ptr __attribute__((unused)), void *mem, const size_t size)
+static void *my_realloc(const memcached_st *ptr __attribute__((unused)), void *mem, const size_t size, void *context)
{
+ (void)context;
#ifdef HARD_MALLOC_TESTS
void *real_ptr= (mem == NULL) ? NULL : (void*)((caddr_t)mem - 8);
void *nmem= realloc(real_ptr, size + 8);
}
-static void *my_calloc(const memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size)
+static void *my_calloc(const memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size, void *context)
{
+ (void)context;
#ifdef HARD_MALLOC_TESTS
void *mem= my_malloc(ptr, nelem * size);
if (mem)
{
memcached_return_t rc;
rc= memcached_set_memory_allocators(memc, NULL, my_free,
- my_realloc, my_calloc);
+ my_realloc, my_calloc, NULL);
test_true(rc == MEMCACHED_FAILURE);
rc= memcached_set_memory_allocators(memc, my_malloc, my_free,
- my_realloc, my_calloc);
+ my_realloc, my_calloc, NULL);
memcached_malloc_fn mem_malloc;
memcached_free_fn mem_free;
return TEST_SUCCESS;
}
+static test_return_t one_at_a_time_run (memcached_st *memc __attribute__((unused)))
+{
+ uint32_t x;
+ const char **ptr;
+
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
+
+ hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_DEFAULT);
+ test_true(one_at_a_time_values[x] == hash_val);
+ }
+
+ return TEST_SUCCESS;
+}
+
static test_return_t md5_run (memcached_st *memc __attribute__((unused)))
{
uint32_t x;
return TEST_SUCCESS;
}
+static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *context)
+{
+ (void)context;
+ return libhashkit_md5(string, string_length);
+}
+
+static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *context)
+{
+ (void)context;
+ return libhashkit_crc32(string, string_length);
+}
+
+static test_return_t memcached_get_hashkit_test (memcached_st *memc)
+{
+ uint32_t x;
+ const char **ptr;
+ hashkit_st *kit;
+ hashkit_return_t hash_rc;
+
+ uint32_t md5_hosts[]= {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U};
+ uint32_t crc_hosts[]= {2U, 4U, 1U, 0U, 2U, 4U, 4U, 4U, 1U, 2U, 3U, 4U, 3U, 4U, 1U, 3U, 3U, 2U, 0U, 0U, 0U, 1U, 2U, 4U, 0U};
+
+ kit= memcached_get_hashkit(memc);
+
+ hash_rc= hashkit_set_custom_function(kit, hash_md5_test_function, NULL);
+ test_true(hash_rc == HASHKIT_SUCCESS);
+
+ /*
+ Verify Setting the hash.
+ */
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
+
+ hash_val= hashkit_digest(kit, *ptr, strlen(*ptr));
+ test_true(md5_values[x] == hash_val);
+ }
+
+
+ /*
+ Now check memcached_st.
+ */
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
+
+ hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr));
+ test_true(md5_hosts[x] == hash_val);
+ }
+
+ hash_rc= hashkit_set_custom_function(kit, hash_crc_test_function, NULL);
+ test_true(hash_rc == HASHKIT_SUCCESS);
+
+ /*
+ Verify Setting the hash.
+ */
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
+
+ hash_val= hashkit_digest(kit, *ptr, strlen(*ptr));
+ test_true(crc_values[x] == hash_val);
+ }
+
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
+
+ hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr));
+ test_true(crc_hosts[x] == hash_val);
+ }
+
+ return TEST_SUCCESS;
+}
+
static test_return_t ketama_compatibility_libmemcached(memcached_st *trash)
{
};
test_st hash_tests[] ={
+ {"one_at_a_time_run", 0, (test_callback_fn)one_at_a_time_run },
{"md5", 0, (test_callback_fn)md5_run },
{"crc", 0, (test_callback_fn)crc_run },
{"fnv1_64", 0, (test_callback_fn)fnv1_64_run },
{"hsieh", 0, (test_callback_fn)hsieh_run },
{"murmur", 0, (test_callback_fn)murmur_run },
{"jenkis", 0, (test_callback_fn)jenkins_run },
+ {"memcached_get_hashkit", 0, (test_callback_fn)memcached_get_hashkit_test },
{0, 0, (test_callback_fn)0}
};