summaryrefslogtreecommitdiff
path: root/tests/functional-tests/ipc
diff options
context:
space:
mode:
authorMartyn Russell <martyn@lanedo.com>2010-10-25 16:16:14 +0100
committerMartyn Russell <martyn@lanedo.com>2010-10-27 15:16:54 +0100
commitb9f51f4c6f09c534287deb191d36141c8b7a78c0 (patch)
tree26c6c3f53e6f3b18ea93da67b0cdbe7fb898dd14 /tests/functional-tests/ipc
parent890bc51dd839d1d5e114422e7bc809a73b5e862a (diff)
downloadtracker-b9f51f4c6f09c534287deb191d36141c8b7a78c0.tar.gz
functional-tests: Moved all IPC tests to ipc/
Also renamed to prefix with test- instead of suffix like other tests
Diffstat (limited to 'tests/functional-tests/ipc')
-rw-r--r--tests/functional-tests/ipc/Makefile.am185
-rw-r--r--tests/functional-tests/ipc/test-bus-query.vala10
-rw-r--r--tests/functional-tests/ipc/test-bus-update.vala10
-rw-r--r--tests/functional-tests/ipc/test-busy-handling.vala164
-rw-r--r--tests/functional-tests/ipc/test-class-signal-performance.vala162
-rw-r--r--tests/functional-tests/ipc/test-class-signal.vala184
-rw-r--r--tests/functional-tests/ipc/test-default-update.vala75
-rw-r--r--tests/functional-tests/ipc/test-direct-query.vala74
-rw-r--r--tests/functional-tests/ipc/test-shared-query.vala139
-rw-r--r--tests/functional-tests/ipc/test-shared-update.vala155
-rw-r--r--tests/functional-tests/ipc/test-update-array-performance.c282
11 files changed, 1440 insertions, 0 deletions
diff --git a/tests/functional-tests/ipc/Makefile.am b/tests/functional-tests/ipc/Makefile.am
new file mode 100644
index 000000000..c2fed718b
--- /dev/null
+++ b/tests/functional-tests/ipc/Makefile.am
@@ -0,0 +1,185 @@
+include $(top_srcdir)/Makefile.decl
+
+INCLUDES = \
+ $(BUILD_CFLAGS) \
+ -I$(top_srcdir)/src \
+ -I$(top_builddir)/src \
+ $(DBUS_CFLAGS) \
+ $(GLIB2_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(GTHREAD_CFLAGS)
+
+noinst_PROGRAMS = \
+ test-busy-handling \
+ test-direct-query \
+ test-bus-query \
+ test-default-update \
+ test-bus-update \
+ test-class-signal \
+ test-class-signal-performance \
+ test-update-array-performance
+
+test_busy_handling_VALASOURCES = test-busy-handling.vala
+
+test_busy_handling_SOURCES = \
+ test-busy-handling.vala.stamp \
+ $(test_busy_handling_VALASOURCES:.vala=.c)
+
+test-busy-handling.vala.stamp: $(test_busy_handling_VALASOURCES)
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 $^
+ $(AM_V_GEN)touch $@
+
+test_busy_handling_LDADD = \
+ $(BUILD_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB2_LIBS) \
+ $(DBUS_LIBS)
+
+test_direct_query_VALASOURCES = test-shared-query.vala test-direct-query.vala
+
+test_direct_query_SOURCES = \
+ test-direct-query.vala.stamp \
+ $(test_direct_query_VALASOURCES:.vala=.c)
+
+test_default_update_VALASOURCES = test-shared-update.vala test-default-update.vala
+
+test_default_update_SOURCES = \
+ test-default-update.vala.stamp \
+ $(test_default_update_VALASOURCES:.vala=.c)
+
+test_bus_query_VALASOURCES = test-shared-query.vala test-bus-query.vala
+
+test_update_array_performance_SOURCES = test-update-array-performance.c
+
+test_bus_query_SOURCES = \
+ test-bus-query.vala.stamp \
+ $(test_bus_query_VALASOURCES:.vala=.c)
+
+test_bus_update_VALASOURCES = test-shared-update.vala test-bus-update.vala
+
+test_bus_update_SOURCES = \
+ test-bus-update.vala.stamp \
+ $(test_bus_update_VALASOURCES:.vala=.c)
+
+direct_vapi_sources = \
+ $(top_srcdir)/src/libtracker-sparql/tracker-sparql-$(TRACKER_API_VERSION).vapi \
+ $(top_srcdir)/src/libtracker-direct/tracker-direct.vapi
+
+test-direct-query.vala.stamp: $(test_direct_query_VALASOURCES) $(direct_vapi_sources)
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 $^
+ $(AM_V_GEN)touch $@
+
+test_direct_query_LDADD = \
+ $(top_builddir)/src/libtracker-direct/libtracker-direct.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+ $(BUILD_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB2_LIBS)
+
+test-default-update.vala.stamp: $(test_default_update_VALASOURCES) $(direct_vapi_sources)
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 $^
+ $(AM_V_GEN)touch $@
+
+test_default_update_LDADD = $(test_direct_query_LDADD)
+
+bus_vapi_sources = \
+ $(top_srcdir)/src/libtracker-sparql/tracker-sparql-$(TRACKER_API_VERSION).vapi \
+ $(top_srcdir)/src/libtracker-bus/tracker-bus.vapi
+
+test-bus-query.vala.stamp: $(test_bus_query_VALASOURCES) $(bus_vapi_sources)
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 $^
+ $(AM_V_GEN)touch $@
+
+test-bus-update.vala.stamp: $(test_bus_update_VALASOURCES) $(bus_vapi_sources)
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 $^
+ $(AM_V_GEN)touch $@
+
+test_bus_query_LDADD = \
+ $(top_builddir)/src/libtracker-bus/libtracker-bus.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(BUILD_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB2_LIBS) \
+ $(DBUS_LIBS)
+
+test_bus_update_LDADD = $(test_bus_query_LDADD)
+
+test_class_signal_VALASOURCES = test-class-signal.vala
+
+test_class_signal_SOURCES = \
+ test-class-signal.vala.stamp \
+ $(test_class_signal_VALASOURCES:.vala=.c)
+
+test-class-signal.vala.stamp: $(test_class_signal_VALASOURCES) $(direct_vapi_sources)
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 $^
+ $(AM_V_GEN)touch $@
+
+test_class_signal_LDADD = \
+ $(top_builddir)/src/libtracker-direct/libtracker-direct.la \
+ $(top_builddir)/src/libtracker-bus/libtracker-bus.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(BUILD_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB2_LIBS) \
+ $(DBUS_LIBS)
+
+test_class_signal_performance_VALASOURCES = test-class-signal-performance.vala
+
+test_class_signal_performance_SOURCES = \
+ test-class-signal-performance.vala.stamp \
+ $(test_class_signal_performance_VALASOURCES:.vala=.c)
+
+test-class-signal-performance.vala.stamp: $(test_class_signal_performance_VALASOURCES) $(direct_vapi_sources)
+ $(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 $^
+ $(AM_V_GEN)touch $@
+
+test_class_signal_performance_LDADD = \
+ $(top_builddir)/src/libtracker-direct/libtracker-direct.la \
+ $(top_builddir)/src/libtracker-bus/libtracker-bus.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(BUILD_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB2_LIBS) \
+ $(DBUS_LIBS)
+
+test_update_array_performance_LDADD = \
+ $(top_builddir)/src/libtracker-direct/libtracker-direct.la \
+ $(top_builddir)/src/libtracker-bus/libtracker-bus.la \
+ $(top_builddir)/src/libtracker-sparql/libtracker-sparql-$(TRACKER_API_VERSION).la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(BUILD_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB2_LIBS) \
+ $(DBUS_LIBS)
+
+BUILT_SOURCES = \
+ test-busy-handling.vala.stamp \
+ test-class-signal.vala.stamp \
+ test-class-signal-performance.vala.stamp \
+ test-direct-query.vala.stamp \
+ test-bus-query.vala.stamp \
+ test-default-update.vala.stamp \
+ test-bus-update.vala.stamp
+
+EXTRA_DIST = \
+ $(BUILT_SOURCES) \
+ $(test_busy_handling_VALASOURCES) \
+ $(test_class_signal_VALASOURCES) \
+ $(test_class_signal_performance_VALASOURCES) \
+ $(test_direct_query_VALASOURCES) \
+ $(test_default_update_VALASOURCES) \
+ $(test_bus_query_VALASOURCES) \
+ $(test_bus_update_VALASOURCES)
+
+MAINTAINERCLEANFILES = \
+ $(BUILT_SOURCES) \
+ $(test_busy_handling_VALASOURCES:.vala=.c) \
+ $(test_class_signal_VALASOURCES:.vala=.c) \
+ $(test_class_signal_performance_VALASOURCES:.vala=.c) \
+ $(test_bus_query_VALASOURCES:.vala=.c) \
+ $(test_bus_update_VALASOURCES:.vala=.c) \
+ $(test_direct_query_VALASOURCES:.vala=.c) \
+ $(test_default_update_VALASOURCES:.vala=.c)
diff --git a/tests/functional-tests/ipc/test-bus-query.vala b/tests/functional-tests/ipc/test-bus-query.vala
new file mode 100644
index 000000000..1867fed46
--- /dev/null
+++ b/tests/functional-tests/ipc/test-bus-query.vala
@@ -0,0 +1,10 @@
+using Tracker;
+using Tracker.Sparql;
+
+int
+main( string[] args )
+{
+ TestApp app = new TestApp (new Tracker.Bus.Connection ());
+
+ return app.run ();
+}
diff --git a/tests/functional-tests/ipc/test-bus-update.vala b/tests/functional-tests/ipc/test-bus-update.vala
new file mode 100644
index 000000000..1867fed46
--- /dev/null
+++ b/tests/functional-tests/ipc/test-bus-update.vala
@@ -0,0 +1,10 @@
+using Tracker;
+using Tracker.Sparql;
+
+int
+main( string[] args )
+{
+ TestApp app = new TestApp (new Tracker.Bus.Connection ());
+
+ return app.run ();
+}
diff --git a/tests/functional-tests/ipc/test-busy-handling.vala b/tests/functional-tests/ipc/test-busy-handling.vala
new file mode 100644
index 000000000..9f9885b36
--- /dev/null
+++ b/tests/functional-tests/ipc/test-busy-handling.vala
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+// To run this test:
+// -===-------------
+//
+// tracker-control -k
+// rm ~/.cache/tracker/meta.db
+// export TRACKER_DEBUG_MAKE_JOURNAL_READER_GO_VERY_SLOW=yes
+// tracker-store
+// ./busy-handling-test
+
+[DBus (name = "org.freedesktop.Tracker1.Resources")]
+private interface Resources : GLib.Object {
+ [DBus (name = "SparqlQuery", timeout = 99999999999)]
+ public abstract async string[,] sparql_query (string query) throws DBus.Error;
+}
+
+[DBus (name = "org.freedesktop.Tracker1.Status")]
+private interface Status: GLib.Object {
+ public signal void progress (string status, double progress);
+ public abstract double get_progress () throws DBus.Error;
+ public abstract string get_status () throws DBus.Error;
+}
+
+public class TestApp {
+ static DBus.Connection connection;
+ static Resources resources_object;
+ static Status status_object;
+ int res = -1;
+ int users = 0;
+ MainLoop loop;
+ bool initialized = false;
+ bool ready = false;
+
+ public TestApp ()
+ requires (!initialized) {
+ try {
+ double progress;
+ string status;
+
+ connection = DBus.Bus.get (DBus.BusType.SESSION);
+ resources_object = (Resources) connection.get_object ("org.freedesktop.Tracker1",
+ "/org/freedesktop/Tracker1/Resources",
+ "org.freedesktop.Tracker1.Resources");
+ status_object = (Status) connection.get_object ("org.freedesktop.Tracker1",
+ "/org/freedesktop/Tracker1/Status",
+ "org.freedesktop.Tracker1.Status");
+
+ status_object.progress.connect (on_status_cb);
+ progress = status_object.get_progress ();
+ status = status_object.get_status ();
+
+ ready = (progress == 1.0 && status == "Idle");
+
+ } catch (DBus.Error e) {
+ warning ("Could not connect to D-Bus service: %s", e.message);
+ initialized = false;
+ res = -1;
+ return;
+ }
+ initialized = true;
+ }
+
+ void on_status_cb (string status, double progress) {
+ print ("%s: %f\n", status, progress);
+ // Don't use status here, it'll be "Journal replaying" when progress = 1
+ if (progress == 1.0) {
+ ready = true;
+ }
+ }
+
+ async void do_query_tests_async (string test_name) {
+ try {
+ int cnt = 0;
+ string[,] results = yield resources_object.sparql_query ("SELECT ?u { ?u a rdfs:Resource }");
+ foreach (string res in results) {
+ cnt++;
+ }
+ print ("%s: Saw %d strings in result\n", test_name, cnt);
+ } catch (GLib.Error e) {
+ print ("Fail: %s\n", e.message);
+ res = -1;
+ }
+ }
+
+ void check_shutdown () {
+ users--;
+ if (users == 0) {
+ print ("Async tests done, now I can quit the mainloop\n");
+ loop.quit ();
+ }
+ }
+
+ async void do_async_query_tests () {
+ print ("Test 1: Just launch the query and let it wait\nTest 1: query launches immediately\n");
+ users++;
+ yield do_query_tests_async ("Test 1");
+
+ check_shutdown ();
+ }
+
+ async void jumper_async () {
+ yield do_query_tests_async ("Test 2");
+ check_shutdown ();
+ }
+
+ bool test_ready () {
+
+ if (ready) {
+ print ("Test 2: query launches now\n");
+ jumper_async ();
+ }
+
+ return !ready;
+ }
+
+ bool in_mainloop () {
+ do_async_query_tests ();
+
+ print ("Test 2: Wait for the status signal to indicate readyness\n");
+ users++;
+
+ if (!ready) {
+ Timeout.add (1, test_ready);
+ } else {
+ test_ready ();
+ }
+
+ return false;
+ }
+
+ public int run () {
+ loop = new MainLoop (null, false);
+
+ Idle.add (in_mainloop);
+
+ loop.run ();
+
+ return res;
+ }
+}
+
+int main (string[] args) {
+ TestApp app = new TestApp ();
+
+ return app.run ();
+}
diff --git a/tests/functional-tests/ipc/test-class-signal-performance.vala b/tests/functional-tests/ipc/test-class-signal-performance.vala
new file mode 100644
index 000000000..02e215533
--- /dev/null
+++ b/tests/functional-tests/ipc/test-class-signal-performance.vala
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+using Tracker;
+using Tracker.Sparql;
+
+const int max_signals = 1000;
+// const int max_signals = 10000;
+const string title_data = "title";
+
+// Always start this test AFTER DOING tracker-control -r. The test IS NOT
+// deleting existing resources, so you CAN'T RUN IT TWICE unless you clear
+// the database before starting it the second time.
+
+// Testreport of Aug 25, 2010 by Philip
+// ------------------------------------
+// On Aug 25 the difference between using tracker-store on master and the
+// tracker-store of class-signal, and then letting this wait until all 10000
+// (in case of max_signals = 10000) insert queries' signals arrived (you'll
+// have in total 20002 events in the signals in both tracker-store versions)
+// was: 20s for class-signals (new class signal) and 23s for master (old class
+// signals). Measured using this performance test.
+//
+// Memory usage of class-signal (new class signal)'s tracker-store:
+// Low: VmRSS: 8860 Kb -- Max: VmRSS: 14116 kB
+//
+// Memory usage of master (old class signal)'s tracker-store:
+// Low: VmRSS: 8868 Kb -- Max: VmRSS: 14060 kB
+
+
+struct Event {
+ int graph_id;
+ int subject_id;
+ int pred_id;
+ int object_id;
+}
+
+[DBus (name = "org.freedesktop.Tracker1.Resources")]
+private interface Resources : GLib.Object {
+ [DBus (name = "GraphUpdated")]
+ public signal void graph_updated (string class_name, Event[] deletes, Event[] inserts);
+
+ [DBus (name = "SparqlUpdate")]
+ public abstract async void sparql_update_async (string query) throws Sparql.Error, DBus.Error;
+}
+
+[DBus (name = "org.freedesktop.Tracker1.Resources.Class")]
+private interface ResourcesClass : GLib.Object {
+ [DBus (name = "SubjectsAdded")]
+ public signal void subjects_added (string [] subjects);
+ [DBus (name = "SubjectsChanged")]
+ public signal void subjects_changed (string [] subjects, string [] preds);
+}
+
+public class TestApp {
+ static DBus.Connection dbus_connection;
+ static Resources resources_object;
+ static ResourcesClass class_object;
+ MainLoop loop;
+ bool initialized = false;
+ Sparql.Connection con;
+ int count = 0;
+ GLib.Timer t;
+
+ public TestApp ()
+ requires (!initialized) {
+ try {
+ con = Tracker.Sparql.Connection.get();
+ dbus_connection = DBus.Bus.get (DBus.BusType.SESSION);
+ resources_object = (Resources) dbus_connection.get_object ("org.freedesktop.Tracker1",
+ "/org/freedesktop/Tracker1/Resources",
+ "org.freedesktop.Tracker1.Resources");
+
+ class_object = (ResourcesClass) dbus_connection.get_object ("org.freedesktop.Tracker1",
+ "/org/freedesktop/Tracker1/Resources/Classes/nmm/MusicPiece",
+ "org.freedesktop.Tracker1.Resources.Class");
+
+ class_object.subjects_added.connect (on_subjects_added);
+ class_object.subjects_changed.connect (on_subjects_changed);
+
+ resources_object.graph_updated.connect (on_graph_updated_received);
+ t = new GLib.Timer ();
+
+ } catch (Sparql.Error e) {
+ warning ("Could not connect to D-Bus service: %s", e.message);
+ initialized = false;
+ return;
+ } catch (DBus.Error e) {
+ warning ("Could not connect to D-Bus service: %s", e.message);
+ initialized = false;
+ return;
+ }
+ initialized = true;
+ }
+
+ private void on_subjects_changed (string [] subjects, string [] preds) {
+ foreach (string s in subjects)
+ count++;
+
+ //if (count == 20002)
+ print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
+ }
+
+ private void on_subjects_added (string [] subjects) {
+ foreach (string s in subjects)
+ count++;
+
+ //if (count == 20002)
+ print ("Old class signal count=%d time=%lf\n", count, t.elapsed ());
+ }
+
+ private void on_graph_updated_received (string class_name, Event[] deletes, Event[] inserts) {
+ foreach (Event insert in inserts)
+ count++;
+ //if (count == 20002)
+ print ("New class signal count=%d time=%lf\n", count, t.elapsed ());
+ }
+
+ private void insert_data () {
+ int i;
+
+ t.start();
+ for (i = 0; i <= max_signals; i++) {
+ string upqry = "INSERT { <%d> a nmm:MusicPiece ; nie:title '%s %d' }".printf(i, title_data, i);
+ resources_object.sparql_update_async (upqry);
+ }
+ }
+
+ private bool in_mainloop () {
+ insert_data ();
+ return false;
+ }
+
+ public int run () {
+ loop = new MainLoop (null, false);
+ Idle.add (in_mainloop);
+ loop.run ();
+ return 0;
+ }
+}
+
+int main (string[] args) {
+ TestApp app = new TestApp ();
+
+ return app.run ();
+}
diff --git a/tests/functional-tests/ipc/test-class-signal.vala b/tests/functional-tests/ipc/test-class-signal.vala
new file mode 100644
index 000000000..2a773a45a
--- /dev/null
+++ b/tests/functional-tests/ipc/test-class-signal.vala
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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 Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+using Tracker;
+using Tracker.Sparql;
+
+const int max_signals = 10;
+const string title_data = "title";
+
+
+struct Event {
+ int graph_id;
+ int subject_id;
+ int pred_id;
+ int object_id;
+}
+
+[DBus (name = "org.freedesktop.Tracker1.Resources")]
+private interface Resources : GLib.Object {
+ [DBus (name = "GraphUpdated")]
+ public signal void graph_updated (string class_name, Event[] deletes, Event[] inserts);
+
+ [DBus (name = "SparqlUpdate")]
+ public abstract async void sparql_update_async (string query) throws Sparql.Error, DBus.Error;
+}
+
+public class TestApp {
+ static DBus.Connection dbus_connection;
+ static Resources resources_object;
+ int res = -1;
+ MainLoop loop;
+ bool initialized = false;
+ Sparql.Connection signal_con;
+ Sparql.Connection con;
+ int total_signals_seen = 0;
+
+ public TestApp ()
+ requires (!initialized) {
+ try {
+ con = Tracker.Sparql.Connection.get();
+
+ // Switch between kinds of query connections here:
+ signal_con = con;
+
+ dbus_connection = DBus.Bus.get (DBus.BusType.SESSION);
+ resources_object = (Resources) dbus_connection.get_object ("org.freedesktop.Tracker1",
+ "/org/freedesktop/Tracker1/Resources",
+ "org.freedesktop.Tracker1.Resources");
+
+ resources_object.graph_updated.connect (on_graph_updated_received);
+
+ } catch (Sparql.Error e) {
+ warning ("Could not connect to D-Bus service: %s", e.message);
+ initialized = false;
+ res = -1;
+ return;
+ } catch (DBus.Error e) {
+ warning ("Could not connect to D-Bus service: %s", e.message);
+ initialized = false;
+ res = -1;
+ return;
+ }
+ initialized = true;
+ }
+
+ // Query looks like this:
+ // SELECT ?r ?t { ?r a nmm:MusicPiece; nie:title ?t .
+ // FILTER (tracker:id (?r) IN (id1, id2, id3))
+ // }
+
+ private StringBuilder build_title_query (string class_name, Event[] ids) {
+ bool first = true;
+ StringBuilder builder = new StringBuilder ("SELECT ?r ?t { ?r a <");
+ builder.append (class_name);
+ builder.append (">; nie:title ?t . FILTER (tracker:id (?r) IN (");
+ foreach (Event event in ids) {
+ if (first)
+ builder.append_printf ("%d", event.subject_id);
+ else
+ builder.append_printf (" , %d", event.subject_id);
+ first = false;
+ }
+ builder.append (")) }");
+ return builder;
+ }
+
+ private int iter_cursor (string kind, Cursor cursor) {
+ try {
+ while (cursor.next()) {
+ string resource = cursor.get_string (0);
+
+ print ("%s <%s> nie:title '%s'\n",
+ kind,
+ resource,
+ cursor.get_string (1));
+ total_signals_seen++;
+
+ // We'll see ~ max_signals*2 things, (insert and delete, plus the
+ // resource creates too - so a little bit more)
+ if (total_signals_seen >= (max_signals*2)) {
+ loop.quit();
+ }
+ }
+ } catch (GLib.Error e) {
+ warning ("Couldn't iterate query results: %s", e.message);
+ res = -1;
+ return -1;
+ }
+ return (0);
+ }
+
+ private async void on_graph_updated_received_async (string dels_query, string ins_query) {
+ try {
+ Sparql.Cursor cursor1, cursor2;
+
+ cursor1 = yield signal_con.query_async (dels_query);
+ cursor2 = yield signal_con.query_async (ins_query);
+
+ res = iter_cursor ("delete of: ", cursor1);
+ if (res != -1)
+ res = iter_cursor ("insert of: ", cursor2);
+
+ } catch (GLib.Error e) {
+ warning ("Couldn't iterate query results: %s", e.message);
+ res = -1;
+ }
+ }
+
+ private void on_graph_updated_received (string class_name, Event[] deletes, Event[] inserts) {
+ string dels_qry = build_title_query (class_name, deletes).str;
+ string ins_qry = build_title_query (class_name, deletes).str;
+
+ on_graph_updated_received_async (dels_qry, ins_qry);
+ }
+
+ private void insert_data () {
+ int i;
+
+ for (i = 0; i <= max_signals; i++) {
+ string upqry = "DELETE { <%d> a rdfs:Resource } INSERT { <%d> a nmm:MusicPiece ; nie:title '%s %d' }".printf(i, i, title_data, i);
+
+ resources_object.sparql_update_async (upqry);
+
+ // Once the FD passing bug is fixed (running out of FDs), replace
+ // above with this:
+ // con.update_async (upqry);
+ }
+ }
+
+ private bool in_mainloop () {
+ insert_data ();
+
+ return false;
+ }
+
+ public int run () {
+ loop = new MainLoop (null, false);
+ Idle.add (in_mainloop);
+ loop.run ();
+ return res;
+ }
+}
+
+int main (string[] args) {
+ TestApp app = new TestApp ();
+
+ return app.run ();
+}
diff --git a/tests/functional-tests/ipc/test-default-update.vala b/tests/functional-tests/ipc/test-default-update.vala
new file mode 100644
index 000000000..3f7424d84
--- /dev/null
+++ b/tests/functional-tests/ipc/test-default-update.vala
@@ -0,0 +1,75 @@
+using Tracker.Sparql;
+
+private static int res;
+private static MainLoop loop;
+
+private async void test_async () {
+ // Quite this loo because we start another one in app.run ()
+ loop.quit ();
+
+ try {
+ Connection c;
+
+ // Test async
+ print ("Getting connection async\n");
+ c = yield Connection.get_async ();
+
+ print ("Got it %p\n", c);
+
+ print ("Creating app with connection\n");
+ TestApp app = new TestApp (c);
+
+ print ("Running app\n");
+ res = app.run();
+ } catch (GLib.IOError e1) {
+ warning ("Couldn't perform test: %s", e1.message);
+ } catch (Tracker.Sparql.Error e2) {
+ warning ("Couldn't perform test: %s", e2.message);
+ }
+
+ print ("\n");
+}
+
+private void test_sync () {
+ try {
+ Connection c;
+
+ // Test async
+ print ("Getting connection\n");
+ c = Connection.get ();
+
+ print ("Got it %p\n", c);
+
+ print ("Creating app with connection\n");
+ TestApp app = new TestApp (c);
+
+ print ("Running app\n");
+ res = app.run();
+ } catch (GLib.IOError e1) {
+ warning ("Couldn't perform test: %s", e1.message);
+ } catch (Tracker.Sparql.Error e2) {
+ warning ("Couldn't perform test: %s", e2.message);
+ }
+
+ print ("\n");
+}
+
+int
+main( string[] args )
+{
+ print ("Starting...\n");
+ loop = new MainLoop (null, false);
+
+ test_sync ();
+
+ if (res < 0) {
+ return res;
+ }
+
+ // Do async second
+ test_async.begin ();
+
+ loop.run ();
+
+ return res;
+}
diff --git a/tests/functional-tests/ipc/test-direct-query.vala b/tests/functional-tests/ipc/test-direct-query.vala
new file mode 100644
index 000000000..a322a4a96
--- /dev/null
+++ b/tests/functional-tests/ipc/test-direct-query.vala
@@ -0,0 +1,74 @@
+using Tracker;
+using Tracker.Sparql;
+
+private static int res;
+private static MainLoop loop;
+
+private async void test_async () {
+ // Quite this loo because we start another one in app.run ()
+ loop.quit ();
+
+ try {
+ Connection c;
+
+ // Test async
+ print ("Getting connection asynchronously\n");
+ c = yield Connection.get_async ();
+
+ print ("Got it %p\n", c);
+
+ print ("Creating app with connection\n");
+ TestApp app = new TestApp (c);
+
+ print ("Running app\n");
+ res = app.run();
+ } catch (GLib.IOError e1) {
+ warning ("Couldn't perform test: %s", e1.message);
+ } catch (Tracker.Sparql.Error e2) {
+ warning ("Couldn't perform test: %s", e2.message);
+ }
+
+ print ("\n");
+}
+
+private void test_sync () {
+ try {
+ Connection c;
+
+ // Test async
+ print ("Getting connection synchronously\n");
+ c = Connection.get ();
+
+ print ("Got it %p\n", c);
+
+ print ("Creating app with connection\n");
+ TestApp app = new TestApp (c);
+
+ print ("Running app\n");
+ res = app.run();
+ } catch (GLib.IOError e1) {
+ warning ("Couldn't perform test: %s", e1.message);
+ } catch (Tracker.Sparql.Error e2) {
+ warning ("Couldn't perform test: %s", e2.message);
+ }
+
+ print ("\n");
+}
+
+int
+main( string[] args )
+{
+ print ("Starting...\n");
+ loop = new MainLoop (null, false);
+
+ test_sync ();
+
+ if (res < 0) {
+ return res;
+ }
+
+ test_async.begin ();
+ loop.run ();
+
+ return res;
+}
diff --git a/tests/functional-tests/ipc/test-shared-query.vala b/tests/functional-tests/ipc/test-shared-query.vala
new file mode 100644
index 000000000..3fb930c75
--- /dev/null
+++ b/tests/functional-tests/ipc/test-shared-query.vala
@@ -0,0 +1,139 @@
+using Tracker;
+using Tracker.Sparql;
+
+public class TestApp : GLib.Object {
+ MainLoop loop;
+ Sparql.Connection con;
+ int res = 0;
+
+ public TestApp (Sparql.Connection connection) {
+ con = connection;
+ }
+
+ string type_to_string (Sparql.ValueType type) {
+ switch (type) {
+ case Sparql.ValueType.UNBOUND:
+ return "unbound";
+ case Sparql.ValueType.URI:
+ return "uri";
+ case Sparql.ValueType.STRING:
+ return "string";
+ case Sparql.ValueType.INTEGER:
+ return "integer";
+ case Sparql.ValueType.DOUBLE:
+ return "double";
+ case Sparql.ValueType.DATETIME:
+ return "datetime";
+ case Sparql.ValueType.BLANK_NODE:
+ return "blank-node";
+ case Sparql.ValueType.BOOLEAN:
+ return "boolean";
+ default:
+ break;
+ }
+ return "unknown";
+ }
+
+ int iter_cursor (Cursor cursor) {
+ int i;
+
+ try {
+ for (i = 0; i < cursor.n_columns; i++) {
+ print ("| %s ", cursor.get_variable_name (i));
+ }
+ print ("| -> %d columns\n", cursor.n_columns);
+
+ while (cursor.next()) {
+ for (i = 0; i < cursor.n_columns; i++) {
+ print ("%s%s a %s", i != 0 ? ",":"",
+ cursor.get_string (i),
+ type_to_string (cursor.get_value_type (i)));
+ }
+
+ print ("\n");
+ }
+ } catch (GLib.Error e) {
+ warning ("Couldn't iterate query results: %s", e.message);
+ return -1;
+ }
+
+ return (0);
+ }
+
+ private void test_query () {
+ Cursor cursor;
+
+ print ("Sync test\n");
+ try {
+ cursor = con.query ("SELECT ?u WHERE { ?u a rdfs:Class }");
+ } catch (GLib.Error e) {
+ warning ("Couldn't perform query: %s", e.message);
+ res = -1;
+ return;
+ }
+
+ res = iter_cursor (cursor);
+
+ if (res == -1)
+ return;
+
+ print ("\nRewinding\n");
+ cursor.rewind ();
+
+ print ("\nSecond run\n");
+ res = iter_cursor (cursor);
+ }
+
+ private async void test_query_async () {
+ Cursor cursor;
+
+ print ("Async test\n");
+ try {
+ cursor = yield con.query_async ("SELECT ?u WHERE { ?u a rdfs:Class }");
+ } catch (GLib.Error e) {
+ warning ("Couldn't perform query: %s", e.message);
+ res = -1;
+ return;
+ }
+
+ res = iter_cursor (cursor);
+
+ if (res == -1)
+ return;
+
+ print ("\nRewinding\n");
+ cursor.rewind ();
+
+ print ("\nSecond run\n");
+ res = iter_cursor (cursor);
+ }
+
+ void do_sync_tests () {
+ test_query ();
+ }
+
+ async void do_async_tests () {
+ yield test_query_async ();
+
+ print ("Async tests done, now I can quit the mainloop\n");
+ loop.quit ();
+ }
+
+ bool in_mainloop () {
+
+ do_sync_tests ();
+ do_async_tests ();
+
+ return false;
+ }
+
+ public int run () {
+ loop = new MainLoop (null, false);
+
+ Idle.add (in_mainloop);
+
+ loop.run ();
+
+ return res;
+ }
+}
diff --git a/tests/functional-tests/ipc/test-shared-update.vala b/tests/functional-tests/ipc/test-shared-update.vala
new file mode 100644
index 000000000..f251e976b
--- /dev/null
+++ b/tests/functional-tests/ipc/test-shared-update.vala
@@ -0,0 +1,155 @@
+using Tracker;
+using Tracker.Sparql;
+
+
+public class TestApp : GLib.Object {
+ MainLoop loop;
+ Sparql.Connection con;
+ private int res = 0;
+
+ public TestApp (Sparql.Connection connection) {
+ con = connection;
+ }
+
+ int iter_cursor (Cursor cursor) {
+ try {
+ while (cursor.next()) {
+ int i;
+
+ for (i = 0; i < cursor.n_columns; i++) {
+ print ("%s%s", i != 0 ? ",":"", cursor.get_string (i));
+ }
+
+ print ("\n");
+ }
+ } catch (GLib.Error e) {
+ warning ("Couldn't iterate query results: %s", e.message);
+ return -1;
+ }
+
+ return (0);
+ }
+
+ int iter_variant (GLib.Variant variant) {
+
+ // TODO: Rest the return value, also check tracker_bus_message_to_variant
+ // in libtracker-bus/tracker-bus-shared.c
+
+ return 0;
+ }
+
+ void update_query () {
+ Cursor cursor;
+ int a;
+
+ try {
+ con.update ("INSERT { <test01> a nie:InformationElement ; nie:title 'test01' }");
+ } catch (Tracker.Sparql.Error ea) {
+ warning ("Couldn't update: %s", ea.message);
+ res = -1;
+ } catch (IOError eb) {
+ warning ("Couldn't update: %s", eb.message);
+ res = -1;
+ }
+
+ try {
+ cursor = con.query ("SELECT ?title WHERE { <test01> nie:title ?title }");
+ a = iter_cursor (cursor);
+ } catch (Tracker.Sparql.Error ec) {
+ warning ("Couldn't query: %s", ec.message);
+ res = -1;
+ } catch (IOError ed) {
+ warning ("Couldn't update: %s", ed.message);
+ res = -1;
+ }
+ }
+
+ async void update_query_async () {
+ Cursor cursor;
+ int a;
+
+ try {
+ yield con.update_async ("INSERT { <test02> a nie:InformationElement ; nie:title 'test01' }");
+ } catch (Tracker.Sparql.Error ea) {
+ warning ("Couldn't update: %s", ea.message);
+ res = -1;
+ } catch (IOError eb) {
+ warning ("Couldn't update: %s", eb.message);
+ res = -1;
+ }
+
+ try {
+ cursor = con.query ("SELECT ?title WHERE { <test02> nie:title ?title }");
+ a = iter_cursor (cursor);
+ } catch (Tracker.Sparql.Error ec) {
+ warning ("Couldn't query: %s", ec.message);
+ res = -1;
+ } catch (IOError ed) {
+ warning ("Couldn't update: %s", ed.message);
+ res = -1;
+ }
+ }
+
+ void update_blank_query () {
+ GLib.Variant variant;
+ int a;
+
+ try {
+ variant = con.update_blank ("INSERT { _:a1 a nie:InformationElement . _:b1 a nie:InformationElement . _:c1 a nie:InformationElement }");
+ a = iter_variant (variant);
+ } catch (Tracker.Sparql.Error ea) {
+ warning ("Couldn't update: %s", ea.message);
+ res = -1;
+ } catch (IOError eb) {
+ warning ("Couldn't update: %s", eb.message);
+ res = -1;
+ }
+ }
+
+ async void update_blank_query_async () {
+ GLib.Variant variant;
+ int a;
+
+ try {
+ variant = yield con.update_blank_async ("INSERT { _:a2 a nie:InformationElement . _:b2 a nie:InformationElement . _:c2 a nie:InformationElement }");
+ a = iter_variant (variant);
+ } catch (Tracker.Sparql.Error ea) {
+ warning ("Couldn't update: %s", ea.message);
+ res = -1;
+ } catch (IOError eb) {
+ warning ("Couldn't update: %s", eb.message);
+ res = -1;
+ }
+ }
+
+ void do_sync_tests () {
+ update_query ();
+ update_blank_query ();
+ }
+
+ async void do_async_tests () {
+ yield update_query_async ();
+ yield update_blank_query_async ();
+
+ print ("Async tests done, now I can quit the mainloop\n");
+ loop.quit ();
+ }
+
+ bool in_mainloop () {
+
+ do_sync_tests ();
+ do_async_tests ();
+
+ return false;
+ }
+
+ public int run () {
+ loop = new MainLoop (null, false);
+
+ Idle.add (in_mainloop);
+
+ loop.run ();
+
+ return res;
+ }
+}
diff --git a/tests/functional-tests/ipc/test-update-array-performance.c b/tests/functional-tests/ipc/test-update-array-performance.c
new file mode 100644
index 000000000..3f0d7262c
--- /dev/null
+++ b/tests/functional-tests/ipc/test-update-array-performance.c
@@ -0,0 +1,282 @@
+/*
+ * Copyright (C) 2010, Codeminded BVBA <abustany@gnome.org>
+ *
+ * This library 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 library 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 library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Copied from ../tracker-steroids/tracker-test.c
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <libtracker-sparql/tracker-sparql.h>
+
+typedef struct {
+ GMainLoop *main_loop;
+ const gchar *query;
+ guint len, cur;
+} AsyncData;
+
+static TrackerSparqlConnection *connection;
+#define MSIZE 90
+#define TEST_STR "Brrr0092323"
+
+static const gchar *queries[90] = {
+ "INSERT { _:a0 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:a9 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:a11 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b0 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b9 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b11 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c0 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c9 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c12 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d0 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d9 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d12 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e0 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e9 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e11 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f0 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f9 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f11 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b1 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b8 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b13 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c1 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c8 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c13 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d1 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d8 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d14 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e1 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e8 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e14 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f1 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f8 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f15 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b7 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b15 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c7 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c15 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d7 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d16 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e7 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e16 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f7 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f17 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b3 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b6 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b16 a nmo:Message; nie:title '" TEST_STR "'}",
+ "INSERT { _:c3 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c6 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c18 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d3 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d6 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d19 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e3 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e6 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e20 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f3 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f6 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f21 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b4 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:b22 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c4 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c23 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d4 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d24 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e4 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e24 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f4 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f25 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:c26 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:d28 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:e29 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f5 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f2 a nmo:Message; nie:title '" TEST_STR "' }",
+ "INSERT { _:f33 a nmo:Message; nie:title '" TEST_STR "' }" };
+
+static void
+async_update_array_callback (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ AsyncData *data = user_data;
+ GError *error = NULL;
+ GPtrArray *errors;
+
+ errors = tracker_sparql_connection_update_array_finish (connection, result, &error);
+ g_assert_no_error (error);
+ g_ptr_array_unref (errors);
+ g_main_loop_quit (data->main_loop);
+}
+
+
+static void
+test_tracker_sparql_update_array_async ()
+{
+ GMainLoop *main_loop;
+ AsyncData *data;
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+
+ data = g_slice_new (AsyncData);
+ data->main_loop = main_loop;
+
+ /* Cast here is because vala doesn't make const-char-** possible :( */
+ tracker_sparql_connection_update_array_async (connection,
+ (char**) queries, MSIZE,
+ 0, NULL,
+ async_update_array_callback,
+ data);
+
+ g_main_loop_run (main_loop);
+
+ g_slice_free (AsyncData, data);
+ g_main_loop_unref (main_loop);
+
+}
+
+static void
+async_update_callback (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ AsyncData *data = user_data;
+ GError *error = NULL;
+
+ data->cur++;
+
+ tracker_sparql_connection_update_finish (connection, result, &error);
+ if (error)
+ g_error_free (error);
+
+ if (data->cur == data->len)
+ g_main_loop_quit (data->main_loop);
+}
+
+static void
+test_tracker_sparql_update_async ()
+{
+ guint i;
+ GMainLoop *main_loop;
+ AsyncData *data;
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+
+ data = g_slice_new (AsyncData);
+ data->len = MSIZE;
+ data->main_loop = main_loop;
+ data->cur = 0;
+
+ for (i = 0; i < data->len; i++) {
+ tracker_sparql_connection_update_async (connection,
+ queries[i],
+ 0, NULL,
+ async_update_callback,
+ data);
+ }
+
+ g_main_loop_run (main_loop);
+
+ g_slice_free (AsyncData, data);
+ g_main_loop_unref (main_loop);
+
+}
+
+
+gint
+main (gint argc, gchar **argv)
+{
+ GTimer *array_t, *update_t;
+
+ g_type_init ();
+
+ /* do not require prior installation */
+ g_setenv ("TRACKER_SPARQL_MODULE_PATH", "../../src/libtracker-bus/.libs", TRUE);
+
+ connection = tracker_sparql_connection_get (NULL, NULL);
+
+ g_print ("First run (first update then array)\n");
+
+ tracker_sparql_connection_update (connection,
+ "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
+ 0, NULL, NULL);
+
+ update_t = g_timer_new ();
+ test_tracker_sparql_update_async ();
+ g_timer_stop (update_t);
+
+ tracker_sparql_connection_update (connection,
+ "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
+ 0, NULL, NULL);
+
+ array_t = g_timer_new ();
+ test_tracker_sparql_update_array_async ();
+ g_timer_stop (array_t);
+
+ tracker_sparql_connection_update (connection,
+ "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
+ 0, NULL, NULL);
+
+ g_print ("Array: %f, Update: %f\n", g_timer_elapsed (array_t, NULL), g_timer_elapsed (update_t, NULL));
+
+ g_print ("Reversing run (first array then update)\n");
+
+ g_timer_destroy (array_t);
+ g_timer_destroy (update_t);
+
+ array_t = g_timer_new ();
+ test_tracker_sparql_update_array_async ();
+ g_timer_stop (array_t);
+
+ tracker_sparql_connection_update (connection,
+ "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
+ 0, NULL, NULL);
+
+ update_t = g_timer_new ();
+ test_tracker_sparql_update_async ();
+ g_timer_stop (update_t);
+
+ tracker_sparql_connection_update (connection,
+ "DELETE { ?r a rdfs:Resource } WHERE { ?r nie:title '" TEST_STR "' }",
+ 0, NULL, NULL);
+
+ g_print ("Array: %f, Update: %f\n", g_timer_elapsed (array_t, NULL), g_timer_elapsed (update_t, NULL));
+
+ g_timer_destroy (array_t);
+ g_timer_destroy (update_t);
+ g_object_unref (connection);
+
+ return 0;
+}