1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Libmemcached Client and Server
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #include <libtest/test.hpp>
41 #include "tests/libmemcached-1.0/haldenbrand.h"
42 #include "tests/libmemcached-1.0/fetch_all_results.h"
44 /* Test case provided by Cal Haldenbrand */
45 #define HALDENBRAND_KEY_COUNT 3000U // * 1024576
46 #define HALDENBRAND_FLAG_KEY 99 // * 1024576
48 test_return_t
haldenbrand_TEST1(memcached_st
*memc
)
50 /* We just keep looking at the same values over and over */
53 test_compare(MEMCACHED_SUCCESS
,
54 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true));
55 test_compare(MEMCACHED_SUCCESS
,
56 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true));
60 unsigned long long total
= 0;
61 for (uint32_t x
= 0 ; total
< 20 * 1024576 ; x
++ )
63 uint32_t size
= (uint32_t)(rand() % ( 5 * 1024 ) ) + 400;
64 char randomstuff
[6 * 1024];
65 memset(randomstuff
, 0, 6 * 1024);
66 test_true(size
< 6 * 1024); /* Being safe here */
68 for (uint32_t j
= 0 ; j
< size
;j
++)
70 randomstuff
[j
] = (signed char) ((rand() % 26) + 97);
74 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
75 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
76 test_compare(MEMCACHED_SUCCESS
,
77 memcached_set(memc
, key
, key_length
,
78 randomstuff
, strlen(randomstuff
),
79 time_t(0), HALDENBRAND_FLAG_KEY
));
81 test_true(total
> HALDENBRAND_KEY_COUNT
);
86 /* Test case provided by Cal Haldenbrand */
87 test_return_t
haldenbrand_TEST2(memcached_st
*memc
)
89 test_compare(MEMCACHED_SUCCESS
,
90 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true));
92 test_compare(MEMCACHED_SUCCESS
,
93 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true));
96 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, 20 * 1024576));
97 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, 20 * 1024576));
98 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
99 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
101 for (x
= 0, errors
= 0; total
< 20 * 1024576 ; x
++);
104 size_t total_value_length
= 0;
105 for (uint32_t x
= 0, errors
= 0; total_value_length
< 24576 ; x
++)
110 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
111 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
113 memcached_return_t rc
;
114 char *getval
= memcached_get(memc
, key
, key_length
, &val_len
, &flags
, &rc
);
115 if (memcached_failed(rc
))
117 if (rc
== MEMCACHED_NOTFOUND
)
128 test_compare(uint32_t(HALDENBRAND_FLAG_KEY
), flags
);
131 total_value_length
+= val_len
;
139 /* Do a large mget() over all the keys we think exist */
140 test_return_t
haldenbrand_TEST3(memcached_st
*memc
)
142 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, true));
143 test_compare(MEMCACHED_SUCCESS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_TCP_NODELAY
, true));
146 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
, 20 * 1024576);
147 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
, 20 * 1024576);
148 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE
);
149 getter
= memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE
);
152 std::vector
<size_t> key_lengths
;
153 key_lengths
.resize(HALDENBRAND_KEY_COUNT
);
154 std::vector
<char *> keys
;
155 keys
.resize(key_lengths
.size());
156 for (uint32_t x
= 0; x
< key_lengths
.size(); x
++)
158 char key
[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1];
159 int key_length
= snprintf(key
, sizeof(key
), "%u", x
);
160 test_true(key_length
> 0 and key_length
< MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH
+1);
161 keys
[x
]= strdup(key
);
162 key_lengths
[x
]= key_length
;
165 test_compare(MEMCACHED_SUCCESS
,
166 memcached_mget(memc
, &keys
[0], &key_lengths
[0], key_lengths
.size()));
168 unsigned int keys_returned
;
169 test_compare(TEST_SUCCESS
, fetch_all_results(memc
, keys_returned
));
170 test_compare(HALDENBRAND_KEY_COUNT
, keys_returned
);
172 for (libtest::vchar_ptr_t::iterator iter
= keys
.begin();