[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: plugin wrapper tests
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: plugin wrapper tests |
Date: |
Thu, 31 Oct 2019 18:11:19 +0100 |
This is an automated email from the git hooks/post-receive script.
ds-meister pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new b95a5de plugin wrapper tests
b95a5de is described below
commit b95a5deaf689324b6ebe64ff38eb4f92772d269d
Author: Dominik Meister <address@hidden>
AuthorDate: Thu Oct 31 18:11:00 2019 +0100
plugin wrapper tests
---
src/backup-db/Makefile.am | 33 ++++--
src/backup-db/anastasis_db_plugin.c | 150 ++++++++++++++++++++++++++
src/backup-db/anastasis_db_postgres.conf | 2 +
src/backup-db/plugin_anastasis_postgres.c | 6 +-
src/backup-db/test_anastasis_db.c | 15 +--
src/backup-db/test_anastasis_db_postgres.conf | 2 +
src/include/Makefile.am | 4 +-
src/include/anastasis_db_lib.h | 77 -------------
8 files changed, 191 insertions(+), 98 deletions(-)
diff --git a/src/backup-db/Makefile.am b/src/backup-db/Makefile.am
index d7f6db5..7cf65c3 100644
--- a/src/backup-db/Makefile.am
+++ b/src/backup-db/Makefile.am
@@ -1,7 +1,7 @@
# This Makefile.am is in the public domain
AM_CPPFLAGS = -I$(top_srcdir)/src/include
-plugindir = $(libdir)/taler
+plugindir = $(libdir)/anastasis
if HAVE_POSTGRESQL
if HAVE_GNUNETPQ
@@ -15,6 +15,21 @@ if USE_COVERAGE
XLIB = -lgcov
endif
+lib_LTLIBRARIES = \
+ libanastasisdb.la
+
+libanastasisdb_la_SOURCES = \
+ anastasis_db_plugin.c
+
+libanastasisdb_la_LIBADD = \
+ -lgnunetpq \
+ -lpq \
+ -lgnunetutil
+libanastasisdb_la_LDFLAGS = \
+ $(POSTGRESQL_LDFLAGS) \
+ -version-info 2:0:0 \
+ -no-undefined
+
libanastasis_plugin_db_postgres_la_SOURCES = \
plugin_anastasis_postgres.c
libanastasis_plugin_db_postgres_la_LIBADD = \
@@ -25,16 +40,20 @@ libanastasis_plugin_db_postgres_la_LDFLAGS = \
-lpq \
-lgnunetutil $(XLIB)
-
-TESTS = \
- test_anastasis_db
-
check_PROGRAMS = \
$(TESTS)
-test_anastasis_db_SOURCES = \
+test_anastasis_db_postgres_SOURCES = \
test_anastasis_db.c
-test_anastasis_db_LDADD = \
+test_anastasis_db_postgres_LDFLAGS = \
-lgnunetutil \
-lgnunetdb \
-ltalerutil
+test_anastasis_db_postgres_LDADD = \
+ $(top_srcdir)/backup-db/libanastasis_db.la
+
+TESTS = \
+ test_anastasis_db_postgres
+
+EXTRA_DIST = \
+ test_anastasis_db_postgres.conf
diff --git a/src/backup-db/anastasis_db_plugin.c
b/src/backup-db/anastasis_db_plugin.c
new file mode 100644
index 0000000..112526d
--- /dev/null
+++ b/src/backup-db/anastasis_db_plugin.c
@@ -0,0 +1,150 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2015, 2016 GNUnet e.V. and INRIA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Lesser General Public License as published by the Free
Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER 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
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file merchantdb/merchantdb_plugin.c
+ * @brief Logic to load database plugin
+ * @author Christian Grothoff
+ * @author Sree Harsha Totakura <address@hidden>
+ */
+#include "platform.h"
+#include "anastasis_database_plugin.h"
+#include <ltdl.h>
+
+
+/**
+ * Initialize the plugin.
+ *
+ * @param cfg configuration to use
+ * @return #GNUNET_OK on success
+ */
+struct ANASTASIS_DatabasePlugin *
+ANASTASIS_DB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *plugin_name;
+ char *lib_name;
+ struct GNUNET_CONFIGURATION_Handle *cfg_dup;
+ struct ANASTASIS_DatabasePlugin *plugin;
+
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "anastasis",
+ "db",
+ &plugin_name))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "anastasis",
+ "db");
+ return NULL;
+ }
+ (void) GNUNET_asprintf (&lib_name,
+ "libanastasis_plugin_db_%s",
+ plugin_name);
+ GNUNET_free (plugin_name);
+ cfg_dup = GNUNET_CONFIGURATION_dup (cfg);
+ plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup);
+ if (NULL != plugin)
+ plugin->library_name = lib_name;
+ else
+ GNUNET_free (lib_name);
+ GNUNET_CONFIGURATION_destroy (cfg_dup);
+ return plugin;
+}
+
+
+/**
+ * Shutdown the plugin.
+ *
+ * @param plugin the plugin to unload
+ */
+void
+ANASTASIS_DB_plugin_unload (struct ANASTASIS_DatabasePlugin *plugin)
+{
+ char *lib_name;
+
+ if (NULL == plugin)
+ return;
+ lib_name = plugin->library_name;
+ GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
+ plugin));
+ GNUNET_free (lib_name);
+}
+
+
+/**
+ * Libtool search path before we started.
+ */
+static char *old_dlsearchpath;
+
+
+/**
+ * Setup libtool paths.
+ */
+void __attribute__ ((constructor))
+plugin_init ()
+{
+ int err;
+ const char *opath;
+ char *path;
+ char *cpath;
+
+ err = lt_dlinit ();
+ if (err > 0)
+ {
+ fprintf (stderr,
+ _ ("Initialization of plugin mechanism failed: %s!\n"),
+ lt_dlerror ());
+ return;
+ }
+ opath = lt_dlgetsearchpath ();
+ if (NULL != opath)
+ old_dlsearchpath = GNUNET_strdup (opath);
+ path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
+ if (NULL != path)
+ {
+ if (NULL != opath)
+ {
+ GNUNET_asprintf (&cpath, "%s:%s", opath, path);
+ lt_dlsetsearchpath (cpath);
+ GNUNET_free (path);
+ GNUNET_free (cpath);
+ }
+ else
+ {
+ lt_dlsetsearchpath (path);
+ GNUNET_free (path);
+ }
+ }
+}
+
+
+/**
+ * Shutdown libtool.
+ */
+void __attribute__ ((destructor))
+plugin_fini ()
+{
+ lt_dlsetsearchpath (old_dlsearchpath);
+ if (NULL != old_dlsearchpath)
+ {
+ GNUNET_free (old_dlsearchpath);
+ old_dlsearchpath = NULL;
+ }
+ lt_dlexit ();
+}
+
+
+/* end of anastasis_db_plugin.c */
+
diff --git a/src/backup-db/anastasis_db_postgres.conf
b/src/backup-db/anastasis_db_postgres.conf
new file mode 100644
index 0000000..504dfdc
--- /dev/null
+++ b/src/backup-db/anastasis_db_postgres.conf
@@ -0,0 +1,2 @@
+[anastasisdb-postgres]
+CONFIG = "postgres:///anastasis"
diff --git a/src/backup-db/plugin_anastasis_postgres.c
b/src/backup-db/plugin_anastasis_postgres.c
index f02d721..affa2ce 100644
--- a/src/backup-db/plugin_anastasis_postgres.c
+++ b/src/backup-db/plugin_anastasis_postgres.c
@@ -824,8 +824,8 @@ postgres_get_recovery_document (void *cls,
* @param cls a configuration instance
* @return NULL on error, otherwise a `struct TALER_ANASTASISDB_Plugin`
*/
-struct ANASTASIS_DatabasePlugin *
-ANASTASIS_DB_plugin_load (void *cls)
+void *
+libanastasis_plugin_db_postgres_init (void *cls)
{
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct PostgresClosure *pg;
@@ -1003,7 +1003,7 @@ ANASTASIS_DB_plugin_load (void *cls)
* @return NULL (always)
*/
void *
-ANASTASIS_DB_plugin_unload (void *cls)
+plugin_anastasis_db_postgres_done (void *cls)
{
struct ANASTASIS_DatabasePlugin *plugin = cls;
struct PostgresClosure *pg = plugin->cls;
diff --git a/src/backup-db/test_anastasis_db.c
b/src/backup-db/test_anastasis_db.c
index 20ec24f..ca81b19 100644
--- a/src/backup-db/test_anastasis_db.c
+++ b/src/backup-db/test_anastasis_db.c
@@ -24,7 +24,6 @@
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_db_lib.h>
#include <taler/taler_util.h>
-#include "anastasis_database_plugin.h"
#include "anastasis_database_lib.h"
#define FAILIF(cond) \
@@ -39,7 +38,7 @@
/**
* Global return value for the test. Initially -1, set to 0 upon
- * completion. Other values indicate some kind of error.
+ * completion. Other values indicate some kind of error.
*/
static int result;
@@ -102,6 +101,7 @@ const unsigned int *version;
static void
run (void *cls)
{
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct GNUNET_TIME_Absolute fake_now;
if (NULL == (plugin = ANASTASIS_DB_plugin_load (cls)))
@@ -142,7 +142,7 @@ run (void *cls)
uuid,
truth_data,
truth_data_size,
- expiration,
+ fake_now,
version));
if (-1 == result)
@@ -153,13 +153,8 @@ drop:
plugin->drop_tables (plugin->cls));
ANASTASIS_DB_plugin_unload (plugin);
plugin = NULL;
- if (NULL != deposit_proof)
- json_decref (deposit_proof);
- if (NULL != transfer_proof)
- json_decref (transfer_proof);
}
-
int
main (int argc,
char *const argv[])
@@ -178,7 +173,7 @@ main (int argc,
GNUNET_log_setup (argv[0], "DEBUG", NULL);
plugin_name++;
(void) GNUNET_asprintf (&testname,
- "test-anastasis-db-%s",
+ "test_anastasis_db_%s",
plugin_name);
(void) GNUNET_asprintf (&config_filename,
"%s.conf",
@@ -200,4 +195,4 @@ main (int argc,
return result;
}
-/* end of test_anastasis_db.c */
\ No newline at end of file
+/* end of test_anastasis_db.c */
diff --git a/src/backup-db/test_anastasis_db_postgres.conf
b/src/backup-db/test_anastasis_db_postgres.conf
new file mode 100644
index 0000000..504dfdc
--- /dev/null
+++ b/src/backup-db/test_anastasis_db_postgres.conf
@@ -0,0 +1,2 @@
+[anastasisdb-postgres]
+CONFIG = "postgres:///anastasis"
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index b2e3f07..4be342e 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -6,4 +6,6 @@ anastasisincludedir = $(includedir)/anastasis
anastasisinclude_HEADERS = \
anastasis_database_plugin.h \
- anastasis_service.h
+ anastasis_service.h \
+ anastasis_error_codes.h \
+ anastasis_database_lib.h
diff --git a/src/include/anastasis_db_lib.h b/src/include/anastasis_db_lib.h
deleted file mode 100644
index 3fa89b7..0000000
--- a/src/include/anastasis_db_lib.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2017 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- 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
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file include/ANASTASIS_DB_lib.h
- * @brief shared defintions for transactional databases
- * @author Christian Grothoff
- * @author Dominik Meister
- */
-#ifndef ANASTASIS_DB_LIB_H
-#define ANASTASIS_DB_LIB_H
-
-
-/**
- * Status code returned from functions running database commands.
- * Can be combined with a function that returns the number
- * of results, so all non-negative values indicate success.
- */
-enum ANASTASIS_DB_QueryStatus
-{
- /**
- * A hard error occurred, retrying will not help.
- */
- ANASTASIS_DB_STATUS_HARD_ERROR = -2,
-
- /**
- * A soft error occurred, retrying the transaction may succeed.
- * Includes DEADLOCKS and SERIALIZATION errors.
- */
- ANASTASIS_DB_STATUS_SOFT_ERROR = -1,
-
- /**
- * The transaction succeeded, but yielded zero results.
- * May include the case where an INSERT failed with UNIQUE
- * violation (i.e. row already exists) or where DELETE
- * failed to remove anything (i.e. nothing matched).
- */
- ANASTASIS_DB_STATUS_SUCCESS_NO_RESULTS = 0,
-
- /**
- * The transaction succeeded, and yielded one result.
- */
- ANASTASIS_DB_STATUS_SUCCESS_ONE_RESULT = 1,
-
- /**
- * The specified User was unknown
- */
- ANASTASIS_DB_STATUS_UNKNOWN_USER = 6000,
-
- /**
- * The Users Payment had not sufficient posts left
- */
- ANASTASIS_DB_STATUS_NOT_SUFFICIENT_POSTS = 6001,
-
- /**
- * The Payment from the User has expired.
- */
- ANASTASIS_DB_STATUS_PAYMENT_EXPIRED = 6002
-};
-
-#endif
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: plugin wrapper tests,
gnunet <=