forked from naver/arcus-memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_engine_testsuite.c
265 lines (244 loc) · 9.59 KB
/
basic_engine_testsuite.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
* arcus-memcached - Arcus memory cache server
* Copyright 2010-2014 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <memcached/engine_testapp.h>
MEMCACHED_PUBLIC_API
engine_test_t* get_tests(void);
/*
* Make sure that get_info returns something and that repeated calls to it
* return the same something.
*/
static enum test_result get_info_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
const engine_info *info = h1->get_info(h);
assert(info != NULL);
assert(info == h1->get_info(h));
return SUCCESS;
}
/*
* Make sure that the structure returned by get_info has a non-null description.
*/
static enum test_result get_info_description_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
const engine_info *info = h1->get_info(h);
assert(info->description != NULL);
return SUCCESS;
}
/*
* Make sure that the structure returned by get_info has a valid number of
* features and that the size of the feautes array equals that value
*/
static enum test_result get_info_features_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
const engine_info *info = h1->get_info(h);
uint32_t nfeats = info->num_features;
assert (nfeats > 0);
const feature_info *fi = info->features;
while (nfeats-- > 0) {
assert(fi != NULL);
fi++;
}
return SUCCESS;
}
/*
* Make sure we can successfully allocate an item, allocate op returns success
* and that item struct is populated
*/
static enum test_result allocate_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
void *key = "akey";
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,1,1,0) == ENGINE_SUCCESS);
assert(test_item != NULL);
h1->release(h,NULL,test_item);
return SUCCESS;
}
/*
* Make sure when we can successfully store an item after it has been allocated
* and that the cas for the stored item has been generated.
*/
static enum test_result store_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
void *key = "bkey";
uint64_t cas = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,1,1,0) == ENGINE_SUCCESS);
assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
assert(cas != 0);
h1->release(h,NULL,test_item);
return SUCCESS;
}
/*
* Make sure when we can successfully retrieve an item that has been stored in
* the engine
*/
static enum test_result get_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
item *test_item_get = NULL;
void *key = "get_test_key";
uint64_t cas = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0,0,0) == ENGINE_SUCCESS);
assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
assert(h1->get(h,NULL,&test_item_get,key,strlen(key),0) == ENGINE_SUCCESS);
h1->release(h,NULL,test_item);
h1->release(h,NULL,test_item_get);
return SUCCESS;
}
/*
* Make sure that we can release an item. For the most part all this test does
* is ensure that thinds dont go splat when we call release. It does nothing to
* ensure that release did much of anything.
*/
static enum test_result release_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
void *key = "release_test_key";
uint64_t cas = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0,0,0) == ENGINE_SUCCESS);
assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
h1->release(h, NULL, test_item);
return SUCCESS;
}
/*
* Make sure that we can remove an item and that after the item has been
* removed it can not be retrieved.
*/
static enum test_result remove_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
void *key = "remove_test_key";
uint64_t cas = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0,0,0) == ENGINE_SUCCESS);
assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
assert(h1->remove(h, NULL, key, strlen(key), cas, 0) == ENGINE_SUCCESS);
item *check_item = test_item;
assert(h1->get(h, NULL, &check_item, key, strlen(key), 0) == ENGINE_KEY_ENOENT);
assert(check_item == NULL);
h1->release(h, NULL, test_item);
return SUCCESS;
}
/*
* Make sure we can arithmetic operations to set the initial value of a key and
* to then later increment that value
*/
static enum test_result incr_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
void *key = "incr_test_key";
uint64_t cas = 0;
uint64_t res = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0,0,0) == ENGINE_SUCCESS);
assert(h1->arithmetic(h, NULL, key, strlen(key), true, true, 0, 1, 0,
0, &cas, &res, 0 ) == ENGINE_SUCCESS);
assert(res == 1);
assert(h1->arithmetic(h, NULL, key, strlen(key), true, false, 1, 0, 0,
0, &cas, &res, 0 ) == ENGINE_SUCCESS);
assert(res == 2);
h1->release(h, NULL, test_item);
return SUCCESS;
}
/*
* Make sure we can arithmetic operations to set the initial value of a key and
* to then later decrement that value
*/
static enum test_result decr_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
void *key = "decr_test_key";
uint64_t cas = 0;
uint64_t res = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0,0,0) == ENGINE_SUCCESS);
assert(h1->arithmetic(h, NULL, key, strlen(key), false, true, 0, 1, 0,
0, &cas, &res, 0 ) == ENGINE_SUCCESS);
assert(res == 1);
assert(h1->arithmetic(h, NULL, key, strlen(key), false, false, 1, 0, 0,
0, &cas, &res, 0 ) == ENGINE_SUCCESS);
assert(res == 0);
h1->release(h, NULL, test_item);
return SUCCESS;
}
/*
* Make sure we can successfully perform a flush operation and that any item
* stored before the flush can not be retrieved
*/
static enum test_result flush_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
void *key = "flush_test_key";
uint64_t cas = 0;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0,0,0) == ENGINE_SUCCESS);
assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
assert(h1->flush(h, NULL, NULL, -1, 0) == ENGINE_SUCCESS);
item *check_item = test_item;
assert(h1->get(h, NULL, &check_item, key, strlen(key), 0) == ENGINE_KEY_ENOENT);
assert(check_item == NULL);
h1->release(h, NULL, test_item);
return SUCCESS;
}
/*
* Make sure we can successfully retrieve the item info struct for an item and
* that the contents of the item_info are as expected.
*/
static enum test_result get_item_info_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *test_item = NULL;
char *key = "get_item_info_test_key";
uint64_t cas = 0;
const rel_time_t exp = 1;
item_info ii;
assert(h1->allocate(h, NULL, &test_item, key, strlen(key), 1,0, exp, 0) == ENGINE_SUCCESS);
assert(h1->store(h, NULL, test_item, &cas, OPERATION_SET,0) == ENGINE_SUCCESS);
/* Had this been actual code, there'd be a connection here */
assert(h1->get_item_info(h, NULL, test_item, &ii) == true);
assert(ii.cas == cas);
assert(ii.flags == 0);
assert(strcmp(key,ii.key) == 0);
assert(ii.nkey == strlen(key));
assert(ii.nbytes == 1);
assert(ii.exptime == exp);
h1->release(h, NULL, test_item);
return SUCCESS;
}
static enum test_result get_stats_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
return PENDING;
}
static enum test_result reset_stats_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
return PENDING;
}
static enum test_result get_stats_struct_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
return PENDING;
}
static enum test_result aggregate_stats_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
return PENDING;
}
static enum test_result unknown_command_test(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
return PENDING;
}
engine_test_t* get_tests(void) {
static engine_test_t tests[] = {
{"get info test", get_info_test, NULL, NULL, NULL},
{"get info description test", get_info_description_test, NULL, NULL, NULL},
{"get info features test", get_info_features_test, NULL, NULL, NULL},
{"allocate test", allocate_test, NULL, NULL, NULL},
{"store test", store_test, NULL, NULL, NULL},
{"get test", get_test, NULL, NULL, NULL},
{"remove test", remove_test, NULL, NULL, NULL},
{"release test", release_test, NULL, NULL, NULL},
{"incr test", incr_test, NULL, NULL, NULL},
{"decr test", decr_test, NULL, NULL, NULL},
{"flush test", flush_test, NULL, NULL, NULL},
{"get item info test", get_item_info_test, NULL, NULL, NULL},
{"get stats test", get_stats_test, NULL, NULL, NULL},
{"reset stats test", reset_stats_test, NULL, NULL, NULL},
{"get stats struct test", get_stats_struct_test, NULL, NULL, NULL},
{"aggregate stats test", aggregate_stats_test, NULL, NULL, NULL},
{"unknown command test", unknown_command_test, NULL, NULL, NULL},
{NULL, NULL, NULL, NULL, NULL}
};
return tests;
}