/*
This file is part of GNUnet.
- (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
+ (C) 2011 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
/*
* @file test_plugin_datastore.c
- * @brief Profile database plugin directly, focusing on iterators.
+ * @brief Test database plugin directly, calling each API function once
* @author Christian Grothoff
*/
#define VERBOSE GNUNET_NO
-/**
- * Target datastore size (in bytes). Realistic sizes are
- * more like 16 GB (not the default of 16 MB); however,
- * those take too long to run them in the usual "make check"
- * sequence. Hence the value used for shipping is tiny.
- */
-#define MAX_SIZE 1024LL * 1024 * 128
-
-#define ITERATIONS 2
-
/**
* Number of put operations to perform.
*/
enum RunPhase phase;
unsigned int cnt;
unsigned int i;
+ uint64_t offset;
};
value[0] = k;
msg = NULL;
prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
+#if VERBOSE
+ fprintf (stderr,
+ "putting type %u, anon %u under key %s\n",
+ i+1, i, GNUNET_h2s (&key));
+#endif
if (GNUNET_OK != api->put (api->cls,
&key,
size,
const struct GNUNET_SCHEDULER_TaskContext *tc);
+static uint64_t guid;
+
+
static int
iterate_one_shot (void *cls,
- void *next_cls,
const GNUNET_HashCode * key,
uint32_t size,
const void *data,
{
struct CpsRunContext *crc = cls;
- GNUNET_assert (NULL == next_cls);
GNUNET_assert (key != NULL);
+ guid = uid;
crc->phase++;
#if VERBOSE
fprintf (stderr,
- "Found result type=%u, priority=%u, size=%u, expire=%llu\n",
+ "Found result type=%u, priority=%u, size=%u, expire=%llu, key %s\n",
type, priority, size,
- (unsigned long long) expiration.abs_value);
+ (unsigned long long) expiration.abs_value,
+ GNUNET_h2s (key));
#endif
GNUNET_SCHEDULER_add_now (&test, crc);
return GNUNET_OK;
}
-static uint64_t guid;
-
-static int
-iterate_with_next (void *cls,
- void *next_cls,
- const GNUNET_HashCode * key,
- uint32_t size,
- const void *data,
- enum GNUNET_BLOCK_Type type,
- uint32_t priority,
- uint32_t anonymity,
- struct GNUNET_TIME_Absolute
- expiration,
- uint64_t uid)
-{
- struct CpsRunContext *crc = cls;
-
- if (key == NULL)
- {
- crc->phase++;
- GNUNET_SCHEDULER_add_now (&test, crc);
- return GNUNET_OK;
- }
- guid = uid;
-#if VERBOSE
- fprintf (stderr,
- "Found result type=%u, priority=%u, size=%u, expire=%llu\n",
- type, priority, size,
- (unsigned long long) expiration.abs_value);
-#endif
- crc->cnt++;
- crc->api->next_request (next_cls,
- GNUNET_NO);
- return GNUNET_OK;
-}
-
-
/**
* Function called when the service shuts
* down. Unloads our datastore plugin.
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Test aborted.\n");
crc->phase = RP_ERROR;
- ok = 1;
}
+#if VERBOSE
+ fprintf (stderr, "In phase %d, iteration %u\n",
+ crc->phase,
+ crc->cnt);
+#endif
switch (crc->phase)
{
case RP_ERROR:
+ ok = 1;
GNUNET_break (0);
crc->api->drop (crc->api->cls);
GNUNET_SCHEDULER_add_now (&cleaning_task, crc);
for (j=0;j<PUT_10;j++)
{
put_value (crc->api, j, crc->i);
- cs = crc->api->get_size (crc->api->cls);
+ cs = crc->api->estimate_size (crc->api->cls);
GNUNET_assert (os < cs);
os = cs;
}
break;
}
gen_key (5, &key);
- crc->api->get (crc->api->cls,
- &key, NULL,
- GNUNET_BLOCK_TYPE_ANY,
- &iterate_with_next,
- crc);
+ crc->api->get_key (crc->api->cls,
+ crc->offset++,
+ &key, NULL,
+ GNUNET_BLOCK_TYPE_ANY,
+ &iterate_one_shot,
+ crc);
break;
case RP_UPDATE:
GNUNET_assert (GNUNET_OK ==
GNUNET_SCHEDULER_add_now (&test, crc);
break;
}
- crc->api->iter_zero_anonymity (crc->api->cls,
- 1,
- &iterate_with_next,
- crc);
+ crc->api->get_zero_anonymity (crc->api->cls,
+ 0,
+ 1,
+ &iterate_one_shot,
+ crc);
break;
case RP_REPL_GET:
- crc->api->replication_get (crc->api->cls,
+ crc->api->get_replication (crc->api->cls,
&iterate_one_shot,
crc);
break;
case RP_EXPI_GET:
- crc->api->expiration_get (crc->api->cls,
+ crc->api->get_expiration (crc->api->cls,
&iterate_one_shot,
crc);
break;
char *pos;
char dir_name[128];
+ sleep (1);
/* determine name of plugin to use */
plugin_name = argv[0];
while (NULL != (pos = strstr(plugin_name, "_")))
GNUNET_snprintf (dir_name,
sizeof (dir_name),
- "/tmp/test-gnunet-datastore-%s",
+ "/tmp/test-gnunet-datastore-plugin-%s",
plugin_name);
GNUNET_DISK_directory_remove (dir_name);
GNUNET_log_setup ("test-plugin-datastore",