aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/test_datastore_api.c
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2009-07-25 14:30:10 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2009-07-25 14:30:10 +0000
commitbc44fe1533ea7e9499531b1d537ee0fb5f5834b0 (patch)
treed46c3294cb791d674ab63829d3559c9a162404f1 /src/datastore/test_datastore_api.c
parent2ec4721bac23839cc55fd58dbd415916a1ffba61 (diff)
more tests
git-svn-id: https://gnunet.org/svn/gnunet@8776 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/datastore/test_datastore_api.c')
-rw-r--r--src/datastore/test_datastore_api.c189
1 files changed, 178 insertions, 11 deletions
diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c
index 3d65bf813e..005c11a586 100644
--- a/src/datastore/test_datastore_api.c
+++ b/src/datastore/test_datastore_api.c
@@ -19,13 +19,11 @@
*/
/*
* @file datastore/test_datastore_api.c
- * @brief Test for the datastore implementation.
+ * @brief Test for the basic datastore API.
* @author Christian Grothoff
*
* TODO:
- * - test multiple values under same key
- * - test "update"
- * - test storage reservations
+ * - test reservation failure
*/
#include "platform.h"
@@ -91,7 +89,7 @@ get_expiration (int i)
{
struct GNUNET_TIME_Absolute av;
- av.value = now.value - i * 1000;
+ av.value = now.value + 200000 - i * 1000;
return av;
}
@@ -102,7 +100,16 @@ enum RunPhase
RP_GET,
RP_DEL,
RP_DO_DEL,
- RP_DELVALIDATE
+ RP_DELVALIDATE,
+ RP_RESERVE,
+ RP_PUT_MULTIPLE,
+ RP_PUT_MULTIPLE_NEXT,
+ RP_GET_MULTIPLE,
+ RP_GET_MULTIPLE_NEXT,
+ RP_GET_MULTIPLE_DONE,
+ RP_UPDATE,
+ RP_UPDATE_VALIDATE,
+ RP_UPDATE_DONE
};
@@ -110,12 +117,14 @@ struct CpsRunContext
{
GNUNET_HashCode key;
int i;
+ int rid;
int *iptr;
struct GNUNET_SCHEDULER_Handle *sched;
struct GNUNET_CONFIGURATION_Handle *cfg;
void *data;
size_t size;
enum RunPhase phase;
+ unsigned long long uid;
};
@@ -144,6 +153,25 @@ check_success (void *cls,
}
+static void
+get_reserved (void *cls,
+ int success,
+ const char *msg)
+{
+ struct CpsRunContext *crc = cls;
+ if (0 >= success)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s\n", msg);
+ GNUNET_assert (0 < success);
+ crc->rid = success;
+ GNUNET_SCHEDULER_add_continuation (crc->sched,
+ GNUNET_NO,
+ &run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
static void
check_value (void *cls,
const GNUNET_HashCode * key,
@@ -227,7 +255,7 @@ check_nothing (void *cls,
GNUNET_assert (key == NULL);
if (crc->i == 0)
{
- crc->phase = RP_DONE;
+ crc->phase = RP_RESERVE;
}
GNUNET_SCHEDULER_add_continuation (crc->sched,
GNUNET_NO,
@@ -237,12 +265,81 @@ check_nothing (void *cls,
}
+static void
+check_multiple (void *cls,
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ uint32_t type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute
+ expiration, uint64_t uid)
+{
+ struct CpsRunContext *crc = cls;
+
+ if (key == NULL)
+ {
+ GNUNET_assert (crc->phase == RP_GET_MULTIPLE_DONE);
+ crc->phase = RP_UPDATE;
+ GNUNET_SCHEDULER_add_continuation (crc->sched,
+ GNUNET_NO,
+ &run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
+ crc->phase++;
+ if (priority == get_priority (42))
+ crc->uid = uid;
+}
+
+
+static void
+check_update (void *cls,
+ const GNUNET_HashCode * key,
+ uint32_t size,
+ const void *data,
+ uint32_t type,
+ uint32_t priority,
+ uint32_t anonymity,
+ struct GNUNET_TIME_Absolute
+ expiration, uint64_t uid)
+{
+ struct CpsRunContext *crc = cls;
+
+ if (key == NULL)
+ {
+ GNUNET_assert (crc->phase == RP_UPDATE_DONE);
+ crc->phase = RP_DONE;
+ GNUNET_SCHEDULER_add_continuation (crc->sched,
+ GNUNET_NO,
+ &run_continuation,
+ crc,
+ GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ return;
+ }
+ if ( (anonymity == get_anonymity (42)) &&
+ (size == get_size (42)) &&
+ (priority == get_priority (42) + 100) )
+ {
+ crc->phase = RP_UPDATE_DONE;
+ }
+ else
+ GNUNET_assert (size == get_size (43));
+}
+
+
static void
run_continuation (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct CpsRunContext *crc = cls;
ok = (int) crc->phase;
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test in phase %u\n", crc->phase);
+#endif
switch (crc->phase)
{
case RP_PUT:
@@ -341,9 +438,79 @@ run_continuation (void *cls,
crc,
TIMEOUT);
break;
- /* check reservations */
- /* check update */
- /* test multiple results */
+ case RP_RESERVE:
+ crc->phase = RP_PUT_MULTIPLE;
+ GNUNET_DATASTORE_reserve (datastore,
+ 128*1024,
+ 2,
+ &get_reserved,
+ crc,
+ TIMEOUT);
+ break;
+ case RP_PUT_MULTIPLE:
+ crc->phase = RP_PUT_MULTIPLE_NEXT;
+ GNUNET_DATASTORE_put (datastore,
+ crc->rid,
+ &crc->key,
+ get_size (42),
+ get_data (42),
+ get_type (42),
+ get_priority (42),
+ get_anonymity (42),
+ get_expiration (42),
+ TIMEOUT,
+ &check_success,
+ crc);
+ break;
+ case RP_PUT_MULTIPLE_NEXT:
+ crc->phase = RP_GET_MULTIPLE;
+ GNUNET_DATASTORE_put (datastore,
+ crc->rid,
+ &crc->key,
+ get_size (43),
+ get_data (43),
+ get_type (42),
+ get_priority (43),
+ get_anonymity (43),
+ get_expiration (43),
+ TIMEOUT,
+ &check_success,
+ crc);
+ break;
+ case RP_GET_MULTIPLE:
+ GNUNET_DATASTORE_get (datastore,
+ &crc->key,
+ get_type (42),
+ &check_multiple,
+ crc,
+ TIMEOUT);
+ break;
+ case RP_GET_MULTIPLE_NEXT:
+ case RP_GET_MULTIPLE_DONE:
+ GNUNET_assert (0);
+ break;
+ case RP_UPDATE:
+ GNUNET_assert (crc->uid > 0);
+ crc->phase = RP_UPDATE_VALIDATE;
+ GNUNET_DATASTORE_update (datastore,
+ crc->uid,
+ 100,
+ get_expiration (42),
+ &check_success,
+ crc,
+ TIMEOUT);
+ break;
+ case RP_UPDATE_VALIDATE:
+ GNUNET_DATASTORE_get (datastore,
+ &crc->key,
+ get_type (42),
+ &check_update,
+ crc,
+ TIMEOUT);
+ break;
+ case RP_UPDATE_DONE:
+ GNUNET_assert (0);
+ break;
case RP_DONE:
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -368,7 +535,7 @@ run (void *cls,
crc->sched = sched;
crc->cfg = cfg;
crc->phase = RP_PUT;
- now.value = 1000000;
+ now = GNUNET_TIME_absolute_get ();
datastore = GNUNET_DATASTORE_connect (cfg, sched);
GNUNET_SCHEDULER_add_continuation (crc->sched,
GNUNET_NO,