/*
Sample test application.
*/
+
#include "libmemcached/common.h"
#include <assert.h>
assert(results);
assert(results->cas);
assert(rc == MEMCACHED_SUCCESS);
- WATCHPOINT_ASSERT(memcached_result_cas(results));
+ assert(memcached_result_cas(results));
assert(!memcmp(value, "we the people", strlen("we the people")));
assert(strlen("we the people") == value_length);
results= memcached_fetch_result(memc, &results_obj, &rc);
assert(results);
assert(rc == MEMCACHED_SUCCESS);
- WATCHPOINT_ASSERT(memcached_result_cas(results));
+ assert(memcached_result_cas(results));
assert(!memcmp(value, memcached_result_value(results), value_length));
assert(strlen(memcached_result_value(results)) == value_length);
assert(rc == MEMCACHED_SUCCESS);
errors++;
else
{
- WATCHPOINT_ERROR(rc);
- assert(0);
+ assert(rc);
}
continue;
return rc;
}
+static memcached_return pre_replication_noblock(memcached_st *memc)
+{
+ memcached_return rc= MEMCACHED_FAILURE;
+ if (pre_replication(memc) == MEMCACHED_SUCCESS &&
+ pre_nonblock(memc) == MEMCACHED_SUCCESS)
+ rc= MEMCACHED_SUCCESS;
+
+ return rc;
+}
+
static void my_free(memcached_st *ptr __attribute__((unused)), void *mem)
{
free(mem);
static test_return replication_set_test(memcached_st *memc)
{
memcached_return rc;
- memcached_st *clone= memcached_clone(NULL, memc);
- memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
+ memcached_st *memc_clone= memcached_clone(NULL, memc);
+ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
rc= memcached_set(memc, "bubba", 5, "0", 1, 0, 0);
assert(rc == MEMCACHED_SUCCESS);
+ /*
+ ** We are using the quiet commands to store the replicas, so we need
+ ** to ensure that all of them are processed before we can continue.
+ ** In the test we go directly from storing the object to trying to
+ ** receive the object from all of the different servers, so we
+ ** could end up in a race condition (the memcached server hasn't yet
+ ** processed the quiet command from the replication set when it process
+ ** the request from the other client (created by the clone)). As a
+ ** workaround for that we call memcached_quit to send the quit command
+ ** to the server and wait for the response ;-) If you use the test code
+ ** as an example for your own code, please note that you shouldn't need
+ ** to do this ;-)
+ */
+ memcached_quit(memc);
+
/*
** "bubba" should now be stored on all of our servers. We don't have an
** easy to use API to address each individual server, so I'll just iterate
char key[2]= { [0]= (char)x };
size_t len;
uint32_t flags;
- char *val= memcached_get_by_key(clone, key, 1, "bubba", 5,
+ char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5,
&len, &flags, &rc);
assert(rc == MEMCACHED_SUCCESS);
assert(val != NULL);
free(val);
}
- memcached_free(clone);
+ memcached_free(memc_clone);
return TEST_SUCCESS;
}
*/
for (uint32_t host= 0; host < memc->number_of_hosts; ++host)
{
- memcached_st *clone= memcached_clone(NULL, memc);
- clone->hosts[host].port= 0;
+ memcached_st *memc_clone= memcached_clone(NULL, memc);
+ memc_clone->hosts[host].port= 0;
for (int x= 'a'; x <= 'z'; ++x)
{
char key[2]= { [0]= (char)x };
size_t len;
uint32_t flags;
- char *val= memcached_get_by_key(clone, key, 1, "bubba", 5,
+ char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5,
&len, &flags, &rc);
assert(rc == MEMCACHED_SUCCESS);
assert(val != NULL);
free(val);
}
- memcached_free(clone);
+ memcached_free(memc_clone);
}
return TEST_SUCCESS;
static test_return replication_mget_test(memcached_st *memc)
{
memcached_return rc;
- memcached_st *clone= memcached_clone(NULL, memc);
- memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
+ memcached_st *memc_clone= memcached_clone(NULL, memc);
+ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
char *keys[]= { "bubba", "key1", "key2", "key3" };
size_t len[]= { 5, 4, 4, 4 };
assert(rc == MEMCACHED_SUCCESS);
}
+ /*
+ ** We are using the quiet commands to store the replicas, so we need
+ ** to ensure that all of them are processed before we can continue.
+ ** In the test we go directly from storing the object to trying to
+ ** receive the object from all of the different servers, so we
+ ** could end up in a race condition (the memcached server hasn't yet
+ ** processed the quiet command from the replication set when it process
+ ** the request from the other client (created by the clone)). As a
+ ** workaround for that we call memcached_quit to send the quit command
+ ** to the server and wait for the response ;-) If you use the test code
+ ** as an example for your own code, please note that you shouldn't need
+ ** to do this ;-)
+ */
+ memcached_quit(memc);
+
/*
* Don't do the following in your code. I am abusing the internal details
* within the library, and this is not a supported interface.
* This is to verify correct behavior in the library
*/
memcached_result_st result_obj;
- for (uint32_t host= 0; host < clone->number_of_hosts; host++)
+ for (uint32_t host= 0; host < memc_clone->number_of_hosts; host++)
{
memcached_st *new_clone= memcached_clone(NULL, memc);
new_clone->hosts[host].port= 0;
static test_return replication_delete_test(memcached_st *memc)
{
memcached_return rc;
- memcached_st *clone= memcached_clone(NULL, memc);
+ memcached_st *memc_clone= memcached_clone(NULL, memc);
/* Delete the items from all of the servers except 1 */
uint64_t repl= memcached_behavior_get(memc,
MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS);
uint32_t hash= memcached_generate_hash(memc, keys[0], len[0]);
for (uint32_t x= 0; x < (repl + 1); ++x)
{
- clone->hosts[hash].port= 0;
- if (++hash == clone->number_of_hosts)
+ memc_clone->hosts[hash].port= 0;
+ if (++hash == memc_clone->number_of_hosts)
hash= 0;
}
memcached_result_st result_obj;
- for (uint32_t host= 0; host < clone->number_of_hosts; ++host)
+ for (uint32_t host= 0; host < memc_clone->number_of_hosts; ++host)
{
for (int x= 'a'; x <= 'z'; ++x)
{
char key[2]= { [0]= (char)x };
- rc= memcached_mget_by_key(clone, key, 1, keys, len, 4);
+ rc= memcached_mget_by_key(memc_clone, key, 1, keys, len, 4);
assert(rc == MEMCACHED_SUCCESS);
- memcached_result_st *results= memcached_result_create(clone, &result_obj);
+ memcached_result_st *results= memcached_result_create(memc_clone, &result_obj);
assert(results);
int hits= 0;
- while ((results= memcached_fetch_result(clone, &result_obj, &rc)) != NULL)
+ while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL)
{
++hits;
}
memcached_result_free(&result_obj);
}
}
- memcached_free(clone);
+ memcached_free(memc_clone);
return TEST_SUCCESS;
}
{"consistent_ketama_weighted", pre_behavior_ketama_weighted, 0, consistent_weighted_tests},
{"test_hashes", 0, 0, hash_tests},
{"replication", pre_replication, 0, replication_tests},
+ {"replication_noblock", pre_replication_noblock, 0, replication_tests},
{0, 0, 0, 0}
};