- mcach.set(key, inc_value, strlen(inc_value));
- ret_value= mcach.get(key, &value_length);
- printf("\nretvalue %s\n",ret_value);
- int_inc_value= atoi(inc_value);
- int_ret_value= atoi(ret_value);
- assert(int_ret_value == int_inc_value);
+ populate_vector(inc_val, inc_value);
+
+ test_true(mcach.set(key, inc_val, 0, 0));
+
+ test_true(mcach.get(key, ret_value));
+ test_false(ret_value.empty());
+ copy_vec_to_string(ret_value, ret_string);
+
+ int_inc_value= uint64_t(atol(inc_value.c_str()));
+ int_ret_value= uint64_t(atol(ret_string.c_str()));
+ test_compare(int_inc_value, int_ret_value);
+
+ test_true(mcach.increment(key, 1, &int_ret_value));
+ test_compare(uint64_t(2), int_ret_value);
+
+ test_true(mcach.increment(key, 1, &int_ret_value));
+ test_compare(uint64_t(3), int_ret_value);
+
+ test_true(mcach.increment(key, 5, &int_ret_value));
+ test_compare(uint64_t(8), int_ret_value);
+
+ return TEST_SUCCESS;
+}
+
+test_return_t basic_master_key_test(memcached_st *original)
+{
+ Memcache foo(original);
+ const string value_set("Data for server A");
+ vector<char> value;
+ vector<char> test_value;
+ const string master_key_a("server-a");
+ const string master_key_b("server-b");
+ const string key("xyz");
+
+ populate_vector(value, value_set);
+
+ test_true(foo.setByKey(master_key_a, key, value, 0, 0));
+ test_true(foo.getByKey(master_key_a, key, test_value));
+
+ test_compare(value.size(), test_value.size());
+ test_memcmp(&value[0], &test_value[0], value.size());
+
+ test_value.clear();
+
+#if 0
+ test_false(foo.getByKey(master_key_b, key, test_value));
+ test_zero(test_value.size());
+#endif