[tracker] Add stress test programs



commit 6eac4fb9715a3ed01d6a7e4e36d8c05a76eefd7d
Author: Ivan Frade <ifrade src gnome org>
Date:   Tue Apr 14 11:00:15 2009 +0200

    Add stress test programs
---
 tests/estress/abstract_engine.py      |   99 +++++++++++++++++++++++++++++++++
 tests/estress/abstract_text_engine.py |   81 +++++++++++++++++++++++++++
 tests/estress/client.py               |   95 +++++++++++++++++++++++++++++++
 tests/estress/mock_engine.py          |   75 +++++++++++++++++++++++++
 tests/estress/options.py              |   78 ++++++++++++++++++++++++++
 tests/estress/rss_engine.py           |   83 +++++++++++++++++++++++++++
 tests/estress/wh_engine.py            |   84 ++++++++++++++++++++++++++++
 7 files changed, 595 insertions(+), 0 deletions(-)

diff --git a/tests/estress/abstract_engine.py b/tests/estress/abstract_engine.py
new file mode 100644
index 0000000..d3304d3
--- /dev/null
+++ b/tests/estress/abstract_engine.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python2.5
+#
+# Random input generator for tracker.
+# Abstract class doing almost all work. Subclasses must
+#     provide some methods to make this functional.
+# Graphical version (GTK)
+#
+# Copyright (C) 2009 Nokia <urho konttori nokia com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+#
+import gobject
+import gtk
+import dbus
+import dbus.service
+from dbus.mainloop.glib import DBusGMainLoop
+from abstract_text_engine import AbstractTextEngine
+import time
+import sys
+
+TRACKER = 'org.freedesktop.Tracker'
+TRACKER_OBJ = '/org/freedesktop/Tracker/Resources'
+
+#
+# Abstract class that does the job.
+# Subclasses must implement some methods.
+#
+class AbstractEngine (gtk.Window, AbstractTextEngine):
+
+    def __init__ (self, name, period, msgsize, timeout):
+        gtk.Window.__init__ (self)
+        AbstractTextEngine.__init__ (self, name, period, msgsize, timeout)
+        
+        self.publicname = name
+        self.msgsize = msgsize
+        self.period = period
+
+        # UI, sweet UI
+        vbox = gtk.VBox ()
+    
+        title_label = gtk.Label (name)
+        freq_label = gtk.Label ("Period: ")
+        freq_adj = gtk.Adjustment (period, 1, 100, 1, 10, 0)
+        self.freq = gtk.SpinButton (freq_adj)
+        size_label = gtk.Label ("# Items: ")
+        size_adj = gtk.Adjustment (msgsize, 1, 100, 1, 10, 0)
+        self.size = gtk.SpinButton (size_adj)
+
+        conf = gtk.HBox ()
+        conf.pack_start (title_label, padding=20)
+        conf.pack_start (freq_label)
+        conf.pack_start (self.freq)
+        conf.pack_start (size_label)
+        conf.pack_start (self.size)
+
+        start = gtk.Button (stock=gtk.STOCK_MEDIA_PLAY)
+        start.connect ("clicked", self.play_cb)
+        stop = gtk.Button (stock=gtk.STOCK_MEDIA_STOP)
+        stop.connect ("clicked", self.stop_cb)
+        conf.pack_start (start)
+        conf.pack_start (stop)
+        
+        vbox.pack_start (conf)
+        
+        self.desc_label = gtk.Label ("No running")
+        vbox.pack_start (self.desc_label)
+
+        self.add (vbox)
+        self.connect ("destroy", gtk.main_quit)
+        self.show_all ()
+
+    def play_cb (self, widget):
+        self.msgsize = int(self.size.get_value ())
+        self.period = int(self.freq.get_value ())
+        self.desc_label.set_label (self.get_running_label ())
+        self.run ()
+
+    def stop_cb (self, widget):
+        self.desc_label.set_label ("No running")
+        self.stop ()
+
+    def run (self):
+        self.desc_label.set_label (self.get_running_label ())
+        self.callback_id = gobject.timeout_add (self.period * 1000,
+                                                self.send_data_cb)
+
diff --git a/tests/estress/abstract_text_engine.py b/tests/estress/abstract_text_engine.py
new file mode 100644
index 0000000..3d113b6
--- /dev/null
+++ b/tests/estress/abstract_text_engine.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python2.5
+#
+# Random input generator for tracker.
+# Abstract class doing almost all work. Subclasses must
+#     provide some methods to make this functional.
+# Text version.
+#
+# Copyright (C) 2009 Nokia <urho konttori nokia com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+#
+import gobject
+import dbus
+import dbus.service
+from dbus.mainloop.glib import DBusGMainLoop
+import time
+import sys
+
+TRACKER = 'org.freedesktop.Tracker'
+TRACKER_OBJ = '/org/freedesktop/Tracker/Resources'
+
+#
+# Abstract class that does the job.
+# Subclasses must implement some methods.
+#
+class AbstractTextEngine:
+
+    def __init__ (self, name, period, msgsize, timeout):
+
+        self.publicname = name
+        self.msgsize = msgsize
+        self.period = period
+
+        # DBus connection
+        bus = dbus.SessionBus ()
+        self.tracker = bus.get_object (TRACKER, TRACKER_OBJ)
+        self.iface = dbus.Interface (self.tracker,
+                                     "org.freedesktop.Tracker.Resources")
+        if (timeout > 0):
+            self.call = 0
+            gobject.timeout_add (timeout * 1000,
+                                 self.exit_cb)
+
+    def exit_cb (self):
+        sys.exit (0)
+
+    def run (self):
+        self.callback_id = gobject.timeout_add (self.period * 1000,
+                                                self.send_data_cb)
+
+    def stop (self):
+        gobject.source_remove (self.callback_id)
+        self.callback_id = 0
+
+    def send_data_cb (self):
+        sparql = self.get_insert_sparql ()
+        self.iface.SparqlUpdate (sparql)
+        print int(time.time()), self.msgsize, self.publicname
+        return True
+
+
+    def get_insert_sparql (self):
+        print "Implement this method in a subclass!!!"
+        assert False
+        
+    def get_running_label (self):
+        print "Implement this method in a subclass!!!"
+        assert False
diff --git a/tests/estress/client.py b/tests/estress/client.py
new file mode 100755
index 0000000..b65949e
--- /dev/null
+++ b/tests/estress/client.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python2.5
+#
+# Random input generator for tracker.
+#  Client querying tracker.
+#
+# Copyright (C) 2009 Nokia <urho konttori nokia com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+#
+import gobject
+import gtk
+import time
+import dbus
+import getopt
+import sys
+
+TRACKER = 'org.freedesktop.Tracker'
+TRACKER_OBJ = '/org/freedesktop/Tracker/Resources'
+
+SPARQL_QUERY = """
+    SELECT ?entry ?title ?date ?isRead WHERE {
+      ?entry a nmo:FeedMessage ;
+         nie:title ?title ;
+         nie:contentLastModified ?date .
+    OPTIONAL {
+       ?entry nmo:isRead ?isRead.
+    }
+    } ORDER BY DESC(?date) LIMIT %s
+"""
+
+bus = dbus.SessionBus ()
+obj = bus.get_object (TRACKER, TRACKER_OBJ)
+iface = dbus.Interface (obj, "org.freedesktop.Tracker.Resources")
+
+def run_query ():
+    start = time.time ()
+    results = iface.SparqlQuery (SPARQL_QUERY % ("10"))
+    end = time.time ()
+    print int (time.time()), "%f" % (end - start)
+    return True
+
+def exit_cb ():
+    sys.exit (0)
+
+def usage ():
+    print "Usage:"
+    print "  client.py [OPTION...] - Run periodically a query on tracker"
+    print ""
+    print "Help Options:"
+    print "  -h, --help             Show help options"
+    print ""
+    print "Application Options:"
+    print "  -p, --period=NUM       Time (in sec) between queries"
+    print "  -t, --timeout=NUM      Switch off the program after NUM seconds"
+    print ""
+
+
+if __name__ == "__main__":
+
+    opts, args = getopt.getopt(sys.argv[1:],
+                               "p:t:h",
+                               ["period", "timeout", "help"])
+    period = 1
+    timeout = 0
+
+    for o, a in opts:
+        if o in ["-p", "--period"]:
+            period = int (a)
+        if o in ["-t", "--timeout"]:
+            timeout = int (a)
+        if o in ["-h", "--help"]:
+            usage ()
+            sys.exit (0)
+            
+    
+    gobject.timeout_add (period * 1000, run_query)
+    if (timeout > 0):
+        gobject.timeout_add (timeout *1000, exit_cb)
+    gtk.main ()
+
+    
+    
diff --git a/tests/estress/mock_engine.py b/tests/estress/mock_engine.py
new file mode 100644
index 0000000..ddcefd2
--- /dev/null
+++ b/tests/estress/mock_engine.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python2.5
+#
+# Random input generator for tracker.
+# Example to implement one data generator.
+#
+# Copyright (C) 2009 Nokia <urho konttori nokia com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+#
+import gobject
+import getopt, sys
+import options
+
+options = options.parse_options (graphic_mode=False, period=1, msgsize=2, timeout=0)
+
+if options['graphic_mode']:
+    import gtk
+    from abstract_engine import AbstractEngine
+    superKlass = AbstractEngine
+    mainloop = gtk.main
+else:
+    from abstract_text_engine import AbstractTextEngine
+    superKlass = AbstractTextEngine
+    mainloop = gobject.MainLoop().run
+
+class MockEngine (superKlass):
+
+    def __init__ (self, name, period, msgsize, timeout):
+        """
+        self.publicname
+        self.msgsize
+        self.period contains these values for the subclasses
+        """
+        superKlass.__init__ (self, name, period, msgsize, timeout)
+        self.run ()
+        
+    def get_insert_sparql (self):
+        """
+        This method returns an string with the sparQL we will send
+        to tracker.SparqlUpdate method
+        """
+        return "INSERT { put here your triplets }"
+
+    def get_running_label (self):
+        """
+        This method returns the string showing the current status
+        when the engine is running
+        """
+        return "%s sends %s items every %s sec." % (self.publicname,
+                                                          self.msgsize,
+                                                          self.period)
+
+
+if __name__ == "__main__":
+
+    gobject.set_application_name ("Here the title of the window")
+    engine = MockEngine ("My mock stuff",
+                         options['period'],
+                         options['msgsize'],
+                         options['timeout'])
+    mainloop ()
+
diff --git a/tests/estress/options.py b/tests/estress/options.py
new file mode 100644
index 0000000..abd6017
--- /dev/null
+++ b/tests/estress/options.py
@@ -0,0 +1,78 @@
+#!/usr/bin/env python2.5
+#
+# Random input generator for tracker.
+#  Command line options parsing
+#
+# Copyright (C) 2009 Nokia <urho konttori nokia com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+#
+import getopt
+import sys
+
+def usage ():
+    print "Usage:"
+    print "  xxx.py [OPTION...] - Input data into tracker"
+    print ""
+    print "Help Options:"
+    print "  -h, --help             Show help options"
+    print ""
+    print "Application Options:"
+    print "  -g, --graphics         Enable GTK interface"
+    print "  -p, --period=NUM       Time (in sec) between insertion message"
+    print "  -s, --size=NUM         Amount of instances in the message"
+    print "  -t, --timeout=NUM      Switch off the program after NUM seconds"
+    print ""
+
+
+def parse_options (graphic_mode=False, period=1, msgsize=1, timeout=0):
+    try:
+        opts, args = getopt.getopt(sys.argv[1:],
+                                   "gp:s:t:h",
+                                   ["graphics", "period", "size", "timeout", "help"])
+    except getopt.GetoptError, err:
+        # print help information and exit:
+        print str (err) # will print something like "option -a not recognized"
+        usage ()
+        sys.exit (2)
+
+    options = { "graphic_mode" : graphic_mode ,
+                "period"  : period,
+                "msgsize" : msgsize,
+                "timeout" : timeout }
+
+
+    for o, a in opts:
+        if o in ["-g", "--graphics"]:
+            options ['graphic_mode'] = True
+            
+        elif o in ["-p", "--period"]:
+            options ['period'] = int(a)
+            
+        elif o in ["-s", "--size"]:
+            options ['msgsize'] = int (a)
+            
+        elif o in ["-t", "--timeout"]:
+            options ['timeout'] = int (a)
+        elif o in ["-h", "--help"]:
+            usage ()
+            sys.exit (-1)
+        else:
+            usage ()
+            assert False, "unhandled option"
+
+    return options
+
diff --git a/tests/estress/rss_engine.py b/tests/estress/rss_engine.py
new file mode 100755
index 0000000..9faeac5
--- /dev/null
+++ b/tests/estress/rss_engine.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python2.5
+#
+# Random input generator for tracker.
+# Implementation simulating RSS feeds input.
+#
+# Copyright (C) 2009 Nokia <urho konttori nokia com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+#
+import gobject
+import datetime, random
+import sys
+import options
+
+options = options.parse_options (graphic_mode=False, period=1, msgsize=2, timeout=0)
+
+if options['graphic_mode']:
+    import gtk
+    from abstract_engine import AbstractEngine
+    superKlass = AbstractEngine
+    mainloop = gtk.main
+else:
+    from abstract_text_engine import AbstractTextEngine
+    superKlass = AbstractTextEngine
+    mainloop = gobject.MainLoop().run
+
+class RSSEngine (superKlass):
+
+    def __init__ (self, name, period, msgsize, timeout=0):
+        superKlass.__init__ (self, name, period, msgsize, timeout)
+        self.run ()
+        
+    def get_insert_sparql (self):
+        triplets = ""
+        for i in range (0, self.msgsize):
+            triplets += self.gen_new_post ()
+
+        query = "INSERT {" + triplets + "}"
+        return query
+
+    def get_running_label (self):
+        return "%s sends %s rss entries every %s sec." % (self.publicname,
+                                                          self.msgsize,
+                                                          self.period)
+
+    def gen_new_post (self):
+        SINGLE_POST = """
+        <%s> a nmo:FeedMessage ;
+        nie:contentLastModified "%s" ;
+        nmo:communicationChannel <http://maemo.org/news/planet-maemo/atom.xml>;
+        nie:title "%s".
+        """
+        today = datetime.datetime.today ()
+        date = today.isoformat () + "+00:00"
+        post_no = str(random.randint (100, 1000000))
+        uri = "http://test.maemo.org/feed/"; + post_no
+        title = "Title %s" % (post_no)
+        
+        return SINGLE_POST % (uri, date, title)
+        
+
+if __name__ == "__main__":
+
+    gobject.set_application_name ("Feeds engine/signals simulator")
+    engine = RSSEngine ("RSS",
+                        options['period'],
+                        options['msgsize'],
+                        options['timeout'])
+    mainloop ()
+
diff --git a/tests/estress/wh_engine.py b/tests/estress/wh_engine.py
new file mode 100755
index 0000000..e16f846
--- /dev/null
+++ b/tests/estress/wh_engine.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python2.5
+#
+# Random input generator for tracker.
+#   Implementation simulating Web History input.
+#
+# Copyright (C) 2009 Nokia <urho konttori nokia com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+# USA
+#
+import gobject
+import datetime, random
+import options, sys
+
+options = options.parse_options (graphic_mode=False, period=2, msgsize=1, timeout=0)
+
+if options['graphic_mode']:
+    import gtk
+    from abstract_engine import AbstractEngine
+    superKlass = AbstractEngine
+    mainloop = gtk.main
+else:
+    from abstract_text_engine import AbstractTextEngine
+    superKlass = AbstractTextEngine
+    mainloop = gobject.MainLoop().run
+
+
+class WebBrowserEngine (superKlass):
+
+    def __init__ (self, name, period, msgsize, timeout):
+        superKlass.__init__ (self, name, period, msgsize, timeout)
+        self.run ()
+        
+    def get_insert_sparql (self):
+        sparql = ""
+        for i in range (0, self.msgsize):
+            sparql += self.get_random_webhistory_click ()
+        return "INSERT {" + sparql + "}"
+
+    def get_running_label (self):
+        """
+        This method returns the string showing the current status
+        when the engine is running
+        """
+        return "%s insert %s clicks every %s sec." % (self.publicname,
+                                                      self.msgsize,
+                                                      self.period)
+
+    def get_random_webhistory_click (self):
+        TEMPLATE = """<%s> a nfo:WebHistory;
+            nie:title "This is one random title";
+            nie:contentCreated "%s";
+            nfo:domain "%s";
+            nfo:uri "%s".
+        """
+        today = datetime.datetime.today ()
+        date = today.isoformat () + "+00:00"
+        click_no = str(random.randint (100, 1000000))
+        resource = "urn:uuid:1234" + click_no
+        uri = "http://www.maemo.org/"; + click_no
+        domain = "http://www.maemo.org";
+        return TEMPLATE % (resource, date, domain, uri)
+
+if __name__ == "__main__":
+
+    gobject.set_application_name ("Web Browser saving clicks (inefficiently)")
+    engine = WebBrowserEngine ("Naughty Web Browser",
+                               options['period'],
+                               options['msgsize'],
+                               options['timeout'])
+    mainloop ()
+



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