def __call__(self): try: test = Test(TestID.PTG_ASYNC, "StoRM ptg-async without release or file transfer") test.record(do_prepare_to_get) do_prepare_to_get(self.SRMclient) except Exception: error("Error executing ptg-async: %s" % traceback.format_exc())
def __call__(self): test = Test(1, "StoRM srmLs") client = SRMClientFactory.newSRMClient(SRM_ENDPOINT, PROXY_FILE) surl_range = range(1, random.randrange(NUM_FILES)) surls = [] for i in surl_range: surls.append(SURL_PREFIX + "/f" + str(i)) test.record(client) log("Listing %d surls..." % surl_range[-1]) res = client.srmLs(surls, MAX_WAITING_TIME_IN_MSEC) log("List result: %s: %s" % (res.returnStatus.statusCode, res.returnStatus.explanation)) statuses = res.getDetails().getPathDetailArray() for s in statuses: log("%s -> %s" %(s.getPath(), s.getStatus().getStatusCode()))
class Instrumented(object): next_test = 1 def __init__(self, partition): grinder.logger.output('Selected dataset %s' % dataset_url) self.test = Test(Instrumented.next_test, 'Partition into %d slices' % partition) self.test_tot = Test(100 + Instrumented.next_test, 'Total for %d slices' % partition) Instrumented.next_test += 1 self.requests = generate_subset_requests(variable, {'time': partition}) # Create a fresh callable to instrument def f(req): return req() self.test.record(f) self.f = f def f2(): for req in self.requests: grinder.logger.output('Requesting %s' % req) data = self.f(req) grinder.logger.output('Data returned of shape %s' % data.shape) self.test_tot.record(f2) self.f2 = f2 def __call__(self): self.f2()
def __call__(self): try: test = Test(TestID.MIX_DAV, "StoRM Mix WebDAV test") test.record(mix_dav) mix_dav(self.HTTP_Client, self.local_file_path) except Exception, e: error("Error executing mix-dav: %s" % traceback.format_exc())
def __call__(self): test = Test(TestID.ATLAS_RENAMING, "Atlas renaming") test.record(atlas_renaming) debug("WEBDAV_ENDPOINT: %s" % WEBDAV_ENDPOINT) atlas_renaming(HTTP_CLIENT)
def __call__(self): try: test = Test(TestID.TXFER_OUT, "StoRM file-transfer OUT") test.record(file_transfer_out) file_transfer_out(self.SRMclient, self.HTTPclient, self.local_file_path, self.target_file_surl, self.transfer_protocol) cleanup(self.SRMclient, self.target_file_surl) except Exception, e: error("Error executing file-transfer-out: %s" % traceback.format_exc())
def __call__(self): if (grinder.runNumber == 0): self.initBarrier.await() try: test = Test(TestID.GET_DAV, "StoRM GET WebDAV test") test.record(get_dav) get_dav(random.choice(FILE_URLS)) except Exception, e: error("Error executing get-dav: %s" % traceback.format_exc())
def __call__(self): if (self.isFirstRun()): self.initBarrier.await() try: test = Test(TestID.PUT_DAV, "StoRM PUT WebDAV test") test.record(put_dav) put_dav(self.remote_URL) except Exception, e: error("Error executing put-dav: %s" % traceback.format_exc())
def __call__(self): try: test = Test(TestID.RM_MULTI, "StoRM srmRm multiple calls") test.record(rm_files) surls = setup(SRM_CLIENT, TEST_NUMFILES) rm_files(SRM_CLIENT, surls) except Exception, e: error("Error executing rm-multi: %s" % traceback.format_exc())
def __call__(self, src_url, dest_url, client): test = Test(TestID.MOVE, "MOVE") test.record(move) try: return move(src_url, dest_url, client) except Exception: error("Error executing MOVE: %s" % traceback.format_exc()) raise
def __call__(self): test = Test(TestID.ATLAS_RENAMING, "Atlas renaming") test.record(atlas_renaming) (base_dir, src_file, dest_file, dir_level1, dir_level2) = setup(SRM_CLIENT) atlas_renaming(src_file, dest_file, dir_level1, dir_level2, HTTP_CLIENT) cleanup(SRM_CLIENT, base_dir)
def __call__(self, url, client): test = Test(TestID.DELETE, "DELETE") test.record(delete) try: return delete(url, client) except Exception: error("Error executing DELETE: %s" % traceback.format_exc()) raise
def __call__(self, url, client): test = Test(TestID.MKCOL, "MKCOL") test.record(mkcol) try: return mkcol(url, client) except Exception: error("Error executing MKCOL: %s" % traceback.format_exc()) raise
def test(function): """ Decorator that creates a Grinder Test object for each function and instruments it. """ global _testCounter description = dedent(function.__doc__).strip() testObject = Test(_testCounter, description) _testCounter = _testCounter + 1 testObject.record(function) return function
def __call__(self): try: test = Test(TestID.PTP_SYNC_PD, "StoRM PTP Sync test") test.record(ptp_sync) file_name = ptp_sync(SRM_CLIENT) cleanup(SRM_CLIENT, file_name) except Exception, e: error("Error executing ptp-sync: %s" % traceback.format_exc()) raise
def __call__(self, surls, transport_protocols, client): if client is None: raise Exception("Please set a non-null SRM client!") test = Test(TestID.PTG, "StoRM PTG") test.record(ptg) try: return ptg(surls, transport_protocols, client) except Exception: error("Error executing ptg: %s" % traceback.format_exc()) raise
def __call__(self): try: if (SETUP_ONCE != "yes"): self.target_file_surl = setup(self.SRMclient) test = Test(TestID.TXFER_IN, "StoRM file-transfer IN") test.record(file_transfer_in) file_transfer_in(self.SRMclient, self.HTTPclient, self.target_file_surl, TRANSFER_PROTOCOL) if (SETUP_ONCE != "yes"): cleanup(self.SRMclient, self.target_file_surl) except Exception, e: error("Error executing file-transfer-in: %s" % traceback.format_exc())
def create_metrics(cls, agent_number): #divide the total number of each query type into the ones need by this worker total_queries = default_config[cls.query_interval_name] start_job, end_job = generate_job_range(total_queries, default_config['num_nodes'], agent_number) cls.num_queries_for_current_node = end_job - start_job # Grinder test infrastructure test = Test(cls.test_number, cls.query_name) cls.query_request = HTTPRequest() test.record(cls.query_request) return [cls] * cls.num_queries_for_current_node
def __call__(self,url,http_client): if http_client is None: raise Exception("Please set a non-null HTTP client!") test = Test(TestID.HTTP_GET, "HTTP GET") test.record(http_get) try: return http_get(url,http_client) except Exception: error("Error executing HTTP GET: %s" % traceback.format_exc()) raise
def __call__(self): method_info = "call" log.debug("START %s" % method_info) try: test = Test(TESTID, "Argus PEPD parallel test") test.record(parallel_test) parallel_test(self) except Exception, e: log.error("Error executing PEPD test: %s" % traceback.format_exc())
def __call__(self): try: test = Test(TestID.MKRMDIR, "StoRM MkDir+RmDir") test.record(mkrmdir) setup(SRM_CLIENT) mkrmdir(SRM_CLIENT) except Exception, e: error("Error executing mkdir-rmdir: %s" % traceback.format_exc()) raise
def __call__(self, dirname, client, recursive=0): if client is None: raise Exception("Please set a non-null SRM client!") test = Test(TestID.RMDIR, "StoRM RMDIR") test.record(rmdir) try: return rmdir(dirname, client, recursive) except Exception: error("Error executing rmdir: %s" % traceback.format_exc()) raise
def __call__(self, surl, token, client): if client is None: raise Exception("Please set a non-null SRM client!") test = Test(TestID.RF, "StoRM RF") test.record(rf) try: return rf(surl, token, client) except Exception: error("Error executing srmRf: %s" % traceback.format_exc()) raise
def __call__(self, surl, client): if client is None: raise Exception("Please set a non-null SRM client!") test = Test(TestID.MKDIR, "StoRM MKDIR") test.record(mkdir) try: return mkdir(surl, client) except Exception: error("Error executing mkdir: %s" % traceback.format_exc()) raise
def __call__(self): try: test = Test(TestID.PTG_SYNC, "StoRM Sync PTG test") test.record(ptg_sync) if DO_HANDSHAKE: get_client()[1].srmPing() (base_dir, surls) = setup() ptg_sync(base_dir) cleanup(base_dir) except Exception: error("Error executing ptg-sync: %s" % traceback.format_exc())
def __call__(self, surls, client): if client is None: raise Exception("Please set a non-null SRM client!") test = Test(TestID.RM, "StoRM RM") test.record(rm) try: return rm(surls, client) except Exception: error("Error executing rmdir: %s" % traceback.format_exc()) raise
def __call__(self, dirname, client): if client is None: raise Exception("Please set a non-null SRM client!") test = Test(TestID.LS, "StoRM LS") test.record(ls) try: return ls(dirname, client) except Exception: error("Error executing ls: %s" % traceback.format_exc()) raise
def __call__(self, ptp_resp, client = None): if ptp_resp is None: raise Exception("Please set a non-null PtP response!") if client is None: raise Exception("Please set a non-null SRM client!") test = Test(TestID.SPTP, "StoRM Status PTP") test.record(sptp) try: return sptp(ptp_resp, client) except Exception, e: error("Error executing SPTP: %s" % traceback.format_exc()) raise
def __call__(self): if ((DO_SETUP == "yes") and (self.isFirstRun())): if (self.isTheInitializer()): setup(SRM_CLIENT) debug("waiting all the other threads") self.SetupCompleteBarrier.await() debug("ok, go!") try: test = Test(TestID.LS_TEST, "StoRM LS test") test.record(ls_test) i = random.randint(1, TEST_DIR_HEIGHT) - 1 info("[i = %d] Ls on %s" % (i, SURLS[i])) ls_test(SRM_CLIENT, SURLS[i]) except Exception, e: error("Error executing ls test: %s" % traceback.format_exc()) raise
def create_request_obj(test_num, test_name, tgroup_name=None, auth_user=None): grinder.logger.debug('Creating %s request object' % test_name) test = Test(test_num, test_name) request = HTTPRequest() request = ResponseCheckingRequest(request) test.record(request) request = ExceptionHandlingRequest(request) request = ErrorLoggingRequest(request, grinder.logger.info) if auth_user: grinder.logger.debug('%s request object will authenticate with ' 'username "%s".' % (test_name, auth_user.username)) request = AuthenticatingRequest(request, auth_user) if tgroup_name: grinder.logger.debug('%s request object will throttle with group ' '"%s".' % (test_name, tgroup_name)) tgroup = throttling_groups[tgroup_name] request = ThrottlingRequest(tgroup, request) return request
def __call__(self): grinder.SSLControl.setKeyStoreFile("mykeystore.jks", "123456") for index in range(len(vo_keys)): vo = vo_keys[index] test = Test(2, "VOMS AC request with custom lifetime") test.record(request) port=list_vo[vo] url="https://"+host+":"+str(port)+resource grinder.statistics.delayReports = 1 result = str(request.GET(url)) if not '200 OK' in result: grinder.statistics.forLastTest.success = 0 grinder.statistics.report() grinder.statistics.delayReports = 0
def __call__(self): grinder.SSLControl.setKeyStoreFile("mykeystore.jks", "123456") for index in range(len(vo_keys)): vo = vo_keys[index] test = Test(1, "Simple VOMS AC request") test.record(request) port=list_vo[vo] url="https://"+host+":"+str(port)+resource grinder.statistics.delayReports = 1 result = str(request.GET(url)) if not '200 OK' in result: grinder.statistics.forLastTest.success = 0 grinder.statistics.report() grinder.statistics.delayReports = 0
# 导入对JSON格式返回值的处理函数 from org.json import JSONObject import random from org.json import JSONArray control = HTTPPluginControl.getConnectionDefaults() # 请求重定向开关 control.followRedirects = 1 # 超时时间设置 control.timeout = 6000 test1 = Test(1, "Test1") request1 = HTTPRequest() # Make any method call on request1 increase TPS test1.record(request1) class TestRunner: # 初始化,仅执行一次 def __init__(self): grinder.statistics.delayReports = True pass # 类似LR的action,压测时会多次执行 # test method def __call__(self): # url地址 url = 'http://183.131.22.111/feeds/com.oppo.os.ads.show.feed.service.IFeedListRankSvc' # headers信息
# Hello World, with functions # # The Hello World example re-written using functions. # # In previous examples we've defined TestRunner as a class; calling # the class creates an instance and calling that instance invokes its # __call__ method. This script is for the Luddites amongst you and # shows how The Grinder engine is quite happy as long as the script # creates a callable thing called TestRunner that can be called to # create another callable thing. from net.grinder.script.Grinder import grinder from net.grinder.script import Test test1 = Test(1, "Log method") test1.record(grinder.logger.info) def doRun(): grinder.logger.info("Hello World") def TestRunner(): return doRun
variable = 'ta' # Take the first dataset at all 3 bases tests = [] i = 1 for server in data_urls.DAP_BASES: url = data_urls.make_dataset_list(server).next() test = Test(i, server) i += 1 print test def f(req): return req() test.record(f) ds = Dataset(url) var = ds.variables[variable] requests = generate_subset_requests(var, partition_dict) tests.append((url, test, f, requests)) class TestRunner(object): def __call__(self): for url, test, f, requests in tests: grinder.logger.output('Scanning dataset %s' % url) # Each invocation of f is recorded
# A minimal script that tests The Grinder logging facility. # # This script shows the recommended style for scripts, with a # TestRunner class. The script is executed just once by each worker # process and defines the TestRunner class. The Grinder creates an # instance of TestRunner for each worker thread, and repeatedly calls # the instance for each run of that thread. from net.grinder.script.Grinder import grinder from net.grinder.script import Test # A shorter alias for the grinder.logger.info() method. log = grinder.logger.info # Create a Test with a test number and a description. The test will be # automatically registered with The Grinder console if you are using # it. test1 = Test(1, "Log method") # Instrument the info() method with our Test. test1.record(log) # A TestRunner instance is created for each thread. It can be used to # store thread-specific data. class TestRunner: # This method is called for every run. def __call__(self): log("Hello World")
# The J2EE Servlet specification defines a common model for form based # authentication. When unauthenticated users try to access a protected # resource, they are challenged with a logon page. The logon page # contains a form that POSTs username and password fields to a special # j_security_check page. from net.grinder.script.Grinder import grinder from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest from HTTPClient import NVPair protectedResourceTest = Test(1, "Request resource") authenticationTest = Test(2, "POST to j_security_check") request = HTTPRequest(url="http://localhost:7001/console") protectedResourceTest.record(request) class TestRunner: def __call__(self): result = request.GET() result = maybeAuthenticate(result) result = request.GET() # Function that checks the passed HTTPResult to see whether # authentication is necessary. If it is, perform the authentication # and record performance information against Test 2. def maybeAuthenticate(lastResult): if lastResult.statusCode == 401 \
from net.grinder.script.Grinder import grinder from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest from net.grinder.plugin.http import HTTPPluginControl control = HTTPPluginControl.getConnectionDefaults() test1 = Test(1, "test") request1 = HTTPRequest() class TestRunner: def __init__(self): grinder.statistics.delayReports = True grinder.logger.info("prepare") grinder.sleep(5000) pass def test(self): grinder.logger.info("test") def __call__(self): self.test() grinder.sleep(100) grinder.statistics.forLastTest.success = 1 test1.record(TestRunner.test)
class G2HTTPTest: """Parses parameters for an individual test and records the test invocation using a G3 Test.""" def __init__(self, testNumber, properties): self.sleepTime = properties["sleepTime"] headers = [] seenContentType = 0 for e in properties.getPropertySubset("parameter.header.").entrySet(): headers.append(NVPair(e.key, e.value)) if not seenContentType and e.key.lower() == "content-type": seenContentType = 1 postDataFilename = properties["parameter.post"] if postDataFilename: file = open(postDataFilename) self.postData = file.read() file.close() if not seenContentType: headers.append( NVPair("Content-type", "application/x-www-form-urlencoded")) else: self.postData = None self.okString = properties["parameter.ok"] self.url = properties["parameter.url"] realm = properties["basicAuthenticationRealm"] user = properties["basicAuthenticationUser"] password = properties["basicAuthenticationPassword"] if realm and user and password: self.basicAuthentication = (realm, user, password) elif not realm and not user and not password: self.basicAuthentication = None else: raise "If you specify one of { basicAuthenticationUser, basicAuthenticationRealm, basicAuthenticationPassword } you must specify all three." self.request = HTTPRequest(headers=headers) self.test = Test(testNumber, properties["description"]) self.test.record(self.request) def doTest(self, iteration): if self.basicAuthentication: connection = HTTPPluginControl.getThreadConnection(self.url) connection.addBasicAuthorization(self.basicAuthentication[0], self.basicAuthentication[1], self.basicAuthentication[2]) grinder.statistics.delayReports = 1 if self.postData: page = self.request.POST(self.url, self.postData).text else: page = self.request.GET(self.url).text if not page: error = self.okString else: error = self.okString and page.find(self.okString) == -1 if error or logHTML: if self.test.description: description = "_%s" % self.test.description else: description = "" filename = grinder.filenameFactory.createFilename( "page", "_%d_%.3d%s" % (iteration, self.test.number, description)) file = open(filename, "w") print >> file, page file.close() if error: grinder.logger.error( "The 'ok' string ('%s') was not found in the page " "received. The output has been written to '%s'." % (self.okString, filename)) if error: grinder.statistics.forLastTest.success = 0 if self.sleepTime: grinder.sleep(long(self.sleepTime))
from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest test = Test(1, "BZT Requests") request = HTTPRequest() test.record(request) class TestRunner(object): def __call__(self): request.GET("http://demo.blazemeter.com/")
# example from # http://xmlrpc-c.sourceforge.net/xmlrpc-howto/xmlrpc-howto-java-server.html # # Copyright (C) 2004 Sebasti�n Fontana # Distributed under the terms of The Grinder license. from java.util import Vector from java.lang import Integer from net.grinder.script.Grinder import grinder from net.grinder.script import Test from org.apache.xmlrpc import XmlRpcClient test1 = Test(1, "XML-RPC example test") server_url = "http://localhost:8080/RPC2" client = XmlRpcClient(server_url) test1.record(client) class TestRunner: def __call__(self): params = Vector() params.addElement(Integer(6)) params.addElement(Integer(3)) result = client.execute("sample.sumAndDifference", params) sum = result.get("sum") grinder.logger.info("SUM %d" % sum)
import data_urls properties = grinder.properties.getPropertySubset('dapbench.') variable = properties['variable'] datasets = properties['datasets'] time_len = int(properties['time_len']) req_sample_size = int(properties['req_sample_size']) partition_dict = {'time': time_len} dataset_list = data_urls.load_dataset_list(datasets) test = Test(1, "Parallel slice request") def call_request(req): return req() test.record(call_request) class TestRunner(object): def __init__(self): self.thread = grinder.getThreadNumber() # Select random dataset #!TODO: select dataset by Thread number? self.dataset_url = random.choice(dataset_list) self.ds = Dataset(self.dataset_url) self.variable = self.ds.variables[variable] self.requests = generate_subset_requests(self.variable, partition_dict) grinder.logger.output('Thread %d selecting %s' % (self.thread, self.dataset_url)) grinder.logger.output('Thread %d has partitions %s' % (self.thread,
# the instance for each run of that thread. from net.grinder.script.Grinder import grinder from net.grinder.script import Test import random import time # A shorter alias for the grinder.logger.info() method. log = grinder.logger.info # Create a Test with a test number and a description. The test will be # automatically registered with The Grinder console if you are using # it. test1 = Test(1, "Hello World") # A TestRunner instance is created for each thread. It can be used to # store thread-specific data. class TestRunner: def fun1(self): time.sleep(random.randint(700, 1100) / 1000.0) print "Hello, hzcaojianglong!" log("Hello, Grinder!") # This method is called for every run. def __call__(self): self.fun1() # Instrument the info() method with our Test. test1.record(TestRunner.fun1)