1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
4 /* Test case provided by Cal Haldenbrand */
6 #define HALDENBRAND_KEY_COUNT 3000U // * 1024576
7 #define HALDENBRAND_FLAG_KEY 99 // * 1024576
11 TEST_CASE("memcached_haldenbrand_nblock_tcp_ndelay") {
12 pair
<string
, MemcachedCluster
> tests
[] = {
13 {"network", MemcachedCluster::network()},
16 for (auto &[name
, test
] : tests
) {
17 REQUIRE_SUCCESS(memcached_behavior_set(&test
.memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true));
18 REQUIRE_SUCCESS(memcached_behavior_set(&test
.memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true));
21 LOOPED_SECTION(tests
) {
22 auto memc
= &test
.memc
;
24 /* We just keep looking at the same values over and over */
28 unsigned long long total
= 0;
29 for (uint32_t x
= 0; total
< 20 * 1024576; x
++) {
30 uint32_t size
= (uint32_t) (rand() % (5 * 1024)) + 400;
31 char randomstuff
[6 * 1024];
32 memset(randomstuff
, 0, 6 * 1024);
33 REQUIRE(size
< 6 * 1024); /* Being safe here */
35 for (uint32_t j
= 0; j
< size
; j
++) {
36 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
40 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+ 1];
41 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
42 REQUIRE_SUCCESS(memcached_set(memc
, key
, key_length
,
43 randomstuff
, strlen(randomstuff
),
44 time_t(0), HALDENBRAND_FLAG_KEY
47 REQUIRE(total
> HALDENBRAND_KEY_COUNT
);
49 size_t total_value_length
= 0;
50 for (uint32_t x
= 0, errors
= 0; total_value_length
< 24576; x
++) {
54 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+ 1];
55 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
57 memcached_return_t rc
;
58 char *getval
= memcached_get(memc
, key
, key_length
, &val_len
, &flags
, &rc
);
59 if (memcached_failed(rc
)) {
60 if (rc
== MEMCACHED_NOTFOUND
) {
68 REQUIRE(uint32_t(HALDENBRAND_FLAG_KEY
) == flags
);
71 total_value_length
+= val_len
;
77 std::vector
<size_t> key_lengths
;
78 key_lengths
.resize(HALDENBRAND_KEY_COUNT
);
79 std::vector
<char *> keys
;
80 keys
.resize(key_lengths
.size());
81 for (uint32_t x
= 0; x
< key_lengths
.size(); x
++) {
82 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+ 1];
83 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
84 REQUIRE(key_length
> 0);
85 REQUIRE(key_length
< MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+ 1);
86 keys
[x
] = strdup(key
);
87 key_lengths
[x
] = key_length
;
90 REQUIRE_SUCCESS(memcached_mget(memc
, &keys
[0], &key_lengths
[0], key_lengths
.size()));
92 unsigned int keys_returned
;
93 REQUIRE(memcached_success(fetch_all_results(memc
, keys_returned
)));
94 REQUIRE(HALDENBRAND_KEY_COUNT
== keys_returned
);
96 for (auto key
: keys
) {