2 This file is part of GNUnet.
3 Copyright (C) 2004, 2005, 2006, 2007, 2009, 2011 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @file datastore/test_datastore_api_management.c
20 * @brief Test for the space management functions of the datastore implementation.
21 * @author Christian Grothoff
24 #include "gnunet_util_lib.h"
25 #include "gnunet_protocols.h"
26 #include "gnunet_datastore_service.h"
27 #include "gnunet_datastore_plugin.h"
28 #include "gnunet_testing_lib.h"
32 * How long until we give up on transmitting the message?
34 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
37 * Number of iterations to run; must be large enough
38 * so that the quota will be exceeded!
40 #define ITERATIONS 5000
53 struct GNUNET_HashCode key;
56 const struct GNUNET_CONFIGURATION_Handle *cfg;
62 static struct GNUNET_DATASTORE_Handle *datastore;
64 static struct GNUNET_TIME_Absolute now;
68 static const char *plugin_name;
74 return 8 + 8 * (i % 256);
81 static char buf[60000];
83 memset (buf, i, 8 + 8 * (i % 256));
103 get_anonymity (int i)
109 static struct GNUNET_TIME_Absolute
110 get_expiration (int i)
112 struct GNUNET_TIME_Absolute av;
114 av.abs_value_us = now.abs_value_us + i * 1000 * 1000LL;
120 run_continuation (void *cls);
124 check_success (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
126 struct CpsRunContext *crc = cls;
128 if (GNUNET_OK != success)
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", msg);
130 GNUNET_assert (GNUNET_OK == success);
131 GNUNET_free_non_null (crc->data);
133 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
138 check_value (void *cls,
139 const struct GNUNET_HashCode *key,
142 enum GNUNET_BLOCK_Type type,
145 uint32_t replication,
146 struct GNUNET_TIME_Absolute expiration,
149 struct CpsRunContext *crc = cls;
154 crc->phase = RP_GET_FAIL;
155 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
159 GNUNET_assert (size == get_size (i));
160 GNUNET_assert (0 == memcmp (data, get_data (i), size));
161 GNUNET_assert (type == get_type (i));
162 GNUNET_assert (priority == get_priority (i));
163 GNUNET_assert (anonymity == get_anonymity (i));
164 GNUNET_assert (expiration.abs_value_us == get_expiration (i).abs_value_us);
167 crc->phase = RP_DONE;
168 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
173 check_nothing (void *cls,
174 const struct GNUNET_HashCode *key,
177 enum GNUNET_BLOCK_Type type,
180 uint32_t replication,
181 struct GNUNET_TIME_Absolute expiration,
184 struct CpsRunContext *crc = cls;
186 GNUNET_assert (key == NULL);
188 crc->phase = RP_DONE;
189 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
194 run_continuation (void *cls)
196 struct CpsRunContext *crc = cls;
198 ok = (int) crc->phase;
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "PUT",
204 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
205 GNUNET_DATASTORE_put (datastore,
211 get_priority (crc->i),
212 get_anonymity (crc->i),
214 get_expiration (crc->i),
217 &check_success, crc);
219 if (crc->i == ITERATIONS)
221 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
222 "Sleeping to give datastore time to clean up\n");
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET",
231 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
232 GNUNET_DATASTORE_get_key (datastore,
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing `%s' number %u\n", "GET(f)",
245 GNUNET_CRYPTO_hash (&crc->i, sizeof (int), &crc->key);
246 GNUNET_DATASTORE_get_key (datastore,
257 GNUNET_assert (0 == crc->i);
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished, disconnecting\n");
259 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
267 run_tests (void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
269 struct CpsRunContext *crc = cls;
271 if (success != GNUNET_YES)
274 "Test 'put' operation failed with error `%s' database likely not setup, skipping test.\n",
276 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
280 GNUNET_SCHEDULER_add_now (&run_continuation, crc);
286 const struct GNUNET_CONFIGURATION_Handle *cfg,
287 struct GNUNET_TESTING_Peer *peer)
289 struct CpsRunContext *crc;
290 static struct GNUNET_HashCode zkey;
292 crc = GNUNET_new (struct CpsRunContext);
295 now = GNUNET_TIME_absolute_get ();
296 datastore = GNUNET_DATASTORE_connect (cfg);
298 GNUNET_DATASTORE_put (datastore,
303 GNUNET_BLOCK_TYPE_TEST,
305 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
311 FPRINTF (stderr, "%s", "Test 'put' operation failed.\n");
319 * Function called when disk utilization changes, does nothing.
322 * @param delta change in utilization
325 ignore_payload_cb (void *cls,
333 * check if plugin is actually working
336 test_plugin (const char *cfg_name)
339 struct GNUNET_CONFIGURATION_Handle *cfg;
340 struct GNUNET_DATASTORE_PluginFunctions *api;
341 struct GNUNET_DATASTORE_PluginEnvironment env;
343 cfg = GNUNET_CONFIGURATION_create ();
345 GNUNET_CONFIGURATION_load (cfg,
348 GNUNET_CONFIGURATION_destroy (cfg);
350 "Failed to load configuration %s\n",
354 memset (&env, 0, sizeof (env));
356 env.duc = &ignore_payload_cb;
357 GNUNET_snprintf (libname,
359 "libgnunet_plugin_datastore_%s",
361 api = GNUNET_PLUGIN_load (libname, &env);
364 GNUNET_CONFIGURATION_destroy (cfg);
366 "Failed to load plugin `%s'\n",
370 GNUNET_PLUGIN_unload (libname, api);
371 GNUNET_CONFIGURATION_destroy (cfg);
377 main (int argc, char *argv[])
382 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
383 GNUNET_snprintf (cfg_name,
385 "test_datastore_api_data_%s.conf",
387 ret = test_plugin (cfg_name);
391 GNUNET_TESTING_peer_run ("test-gnunet-datastore-management",
399 /* end of test_datastore_api_management.c */