[tracker/rss-enclosures] Add exec permission to the relevant tests



commit b005466bfefa283694a177851c7b95f39b2db86f
Author: Ivan Frade <ivan frade nokia com>
Date:   Wed Aug 18 18:32:06 2010 +0300

    Add exec permission to the relevant tests

 tests/functional-tests/04-group-concat.py         |   35 +++----
 tests/functional-tests/05-coalesce.py             |   37 ++++---
 tests/functional-tests/06-distance.py             |   32 +++---
 tests/functional-tests/07-graph.py                |   36 ++++----
 tests/functional-tests/08-unique-insertions.py    |   41 ++++----
 tests/functional-tests/09-concurrent-query.py     |   47 +++++-----
 tests/functional-tests/10-sqlite-misused.py       |   44 ++++-----
 tests/functional-tests/11-sqlite-batch-misused.py |   40 ++++----
 tests/functional-tests/12-transactions.py         |  111 ++++++++++-----------
 9 files changed, 204 insertions(+), 219 deletions(-)
---
diff --git a/tests/functional-tests/04-group-concat.py b/tests/functional-tests/04-group-concat.py
old mode 100644
new mode 100755
index b4eb3ad..4a6b4ca
--- a/tests/functional-tests/04-group-concat.py
+++ b/tests/functional-tests/04-group-concat.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,23 +17,22 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
-
+"""
+Test the GROUP_CONCAT function in Sparql. Only requires the store.
+"""
 import dbus
 import unittest
 import random
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
-RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
-
-class TestGroupConcat (unittest.TestCase):
-
-    def setUp (self):
-        bus = dbus.SessionBus ()
-        tracker = bus.get_object (TRACKER, TRACKER_OBJ)
-        self.resources = dbus.Interface (tracker,
-                                         dbus_interface=RESOURCES_IFACE);
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
+class TestGroupConcat (CommonTrackerStoreTest):
+    """
+    Insert a multivalued property and request the results in GROUP_CONCAT
+    """
     def test_group_concat (self):
         """
         1. Insert 3 capabilities for a test contact
@@ -52,7 +51,7 @@ class TestGroupConcat (unittest.TestCase):
                       nco:imContactCapability nco:im-capability-file-transfers .
          }
         """ % (uri)
-        self.resources.SparqlUpdate (insert)
+        self.tracker.update (insert)
 
         query = """
         SELECT ?c ?capability WHERE {
@@ -61,7 +60,7 @@ class TestGroupConcat (unittest.TestCase):
               nco:imContactCapability ?capability .
         }
         """ 
-        results = self.resources.SparqlQuery (query)
+        results = self.tracker.query (query)
 
         assert len (results) == 3
         group_concat_query = """
@@ -71,7 +70,7 @@ class TestGroupConcat (unittest.TestCase):
               nco:imContactCapability ?capability .
         } GROUP BY (?c)
         """ 
-        results = self.resources.SparqlQuery (group_concat_query)
+        results = self.tracker.query (group_concat_query)
         assert len (results) == 1
         
         instances = results[0][1].split ('|')
@@ -90,8 +89,8 @@ class TestGroupConcat (unittest.TestCase):
         delete = """
         DELETE { <%s> a rdfs:Resource. }
         """ % (uri)
-        self.resources.SparqlUpdate (delete)
+        self.tracker.update (delete)
         
 
 if __name__ == '__main__':
-    unittest.main()
+    ut.main()
diff --git a/tests/functional-tests/05-coalesce.py b/tests/functional-tests/05-coalesce.py
old mode 100644
new mode 100755
index 06a44fe..10885ac
--- a/tests/functional-tests/05-coalesce.py
+++ b/tests/functional-tests/05-coalesce.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,23 +17,26 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
-
+"""
+Test tracker:coalesce function in Sparql. Only uses the Store
+"""
 import dbus
 import unittest
 import random
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
-RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
 
-class TestCoalesce (unittest.TestCase):
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
-    def setUp (self):
-        bus = dbus.SessionBus ()
-        tracker = bus.get_object (TRACKER, TRACKER_OBJ)
-        self.resources = dbus.Interface (tracker,
-                                         dbus_interface=RESOURCES_IFACE);
+class TestCoalesce (CommonTrackerStoreTest):
+    """
+    Insert and instance with some values, and tracker coalesce of some of them
+    with different combinations (first NULL, none NULL, all NULL...)
+    """
 
+    def setUp (self):
         self.resource_uri = "contact://test_group_concat"
 
         #
@@ -45,13 +48,13 @@ class TestCoalesce (unittest.TestCase):
                       nco:nameFamily \"family name\" .
          }
         """ % (self.resource_uri)
-        self.resources.SparqlUpdate (insert)
+        self.tracker.update (insert)
 
     def tearDown (self):
         delete = """
         DELETE { <%s> a rdfs:Resource. }
         """ % (self.resource_uri)
-        self.resources.SparqlUpdate (delete)
+        self.tracker.update (delete)
 
 
         
@@ -71,7 +74,7 @@ class TestCoalesce (unittest.TestCase):
            OPTIONAL { ?c nco:note ?note }
         }
         """ 
-        results = self.resources.SparqlQuery (query)
+        results = self.tracker.query (query)
         assert len (results) == 1
         assert results[0][0] == "full name"
 
@@ -92,7 +95,7 @@ class TestCoalesce (unittest.TestCase):
            OPTIONAL { ?c nco:note ?note }
         }
         """ 
-        results = self.resources.SparqlQuery (query)
+        results = self.tracker.query (query)
         assert len (results) == 1
         assert results[0][0] == "family name"
 
@@ -113,10 +116,10 @@ class TestCoalesce (unittest.TestCase):
            OPTIONAL { ?c nco:note ?note }
         }
         """ 
-        results = self.resources.SparqlQuery (query)
+        results = self.tracker.query (query)
         assert len (results) == 1
         assert results[0][0] == "test_coalesce"
         
 
 if __name__ == '__main__':
-    unittest.main()
+    ut.main()
diff --git a/tests/functional-tests/06-distance.py b/tests/functional-tests/06-distance.py
old mode 100644
new mode 100755
index e97d599..1966de6
--- a/tests/functional-tests/06-distance.py
+++ b/tests/functional-tests/06-distance.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,27 +17,27 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
-
+"""
+Test the distance-calculation functions in Sparql. Only requires the Store
+"""
 import dbus
 import unittest
 import random
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
-RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
 POINT_COORDS = [
     (0, 0), (1, 1), (2, 2), (3, 3), (4, 4)
     ]
 
-class TestCoalesce (unittest.TestCase):
-
+class TestDistanceFunctions (CommonTrackerStoreTest):
+    """
+    Insert some points and get the distance between them.
+    """
     def setUp (self):
-        bus = dbus.SessionBus ()
-        tracker = bus.get_object (TRACKER, TRACKER_OBJ)
-        self.resources = dbus.Interface (tracker,
-                                         dbus_interface=RESOURCES_IFACE);
-
         self.counter = 0
         for lat, log in POINT_COORDS:
             insert = """
@@ -47,7 +47,7 @@ class TestCoalesce (unittest.TestCase):
                 mlo:latitude %d .                
             }
             """ % ("point://test/point/" + str(self.counter), log, lat)
-            self.resources.SparqlUpdate (insert)
+            self.tracker.update (insert)
             self.counter += 1
 
     def tearDown (self):
@@ -57,7 +57,7 @@ class TestCoalesce (unittest.TestCase):
             <%s> a rdfs:Resource.
             }
             """ % ("point://test/point/" + str (i))
-            self.resources.SparqlUpdate (delete)
+            self.tracker.update (delete)
 
 
     def get_distance_between_points (self, sum_func, id1, id2):
@@ -78,7 +78,7 @@ class TestCoalesce (unittest.TestCase):
              mlo:longitude ?lon2 .
         }
         """ % (sum_func, id1, id2)
-        result = self.resources.SparqlQuery (query_1_to_2)
+        result = self.tracker.query (query_1_to_2)
         return int (result[0][0])
         
         
@@ -132,4 +132,4 @@ class TestCoalesce (unittest.TestCase):
         
 
 if __name__ == '__main__':
-    unittest.main()
+    ut.main()
diff --git a/tests/functional-tests/07-graph.py b/tests/functional-tests/07-graph.py
old mode 100644
new mode 100755
index bd228a1..206d100
--- a/tests/functional-tests/07-graph.py
+++ b/tests/functional-tests/07-graph.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,23 +17,23 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
-
+"""
+Tests graphs in Sparql. Only requires the store.
+"""
 import dbus
 import unittest
 import random
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
-RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
-
-class TestFTSFunctions (unittest.TestCase):
-
-    def setUp (self):
-        bus = dbus.SessionBus ()
-        tracker = bus.get_object (TRACKER, TRACKER_OBJ)
-        self.resources = dbus.Interface (tracker,
-                                         dbus_interface=RESOURCES_IFACE);
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
+class TestGraphs (CommonTrackerStoreTest):
+    """
+    Insert triplets in different graphs and check the query results asking in
+    one specific graph, in all of them and so on.
+    """
 
     def test_graph_filter (self):
         """
@@ -62,7 +62,7 @@ class TestFTSFunctions (unittest.TestCase):
             }
         }
         """
-        self.resources.SparqlUpdate (insert_sparql)
+        self.tracker.update (insert_sparql)
 
         query = """
         SELECT ?contact ?number WHERE {
@@ -72,7 +72,7 @@ class TestFTSFunctions (unittest.TestCase):
             }
         } ORDER BY DESC (fts:rank(?contact))
         """
-        results = self.resources.SparqlQuery (query)
+        results = self.tracker.query (query)
 
         self.assertEquals (len(results), 1)
         self.assertEquals (results[0][0], "contact://test/graph/1")
@@ -110,7 +110,7 @@ class TestFTSFunctions (unittest.TestCase):
             }
         }
         """
-        self.resources.SparqlUpdate (insert_sparql)
+        self.tracker.update (insert_sparql)
 
         query = """
         SELECT ?contact ?g WHERE {
@@ -120,7 +120,7 @@ class TestFTSFunctions (unittest.TestCase):
             }
         }
         """
-        results = self.resources.SparqlQuery (query)
+        results = self.tracker.query (query)
         self.assertEquals (len(results), 1)
         self.assertEquals (results[0][0], "contact://test/graph/1")
         self.assertEquals (results[0][1], "graph://test/graph/0")
@@ -135,4 +135,4 @@ class TestFTSFunctions (unittest.TestCase):
 
 
 if __name__ == '__main__':
-    unittest.main()
+    ut.main()
diff --git a/tests/functional-tests/08-unique-insertions.py b/tests/functional-tests/08-unique-insertions.py
old mode 100644
new mode 100755
index b7af37a..abb2259
--- a/tests/functional-tests/08-unique-insertions.py
+++ b/tests/functional-tests/08-unique-insertions.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,24 +17,25 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
-
+"""
+Replicate the behaviour of the miner inserting information in the store.
+"""
 import dbus
 import unittest
 import random
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
-RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
-
-class TestFTSFunctions (unittest.TestCase):
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
-    def setUp (self):
-        bus = dbus.SessionBus ()
-        tracker = bus.get_object (TRACKER, TRACKER_OBJ)
-        self.resources = dbus.Interface (tracker,
-                                         dbus_interface=RESOURCES_IFACE);
+class TestMinerInsertBehaviour (CommonTrackerStoreTest):
+    """
+    Mimic the behaviour of the miner, removing the previous information of the resource
+    and inserting a new one.
+    """
 
-    def test_unique_insertion (self):
+    def test_miner_unique_insertion (self):
         """
         We actually can't test tracker-miner-fs, so we mimick its behavior in this test
         1. Insert one resource
@@ -62,23 +63,23 @@ class TestFTSFunctions (unittest.TestCase):
         """
 
         ''' First insertion '''
-        self.resources.SparqlUpdate (insert_sparql)
+        self.tracker.update (insert_sparql)
 
-        results = self.resources.SparqlQuery (select_sparql)
+        results = self.tracker.query (select_sparql)
         self.assertEquals (len(results), 1)
 
         ''' Second insertion / update '''
-        self.resources.SparqlUpdate (insert_sparql)
+        self.tracker.update (insert_sparql)
 
-        results = self.resources.SparqlQuery (select_sparql)
+        results = self.tracker.query (select_sparql)
         self.assertEquals (len(results), 1)
 
         ''' Clean up '''
-        self.resources.SparqlUpdate (delete_sparql)
+        self.tracker.update (delete_sparql)
 
-        results = self.resources.SparqlQuery (select_sparql)
+        results = self.tracker.query (select_sparql)
         self.assertEquals (len(results), 0)
 
 
 if __name__ == '__main__':
-    unittest.main()
+    ut.main()
diff --git a/tests/functional-tests/09-concurrent-query.py b/tests/functional-tests/09-concurrent-query.py
old mode 100644
new mode 100755
index 9b22628..4cc626e
--- a/tests/functional-tests/09-concurrent-query.py
+++ b/tests/functional-tests/09-concurrent-query.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,37 +17,34 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 #
-
+"""
+Send concurrent inserts and queries to the daemon to check the concurrency.
+"""
 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"
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
 AMOUNT_OF_TEST_INSTANCES = 100
 AMOUNT_OF_QUERIES = 10
 
-class TestConcurrentQuery (unittest.TestCase):
+class TestConcurrentQuery (CommonTrackerStoreTest):
     """
     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
         
@@ -56,30 +53,32 @@ class TestConcurrentQuery (unittest.TestCase):
         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)
+        self.tracker.update (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)
+        self.tracker.update (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)
+        self.tracker.update (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)
+            self.tracker.get_tracker_iface ().SparqlQuery (QUERY,
+                                                           reply_handler=self.reply_cb,
+                                                           error_handler=self.error_handler)
+            self.tracker.get_tracker_iface ().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)
@@ -87,16 +86,16 @@ class TestConcurrentQuery (unittest.TestCase):
         
     def reply_cb (self, results):
         self.finish_counter += 1
-        assert len (results) == AMOUNT_OF_TEST_INSTANCES
+        self.assertEquals (len (results), AMOUNT_OF_TEST_INSTANCES)
         if (self.finish_counter >= AMOUNT_OF_QUERIES):
             self.timeout_cb ()
 
     def update_cb (self):
-        assert True
+        self.assertTrue (True)
 
     def error_handler (self):
         print "ERROR in DBus call"
-        assert False
+        self.assertTrue (False)
 
     def timeout_cb (self):
         self.mock_data_delete ()
@@ -104,4 +103,4 @@ class TestConcurrentQuery (unittest.TestCase):
         return False
 
 if __name__ == "__main__":
-    unittest.main ()
+    ut.main ()
diff --git a/tests/functional-tests/10-sqlite-misused.py b/tests/functional-tests/10-sqlite-misused.py
old mode 100644
new mode 100755
index 85c975b..0e7f1ec
--- a/tests/functional-tests/10-sqlite-misused.py
+++ b/tests/functional-tests/10-sqlite-misused.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,43 +17,34 @@
 # 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
+"""
+Test the query while importing at the same time. This was raising
+some SQLITE_MISUSED errors before.
+"""
+import os, dbus
 import gobject
 from dbus.mainloop.glib import DBusGMainLoop
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
-RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
-class TestSqliteMisused (unittest.TestCase):
+class TestSqliteMisused (CommonTrackerStoreTest):
     """
     Send queries while importing files (in .ttl directory)
-    Don't run this script directly, use the bash script "force-sqlite-misused.sh" instead
-    to configure properly the environment
     """
     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.files_counter = 0
         
     def test_queries_while_import (self):
+        self.assertTrue (os.path.exists ('ttl'))
         for root, dirs, files in os.walk('ttl'):
             for ttl_file in filter (lambda f: f.endswith (".ttl"), files):
                 full_path = os.path.abspath(os.path.join (root, ttl_file))
                 self.files_counter += 1
-                self.resources.Load ("file://" + full_path,
+                self.tracker.get_tracker_iface ().Load ("file://" + full_path,
                                      timeout=30000,
                                      reply_handler=self.loaded_success_cb,
                                      error_handler=self.loaded_failed_cb)
@@ -65,8 +56,9 @@ class TestSqliteMisused (unittest.TestCase):
 
     def run_a_query (self):
         QUERY = "SELECT ?u ?title WHERE { ?u a nie:InformationElement; nie:title ?title. }"
-        self.resources.SparqlQuery (QUERY, timeout=20000,
-                                    reply_handler=self.reply_cb, error_handler=self.error_handler)
+        self.tracker.get_tracker_iface ().SparqlQuery (QUERY, timeout=20000,
+                                                       reply_handler=self.reply_cb,
+                                                       error_handler=self.error_handler)
         return True
         
     def reply_cb (self, results):
@@ -84,7 +76,7 @@ class TestSqliteMisused (unittest.TestCase):
 
     def loaded_failed_cb (self, error):
         print "Failed loading a file"
-        assert False
+        self.assertTrue (False)
 
     def timeout_cb (self):
         print "Forced timeout after 60 sec."
@@ -92,4 +84,4 @@ class TestSqliteMisused (unittest.TestCase):
         return False
 
 if __name__ == "__main__":
-    unittest.main ()
+    ut.main ()
diff --git a/tests/functional-tests/11-sqlite-batch-misused.py b/tests/functional-tests/11-sqlite-batch-misused.py
old mode 100644
new mode 100755
index b3ad74e..be24044
--- a/tests/functional-tests/11-sqlite-batch-misused.py
+++ b/tests/functional-tests/11-sqlite-batch-misused.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 #
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
@@ -17,25 +17,23 @@
 # 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
+"""
+Test the query while running BatchSparqlUpdate at the same time. This was raising
+some SQLITE_MISUSED errors before.
+"""
+import os, dbus
 import gobject
 from dbus.mainloop.glib import DBusGMainLoop
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
-RESOURCES_IFACE = "org.freedesktop.Tracker1.Resources"
+from common.utils import configuration as cfg
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
 # Number of instances per batch
 BATCH_SIZE = 3000
 
-class TestSqliteBatchMisused (unittest.TestCase):
+class TestSqliteBatchMisused (CommonTrackerStoreTest):
     """
     Send big batchSparqlUpdates and run queries at the same time
     Don't run this script directly, use the bash script "force-sqlite-misused.sh" instead
@@ -43,15 +41,11 @@ class TestSqliteBatchMisused (unittest.TestCase):
     """
     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.batch_counter = 0
         
     def test_queries_while_batch_insert (self):
+        self.assertTrue (os.path.exists ('ttl'))
+        
         for root, dirs, files in os.walk('ttl'):
             for ttl_file in filter (lambda f: f.endswith (".ttl"), files):
                 full_path = os.path.abspath(os.path.join (root, ttl_file))
@@ -68,7 +62,7 @@ class TestSqliteBatchMisused (unittest.TestCase):
                 
                     if counter == BATCH_SIZE:
                         query = "INSERT {" + current_batch + "}"
-                        self.resources.BatchSparqlUpdate (query,
+                        self.tracker.get_tracker_iface ().BatchSparqlUpdate (query,
                                                           timeout=20000,
                                                           reply_handler=self.batch_success_cb,
                                                           error_handler=self.batch_failed_cb)
@@ -85,7 +79,9 @@ class TestSqliteBatchMisused (unittest.TestCase):
 
     def run_a_query (self):
         QUERY = "SELECT ?u ?title WHERE { ?u a nie:InformationElement; nie:title ?title. }"
-        self.resources.SparqlQuery (QUERY, timeout=20000, reply_handler=self.reply_cb, error_handler=self.error_handler)
+        self.tracker.get_tracker_iface ().SparqlQuery (QUERY, timeout=20000,
+                                                       reply_handler=self.reply_cb,
+                                                       error_handler=self.error_handler)
         return True
         
     def reply_cb (self, results):
@@ -110,4 +106,4 @@ class TestSqliteBatchMisused (unittest.TestCase):
         return False
 
 if __name__ == "__main__":
-    unittest.main ()
+    ut.main ()
diff --git a/tests/functional-tests/12-transactions.py b/tests/functional-tests/12-transactions.py
old mode 100644
new mode 100755
index 229f32a..ea02335
--- a/tests/functional-tests/12-transactions.py
+++ b/tests/functional-tests/12-transactions.py
@@ -1,55 +1,57 @@
-import dbus
-import os
-from dbus.mainloop.glib import DBusGMainLoop
-import gobject
-import unittest
+#!/usr/bin/python
+#
+# 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.
+#
+"""
+Make sure that when COMMIT returns, the data is in the DB
+"""
 import time
-import commands, signal
 
-TRACKER = 'org.freedesktop.Tracker1'
-TRACKER_OBJ = '/org/freedesktop/Tracker1/Resources'
+from common.utils import configuration as cfg
+from common.utils.helpers import StoreHelper as StoreHelper
+import unittest2 as ut
+#import unittest as ut
+from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
-TEST_INSTANCE_PATTERN = "test://test-instance-%d"
+TEST_INSTANCE_PATTERN = "test://12-transactions-%d"
 
-def kill_store ():
-    for pid in commands.getoutput("ps -ef| grep tracker-store | awk '{print $2}'").split() :
-        try:
-            print "Killing tracker process", pid
-            os.kill(int(pid), signal.SIGKILL)
-        except OSError, e:
-            if not e.errno == 3 : raise e
+class TrackerTransactionsTest (CommonTrackerStoreTest):
+    """
+    In a loop:
+       1. Inserts a Batch of instances
+       2. Wait for batch commit
+       3. Abort (SIGKILL) the daemon
+       4. Restart daemon a query # of instances
 
-class TrackerTransactionsTest (unittest.TestCase):
+    If the commit was real, all the inserted instances should be there.
+    """
 
     def setUp (self):
-        self.connect_dbus ()
         self.instance_counter = 0
 
-    def connect_dbus (self):
-        dbus_loop = DBusGMainLoop(set_as_default=True)
-        self.bus = dbus.SessionBus (dbus_loop)
-        self.tracker = self.bus.get_object (TRACKER, TRACKER_OBJ)
-        self.iface = dbus.Interface (self.tracker,
-                                     "org.freedesktop.Tracker1.Resources")
-
-
     def tearDown (self):
         print "Tear down (will take some time to remove all resources)"
         delete_sparql = "DELETE { ?u a rdfs:Resource } WHERE { ?u a nmo:Email} \n"
-        self.iface.SparqlUpdate (delete_sparql,
-                                 #reply_handler=self.delete_ok_cb,
-                                 #error_handler=self.delete_error_cb,
-                                 timeout=60000)
+        self.tracker.update (delete_sparql,
+                             timeout=60000)
         self.instance_counter = 0
 
-    def delete_ok_cb (self):
-        print "Delete ok"
-
-    def delete_error_cb (self, error):
-        print "Delete error"
-    
     def insert_and_commit (self, number):
-        print "Preparing the batch sparql"
         insert_sparql = "INSERT {\n"
         for i in range (0, number):
             insert_sparql += "  <" + TEST_INSTANCE_PATTERN % (self.instance_counter) + ">"
@@ -57,39 +59,32 @@ class TrackerTransactionsTest (unittest.TestCase):
             self.instance_counter += 1
 
         insert_sparql += "}"
-        self.iface.BatchSparqlUpdate (insert_sparql)
-        print "Waiting for commit (", number," instances)"
-        start = time.time ()
-        self.iface.BatchCommit ()
-        end = time.time ()
-        print "BatchCommit returned (after %d s.)" % (end - start)
+        self.tracker.batch_update (insert_sparql)
+        #print "Waiting for commit (", number," instances)"
+        #start = time.time ()
+        self.tracker.batch_commit ()
+        #end = time.time ()
+        #print "BatchCommit returned (after %d s.)" % (end - start)
 
-    def count_instances (self):
-        #query_sparql = "SELECT COUNT(?u) WHERE { ?u a nmo:Email. FILTER (REGEX (?u, '%s*'))}" % TEST_INSTANCE_PATTERN[:-3]
-        query_sparql = "SELECT COUNT(?u) WHERE { ?u a nmo:Email.}"
-        return int (self.iface.SparqlQuery (query_sparql)[0][0])
 
     def test_commit_and_abort (self):
 
         for i in range (0, 20):
-            NUMBER_OF_INSTANCES = 100
+            NUMBER_OF_INSTANCES = 1000
             self.insert_and_commit (NUMBER_OF_INSTANCES)
 
-            print "Abort daemon"
-            kill_store ()
-            time.sleep (3)
-            # Reconnect dbus to autoactivate the daemon!
-            self.connect_dbus ()
+            self.system.tracker_store_brutal_restart ()
+            # Reconnect dbus
+            self.tracker.connect ()
             try:
-                print "Wake up the store with a query"
-                results = self.count_instances ()
+                results = self.tracker.count_instances ("nmo:Email")
             except:
                 print "Timeout, probably replaying journal or something (wait 20 sec.)"
                 time.sleep (20)
                 results = self.count_instances ()
 
-            self.assertEqual (results, NUMBER_OF_INSTANCES * (i+1))
-            print "Yep,", results, "results"
+            # Every iteration we are adding new instances in the store!
+            self.assertEquals (results, NUMBER_OF_INSTANCES * (i+1))
 
 if __name__ == "__main__":
-    unittest.main ()
+    ut.main ()



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