[rhmessaging-commits] rhmessaging commits: r1671 - in mgmt/cumin: python/cumin and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Sat Feb 9 13:12:22 EST 2008


Author: justi9
Date: 2008-02-09 13:12:22 -0500 (Sat, 09 Feb 2008)
New Revision: 1671

Added:
   mgmt/cumin/bin/cumin-bench
Modified:
   mgmt/cumin/bin/cumin-test
   mgmt/cumin/python/cumin/test.py
Log:
Moves the benchmarking stuff out of cumin-test and into a dedicated
tool, cumin-bench.

Expands the tests.

Makes cumin-test the test launcher.

Improves the help text of the command line tools.



Added: mgmt/cumin/bin/cumin-bench
===================================================================
--- mgmt/cumin/bin/cumin-bench	                        (rev 0)
+++ mgmt/cumin/bin/cumin-bench	2008-02-09 18:12:22 UTC (rev 1671)
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+
+import sys, os
+from time import time
+from wooly.devel import BenchmarkHarness
+
+from cumin import *
+from cumin.test import *
+from cumin.util import *
+
+def usage():
+    print """Usage: cumin-bench OPTIONS...
+Options:
+    -h, --help            Print this message
+    --data URL            Connect to database at URL
+                          (default postgesql://cumin@localhost/cumin)
+    --hits HITS           Stop at HITS page hits (default 1000)
+    --profile"""
+    sys.exit(1)
+
+def do_main(home, data, hits):
+    app = Cumin(home, data)
+
+    app.enable_debug()
+
+    try:
+        app.check()
+    except Exception, e:
+        if hasattr(e, "message"):
+            print e.message
+
+        sys.exit(1)
+
+    app.init()
+
+    harness = BenchmarkHarness(app)
+
+    try:
+        harness.run(hits)
+    except KeyboardInterrupt:
+        pass
+
+def main():
+    if "-h" in sys.argv or "--help" in sys.argv:
+        usage()
+
+    home = os.environ.get("CUMIN_HOME")
+
+    if not home:
+        home = os.path.normpath("/usr/share/cumin")
+
+    config = Config()
+    config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
+    config.add_param("hits", "i", 1000)
+    config.add_param("profile", "b", False)
+
+    config.load_file(os.path.join(home, "etc", "cumin.conf"))
+    config.load_file(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
+    config.load_args(sys.argv)
+
+    config.prt()
+
+    home = os.environ["CUMIN_HOME"]
+    data = config.get("data")
+    hits = config.get("hits")
+    profile = config.get("profile")
+
+    if profile:
+        from profile import Profile
+        from pstats import Stats
+
+        prof = Profile()
+
+        try:
+            statement = "do_main('%s', '%s', %i)" % (home, data, hits)
+
+	    prof.run(statement)
+
+	    raise KeyboardInterrupt()
+	except KeyboardInterrupt:
+            file = "/tmp/cumin-test-stats"
+
+            prof.dump_stats(file)
+
+	    stats = Stats(file)
+
+	    stats.sort_stats("cumulative").print_stats(15)
+	    stats.sort_stats("time").print_stats(15)
+
+            stats.print_callees("wooly/__init__.*\\(marshal_url_vars\\)")
+            stats.print_callees("wooly/__init__.*\\(path\\)")
+            stats.print_callees("wooly/__init__.*\\(get\\)")
+            stats.print_callees("wooly/__init__.*\\(render\\)")
+
+	    stats.strip_dirs()
+    else:
+        do_main(home, data, hits)
+
+if __name__ == "__main__":
+    main()


Property changes on: mgmt/cumin/bin/cumin-bench
___________________________________________________________________
Name: svn:executable
   + *

Modified: mgmt/cumin/bin/cumin-test
===================================================================
--- mgmt/cumin/bin/cumin-test	2008-02-09 18:09:50 UTC (rev 1670)
+++ mgmt/cumin/bin/cumin-test	2008-02-09 18:12:22 UTC (rev 1671)
@@ -5,22 +5,25 @@
 from wooly.devel import BenchmarkHarness
 
 from cumin import *
-from cumin.demo import *
-from cumin.model import *
+from cumin.test import *
+from cumin.util import *
 
 def usage():
     print """Usage: cumin-test OPTIONS...
 Options:
-    --data DATABASE-URL
-    --bench [HITS]
+    -h, --help            Print this message
+    --data URL            Connect to database at URL
+                          (default postgesql://cumin@localhost/cumin)
+    --broker ADDRESS      Register new test broker at ADDRESS
+                          (default localhost:5672)
     --profile
     --debug"""
     sys.exit(1)
 
-def do_main(home, data, bench_hits, debug):
+def do_main(home, data, broker_host, broker_port, debug):
     app = Cumin(home, data)
 
-    if debug or bench_hits:
+    if debug or bench:
         app.enable_debug()
 
     try:
@@ -33,13 +36,15 @@
 
     app.init()
 
-    harness = BenchmarkHarness(app)
+    env = TestEnvironment(app, broker_host, broker_port)
+    env.init();
 
-    try:
-        harness.run(bench_hits)
-    except KeyboardInterrupt:
-        pass
+    main = MainTest(env)
 
+    session = TestSession(env)
+    main.run(session)
+    session.report(sys.stdout)
+
 def main():
     if "-h" in sys.argv or "--help" in sys.argv:
         usage()
@@ -51,9 +56,8 @@
 
     config = Config()
     config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
-    config.add_param("port", "i", 80)
+    config.add_param("broker", "s", "localhost:5672")
     config.add_param("debug", "b", True)
-    config.add_param("bench", "i", 1000)
     config.add_param("profile", "b", False)
 
     config.load_file(os.path.join(home, "etc", "cumin.conf"))
@@ -64,10 +68,12 @@
 
     home = os.environ["CUMIN_HOME"]
     data = config.get("data")
-    bench = config.get("bench")
+    broker = config.get("broker")
+    debug = config.get("debug")
     profile = config.get("profile")
-    debug = config.get("debug")
 
+    host, port = parse_broker_addr(broker)
+
     if profile:
         from profile import Profile
         from pstats import Stats
@@ -75,8 +81,8 @@
         prof = Profile()
 
         try:
-            statement = "do_main('%s', '%s', %i, %r)" \
-                % (home, data, bench, debug)
+            statement = "do_main('%s', '%s', %s, %i, %r)" \
+                % (home, data, host, port, debug)
 
 	    prof.run(statement)
 
@@ -98,7 +104,7 @@
 
 	    stats.strip_dirs()
     else:
-        do_main(home, data, bench, debug)
+        do_main(home, data, host, port, debug)
 
 if __name__ == "__main__":
     main()

Modified: mgmt/cumin/python/cumin/test.py
===================================================================
--- mgmt/cumin/python/cumin/test.py	2008-02-09 18:09:50 UTC (rev 1670)
+++ mgmt/cumin/python/cumin/test.py	2008-02-09 18:12:22 UTC (rev 1671)
@@ -3,16 +3,36 @@
 from traceback import print_exc
 from datetime import datetime
 from wooly import Session
+import qpid, quirk
 
 from cumin import Cumin
+from util import *
 import time
 
 class TestEnvironment(object):
-    def __init__(self, app, broker_address):
+    def __init__(self, app, broker_host, broker_port):
         self.app = app
-        self.broker_address = broker_address
+
+        self.broker_client = quirk.Client(broker_host, broker_port)
+        self.broker_queue = quirk.Queue("cumin.queue")
+        self.broker_exchange = quirk.Exchange("cumin.exchange")
+
         self.broker = None
+        self.queue = None
+        self.exchange = None
 
+    def init(self):
+        self.broker_client.login("guest", "guest")
+        
+        session = quirk.Session(self.broker_client)
+        session.open()
+
+        try:
+            self.broker_queue.declare(session)
+            self.broker_exchange.declare(session)
+        finally:
+            session.close()
+
 class TestSession(object):
     def __init__(self, env):
         self.env = env
@@ -34,7 +54,7 @@
     def report(self, out):
         out.write("Succcesses (%i)\n" % len(self.successes))
 
-        for succcess in self.successes:
+        for success in self.successes:
             out.write("    %s\n" % success)
 
         out.write("Failures (%i)\n" % len(self.failures))
@@ -63,6 +83,7 @@
     def run(self, session):
         try:
             self.do_run(session)
+            session.add_success(self, "OK", None)
         except Exception, e:
             session.add_failure(self, e.message, e)
 
@@ -102,7 +123,9 @@
         name = "test-" + datetime.now().strftime("%Y-%m-%d-%H-%M")
 
         form.names.get(s).append(name)
-        form.addrs.get(s).append(self.env.broker_address)
+        addr = "%s:%s" % \
+            (self.env.broker_client.host, self.env.broker_client.port)
+        form.addrs.get(s).append(addr)
         form.groups.get(s).append(None)
         form.submit.set(s, True)
  
@@ -118,9 +141,9 @@
 
         html = page.render(s, None)
 
-        file = open("BrokerTest.%s.html" % name, "w")
-        file.write(html)
-        file.close()
+        #file = open("BrokerTest.%s.html" % name, "w")
+        #file.write(html)
+        #file.close()
 
         reg = BrokerRegistration.selectBy(name=name)[0]
 
@@ -132,35 +155,26 @@
 
 class QueueTest(Test):
     def do_run(self, session):
-        print self.env.broker
+        def predicate():
+            for item in Vhost.selectBy(broker=self.env.broker, name="/"):
+                return True
 
+        wait(predicate)
+
+        vhost = Vhost.selectBy(broker=self.env.broker, name="/")[0]
+        name = self.env.broker_queue.name
+        self.queue = Queue.selectBy(vhost=vhost, name=name)[0]
+
+        print self.queue
+
 def wait(predicate, timeout=30):
     start = time.time()
 
     while True:
-        time.sleep(1)
-
         if predicate():
             return
 
         if time.time() - start > timeout:
-            print "Operation timed out"
-            return
+            raise Exception("Operation timed out")
 
-def main():
-    home = os.environ["CUMIN_HOME"]
-    data = "postgresql://cumin@localhost/cumin"
-    app = Cumin(home, data)
-
-    app.init()
-
-    env = TestEnvironment(app, "qpid-test3.lab.boston.redhat.com")
-    session = TestSession(env)
-    main = MainTest(env)
-
-    main.run(session)
-
-    session.report(sys.stdout)
-
-if __name__ == "__main__":
-    main()
+        time.sleep(1)




More information about the rhmessaging-commits mailing list