本文整理汇总了Python中bzt.jmx.JMX类的典型用法代码示例。如果您正苦于以下问题:Python JMX类的具体用法?Python JMX怎么用?Python JMX使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JMX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
def convert(self, group, target, load, concurrency):
"""
Convert a thread group to ThreadGroup/ConcurrencyThreadGroup for applying of load
"""
msg = "Converting %s (%s) to %s and apply load parameters"
self.log.debug(msg, group.gtype, group.get_testname(), target)
on_error = group.get_on_error()
if target == ThreadGroup.__name__:
new_group_element = JMX.get_thread_group(
concurrency=concurrency,
rampup=load.ramp_up,
hold=load.hold,
iterations=load.iterations,
testname=group.get_testname(),
on_error=on_error)
elif target == ConcurrencyThreadGroup.__name__:
new_group_element = JMX.get_concurrency_thread_group(
concurrency=concurrency,
rampup=load.ramp_up,
hold=load.hold,
steps=load.steps,
testname=group.get_testname(),
on_error=on_error)
else:
self.log.warning('Unsupported preferred thread group: %s', target)
return
group.element.getparent().replace(group.element, new_group_element)
示例2: test_regexp_subject
def test_regexp_subject(self):
res = JMX._get_extractor('test_name', 'baddy', 'regexp', 1, 1, 'error')
self.assertEqual("body", res.find(".//stringProp[@name='RegexExtractor.useHeaders']").text)
res = JMX._get_extractor('test_name', 'headers', 'regexp', 1, 1, 'error')
self.assertEqual("true", res.find(".//stringProp[@name='RegexExtractor.useHeaders']").text)
res = JMX._get_extractor('test_name', 'http-code', 'regexp', 1, 1, 'error')
self.assertEqual("code", res.find(".//stringProp[@name='RegexExtractor.useHeaders']").text)
self.assertIsNone(res.find(".//stringProp[@name='Sample.scope']"))
示例3: test_json_body_app_str
def test_json_body_app_str(self):
obj = JMeterExecutor()
obj.engine = EngineEmul()
obj.execution.merge({
"scenario": {
"requests": [{
"url": "http://blazedemo.com",
"headers": {"Content-Type": "application/json"},
"body": "{\"store_id\": \"${store_id}\", \"display_name\": \"${display_name}\"}"
}]}})
obj.prepare()
jmx = JMX(obj.original_jmx)
selector = 'elementProp[name="HTTPsampler.Arguments"]>collectionProp'
selector += '>elementProp>stringProp[name="Argument.value"]'
self.assertNotEqual(jmx.get(selector)[0].text.find('store_id'), -1)
示例4: configure
def configure(self, jmx_file=None, load=None, settings=None, has_ctg=None):
executor = MockJMeterExecutor(load, settings, has_ctg)
executor.engine.config.merge({Provisioning.PROV: 'local'})
executor.install_required_tools()
self.obj = LoadSettingsProcessor(executor)
if jmx_file:
self.jmx = JMX(jmx_file)
示例5: compile_request
def compile_request(self, request):
"""
:type request: HierarchicHTTPRequest
:return:
"""
sampler = children = None
protocol_name = request.priority_option('protocol', default=self.default_protocol)
if protocol_name in self.protocol_handlers:
protocol = self.protocol_handlers[protocol_name]
sampler, children = protocol.get_sampler_pair(request)
if sampler is None:
self.log.warning("Problematic request: %s", request.config)
raise TaurusInternalException("Unable to handle request, please review missing options")
children.extend(self._get_timer(request))
self.__add_assertions(children, request)
timeout = ProtocolHandler.safe_time(request.priority_option('timeout'))
if timeout is not None:
children.append(JMX._get_dur_assertion(timeout))
children.append(etree.Element("hashTree"))
self.__add_extractors(children, request)
self.__add_jsr_elements(children, request)
return [sampler, children]
示例6: __gen_authorization
def __gen_authorization(scenario):
"""
Generates HTTP Authorization Manager
"""
elements = []
authorizations = scenario.get("authorization")
if authorizations:
clear_flag = False
if isinstance(authorizations, dict):
if "clear" in authorizations or "list" in authorizations: # full form
clear_flag = authorizations.get("clear", False)
authorizations = authorizations.get("list", [])
else:
authorizations = [authorizations] # short form
if not isinstance(authorizations, list):
raise TaurusConfigError("Wrong authorization format: %s" % authorizations)
auth_manager = JMX.get_auth_manager(authorizations, clear_flag)
elements.append(auth_manager)
elements.append(etree.Element("hashTree"))
return elements
示例7: __gen_datasources
def __gen_datasources(self, scenario):
sources = scenario.get("data-sources")
if not sources:
return []
if not isinstance(sources, list):
raise TaurusConfigError("data-sources '%s' is not a list" % sources)
elements = []
for idx, source in enumerate(sources):
source = ensure_is_dict(sources, idx, "path")
source_path = source["path"]
delimiter = source.get("delimiter")
if has_variable_pattern(source_path):
msg = "Path to CSV contains JMeter variable/function, can't check for file existence: %s"
self.log.warning(msg, source_path)
if not delimiter:
delimiter = ','
self.log.warning("Can't detect CSV dialect, default delimiter will be '%s'", delimiter)
else:
modified_path = self.executor.engine.find_file(source_path)
if not os.path.isfile(modified_path):
raise TaurusConfigError("data-sources path not found: %s" % modified_path)
if not delimiter:
delimiter = self.__guess_delimiter(modified_path)
source_path = get_full_path(modified_path)
config = JMX._get_csv_config(source_path, delimiter, source.get("quoted", False), source.get("loop", True),
source.get("variable-names", ""))
elements.append(config)
elements.append(etree.Element("hashTree"))
return elements
示例8: test_jmx_2tg
def test_jmx_2tg(self):
obj = JMeterExecutor()
obj.engine = EngineEmul()
obj.engine.config[Provisioning.PROV] = 'test'
obj.execution.merge({
"concurrency": 1051,
"ramp-up": 15,
"iterations": 100,
"scenario": {"script": __dir__() + "/../jmx/two_tg.jmx"}
})
obj.prepare()
jmx = JMX(obj.modified_jmx)
selector = 'jmeterTestPlan>hashTree>hashTree>ThreadGroup'
selector += '>stringProp[name=ThreadGroup\.num_threads]'
thr = jmx.get(selector)
self.assertEquals('420', thr[0].text)
self.assertEquals('631', thr[1].text)
示例9: __add_regexp_ext
def __add_regexp_ext(self, children, req):
extractors = req.config.get("extract-regexp")
for varname in extractors:
cfg = ensure_is_dict(extractors, varname, "regexp")
extractor = JMX._get_extractor(varname, cfg.get('subject', 'body'), cfg['regexp'], cfg.get('template', 1),
cfg.get('match-no', 1), cfg.get('default', 'NOT_FOUND'))
children.append(extractor)
children.append(etree.Element("hashTree"))
示例10: compile_transaction_block
def compile_transaction_block(self, block):
elements = []
controller = JMX._get_transaction_controller(block.name, block.priority_option('force-parent-sample', True))
children = etree.Element("hashTree")
for compiled in self.compile_requests(block.requests):
for element in compiled:
children.append(element)
elements.extend([controller, children])
return elements
示例11: compile_include_scenario_block
def compile_include_scenario_block(self, block):
elements = []
controller = JMX._get_simple_controller(block.scenario_name)
children = etree.Element("hashTree")
scenario = self.executor.get_scenario(name=block.scenario_name)
for element in self.compile_scenario(scenario):
children.append(element)
elements.extend([controller, children])
return elements
示例12: compile_http_request
def compile_http_request(self, request):
"""
:type request: HierarchicHTTPRequest
:return:
"""
timeout = request.priority_option('timeout')
if timeout is not None:
timeout = self.smart_time(timeout)
content_type = self._get_merged_ci_headers(request, 'content-type')
if content_type == 'application/json' and isinstance(request.body, (dict, list)):
body = json.dumps(request.body)
else:
body = request.body
use_random_host_ip = request.priority_option('random-source-ip', default=False)
host_ips = get_host_ips(filter_loopbacks=True) if use_random_host_ip else []
http = JMX._get_http_request(request.url, request.label, request.method, timeout, body,
request.priority_option('keepalive', default=True),
request.upload_files, request.content_encoding,
request.priority_option('follow-redirects', default=True),
use_random_host_ip, host_ips)
children = etree.Element("hashTree")
if request.headers:
children.append(JMX._get_header_mgr(request.headers))
children.append(etree.Element("hashTree"))
self.__add_think_time(children, request)
self.__add_assertions(children, request)
if timeout is not None:
children.append(JMX._get_dur_assertion(timeout))
children.append(etree.Element("hashTree"))
self.__add_extractors(children, request)
self.__add_jsr_elements(children, request)
return [http, children]
示例13: _get_timer
def _get_timer(req):
think_time = req.get_think_time(full=True)
if not think_time:
return []
if not isinstance(think_time, list): # constant
return JMX.get_constant_timer(delay=ProtocolHandler.safe_time(think_time))
mean = ProtocolHandler.safe_time(think_time[1])
dev = ProtocolHandler.safe_time(think_time[2])
if think_time[0] == "uniform":
return JMX.get_uniform_timer(maximum=dev * 2, offset=mean - dev)
elif think_time[0] == "gaussian":
return JMX.get_gaussian_timer(dev=dev, offset=mean)
elif think_time[0] == "poisson":
return JMX.get_poisson_timer(lam=mean - dev, delay=dev)
else:
raise TaurusConfigError("Wrong timer type: %s" % think_time[0])
示例14: __add_json_ext
def __add_json_ext(self, children, req):
jextractors = req.config.get("extract-jsonpath")
for varname in jextractors:
cfg = ensure_is_dict(jextractors, varname, "jsonpath")
if LooseVersion(str(self.executor.settings.get("version"))) < LooseVersion("3.0"):
extractor = JMX._get_json_extractor(varname,
cfg["jsonpath"],
cfg.get("default", "NOT_FOUND"),
cfg.get("from-variable", None))
else:
extractor = JMX._get_internal_json_extractor(varname,
cfg["jsonpath"],
cfg.get("default", "NOT_FOUND"),
cfg.get("scope", None),
cfg.get("from-variable", None),
cfg.get("match-no", "0"),
cfg.get("concat", False))
children.append(extractor)
children.append(etree.Element("hashTree"))
示例15: __add_xpath_ext
def __add_xpath_ext(self, children, req):
xpath_extractors = req.config.get("extract-xpath")
for varname in xpath_extractors:
cfg = ensure_is_dict(xpath_extractors, varname, "xpath")
children.append(JMX._get_xpath_extractor(varname,
cfg['xpath'],
cfg.get('default', 'NOT_FOUND'),
cfg.get('validate-xml', False),
cfg.get('ignore-whitespace', True),
cfg.get('use-tolerant-parser', False)))
children.append(etree.Element("hashTree"))