aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_datastore_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-04-26 18:19:15 +0000
committerChristian Grothoff <christian@grothoff.org>2011-04-26 18:19:15 +0000
commit27ed8fcbc85a361864948edb517d47804c2b5a56 (patch)
tree01626713ea5b2ead4691f13eb66a1574b1c0c7fd /src/datastore/test_datastore_api.c
parentb6c71d97d2a4bb3cb0e0e0ac1cd2a4e145748cc6 (diff)
downloadgnunet-27ed8fcbc85a361864948edb517d47804c2b5a56.tar.gz
gnunet-27ed8fcbc85a361864948edb517d47804c2b5a56.zip
datastore and fs fixes from Easter
Diffstat (limited to 'src/datastore/test_datastore_api.c')
-rw-r--r--src/datastore/test_datastore_api.c285
1 files changed, 130 insertions, 155 deletions
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index 4a4bbc439..deeee7164 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -102,20 +102,18 @@ get_expiration (int i)
102enum RunPhase 102enum RunPhase
103 { 103 {
104 RP_DONE = 0, 104 RP_DONE = 0,
105 RP_PUT, 105 RP_PUT = 1,
106 RP_GET, 106 RP_GET = 2,
107 RP_DEL, 107 RP_DEL = 3,
108 RP_DO_DEL, 108 RP_DO_DEL = 4,
109 RP_DELVALIDATE, 109 RP_DELVALIDATE = 5,
110 RP_RESERVE, 110 RP_RESERVE = 6,
111 RP_PUT_MULTIPLE, 111 RP_PUT_MULTIPLE = 7,
112 RP_PUT_MULTIPLE_NEXT, 112 RP_PUT_MULTIPLE_NEXT = 8,
113 RP_GET_MULTIPLE, 113 RP_GET_MULTIPLE = 9,
114 RP_GET_MULTIPLE_NEXT, /* 10 */ 114 RP_GET_MULTIPLE_NEXT = 10,
115 RP_GET_MULTIPLE_DONE, 115 RP_UPDATE = 11,
116 RP_UPDATE, 116 RP_UPDATE_VALIDATE = 12,
117 RP_UPDATE_VALIDATE, /* 13 */
118 RP_UPDATE_DONE,
119 RP_ERROR 117 RP_ERROR
120 }; 118 };
121 119
@@ -129,7 +127,9 @@ struct CpsRunContext
129 void *data; 127 void *data;
130 size_t size; 128 size_t size;
131 enum RunPhase phase; 129 enum RunPhase phase;
132 unsigned long long uid; 130 uint64_t uid;
131 uint64_t offset;
132 uint64_t first_uid;
133}; 133};
134 134
135 135
@@ -144,16 +144,15 @@ check_success (void *cls,
144 const char *msg) 144 const char *msg)
145{ 145{
146 struct CpsRunContext *crc = cls; 146 struct CpsRunContext *crc = cls;
147
147 if (GNUNET_OK != success) 148 if (GNUNET_OK != success)
148 { 149 {
149 ok = 42;
150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
151 "Operation not successfull: `%s'\n", msg); 151 "Operation %d/%d not successfull: `%s'\n",
152 crc->phase,
153 crc->i,
154 msg);
152 crc->phase = RP_ERROR; 155 crc->phase = RP_ERROR;
153 GNUNET_SCHEDULER_add_continuation (&run_continuation,
154 crc,
155 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
156 return;
157 } 156 }
158 GNUNET_free_non_null (crc->data); 157 GNUNET_free_non_null (crc->data);
159 crc->data = NULL; 158 crc->data = NULL;
@@ -171,7 +170,8 @@ get_reserved (void *cls,
171 struct CpsRunContext *crc = cls; 170 struct CpsRunContext *crc = cls;
172 if (0 >= success) 171 if (0 >= success)
173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 172 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
174 "%s\n", msg); 173 "Error obtaining reservation: `%s'\n",
174 msg);
175 GNUNET_assert (0 < success); 175 GNUNET_assert (0 < success);
176 crc->rid = success; 176 crc->rid = success;
177 GNUNET_SCHEDULER_add_continuation (&run_continuation, 177 GNUNET_SCHEDULER_add_continuation (&run_continuation,
@@ -188,42 +188,48 @@ check_value (void *cls,
188 enum GNUNET_BLOCK_Type type, 188 enum GNUNET_BLOCK_Type type,
189 uint32_t priority, 189 uint32_t priority,
190 uint32_t anonymity, 190 uint32_t anonymity,
191 struct GNUNET_TIME_Absolute 191 struct GNUNET_TIME_Absolute expiration,
192 expiration, uint64_t uid) 192 uint64_t uid)
193{ 193{
194 static int matched;
195 struct CpsRunContext *crc = cls; 194 struct CpsRunContext *crc = cls;
196 int i; 195 int i;
197 196
198 if (key == NULL)
199 {
200 if (crc->i == 0)
201 {
202 crc->phase = RP_DEL;
203 crc->i = ITERATIONS;
204 }
205 GNUNET_assert (matched == GNUNET_YES);
206 matched = GNUNET_NO;
207 GNUNET_SCHEDULER_add_continuation (&run_continuation,
208 crc,
209 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
210 return;
211 }
212 i = crc->i; 197 i = crc->i;
198#if 0
199 fprintf (stderr,
200 "Check value got `%s' of size %u, type %d, expire %llu\n",
201 GNUNET_h2s (key),
202 (unsigned int) size,
203 type,
204 (unsigned long long) expiration.abs_value);
205 fprintf (stderr,
206 "Check value iteration %d wants size %u, type %d, expire %llu\n",
207 i,
208 (unsigned int) get_size (i),
209 get_type (i),
210 (unsigned long long) get_expiration(i).abs_value);
211#endif
213 GNUNET_assert (size == get_size (i)); 212 GNUNET_assert (size == get_size (i));
214 GNUNET_assert (0 == memcmp (data, get_data(i), size)); 213 GNUNET_assert (0 == memcmp (data, get_data(i), size));
215 GNUNET_assert (type == get_type (i)); 214 GNUNET_assert (type == get_type (i));
216 GNUNET_assert (priority == get_priority (i)); 215 GNUNET_assert (priority == get_priority (i));
217 GNUNET_assert (anonymity == get_anonymity(i)); 216 GNUNET_assert (anonymity == get_anonymity(i));
218 GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value); 217 GNUNET_assert (expiration.abs_value == get_expiration(i).abs_value);
219 matched = GNUNET_YES; 218 crc->offset++;
220 GNUNET_DATASTORE_iterate_get_next (datastore); 219 if (crc->i == 0)
220 {
221 crc->phase = RP_DEL;
222 crc->i = ITERATIONS;
223 }
224 GNUNET_SCHEDULER_add_continuation (&run_continuation,
225 crc,
226 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
221} 227}
222 228
223 229
224static void 230static void
225delete_value (void *cls, 231delete_value (void *cls,
226 const GNUNET_HashCode * key, 232 const GNUNET_HashCode *key,
227 size_t size, 233 size_t size,
228 const void *data, 234 const void *data,
229 enum GNUNET_BLOCK_Type type, 235 enum GNUNET_BLOCK_Type type,
@@ -233,36 +239,23 @@ delete_value (void *cls,
233 expiration, uint64_t uid) 239 expiration, uint64_t uid)
234{ 240{
235 struct CpsRunContext *crc = cls; 241 struct CpsRunContext *crc = cls;
236 if (key == NULL) 242
237 {
238 if (crc->data == NULL)
239 {
240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
241 "Content %u not found!\n",
242 crc->i);
243 crc->phase = RP_ERROR;
244 }
245 else
246 {
247 crc->phase = RP_DO_DEL;
248 }
249 GNUNET_SCHEDULER_add_continuation (&run_continuation,
250 crc,
251 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
252 return;
253 }
254 GNUNET_assert (crc->data == NULL); 243 GNUNET_assert (crc->data == NULL);
244 GNUNET_assert (NULL != key);
255 crc->size = size; 245 crc->size = size;
256 crc->key = *key; 246 crc->key = *key;
257 crc->data = GNUNET_malloc (size); 247 crc->data = GNUNET_malloc (size);
258 memcpy (crc->data, data, size); 248 memcpy (crc->data, data, size);
259 GNUNET_DATASTORE_iterate_get_next (datastore); 249 crc->phase = RP_DO_DEL;
250 GNUNET_SCHEDULER_add_continuation (&run_continuation,
251 crc,
252 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
260} 253}
261 254
262 255
263static void 256static void
264check_nothing (void *cls, 257check_nothing (void *cls,
265 const GNUNET_HashCode * key, 258 const GNUNET_HashCode *key,
266 size_t size, 259 size_t size,
267 const void *data, 260 const void *data,
268 enum GNUNET_BLOCK_Type type, 261 enum GNUNET_BLOCK_Type type,
@@ -272,11 +265,10 @@ check_nothing (void *cls,
272 expiration, uint64_t uid) 265 expiration, uint64_t uid)
273{ 266{
274 struct CpsRunContext *crc = cls; 267 struct CpsRunContext *crc = cls;
268
275 GNUNET_assert (key == NULL); 269 GNUNET_assert (key == NULL);
276 if (crc->i == 0) 270 if (crc->i == 0)
277 { 271 crc->phase = RP_RESERVE;
278 crc->phase = RP_RESERVE;
279 }
280 GNUNET_SCHEDULER_add_continuation (&run_continuation, 272 GNUNET_SCHEDULER_add_continuation (&run_continuation,
281 crc, 273 crc,
282 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 274 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
@@ -296,47 +288,28 @@ check_multiple (void *cls,
296{ 288{
297 struct CpsRunContext *crc = cls; 289 struct CpsRunContext *crc = cls;
298 290
299 if (key == NULL) 291 GNUNET_assert (key != NULL);
300 {
301 if (crc->phase != RP_GET_MULTIPLE_DONE)
302 {
303 fprintf (stderr,
304 "Wrong phase: %d\n",
305 crc->phase);
306 GNUNET_break (0);
307 crc->phase = RP_ERROR;
308 }
309 else
310 {
311 crc->phase = RP_UPDATE;
312 }
313 GNUNET_SCHEDULER_add_continuation (&run_continuation,
314 crc,
315 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
316 return;
317 }
318 switch (crc->phase) 292 switch (crc->phase)
319 { 293 {
320 case RP_GET_MULTIPLE: 294 case RP_GET_MULTIPLE:
321 crc->phase = RP_GET_MULTIPLE_NEXT; 295 crc->phase = RP_GET_MULTIPLE_NEXT;
296 crc->first_uid = uid;
297 crc->offset++;
322 break; 298 break;
323 case RP_GET_MULTIPLE_NEXT: 299 case RP_GET_MULTIPLE_NEXT:
324 crc->phase = RP_GET_MULTIPLE_DONE; 300 GNUNET_assert (uid != crc->first_uid);
325 break; 301 crc->phase = RP_UPDATE;
326 case RP_GET_MULTIPLE_DONE:
327 /* do not advance further */
328 break; 302 break;
329 default: 303 default:
330 GNUNET_break (0); 304 GNUNET_break (0);
305 crc->phase = RP_ERROR;
331 break; 306 break;
332 } 307 }
333#if VERBOSE
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
335 "Test in phase %u\n", crc->phase);
336#endif
337 if (priority == get_priority (42)) 308 if (priority == get_priority (42))
338 crc->uid = uid; 309 crc->uid = uid;
339 GNUNET_DATASTORE_iterate_get_next (datastore); 310 GNUNET_SCHEDULER_add_continuation (&run_continuation,
311 crc,
312 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
340} 313}
341 314
342 315
@@ -353,31 +326,19 @@ check_update (void *cls,
353{ 326{
354 struct CpsRunContext *crc = cls; 327 struct CpsRunContext *crc = cls;
355 328
356 if (key == NULL) 329 GNUNET_assert (key != NULL);
357 {
358 if (crc->phase != RP_UPDATE_DONE)
359 {
360 GNUNET_break (0);
361 crc->phase = RP_ERROR;
362 }
363 else
364 {
365 crc->phase = RP_DONE;
366 }
367 GNUNET_SCHEDULER_add_continuation (&run_continuation,
368 crc,
369 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
370 return;
371 }
372 if ( (anonymity == get_anonymity (42)) && 330 if ( (anonymity == get_anonymity (42)) &&
373 (size == get_size (42)) && 331 (size == get_size (42)) &&
374 (priority == get_priority (42) + 100) ) 332 (priority == get_priority (42) + 100) )
333 crc->phase = RP_DONE;
334 else
375 { 335 {
376 crc->phase = RP_UPDATE_DONE; 336 GNUNET_assert (size == get_size (43));
337 crc->offset++;
377 } 338 }
378 else 339 GNUNET_SCHEDULER_add_continuation (&run_continuation,
379 GNUNET_assert (size == get_size (43)); 340 crc,
380 GNUNET_DATASTORE_iterate_get_next (datastore); 341 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
381} 342}
382 343
383 344
@@ -427,12 +388,13 @@ run_continuation (void *cls,
427 crc->i); 388 crc->i);
428#endif 389#endif
429 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 390 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
430 GNUNET_DATASTORE_iterate_key (datastore, 391 GNUNET_DATASTORE_get_key (datastore,
431 &crc->key, 392 crc->offset,
432 get_type (crc->i), 393 &crc->key,
433 1, 1, TIMEOUT, 394 get_type (crc->i),
434 &check_value, 395 1, 1, TIMEOUT,
435 crc); 396 &check_value,
397 crc);
436 break; 398 break;
437 case RP_DEL: 399 case RP_DEL:
438 crc->i--; 400 crc->i--;
@@ -444,12 +406,14 @@ run_continuation (void *cls,
444#endif 406#endif
445 crc->data = NULL; 407 crc->data = NULL;
446 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 408 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
447 GNUNET_DATASTORE_iterate_key (datastore, 409 GNUNET_assert (NULL !=
448 &crc->key, 410 GNUNET_DATASTORE_get_key (datastore,
449 get_type (crc->i), 411 crc->offset,
450 1, 1, TIMEOUT, 412 &crc->key,
451 &delete_value, 413 get_type (crc->i),
452 crc); 414 1, 1, TIMEOUT,
415 &delete_value,
416 crc));
453 break; 417 break;
454 case RP_DO_DEL: 418 case RP_DO_DEL:
455#if VERBOSE 419#if VERBOSE
@@ -467,13 +431,14 @@ run_continuation (void *cls,
467 { 431 {
468 crc->phase = RP_DEL; 432 crc->phase = RP_DEL;
469 } 433 }
470 GNUNET_DATASTORE_remove (datastore, 434 GNUNET_assert (NULL !=
471 &crc->key, 435 GNUNET_DATASTORE_remove (datastore,
472 crc->size, 436 &crc->key,
473 crc->data, 437 crc->size,
474 1, 1, TIMEOUT, 438 crc->data,
475 &check_success, 439 1, 1, TIMEOUT,
476 crc); 440 &check_success,
441 crc));
477 break; 442 break;
478 case RP_DELVALIDATE: 443 case RP_DELVALIDATE:
479 crc->i--; 444 crc->i--;
@@ -484,12 +449,14 @@ run_continuation (void *cls,
484 crc->i); 449 crc->i);
485#endif 450#endif
486 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key); 451 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
487 GNUNET_DATASTORE_iterate_key (datastore, 452 GNUNET_assert (NULL !=
488 &crc->key, 453 GNUNET_DATASTORE_get_key (datastore,
489 get_type (crc->i), 454 crc->offset,
490 1, 1, TIMEOUT, 455 &crc->key,
491 &check_nothing, 456 get_type (crc->i),
492 crc); 457 1, 1, TIMEOUT,
458 &check_nothing,
459 crc));
493 break; 460 break;
494 case RP_RESERVE: 461 case RP_RESERVE:
495 crc->phase = RP_PUT_MULTIPLE; 462 crc->phase = RP_PUT_MULTIPLE;
@@ -533,16 +500,24 @@ run_continuation (void *cls,
533 crc); 500 crc);
534 break; 501 break;
535 case RP_GET_MULTIPLE: 502 case RP_GET_MULTIPLE:
536 GNUNET_DATASTORE_iterate_key (datastore, 503 GNUNET_assert (NULL !=
537 &crc->key, 504 GNUNET_DATASTORE_get_key (datastore,
538 get_type (42), 505 crc->offset,
539 1, 1, TIMEOUT, 506 &crc->key,
540 &check_multiple, 507 get_type (42),
541 crc); 508 1, 1, TIMEOUT,
509 &check_multiple,
510 crc));
542 break; 511 break;
543 case RP_GET_MULTIPLE_NEXT: 512 case RP_GET_MULTIPLE_NEXT:
544 case RP_GET_MULTIPLE_DONE: 513 GNUNET_assert (NULL !=
545 GNUNET_assert (0); 514 GNUNET_DATASTORE_get_key (datastore,
515 crc->offset,
516 &crc->key,
517 get_type (42),
518 1, 1, TIMEOUT,
519 &check_multiple,
520 crc));
546 break; 521 break;
547 case RP_UPDATE: 522 case RP_UPDATE:
548 GNUNET_assert (crc->uid > 0); 523 GNUNET_assert (crc->uid > 0);
@@ -556,15 +531,14 @@ run_continuation (void *cls,
556 crc); 531 crc);
557 break; 532 break;
558 case RP_UPDATE_VALIDATE: 533 case RP_UPDATE_VALIDATE:
559 GNUNET_DATASTORE_iterate_key (datastore, 534 GNUNET_assert (NULL !=
560 &crc->key, 535 GNUNET_DATASTORE_get_key (datastore,
561 get_type (42), 536 crc->offset,
562 1, 1, TIMEOUT, 537 &crc->key,
563 &check_update, 538 get_type (42),
564 crc); 539 1, 1, TIMEOUT,
565 break; 540 &check_update,
566 case RP_UPDATE_DONE: 541 crc));
567 GNUNET_assert (0);
568 break; 542 break;
569 case RP_DONE: 543 case RP_DONE:
570#if VERBOSE 544#if VERBOSE
@@ -681,6 +655,7 @@ check ()
681 argv, "test-datastore-api", "nohelp", 655 argv, "test-datastore-api", "nohelp",
682 options, &run, NULL); 656 options, &run, NULL);
683#if START_DATASTORE 657#if START_DATASTORE
658 sleep (1); /* give datastore chance to receive 'DROP' request */
684 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 659 if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
685 { 660 {
686 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 661 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");