[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r33530 - gnunet/src/peerstore
From: |
gnunet |
Subject: |
[GNUnet-SVN] r33530 - gnunet/src/peerstore |
Date: |
Wed, 4 Jun 2014 21:03:43 +0200 |
Author: otarabai
Date: 2014-06-04 21:03:43 +0200 (Wed, 04 Jun 2014)
New Revision: 33530
Added:
gnunet/src/peerstore/test_peerstore_api_store.c
Removed:
gnunet/src/peerstore/test_peerstore_api.c
Modified:
gnunet/src/peerstore/Makefile.am
gnunet/src/peerstore/peerstore_api.c
gnunet/src/peerstore/plugin_peerstore_sqlite.c
Log:
peerstore: db index + store test
Modified: gnunet/src/peerstore/Makefile.am
===================================================================
--- gnunet/src/peerstore/Makefile.am 2014-06-04 18:07:22 UTC (rev 33529)
+++ gnunet/src/peerstore/Makefile.am 2014-06-04 19:03:43 UTC (rev 33530)
@@ -65,16 +65,16 @@
libgnunetpeerstore.la
check_PROGRAMS = \
- test_peerstore_api
+ test_peerstore_api_store
if ENABLE_TEST_RUN
AM_TESTS_ENVIRONMENT=export
GNUNET_PREFIX=$${GNUNET_PREFIX:address@hidden@};export
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;
TESTS = $(check_PROGRAMS)
endif
-test_peerstore_api_SOURCES = \
- test_peerstore_api.c
-test_peerstore_api_LDADD = \
+test_peerstore_api_store_SOURCES = \
+ test_peerstore_api_store.c
+test_peerstore_api_store_LDADD = \
$(top_builddir)/src/peerstore/libgnunetpeerstore.la \
$(top_builddir)/src/testing/libgnunettesting.la \
$(top_builddir)/src/util/libgnunetutil.la
Modified: gnunet/src/peerstore/peerstore_api.c
===================================================================
--- gnunet/src/peerstore/peerstore_api.c 2014-06-04 18:07:22 UTC (rev
33529)
+++ gnunet/src/peerstore/peerstore_api.c 2014-06-04 19:03:43 UTC (rev
33530)
@@ -423,7 +423,7 @@
GNUNET_PEERSTORE_Continuation cont,
void *cont_cls)
{
- struct GNUNET_MQ_Envelope *ev; //FIXME: add 'replace' flag in store function
(similar to multihashmap)
+ struct GNUNET_MQ_Envelope *ev;
struct GNUNET_PEERSTORE_StoreContext *sc;
LOG (GNUNET_ERROR_TYPE_DEBUG,
Modified: gnunet/src/peerstore/plugin_peerstore_sqlite.c
===================================================================
--- gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-06-04 18:07:22 UTC
(rev 33529)
+++ gnunet/src/peerstore/plugin_peerstore_sqlite.c 2014-06-04 19:03:43 UTC
(rev 33530)
@@ -51,8 +51,6 @@
#define LOG(kind,...) GNUNET_log_from (kind, "peerstore-sqlite", __VA_ARGS__)
-//FIXME: Indexes
-
/**
* Context for all functions in this plugin.
*/
@@ -459,6 +457,18 @@
sqlite3_create_function(plugin->dbh, "UINT64_LT", 2, SQLITE_UTF8, NULL,
&sqlite3_lessthan, NULL, NULL);
+ /* Create Indices */
+ if (SQLITE_OK !=
+ sqlite3_exec(plugin->dbh,
+ "CREATE INDEX IF NOT EXISTS peerstoredata_key_index ON peerstoredata
(sub_system, peer_id, key)",
+ NULL, NULL, NULL))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to create indices: %s.\n"),
+ sqlite3_errmsg (plugin->dbh));
+ return GNUNET_SYSERR;
+ }
+
/* Prepare statements */
sql_prepare (plugin->dbh,
Deleted: gnunet/src/peerstore/test_peerstore_api.c
===================================================================
--- gnunet/src/peerstore/test_peerstore_api.c 2014-06-04 18:07:22 UTC (rev
33529)
+++ gnunet/src/peerstore/test_peerstore_api.c 2014-06-04 19:03:43 UTC (rev
33530)
@@ -1,144 +0,0 @@
-/*
- This file is part of GNUnet.
- (C)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/**
- * @file peerstore/test_peerstore_api.c
- * @brief testcase for peerstore_api.c
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_lib.h"
-#include "gnunet_peerstore_service.h"
-#include <inttypes.h>
-
-//TODO: test single cycle of watch, store, iterate
-
-static int ok = 1;
-
-static int counter = 0;
-
-struct GNUNET_PEERSTORE_Handle *h;
-
-int iterate_cb (void *cls,
- struct GNUNET_PEERSTORE_Record *record,
- char *emsg)
-{
- if(NULL != emsg)
- {
- printf("Error received: %s.\n", emsg);
- return GNUNET_YES;
- }
- printf("Record:\n");
- if(NULL == record)
- {
- GNUNET_assert(counter > 0);
- counter = 0;
- printf("END\n");
- GNUNET_PEERSTORE_disconnect(h);
- return GNUNET_YES;
- }
- printf("Sub system: %s\n", record->sub_system);
- printf("Peer: %s\n", GNUNET_i2s (record->peer));
- printf("Key: %s\n", record->key);
- printf("Value: %.*s\n", (int)record->value_size, (char *)record->value);
- printf("Expiry: %" PRIu64 "\n", record->expiry->abs_value_us);
- counter ++;
-
- return GNUNET_YES;
-}
-
-void store_cont(void *cls, int success)
-{
- if(GNUNET_OK == success)
- ok = 0;
- else
- ok = 1;
- printf("Store success: %d\n", success);
- GNUNET_PEERSTORE_iterate(h, "peerstore-test",
- NULL,
- NULL,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &iterate_cb,
- NULL);
-}
-
-int watch_cb (void *cls,
- struct GNUNET_PEERSTORE_Record *record,
- char *emsg)
-{
- if(NULL != emsg)
- {
- printf("Error received: %s.\n", emsg);
- return GNUNET_YES;
- }
-
- printf("Watch Record:\n");
- printf("Sub system: %s\n", record->sub_system);
- printf("Peer: %s\n", GNUNET_i2s (record->peer));
- printf("Key: %s\n", record->key);
- printf("Value: %.*s\n", (int)record->value_size, (char *)record->value);
- printf("Expiry: %" PRIu64 "\n", record->expiry->abs_value_us);
- return GNUNET_YES;
-}
-
-static void
-run (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Peer *peer)
-{
- struct GNUNET_PeerIdentity pid;
- char *val = "peerstore-test-value";
- size_t val_size = strlen(val);
- struct GNUNET_TIME_Absolute expiry;
-
- ok = 1;
- memset (&pid, 32, sizeof (pid));
- expiry = GNUNET_TIME_absolute_get();
- h = GNUNET_PEERSTORE_connect(cfg);
- GNUNET_assert(NULL != h);
- GNUNET_PEERSTORE_watch(h,
- "peerstore-test",
- &pid,
- "peerstore-test-key",
- &watch_cb,
- NULL);
- GNUNET_PEERSTORE_store(h,
- "peerstore-test",
- &pid,
- "peerstore-test-key",
- val,
- val_size,
- expiry,
- GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
- &store_cont,
- NULL);
-}
-
-int
-main (int argc, char *argv[])
-{
- if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore",
- "peerstore",
- "test_peerstore_api_data.conf",
- &run, NULL))
- return 1;
- return ok;
-}
-
-/* end of test_peerstore_api.c */
Added: gnunet/src/peerstore/test_peerstore_api_store.c
===================================================================
--- gnunet/src/peerstore/test_peerstore_api_store.c
(rev 0)
+++ gnunet/src/peerstore/test_peerstore_api_store.c 2014-06-04 19:03:43 UTC
(rev 33530)
@@ -0,0 +1,222 @@
+/*
+ This file is part of GNUnet.
+ (C)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file peerstore/test_peerstore_api.c
+ * @brief testcase for peerstore_api.c
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_peerstore_service.h"
+
+static int ok = 1;
+
+struct GNUNET_PEERSTORE_Handle *h;
+
+char *subsystem = "test_peerstore_api_store";
+struct GNUNET_PeerIdentity pid;
+char *key = "test_peerstore_api_store_key";
+char *val1 = "test_peerstore_api_store_val1";
+char *val2 = "test_peerstore_api_store_val2-";
+char *val3 = "test_peerstore_api_store_val3--";
+
+int count = 0;
+
+int test3_cont2(void *cls,
+ struct GNUNET_PEERSTORE_Record *record,
+ char *emsg)
+{
+ if(NULL != emsg)
+ return GNUNET_NO;
+ if(NULL != record)
+ {
+ GNUNET_assert((strlen(val3) + 1) == record->value_size);
+ GNUNET_assert(0 == strcmp((char *)val3, (char *)record->value));
+ count++;
+ return GNUNET_YES;
+ }
+ GNUNET_assert(count == 1);
+ ok = 0;
+ GNUNET_PEERSTORE_disconnect(h);
+ GNUNET_SCHEDULER_shutdown();
+ return GNUNET_YES;
+}
+
+static void
+test3_cont(void *cls, int success)
+{
+ if(GNUNET_YES != success)
+ return;
+ count = 0;
+ GNUNET_PEERSTORE_iterate(h,
+ subsystem,
+ &pid,
+ key,
+ GNUNET_TIME_UNIT_SECONDS,
+ &test3_cont2,
+ NULL);
+}
+
+/**
+ * Replace the previous 2 records
+ */
+static void
+test3()
+{
+ GNUNET_PEERSTORE_store(h,
+ subsystem,
+ &pid,
+ key,
+ val3,
+ strlen(val3) + 1,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_PEERSTORE_STOREOPTION_REPLACE,
+ &test3_cont,
+ NULL);
+}
+
+int test2_cont2(void *cls,
+ struct GNUNET_PEERSTORE_Record *record,
+ char *emsg)
+{
+ if(NULL != emsg)
+ return GNUNET_NO;
+ if(NULL != record)
+ {
+ GNUNET_assert(((strlen(val1) + 1) == record->value_size)
+ || ((strlen(val2) + 1) == record->value_size));
+ GNUNET_assert((0 == strcmp((char *)val1, (char *)record->value))
+ || (0 == strcmp((char *)val2, (char *)record->value)));
+ count++;
+ return GNUNET_YES;
+ }
+ GNUNET_assert(count == 2);
+ count = 0;
+ test3();
+ return GNUNET_YES;
+}
+
+static void
+test2_cont(void *cls, int success)
+{
+ if(GNUNET_YES != success)
+ return;
+ count = 0;
+ GNUNET_PEERSTORE_iterate(h,
+ subsystem,
+ &pid,
+ key,
+ GNUNET_TIME_UNIT_SECONDS,
+ &test2_cont2,
+ NULL);
+}
+
+/**
+ * Test storing a second value with the same key
+ */
+void test2()
+{
+ GNUNET_PEERSTORE_store(h,
+ subsystem,
+ &pid,
+ key,
+ val2,
+ strlen(val2) + 1,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
+ &test2_cont,
+ NULL);
+}
+
+int test1_cont2(void *cls,
+ struct GNUNET_PEERSTORE_Record *record,
+ char *emsg)
+{
+ if(NULL != emsg)
+ return GNUNET_NO;
+ if(NULL != record)
+ {
+ GNUNET_assert((strlen(val1) + 1) == record->value_size);
+ GNUNET_assert(0 == strcmp((char *)val1, (char *)record->value));
+ count++;
+ return GNUNET_YES;
+ }
+ GNUNET_assert(count == 1);
+ count = 0;
+ test2();
+ return GNUNET_YES;
+}
+
+static void
+test1_cont(void *cls, int success)
+{
+ if(GNUNET_YES != success)
+ return;
+ count = 0;
+ GNUNET_PEERSTORE_iterate(h,
+ subsystem,
+ &pid,
+ key,
+ GNUNET_TIME_UNIT_SECONDS,
+ &test1_cont2,
+ NULL);
+}
+
+/**
+ * Store a single record
+ */
+static void
+test1()
+{
+ GNUNET_PEERSTORE_store(h,
+ subsystem,
+ &pid,
+ key,
+ val1,
+ strlen(val1) + 1,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ GNUNET_PEERSTORE_STOREOPTION_REPLACE,
+ &test1_cont,
+ NULL);
+}
+
+static void
+run (void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ struct GNUNET_TESTING_Peer *peer)
+{
+ h = GNUNET_PEERSTORE_connect(cfg);
+ GNUNET_assert(NULL != h);
+ memset (&pid, 1, sizeof (pid));
+ test1();
+}
+
+int
+main (int argc, char *argv[])
+{
+ if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore",
+ "peerstore",
+ "test_peerstore_api_data.conf",
+ &run, NULL))
+ return 1;
+ return ok;
+}
+
+/* end of test_peerstore_api.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r33530 - gnunet/src/peerstore,
gnunet <=