[libgda] postgres: added test for partial meta data update



commit fbe718ba7bf1ac547a73f133635d74765c351b71
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date:   Wed Jan 9 12:22:21 2019 -0600

    postgres: added test for partial meta data update
    
    Partial updates takes longer than expected. This
    step shows it is working for _tables

 tests/providers/check_postgres_meta_partial-1.c |  58 +++++++++++++
 tests/providers/meson.build                     |  26 ++++++
 tests/providers/prov-test-common.c              | 103 +++++++++++++++++++++++-
 tests/providers/prov-test-common.h              |   1 +
 4 files changed, 187 insertions(+), 1 deletion(-)
---
diff --git a/tests/providers/check_postgres_meta_partial-1.c b/tests/providers/check_postgres_meta_partial-1.c
new file mode 100644
index 000000000..745638181
--- /dev/null
+++ b/tests/providers/check_postgres_meta_partial-1.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
+ *
+ * This program 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 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#define PROVIDER "PostgreSQL"
+#include "prov-test-common.h"
+#include <sql-parser/gda-sql-parser.h>
+#include "../test-errors.h"
+
+#define CHECK_EXTRA_INFO 1
+
+extern GdaProviderInfo *pinfo;
+extern GdaConnection   *cnc;
+extern gboolean         params_provided;
+extern gboolean         fork_tests;
+
+int
+main (int argc, char **argv)
+{
+       int number_failed = 0;
+       fork_tests = FALSE;
+
+       gda_init ();
+
+       pinfo = gda_config_get_provider_info (PROVIDER);
+       if (!pinfo) {
+               g_warning ("Could not find provider information for %s", PROVIDER);
+               return EXIT_SUCCESS;
+       }
+       g_print ("============= Provider Meta Partial Update now testing: %s =============\n", pinfo->id);
+
+       number_failed = prov_test_common_setup ();
+
+       if (cnc) {
+               number_failed += prov_test_common_check_meta_partial ();
+               number_failed += prov_test_common_clean ();
+       }
+
+       g_print ("Test %s\n", (number_failed == 0) ? "Ok" : "failed");
+       return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
diff --git a/tests/providers/meson.build b/tests/providers/meson.build
index deda29ac3..d11398720 100644
--- a/tests/providers/meson.build
+++ b/tests/providers/meson.build
@@ -74,7 +74,33 @@ tchkpg = executable('check_postgres',
        install: false
        )
 test('ProviderPostgreSQL', tchkpg,
+       timeout: 300,
+       is_parallel: false,
+       env: [
+               'GDA_TOP_SRC_DIR='+meson.source_root(),
+               'GDA_TOP_BUILD_DIR='+meson.build_root()
+               ]
+       )
+
+tchkpg_mu1 = executable('check_postgres_meta_partial_1',
+       ['check_postgres_meta_partial-1.c']+providers_common_sources+common_sources+tests_sources,
+       c_args: [
+               '-include',
+               meson.build_root() + '/config.h',
+               '-DCHECK_SQL_FILES="'+meson.source_root()+'"',
+               ],
+       link_with: libgda,
+       dependencies: [
+               libgda_dep,
+               inc_rooth_dep,
+               inc_sqliteh_dep,
+               inc_testsh_dep
+               ],
+       install: false
+       )
+test('ProviderMetaPartialUpdate1PostgreSQL', tchkpg_mu1,
        timeout: 2000,
+       is_parallel: false,
        env: [
                'GDA_TOP_SRC_DIR='+meson.source_root(),
                'GDA_TOP_BUILD_DIR='+meson.build_root()
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index 7888b62f1..34bf6ebc2 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -228,7 +228,108 @@ prov_test_common_check_meta_partial (void)
        /* Update meta store by context */
        GdaMetaContext *ctx;
        ctx = gda_meta_context_new ();
-       gchar *meta_tables[] = {"_tables", "_attributes", "_information_schema_catalog_name",
+       gchar *meta_tables[] = {"_tables",
+                                               NULL};
+       for (i = 0; meta_tables[i]; i++) {
+               gda_meta_context_set_table (ctx, meta_tables[i]);
+#ifdef CHECK_EXTRA_INFO
+               g_print ("Updating the meta store for table '%s'\n", meta_tables[i]);
+#endif
+               if (! gda_connection_update_meta_store (cnc, ctx, &gerror)) {
+#ifdef CHECK_EXTRA_INFO
+                       g_warning ("Can't update meta store (on table %s): %s\n",
+                                  meta_tables[i], gerror && gerror->message ? gerror->message : "???");
+#endif
+                       g_error_free (gerror);
+                       number_failed++;
+                       goto theend;
+               }
+       }
+       gda_meta_context_free (ctx);
+
+       for (i = 0, list = tables; list; i++, list = list->next) {
+               GdaDataModel *model;
+               gchar *tmp;
+               GError *gerror = NULL;
+
+               tmp = g_strdup_printf ("SELECT * FROM %s", (gchar*) list->data);
+               model = gda_meta_store_extract (store, tmp, &gerror, NULL);
+               g_free (tmp);
+               if (!model) {
+#ifdef CHECK_EXTRA_INFO
+                       g_warning ("Can't execute SELECT statement: %s\n",
+                                  gerror && gerror->message ? gerror->message : "???");
+#endif
+                       g_error_free (gerror);
+                       number_failed++;
+                       continue;
+               }
+
+               tmp = gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_DATA_ARRAY_XML,
+                                                      NULL, 0, NULL, 0, NULL);
+               g_object_unref (model);
+               if (!tmp) {
+#ifdef CHECK_EXTRA_INFO
+                       g_warning ("Can't export data model\n");
+#endif
+                       number_failed++;
+                       continue;
+               }
+               if (strcmp (tmp, dump1[i])) {
+#ifdef CHECK_EXTRA_INFO
+                       g_warning ("Meta data has changed after update for table %s\n", (gchar*) list->data);
+                       g_print ("===\n%s\n===\n%s\n===\n", tmp, dump1[i]);
+#endif
+                       number_failed++;
+                       g_free (tmp);
+                       continue;
+               }
+#ifdef CHECK_EXTRA_INFO
+               else
+                       g_print ("Meta for table '%s' Ok\n", (gchar*) list->data);
+#endif
+               g_free (tmp);
+       }
+
+ theend:
+       /* remove tmp files */
+       if (dump1)
+               g_strfreev (dump1);
+       g_slist_free (tables);
+
+       return number_failed;
+}
+
+int
+prov_test_common_check_meta_partial2 (void)
+{
+       int number_failed = 0;
+       GSList *tables = NULL, *list;
+       gboolean dump_ok = TRUE;
+       GdaMetaStore *store;
+       gchar **dump1 = NULL;
+       GError *gerror = NULL;
+       gint ntables, i;
+
+       store = gda_connection_get_meta_store (cnc);
+
+       /* update meta store */
+#ifdef CHECK_EXTRA_INFO
+       g_print ("Updating the complete meta store...\n");
+#endif
+       if (! gda_connection_update_meta_store (cnc, NULL, &gerror)) {
+#ifdef CHECK_EXTRA_INFO
+               g_warning ("Can't update meta store (2): %s\n",
+                          gerror && gerror->message ? gerror->message : "???");
+#endif
+               g_error_free (gerror);
+               number_failed++;
+               goto theend;
+       }
+       /* Update meta store by context */
+       GdaMetaContext *ctx;
+       ctx = gda_meta_context_new ();
+       gchar *meta_tables[] = {"_attributes", "_information_schema_catalog_name",
                                                "_schemata", "_builtin_data_types", "_udt", "_udt_columns",
                                                "_enums", "_element_types", "_domains", "_views", 
"_collations",
                                                "_character_sets", "_routines", "_triggers", "_columns",
diff --git a/tests/providers/prov-test-common.h b/tests/providers/prov-test-common.h
index 15b38ac4c..9fb79fdc2 100644
--- a/tests/providers/prov-test-common.h
+++ b/tests/providers/prov-test-common.h
@@ -29,6 +29,7 @@ GdaConnection *prov_test_common_create_extra_connection (void);
 int prov_test_common_load_data (void);
 int prov_test_common_check_meta_full (void);
 int prov_test_common_check_meta_partial (void);
+int prov_test_common_check_meta_partial2 (void);
 int prov_test_common_check_meta_identifiers (gboolean case_sensitive, gboolean update_all);
 int prov_test_common_check_cursor_models (void);
 int prov_test_common_check_data_select (void);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]