1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
4 TEST_CASE("memcached_cas") {
5 pair
<string
, MemcachedCluster
> tests
[] = {
6 {"network", MemcachedCluster::network()},
7 {"socket", MemcachedCluster::socket()}
10 LOOPED_SECTION(tests
) {
11 auto memc
= &test
.memc
;
12 const char *keys
[2] = {__func__
, NULL
};
13 size_t keylengths
[2] = {strlen(__func__
), 0};
15 REQUIRE_SUCCESS(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SUPPORT_CAS
, true));
16 REQUIRE_SUCCESS(memcached_set(memc
, S(__func__
), S("we the people"), (time_t) 0, (uint32_t) 0));
17 REQUIRE_SUCCESS(memcached_mget(memc
, keys
, keylengths
, 1));
19 memcached_result_st
*results
= memcached_result_create(memc
, nullptr);
22 memcached_return_t rc
;
23 results
= memcached_fetch_result(memc
, results
, &rc
);
27 REQUIRE(memcached_result_cas(results
));
28 REQUIRE("we the people"s
== string(memcached_result_value(results
), memcached_result_length(results
)));
30 uint64_t cas
= memcached_result_cas(results
);
31 REQUIRE(memcached_success(memcached_cas(memc
, S(__func__
), S("change the value"), 0, 0, cas
)));
34 * The item will have a new cas value, so try to set it again with the old
35 * value. This should fail!
37 REQUIRE_RC(MEMCACHED_DATA_EXISTS
, memcached_cas(memc
, S(__func__
), S("change the value"), 0, 0, cas
));
39 memcached_result_free(results
);