You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2010/02/25 23:07:12 UTC

svn commit: r916473 - /qpid/trunk/qpid/cpp/src/tests/verify_cluster_objects

Author: aconway
Date: Thu Feb 25 22:07:12 2010
New Revision: 916473

URL: http://svn.apache.org/viewvc?rev=916473&view=rev
Log:
Minor improvements to verify_cluster_objects.

Cached IDs, runs about 3x faster.

Modified:
    qpid/trunk/qpid/cpp/src/tests/verify_cluster_objects   (contents, props changed)

Modified: qpid/trunk/qpid/cpp/src/tests/verify_cluster_objects
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/verify_cluster_objects?rev=916473&r1=916472&r2=916473&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/verify_cluster_objects (original)
+++ qpid/trunk/qpid/cpp/src/tests/verify_cluster_objects Thu Feb 25 22:07:12 2010
@@ -75,6 +75,12 @@
                 bestAddr = addrPort
         return bestAddr
 
+class ObjectId:
+    """Object identity, use for dictionaries by object id"""
+    def __init__(self, object): self.object = object
+    def __eq__(self, other): return self.object is other.object
+    def __hash__(self): return hash(id(self.object))
+
 class Broker(object):
     def __init__(self, qmf, broker):
         self.broker = broker
@@ -94,6 +100,7 @@
             self.uptime = 0
         self.tablesByName = {}
         self.package = "org.apache.qpid.broker"
+        self.id_cache = {}              # Cache for getAbstractId
 
     def getUrl(self):
         return self.broker.getUrl()
@@ -114,13 +121,14 @@
     #
     def getAbstractId(self, object):
       """ return a string the of the hierarchical name """
+      if (ObjectId(object) in self.id_cache): return self.id_cache[ObjectId(object)]
       global _debug_recursion
       result = u""
       valstr = u""
       _debug_recursion += 1
       debug_prefix = _debug_recursion
       if (_verbose > 9):
-          print debug_prefix, "  enter gai: props ", self._properties
+          print debug_prefix, "  enter gai: props ", object._properties
       for property, value in object._properties:
 
           # we want to recurse on things which are refs.  we tell by
@@ -138,6 +146,7 @@
 
           if property.name == "systemRef":
               _debug_recursion -= 1
+              self.id_cache[ObjectId(object)] = ""
               return ""
 
           if property.index:
@@ -176,6 +185,7 @@
           if (_verbose > 9):
               print debug_prefix, "    id ", self, " -> ", result
       _debug_recursion -= 1
+      self.id_cache[ObjectId(object)] = result
       return result
 
     def loadTable(self, cls):
@@ -196,13 +206,12 @@
             # error (ie, the name-generation code is busted) if we do
             key = self.getAbstractId(obj)
             if key in self.tablesByName[cls.getClassName()]:
-                print "internal error: collision for %s on key %s\n" % (obj, key)
-                sys.exit(1)
+                raise Exception("internal error: collision for %s on key %s\n"
+                                % (obj, key))
                 
-            self.tablesByName[cls.getClassName()][self.getAbstractId(obj)] = obj
-#            sys.exit(1)
+            self.tablesByName[cls.getClassName()][key] = obj
             if _verbose > 1:
-                print "   ", obj.getObjectId(), " ", obj.getIndex(), " ", self.getAbstractId(obj)
+                print "   ", obj.getObjectId(), " ", obj.getIndex(), " ", key
 
 
 class BrokerManager:
@@ -253,9 +262,10 @@
                     raise Exception("Invalid URL 2")
                 addrList.append((tokens[1], tokens[2]))
 
-            # Find the address in the list that is most likely to be in the same subnet as the address
-            # with which we made the original QMF connection.  This increases the probability that we will
-            # be able to reach the cluster member.
+            # Find the address in the list that is most likely to be
+            # in the same subnet as the address with which we made the
+            # original QMF connection.  This increases the probability
+            # that we will be able to reach the cluster member.
 
             best = hostAddr.bestAddr(addrList)
             bestUrl = best[0] + ":" + best[1]
@@ -284,8 +294,7 @@
                 if _verbose > 0:
                     print "   ", b
         else:
-            print "Failed - Not a cluster"
-            sys.exit(1)
+            raise Exception("Failed - Not a cluster")
 
         failures = []
 
@@ -348,11 +357,10 @@
             print "Failures:"
             for failure in failures:
                 print "  %s" % failure
-            sys.exit(1)
+            raise Exception("Failures")
 
         if _verbose > 0:
             print "Success"
-        sys.exit(0)
 
 ##
 ## Main Program

Propchange: qpid/trunk/qpid/cpp/src/tests/verify_cluster_objects
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org