2 This file is part of GNUnet.
3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file datastore/test_datastore_api_management.c
22 * @brief Test for the space management functions of the datastore implementation.
23 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_protocols.h"
29 #include "gnunet_datastore_service.h"
31 #define VERBOSE GNUNET_NO
34 * How long until we give up on transmitting the message?
36 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
39 * Number of iterations to run; must be large enough
40 * so that the quota will be exceeded!
42 #define ITERATIONS 5000
44 static struct GNUNET_DATASTORE_Handle *datastore;
46 static struct GNUNET_TIME_Absolute now;
54 return 8 + 8 * (i % 256);
61 static char buf[60000];
62 memset (buf, i, 8 + 8 * (i % 256));
88 static struct GNUNET_TIME_Absolute
89 get_expiration (int i)
91 struct GNUNET_TIME_Absolute av;
93 av.value = now.value + i * 1000;
111 struct GNUNET_SCHEDULER_Handle *sched;
112 const struct GNUNET_CONFIGURATION_Handle *cfg;
120 run_continuation (void *cls,
121 const struct GNUNET_SCHEDULER_TaskContext *tc);
125 check_success (void *cls,
129 struct CpsRunContext *crc = cls;
130 if (GNUNET_OK != success)
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
133 GNUNET_assert (GNUNET_OK == success);
134 GNUNET_free_non_null (crc->data);
136 GNUNET_SCHEDULER_add_continuation (crc->sched,
140 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
145 check_value (void *cls,
146 const GNUNET_HashCode * key,
152 struct GNUNET_TIME_Absolute
153 expiration, uint64_t uid)
155 struct CpsRunContext *crc = cls;
161 if (crc->found == GNUNET_YES)
164 crc->found = GNUNET_NO;
169 "First not found was %u\n", crc->i);
170 crc->phase = RP_GET_FAIL;
173 crc->phase = RP_DONE;
174 GNUNET_SCHEDULER_add_continuation (crc->sched,
178 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
182 crc->found = GNUNET_YES;
183 GNUNET_assert (size == get_size (i));
184 GNUNET_assert (0 == memcmp (data, get_data(i), size));
185 GNUNET_assert (type == get_type (i));
186 GNUNET_assert (priority == get_priority (i));
187 GNUNET_assert (anonymity == get_anonymity(i));
188 GNUNET_assert (expiration.value == get_expiration(i).value);
193 check_nothing (void *cls,
194 const GNUNET_HashCode * key,
200 struct GNUNET_TIME_Absolute
201 expiration, uint64_t uid)
203 struct CpsRunContext *crc = cls;
204 GNUNET_assert (key == NULL);
207 crc->phase = RP_DONE;
209 GNUNET_SCHEDULER_add_continuation (crc->sched,
213 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
218 run_continuation (void *cls,
219 const struct GNUNET_SCHEDULER_TaskContext *tc)
221 struct CpsRunContext *crc = cls;
222 ok = (int) crc->phase;
227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
228 "Executing `%s' number %u\n",
232 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
233 GNUNET_DATASTORE_put (datastore,
239 get_priority (crc->i),
240 get_anonymity (crc->i),
241 get_expiration (crc->i),
246 if (crc->i == ITERATIONS)
248 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
249 "Sleeping to give datastore time to clean up\n");
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
258 "Executing `%s' number %u\n",
262 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
263 GNUNET_DATASTORE_get (datastore,
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
273 "Executing `%s' number %u\n",
277 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
278 GNUNET_DATASTORE_get (datastore,
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "Finished, disconnecting\n");
290 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
299 struct GNUNET_SCHEDULER_Handle *sched,
302 const struct GNUNET_CONFIGURATION_Handle *cfg)
304 struct CpsRunContext *crc;
306 crc = GNUNET_malloc(sizeof(struct CpsRunContext));
310 now = GNUNET_TIME_absolute_get ();
311 datastore = GNUNET_DATASTORE_connect (cfg, sched);
312 GNUNET_SCHEDULER_add_continuation (crc->sched,
316 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
326 char *const argv[] = { "test-datastore-api-management",
328 "test_datastore_api_data.conf",
334 struct GNUNET_GETOPT_CommandLineOption options[] = {
335 GNUNET_GETOPT_OPTION_END
337 pid = GNUNET_OS_start_process ("gnunet-service-datastore",
338 "gnunet-service-datastore",
342 "-c", "test_datastore_api_data.conf", NULL);
344 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
345 argv, "test-datastore-api", "nohelp",
346 options, &run, NULL);
347 if (0 != PLIBC_KILL (pid, SIGTERM))
349 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
352 GNUNET_OS_process_wait(pid);
354 fprintf (stderr, "Missed some testcases: %u\n", ok);
359 main (int argc, char *argv[])
363 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-datastore");
364 GNUNET_log_setup ("test-datastore-api",
378 /* end of test_datastore_api_management.c */