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, 60)
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;
119 run_continuation (void *cls,
120 const struct GNUNET_SCHEDULER_TaskContext *tc);
124 check_success (void *cls,
128 struct CpsRunContext *crc = cls;
129 if (GNUNET_OK != success)
130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
132 GNUNET_assert (GNUNET_OK == success);
133 GNUNET_free_non_null (crc->data);
135 GNUNET_SCHEDULER_add_continuation (crc->sched,
138 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
143 check_value (void *cls,
144 const GNUNET_HashCode * key,
147 enum GNUNET_BLOCK_Type type,
150 struct GNUNET_TIME_Absolute
151 expiration, uint64_t uid)
153 struct CpsRunContext *crc = cls;
159 if (crc->found == GNUNET_YES)
162 crc->found = GNUNET_NO;
167 "First not found was %u\n", crc->i);
168 crc->phase = RP_GET_FAIL;
171 crc->phase = RP_DONE;
172 GNUNET_SCHEDULER_add_continuation (crc->sched,
175 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
179 crc->found = GNUNET_YES;
180 GNUNET_assert (size == get_size (i));
181 GNUNET_assert (0 == memcmp (data, get_data(i), size));
182 GNUNET_assert (type == get_type (i));
183 GNUNET_assert (priority == get_priority (i));
184 GNUNET_assert (anonymity == get_anonymity(i));
185 GNUNET_assert (expiration.value == get_expiration(i).value);
186 GNUNET_DATASTORE_get_next (datastore, GNUNET_YES);
191 check_nothing (void *cls,
192 const GNUNET_HashCode * key,
195 enum GNUNET_BLOCK_Type type,
198 struct GNUNET_TIME_Absolute
199 expiration, uint64_t uid)
201 struct CpsRunContext *crc = cls;
203 GNUNET_assert (key == NULL);
205 crc->phase = RP_DONE;
206 GNUNET_SCHEDULER_add_continuation (crc->sched,
209 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
214 run_continuation (void *cls,
215 const struct GNUNET_SCHEDULER_TaskContext *tc)
217 struct CpsRunContext *crc = cls;
218 ok = (int) crc->phase;
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Executing `%s' number %u\n",
228 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
229 GNUNET_DATASTORE_put (datastore,
235 get_priority (crc->i),
236 get_anonymity (crc->i),
237 get_expiration (crc->i),
242 if (crc->i == ITERATIONS)
244 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
245 "Sleeping to give datastore time to clean up\n");
253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "Executing `%s' number %u\n",
258 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
259 GNUNET_DATASTORE_get (datastore,
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
269 "Executing `%s' number %u\n",
273 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
274 GNUNET_DATASTORE_get (datastore,
282 GNUNET_assert (0 == crc->i);
284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
285 "Finished, disconnecting\n");
287 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
296 struct GNUNET_SCHEDULER_Handle *sched,
299 const struct GNUNET_CONFIGURATION_Handle *cfg)
301 struct CpsRunContext *crc;
303 crc = GNUNET_malloc(sizeof(struct CpsRunContext));
307 now = GNUNET_TIME_absolute_get ();
308 datastore = GNUNET_DATASTORE_connect (cfg, sched);
309 GNUNET_SCHEDULER_add_continuation (crc->sched,
312 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
322 char *const argv[] = { "test-datastore-api-management",
324 "test_datastore_api_data.conf",
330 struct GNUNET_GETOPT_CommandLineOption options[] = {
331 GNUNET_GETOPT_OPTION_END
333 pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
334 "gnunet-service-arm",
338 "-c", "test_datastore_api_data.conf", NULL);
339 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
340 argv, "test-datastore-api", "nohelp",
341 options, &run, NULL);
342 if (0 != PLIBC_KILL (pid, SIGTERM))
344 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
347 GNUNET_OS_process_wait(pid);
349 fprintf (stderr, "Missed some testcases: %u\n", ok);
354 main (int argc, char *argv[])
358 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-datastore");
359 GNUNET_log_setup ("test-datastore-api",
367 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-datastore");
373 /* end of test_datastore_api_management.c */