📄 testpythonmarshallingperf.py
字号:
############################################################################## Software Testing Automation Framework (STAF) ## (C) Copyright IBM Corp. 2006 ## ## This software is licensed under the Common Public License (CPL) V1.0. ###############################################################################===========================================================================# TestPythonMarshallingPerf - Tests performance of Python marshalling and# formatObject#===========================================================================# Accepts: The number of entries to marshall# Returns: 0 if successful; non-zero if not successful#===========================================================================# Purpose: Create some marshalled data for a specified number of entries to# test performance of Python marshalling and formatObject.## Expected Result:"""C:\dev\sf\src\staf\lang\python>python TestPythonMarshallingPerf.py 100000*************************************************************Test for Errors in Marshalling, FormatObject, and Unmarshall************************************************************Test for errors using a list with 1 entries of map class objects with 2 keysVerify you can format, marshall, and unmarshall an object that references a mapclass but does not define the map class in the context:FormatObject result without map class definition in context:[ { staf-map-class-name: STAF/Test/MyMapClassDefinition key1 : Value 1 1 key2 : Value 2 1 }]Marshalled string:@SDT/[1:127:@SDT/{:116::19:staf-map-class-name@SDT/$S:30:STAF/Test/MyMapClassDefinition:4:key1@SDT/$S:9:Value 1 1:4:key2@SDT/$S:9:Value 2 1Length of marshalled string: 139Unmarshall and call FormatObject on the context:[ { staf-map-class-name: STAF/Test/MyMapClassDefinition key1 : Value 1 1 key2 : Value 2 1 }]Print root list object as a formatted string:[ { staf-map-class-name: STAF/Test/MyMapClassDefinition key1 : Value 1 1 key2 : Value 2 1 }]FormatObject result with wrong map class definition in context:[ { staf-map-class-name: STAF/Test/MyMapClassDefinition key1 : Value 1 1 key2 : Value 2 1 }]Marshalling string with wrong map class definition in context:@SDT/*:289:@SDT/{:139::13:map-class-map@SDT/{:111::31:STAF/Test/MyMapClassDefinition2@SDT/{:66::4:keys@SDT/[0:0::4:name@SDT/$S:31:STAF/Test/MyMapClassDefinition2@SDT/[1:127:@SDT/{:116::19:staf-map-class-name@SDT/$S:30:STAF/Test/MyMapClassDefinition:4:key1@SDT/$S:9:Value 1 1:4:key2@SDT/$S:9:Value 2 1Length of marshalled data: 300Unmarshall and call FormatObject on the context:[ { staf-map-class-name: STAF/Test/MyMapClassDefinition key1 : Value 1 1 key2 : Value 2 1 }]FormatObject result with map class definition in context:[ { Key #1: Value 1 1 Key #2: Value 2 1 }]Add a map object created for the map class definition with no keysVerify you can format, marshall, and unmarshall an object that references a mapclass without any keys defined:FormatObject Result:[ { Key #1: Value 1 1 Key #2: Value 2 1 } { }]MarshalledString:@SDT/*:525:@SDT/{:375::13:map-class-map@SDT/{:347::31:STAF/Test/MyMapClassDefinition2@SDT/{:66::4:keys@SDT/[0:0::4:name@SDT/$S:31:STAF/Test/MyMapClassDefinition2:30:STAF/Test/MyMapClassDefinition@SDT/{:191::4:keys@SDT/[2:124:@SDT/{:52::12:display-name@SDT/$S:6:Key #1:3:key@SDT/$S:4:key1@SDT/{:52::12:display-name@SDT/$S:6:Key #2:3:key@SDT/$S:4:key2:4:name@SDT/$S:30:STAF/Test/MyMapClassDefinition@SDT/[2:127:@SDT/%:72::30:STAF/Test/MyMapClassDefinition@SDT/$S:9:Value 1 1@SDT/$S:9:Value 2 1@SDT/%:35::31:STAF/Test/MyMapClassDefinition2Length of marshalled data: 536Unmarshall and call FormatObject on the context[ { Key #1: Value 1 1 Key #2: Value 2 1 } { }]Verify you can format, marshall, and unmarshall an object that references a mapclass without a key that it doesn't provide an entry for:FormatObject Result:[ { Key #1: Value 1 1 Key #2: Value 2 1 } { Key YYY: <None> Key XXX: ValueXXX }]MarshalledString:@SDT/*:686:@SDT/{:508::13:map-class-map@SDT/{:480::31:STAF/Test/MyMapClassDefinition2@SDT/{:198::4:keys@SDT/[2:130:@SDT/{:55::12:display-name@SDT/$S:7:Key YYY:3:key@SDT/$S:6:KeyYYY@SDT/{:55::12:display-name@SDT/$S:7:Key XXX:3:key@SDT/$S:6:KeyXXX:4:name@SDT/$S:31:STAF/Test/MyMapClassDefinition2:30:STAF/Test/MyMapClassDefinition@SDT/{:191::4:keys@SDT/[2:124:@SDT/{:52::12:display-name@SDT/$S:6:Key #1:3:key@SDT/$S:4:key1@SDT/{:52::12:display-name@SDT/$S:6:Key #2:3:key@SDT/$S:4:key2:4:name@SDT/$S:30:STAF/Test/MyMapClassDefinition@SDT/[2:155:@SDT/%:72::30:STAF/Test/MyMapClassDefinition@SDT/$S:9:Value 1 1@SDT/$S:9:Value 2 1@SDT/%:63::31:STAF/Test/MyMapClassDefinition2@SDT/$0:0:@SDT/$S:8:ValueXXXLength of marshalled data: 697Unmarshall and call FormatObject onn the context[ { Key #1: Value 1 1 Key #2: Value 2 1 } { Key YYY: <None> Key XXX: ValueXXX }]**************************************************************Test Performance for Marshalling, FormatObject, and Unmarshall**************************************************************Test using a list with 100000 entriesFormatObject starting...FormatObject Elapsed Time: 1 secondsMarshalling starting...Marshalling Elapsed Time: 1 secondsLength of marshalled string: 2888911Unmarshalling starting...Unmarshalling Elapsed Time: 2 secondsTest using a map with 100000 entriesFormatObject starting...FormatObject Elapsed Time: 2 secondsMarshalling starting...Marshalling Elapsed Time: 2 secondsLength of marshalled string: 3167795Unmarshalling starting...Unmarshalling Elapsed Time: 3 secondsTest using a list with 10000 entries of map class objects each with 10 keysFormatObject starting...FormatObject Elapsed Time: 3 secondsMarshalling starting...Marshalling Elapsed Time: 2 secondsLength of marshalled string: 2749668Unmarshalling starting...Unmarshalling Elapsed Time: 3 seconds"""#===========================================================================from PySTAF import *import stringimport sysimport timedef main(): # Verify the command line arguments args = sys.argv if len(args) != 2: print "Usage: python TestPythonMarshallingPerf <number>" sys.exit(1) entries = 1 ############################################################# # Test for errors in marshalling/unmarshalling/formatObject # ############################################################# print "\n*************************************************************" print "Test for Errors in Marshalling, FormatObject, and Unmarshall" print "************************************************************" numKeys = 2; print "\nTest for errors using a list with %s entries of map class objects with %s keys" % (entries, numKeys) # Define a map class with 2 keys myMapClass = STAFMapClassDefinition('STAF/Test/MyMapClassDefinition') for k in range(1, numKeys + 1): myMapClass.addKey("key%s" % (k), "Key #%s" % (k)) # Create a marshalling context mc = STAFMarshallingContext() resultList = [] for i in range(1, entries + 1): # Create an instance of this map class definition and assign # data to the map class instance theMap = myMapClass.createInstance() for j in range(1, numKeys + 1): theMap["key%s" % (j)] = "Value %s %s" % (j, i)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -