[tracker/rss-enclosures] Testing queue sending async queries and updates.
- From: Roberto Guido <rguido src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/rss-enclosures] Testing queue sending async queries and updates.
- Date: Mon, 3 May 2010 00:31:03 +0000 (UTC)
commit 55b6bca15864acf0f07400680630509449c5ca53
Author: Ivan Frade <ivan frade nokia com>
Date: Fri Apr 9 19:10:53 2010 +0300
Testing queue sending async queries and updates.
tests/functional-tests/09-concurrent-query.py | 107 +++++++++++++++++++++++++
tests/functional-tests/Makefile.am | 1 +
tests/functional-tests/tests.xml | 11 +++
3 files changed, 119 insertions(+), 0 deletions(-)
---
diff --git a/tests/functional-tests/09-concurrent-query.py b/tests/functional-tests/09-concurrent-query.py
new file mode 100644
index 0000000..35f7aca
--- /dev/null
+++ b/tests/functional-tests/09-concurrent-query.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python2.5
+#
+# Copyright (C) 2010, Nokia <ivan frade nokia 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.
+#
+
+import sys,os,dbus
+import unittest
+import time
+import random
+import configuration
+import commands
+import signal
+import gobject
+from dbus.mainloop.glib import DBusGMainLoop
+
+TRACKER = 'org.freedesktop.Tracker1'
+TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
+RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
+
+AMOUNT_OF_TEST_INSTANCES = 100
+AMOUNT_OF_QUERIES = 10
+
+class TestConcurrentQuery (unittest.TestCase):
+ """
+ Send a bunch of queries to the daemon asynchronously, to test the queue
+ holding those queries
+ """
+ def setUp (self):
+ self.main_loop = gobject.MainLoop ()
+ dbus_loop = DBusGMainLoop(set_as_default=True)
+
+ bus = dbus.SessionBus(mainloop=dbus_loop)
+ tracker = bus.get_object(TRACKER, TRACKER_OBJ)
+ self.resources = dbus.Interface (tracker,
+ dbus_interface=RESOURCES_IFACE)
+ self.mock_data_insert ()
+ self.finish_counter = 0
+
+ def mock_data_insert (self):
+ query = "INSERT {\n"
+ for i in range (0, AMOUNT_OF_TEST_INSTANCES):
+ query += "<test-09:instance-%d> a nco:PersonContact ; nco:fullname 'moe %d'.\n" % (i, i)
+ query += "}"
+ self.resources.SparqlUpdate (query)
+
+ def mock_data_delete (self):
+ query = "DELETE {\n"
+ for i in range (0, AMOUNT_OF_TEST_INSTANCES):
+ query += "<test-09:instance-%d> a rdfs:Resource.\n" % (i)
+ query += "}"
+ self.resources.SparqlUpdate (query)
+
+ query = "DELETE {\n"
+ for i in range (0, AMOUNT_OF_QUERIES):
+ query += "<test-09:picture-%d> a rdfs:Resource.\n" % (i)
+ query += "}"
+ self.resources.SparqlUpdate (query)
+
+
+ def test_async_queries (self):
+ QUERY = "SELECT ?u WHERE { ?u a nco:PersonContact. FILTER regex (?u, 'test-09:ins')}"
+ UPDATE = "INSERT { <test-09:picture-%d> a nmm:Photo. }"
+ for i in range (0, AMOUNT_OF_QUERIES):
+ self.resources.SparqlQuery (QUERY, reply_handler=self.reply_cb, error_handler=self.error_handler)
+ self.resources.SparqlUpdate (UPDATE % (i),
+ reply_handler=self.update_cb,
+ error_handler=self.error_handler)
+
+ # Safeguard of 50 seconds. The last reply should quit the loop
+ gobject.timeout_add_seconds (60, self.timeout_cb)
+ self.main_loop.run ()
+
+ def reply_cb (self, results):
+ self.finish_counter += 1
+ assert len (results) == AMOUNT_OF_TEST_INSTANCES
+ if (self.finish_counter >= AMOUNT_OF_QUERIES):
+ self.timeout_cb ()
+
+ def update_cb (self):
+ assert True
+
+ def error_handler (self):
+ print "ERROR in DBus call"
+ assert False
+
+ def timeout_cb (self):
+ self.mock_data_delete ()
+ self.main_loop.quit ()
+ return False
+
+if __name__ == "__main__":
+ unittest.main ()
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index 4b2decb..8a953f8 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -13,6 +13,7 @@ config_SCRIPTS = \
06-distance.py \
07-graph.py \
08-unique-insertions.py \
+ 09-concurrent-query.py \
bootup-tc.py \
configuration.py \
metadata_extraction_tc.py \
diff --git a/tests/functional-tests/tests.xml b/tests/functional-tests/tests.xml
index 933fec8..fac2c55 100644
--- a/tests/functional-tests/tests.xml
+++ b/tests/functional-tests/tests.xml
@@ -165,6 +165,17 @@
<hardware>true</hardware>
</environments>
</set>
+ <set name="_usr_share_tracker-tests_09-concurrent-query.py">
+ <description>tracker:09-concurrent-query.py</description>
+ <case name="09-concurrent-query.py-TestConcurrentQuery.test_async_queries">
+ <description>tracker:09-concurrent-query.py:TestConcurrentQuery.test_async_queries</description>
+ <step>/usr/share/tracker-tests/09-concurrent-query.py TestConcurrentQuery.test_async_queries</step>
+ </case>
+ <environments>
+ <scratchbox>true</scratchbox>
+ <hardware>true</hardware>
+ </environments>
+ </set>
<set name="_usr_share_tracker-tests_06-distance.py">
<description>tracker:06-distance.py</description>
<case name="06-distance.py-TestCoalesce.test_distance_cartesian_proportion">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]