(no commit message)
[oweals/gnunet.git] / src / datastore / perf_datastore_api.c
index 61724e9643d896c9c4f178f40eafe6494beda388..bb4f88cf3d3395e384ac3d300a5a979319435132 100644 (file)
@@ -101,7 +101,7 @@ struct CpsRunContext
   int i;
 
   GNUNET_HashCode key;
-  uint32_t esize;
+  size_t esize;
   char data[65536];
 };
 
@@ -197,7 +197,7 @@ do_delete (void *cls,
 static void 
 delete_value (void *cls,
              const GNUNET_HashCode * key,
-             uint32_t size,
+             size_t size,
              const void *data,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
@@ -295,7 +295,7 @@ run_continuation (void *cls,
                "Stored %llu kB / %lluk ops / %llu ops/s\n", 
               stored_bytes / 1024,     /* used size in k */
                stored_ops / 1024,        /* total operations (in k) */
-               1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration(start_time).value));
+               1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration(start_time).rel_value));
       crc->phase = RP_PUT;
       crc->j = 0;
       GNUNET_SCHEDULER_add_continuation (crc->sched,
@@ -314,6 +314,29 @@ run_continuation (void *cls,
 }
 
 
+
+static void
+run_tests (void *cls,
+          int success,
+          const char *msg)
+{
+  struct CpsRunContext *crc = cls;
+
+  if (success != GNUNET_YES)
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+              msg);
+      GNUNET_free (crc);
+      return;
+    }
+  GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                    &run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
 static void
 run (void *cls,
      struct GNUNET_SCHEDULER_Handle *sched,
@@ -322,6 +345,7 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct CpsRunContext *crc;
+  static GNUNET_HashCode zkey;
 
   datastore = GNUNET_DATASTORE_connect (cfg, sched);
   start_time = GNUNET_TIME_absolute_get ();
@@ -329,10 +353,19 @@ run (void *cls,
   crc->sched = sched;
   crc->cfg = cfg;
   crc->phase = RP_PUT;
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+  if (NULL ==
+      GNUNET_DATASTORE_put (datastore, 0,
+                           &zkey, 4, "TEST",
+                           GNUNET_BLOCK_TYPE_TEST,
+                           0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
+                           0, 1, GNUNET_TIME_UNIT_MINUTES,
+                           &run_tests, crc))
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed.\n");
+      ok = 1;
+      GNUNET_free (crc);
+    }
 }