using namespace std;
extern "C" {
- test_return basic_test(memcached_st *memc);
- test_return increment_test(memcached_st *memc);
- test_return basic_master_key_test(memcached_st *memc);
void *world_create(void);
void world_destroy(void *p);
}
-test_return basic_test(memcached_st *memc)
+static test_return basic_test(memcached_st *memc)
{
Memcached foo(memc);
const string value_set("This is some data");
string value;
size_t value_length;
- foo.set("mine", value_set);
+ foo.set("mine", value_set, 0, 0);
value= foo.get("mine", &value_length);
assert((memcmp(value.c_str(), value_set.c_str(), value_length) == 0));
return TEST_SUCCESS;
}
-test_return increment_test(memcached_st *memc)
+static test_return increment_test(memcached_st *memc)
{
Memcached mcach(memc);
bool rc;
uint64_t int_ret_value;
size_t value_length;
- mcach.set(key, inc_value);
+ mcach.set(key, inc_value, 0, 0);
ret_value= mcach.get(key, &value_length);
printf("\nretvalue %s\n",ret_value.c_str());
int_inc_value= uint64_t(atol(inc_value.c_str()));
return TEST_SUCCESS;
}
-test_return basic_master_key_test(memcached_st *memc)
+static test_return basic_master_key_test(memcached_st *memc)
{
Memcached foo(memc);
const string value_set("Data for server A");
string value;
size_t value_length;
- foo.set_by_key(master_key_a, key, value_set);
+ foo.set_by_key(master_key_a, key, value_set, 0, 0);
value= foo.get_by_key(master_key_a, key, &value_length);
assert((memcmp(value.c_str(), value_set.c_str(), value_length) == 0));
return TEST_SUCCESS;
}
+/* Count the results */
+static memcached_return callback_counter(memcached_st *ptr __attribute__((unused)),
+ memcached_result_st *result __attribute__((unused)),
+ void *context)
+{
+ unsigned int *counter= static_cast<unsigned int *>(context);
+
+ *counter= *counter + 1;
+
+ return MEMCACHED_SUCCESS;
+}
+
+static test_return mget_result_function(memcached_st *memc)
+{
+ Memcached mc(memc);
+ bool rc;
+ string key1("fudge");
+ string key2("son");
+ string key3("food");
+ vector<string> keys;
+ keys.reserve(3);
+ keys.push_back(key1);
+ keys.push_back(key2);
+ keys.push_back(key3);
+ unsigned int counter;
+ memcached_execute_function callbacks[1];
+
+ /* We need to empty the server before we continue the test */
+ rc= mc.flush(0);
+ rc= mc.set_all(keys, keys, 50, 9);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ callbacks[0]= &callback_counter;
+ counter= 0;
+ rc= mc.fetch_execute(callbacks, static_cast<void *>(&counter), 1);
+
+ assert(counter == 3);
+
+ return TEST_SUCCESS;
+}
+
+static test_return mget_test(memcached_st *memc)
+{
+ Memcached mc(memc);
+ bool rc;
+ memcached_return mc_rc;
+ vector<string> keys;
+ keys.reserve(3);
+ keys.push_back("fudge");
+ keys.push_back("son");
+ keys.push_back("food");
+ uint32_t flags;
+
+ string return_key;
+ size_t return_key_length;
+ string return_value;
+ size_t return_value_length;
+
+ /* We need to empty the server before we continue the test */
+ rc= mc.flush(0);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ while (mc.fetch(return_key, return_value, &return_key_length,
+ &return_value_length, &flags, &mc_rc))
+ {
+ assert(return_value.length() != 0);
+ }
+ assert(return_value_length == 0);
+ assert(mc_rc == MEMCACHED_END);
+
+ rc= mc.set_all(keys, keys, 50, 9);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ while ((mc.fetch(return_key, return_value, &return_key_length,
+ &return_value_length, &flags, &mc_rc)))
+ {
+ assert(return_value.length() != 0);
+ assert(mc_rc == MEMCACHED_SUCCESS);
+ assert(return_key_length == return_value_length);
+ assert(!memcmp(return_value.c_str(), return_key.c_str(), return_value_length));
+ }
+
+ return TEST_SUCCESS;
+}
test_st tests[] ={
{ "basic", 0, basic_test },
{ "basic_master_key", 0, basic_master_key_test },
{ "increment_test", 0, increment_test },
+ { "mget", 1, mget_test },
+ { "mget_result_function", 1, mget_result_function },
{0, 0, 0}
};