本文整理汇总了Java中org.apache.jmeter.protocol.java.sampler.JavaSamplerContext.getParameter方法的典型用法代码示例。如果您正苦于以下问题:Java JavaSamplerContext.getParameter方法的具体用法?Java JavaSamplerContext.getParameter怎么用?Java JavaSamplerContext.getParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jmeter.protocol.java.sampler.JavaSamplerContext
的用法示例。
在下文中一共展示了JavaSamplerContext.getParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
/**
* Do any initialization required by this client. In this case,
* initialization consists of getting the value of the AWS region
* and credentials parameters.
*
* @param context
* the context to run with. This provides access to
* initialization parameters.
*/
@Override
public void setupTest(JavaSamplerContext context) {
apigatewayBaseUrl = context.getParameter("APIGATEWAY_BASE_URL");
accessKeyId = context.getParameter("ACCESS_KEY_ID");
secretKey = context.getParameter("SECRET_KEY");
sessionToken = context.getParameter("SESSION_TOKEN");
AWSCredentials awsCredentials = new BasicSessionCredentials(accessKeyId, secretKey,
sessionToken);
AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider(
awsCredentials);
String region = context.getParameter("REGION");
client = Squash.builder().iamRegion(region)
.iamCredentials((AWSCredentialsProvider) awsStaticCredentialsProvider).build();
samplerName = context.getParameter(TestElement.NAME);
bookingName = context.getParameter("BOOKING_NAME");
court = context.getParameter("COURT");
courtSpan = context.getParameter("COURTSPAN");
slot = context.getParameter("SLOT");
slotSpan = context.getParameter("SLOTSPAN");
date = context.getParameter("DATE");
putOrDelete = context.getParameter("PUT_OR_DELETE");
}
示例2: runTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
/**
* 开始测试,从arg0参数可以获得参数值;
*/
public SampleResult runTest(JavaSamplerContext arg0) {
name = arg0.getParameter("name");
SampleResult sr = new SampleResult();
sr.setSampleLabel("Java请求--sayHelloToPerson");
try {
// jmeter 开始统计响应时间标记
sr.sampleStart();
Hello test = new Hello();
// 通过下面的操作就可以将被测方法的响应输出到Jmeter的察看结果树中的响应数据里面了。
resultData = test.sayHelloToPerson(name);
if (resultData != null && resultData.length() > 0) {
sr.setResponseData("结果是:" + resultData, null);
sr.setDataType(SampleResult.TEXT);
}
sr.setSuccessful(true);
} catch (Throwable e) {
sr.setSuccessful(false);
e.printStackTrace();
} finally {
// jmeter 结束统计响应时间标记
sr.sampleEnd();
}
return sr;
}
示例3: runTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
public SampleResult runTest(JavaSamplerContext context) {
String name = context.getParameter("name");
getNewLogger().info("dubbo test - {} start", name);
SampleResult sr = new SampleResult();
// 开始测试
sr.sampleStart();
start = System.currentTimeMillis();
sr.setSampleLabel("Dubbo请求--sayHello");
try {
String result = this.userService.sayHello();
if (null != result && result.length() > 0) {
sr.setResponseData("结果是:" + result, null);
sr.setDataType(SampleResult.TEXT);
}
sr.setSuccessful(true);
} catch (Exception e) {
sr.setSuccessful(false);
e.printStackTrace();
} finally {
sr.sampleEnd();
}
return sr;
}
示例4: setupTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
/**
* Gets invoked exactly once before thread starts
*
* @param context
*/
@Override
public void setupTest(JavaSamplerContext context) {
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, getBrokerServers(context));
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, context.getParameter(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG));
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, context.getParameter(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG));
props.put(ProducerConfig.ACKS_CONFIG, context.getParameter(ProducerConfig.ACKS_CONFIG));
props.put(ProducerConfig.SEND_BUFFER_CONFIG, context.getParameter(ProducerConfig.SEND_BUFFER_CONFIG));
props.put(ProducerConfig.RECEIVE_BUFFER_CONFIG, context.getParameter(ProducerConfig.RECEIVE_BUFFER_CONFIG));
props.put(ProducerConfig.BATCH_SIZE_CONFIG, context.getParameter(ProducerConfig.BATCH_SIZE_CONFIG));
props.put(ProducerConfig.LINGER_MS_CONFIG, context.getParameter(ProducerConfig.LINGER_MS_CONFIG));
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, context.getParameter(ProducerConfig.BUFFER_MEMORY_CONFIG));
props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, context.getParameter(ProducerConfig.COMPRESSION_TYPE_CONFIG));
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, context.getParameter(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG));
props.put(ProducerKeys.SASL_MECHANISM, context.getParameter(ProducerKeys.SASL_MECHANISM));
Iterator<String> parameters = context.getParameterNamesIterator();
parameters.forEachRemaining(parameter -> {
if (parameter.startsWith("_")) {
props.put(parameter.substring(1), context.getParameter(parameter));
}
});
String kerberosEnabled = context.getParameter(ProducerKeys.KERBEROS_ENABLED);
if (kerberosEnabled != null && kerberosEnabled.equals(ProducerKeys.FLAG_YES)) {
System.setProperty(ProducerKeys.JAVA_SEC_AUTH_LOGIN_CONFIG, context.getParameter(ProducerKeys.JAVA_SEC_AUTH_LOGIN_CONFIG));
System.setProperty(ProducerKeys.JAVA_SEC_KRB5_CONFIG, context.getParameter(ProducerKeys.JAVA_SEC_KRB5_CONFIG));
props.put(ProducerKeys.SASL_KERBEROS_SERVICE_NAME, context.getParameter(ProducerKeys.SASL_KERBEROS_SERVICE_NAME));
}
placeHolder = context.getParameter(PropsKeys.MESSAGE_PLACEHOLDER_KEY);
topic = context.getParameter(ProducerKeys.KAFKA_TOPIC_CONFIG);
producer = new KafkaProducer<String, Object>(props);
}
示例5: setupTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
@Override
public void setupTest(JavaSamplerContext ctx) {
loopCount = ctx.getIntParameter("loopCount");
name = ctx.getParameter("name");
sleepWhenUnsuccesful = ctx.getIntParameter("sleepWhenUnsuccesful");
testcase = ctx.getParameter("testcase");
param2 = ctx.getParameter("param2");
System.out.println("---- setup");
}
示例6: runTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
public SampleResult runTest(JavaSamplerContext context) {
SampleResult result = newSampleResult();
String topic = context.getParameter(PARAMETER_KAFKA_TOPIC);
//Long key = context.getLongParameter(PARAMETER_KAFKA_KEY);
String message = context.getParameter(PARAMETER_KAFKA_MESSAGE);
sampleResultStart(result, message);
try {
//producer.send(new ProducerRecord(topic, key, message.getBytes()));
producer.send(new ProducerRecord(topic, message.getBytes()));
sampleResultSuccess(result, null);
} catch (Exception e) {
sampleResultFailed(result, "500", e);
}
return result;
}
示例7: delayedSetupTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
public void delayedSetupTest(JavaSamplerContext context){
log.debug(myname + ">>>> in setupTest");
host = context.getParameter("HOST");
throttle = Integer.parseInt((context.getParameter("PUBLISHER_THROTTLE")));
acksTimeout = Integer.parseInt((context.getParameter("PUBLISHER_ACKS_TIMEOUT")));
//System.out.println("Publisher acks timeout: " + acksTimeout);
clientId = context.getParameter("CLIENT_ID");
if("TRUE".equalsIgnoreCase(context.getParameter("RANDOM_SUFFIX"))){
clientId= MqttPubSub.getClientId(clientId,Integer.parseInt(context.getParameter("SUFFIX_LENGTH")));
}
try {
log.debug("Host: " + host + "clientID: " + clientId);
client = new MqttAsyncClient(host, clientId, new MemoryPersistence());
} catch (MqttException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
//options.setCleanSession(false);
options.setCleanSession(Boolean.parseBoolean((context.getParameter("CLEAN_SESSION"))));
//System.out.println("Pubs cleansession ====> " + context.getParameter("CLEAN_SESSION"));
options.setKeepAliveInterval(0);
timeout = Integer.parseInt((context.getParameter("CONNECTION_TIMEOUT")));
myname = context.getParameter("SAMPLER_NAME");
String user = context.getParameter("USER");
String pwd = context.getParameter("PASSWORD");
if (user != null) {
options.setUserName(user);
if ( pwd!=null ) {
options.setPassword(pwd.toCharArray());
}
}
clientConnect(timeout);
client.setCallback(this);
}
示例8: setupTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
@Override
public void setupTest(JavaSamplerContext ctx) {
File rootFolder_ = null;
try {
String rootFolder = null;
if (ctx!=null) {
rootFolder = ctx.getParameter(PARM_XSD_FOLDER_ROOT);
}
if (rootFolder!=null && rootFolder.trim().length()>0) {
getLogger().info("Using xsd.root folder [" + rootFolder + "] from JMeter variable [" + this.PARM_XSD_FOLDER_ROOT + "]");
rootFolder_ = new File(rootFolder);
this.repos = new TextFileRepos(rootFolder_, TextFileRepos.OnePerFolder.XSD);
} else {
this.repos = new TextFileRepos(XSD_ROOT, TextFileRepos.OnePerFolder.XSD);
getLogger().info("JMeter variable [" + PARM_XSD_FOLDER_ROOT + "] is ignored.");
}
getLogger().info("Process xsd and xml files from folder [" + this.repos.root.getAbsolutePath() + "] from classpath");
SchemaRepo.SchemaFinder schemaFinder = new SchemaRepo.SchemaFinder() {
@Override
public File getSchema(String key) {
return repos.getFile(key);
}
};
this.schemaRepo = new SchemaRepo(schemaFinder, this.ynUseCache);
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
getLogger().error("Error reading xsd and xml files from disk. Stack trace:\n"+sw.toString(), e);
getLogger().error("Message:\n"+e.getMessage());
}
}
示例9: extractParameters
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
protected Map<String, String> extractParameters(JavaSamplerContext context) {
Map<String, String> mapParams = new ConcurrentHashMap<>();
for (Iterator<String> it = context.getParameterNamesIterator(); it.hasNext(); ) {
String paramName = it.next();
String paramValue = context.getParameter(paramName);
mapParams.put(paramName, paramValue);
}
return mapParams;
}
示例10: run
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
@Override
protected void run(JavaSamplerContext context) throws Exception {
String uploadFile = context.getParameter(ExampleParameter.SWIFT_UPLOAD_FILE.name());
int readTimeout = context.getIntParameter(ExampleParameter.SWIFT_READ_TIMEOUT.name());
String containerName = OpenstackUtil.generateName();
String objectName = OpenstackUtil.generateName();
log.debug("creating container " + containerName);
exceptionIfError(os.objectStorage().containers().create(containerName));
log.debug("uploading file " + uploadFile);
os.objectStorage().objects().put(containerName, objectName, Payloads.create(new File(uploadFile)));
int waited = 0;
SwiftObject object = null;
while (waited < readTimeout) {
object = os.objectStorage().objects().get(containerName, objectName);
if (object != null)
break;
log.debug("waiting for object " + objectName);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
break;
}
}
log.debug("deleting object " + objectName);
logIfError(os.objectStorage().objects().delete(containerName, objectName));
log.debug("deleting container " + containerName);
logIfError(os.objectStorage().containers().delete(containerName));
if (object == null)
throw new OpenstackException("object " + uploadFile + " read failed");
}
示例11: run
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
@Override
protected void run(JavaSamplerContext context) throws Exception {
String uploadImage = context.getParameter(ExampleParameter.GLANCE_UPLOAD_IMAGE.name());
int readTimeout = context.getIntParameter(ExampleParameter.GLANCE_READ_TIMEOUT.name());
String imageName = OpenstackUtil.generateName();
log.debug("uploading image " + uploadImage);
Payload<File> payload = Payloads.create(new File(uploadImage));
Image image = os.images().create(
Builders.image().name(imageName).isPublic(true).containerFormat(ContainerFormat.BARE)
.diskFormat(DiskFormat.QCOW2).build(), payload);
int waited = 0;
String imageId = image.getId();
image = null;
while (waited < readTimeout) {
image = os.images().get(imageId);
if (image != null)
break;
log.debug("waiting for image " + uploadImage);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
break;
}
}
log.debug("deleting image " + imageName);
logIfError(os.images().delete(imageId));
if (image == null)
throw new OpenstackException("image " + uploadImage + " read failed");
}
示例12: run
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
@Override
protected void run(JavaSamplerContext context) throws Exception {
String myParameter = context.getParameter(MyParameter.MY_PARAMETER.name());
log.debug(myParameter);
log.info("instances:");
for (Server instance : os.compute().servers().list())
log.info(instance.getName());
}
示例13: setupValues
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
private void setupValues(JavaSamplerContext context) {
sleepTime = context.getLongParameter(SLEEP_NAME, DEFAULT_SLEEP_TIME);
sleepMask = context.getLongParameter(MASK_NAME, DEFAULT_SLEEP_MASK);
responseMessage = context.getParameter(RESPONSE_MESSAGE_NAME, RESPONSE_MESSAGE_DEFAULT);
responseCode = context.getParameter(RESPONSE_CODE_NAME, RESPONSE_CODE_DEFAULT);
success = context.getParameter(SUCCESS_NAME, SUCCESS_DEFAULT).equalsIgnoreCase("OK");
label = context.getParameter(LABEL_NAME, "");
if (label.length() == 0) {
label = context.getParameter(TestElement.NAME); // default to name of element
}
samplerData = context.getParameter(SAMPLER_DATA_NAME, SAMPLER_DATA_DEFAULT);
resultData = context.getParameter(RESULT_DATA_NAME, RESULT_DATA_DEFAULT);
}
示例14: delayedSetup
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
public void delayedSetup(JavaSamplerContext context){
myname = context.getParameter("SAMPLER_NAME");
host = context.getParameter("HOST");
clientId = context.getParameter("CLIENT_ID");
if("TRUE".equalsIgnoreCase(context.getParameter("RANDOM_SUFFIX"))){
clientId= MqttPublisher.getClientId(clientId,Integer.parseInt(context.getParameter("SUFFIX_LENGTH")));
}
try {
log.info(myname + ": Host: " + host + "clientID: " + clientId);
if (!clientsMap.containsKey(clientId)) {
MqttAsyncClient cli = new MqttAsyncClient(host, clientId, new MemoryPersistence());
clientsMap.put(clientId, cli);
}
} catch (MqttException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if ( !context.getParameter("AGGREGATE").equals("")) {
msgs_aggregate = Long.parseLong(context.getParameter("AGGREGATE"));
}
if ( !context.getParameter("SAMPLER_TIMEOUT").equals("") ) {
samplerTimeout = Long.parseLong(context.getParameter("SAMPLER_TIMEOUT"));
}
//System.out.println("nummsgs: " + msgs_aggregate + " - sampler timeout: " + samplerTimeout);
//options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
options.setCleanSession(Boolean.parseBoolean((context.getParameter("CLEAN_SESSION"))));
//System.out.println("Subs clean session====> " + context.getParameter("CLEAN_SESSION"));
options.setKeepAliveInterval(0);
connectionTimeout = Integer.parseInt((context.getParameter("CONNECTION_TIMEOUT")));
String user = context.getParameter("USER");
String pwd = context.getParameter("PASSWORD");
if (user != null) {
options.setUserName(user);
if ( pwd!=null ) {
options.setPassword(pwd.toCharArray());
}
}
//System.out.println("============> " + options.getKeepAliveInterval());
clientConnect();
client().setCallback(this);
}
示例15: delayedSetupTest
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; //导入方法依赖的package包/类
public void delayedSetupTest(JavaSamplerContext context){
log.debug(myname + ">>>> in setupTest");
host = context.getParameter("HOST");
throttle = Integer.parseInt((context.getParameter("PUBLISHER_THROTTLE")));
acksTimeout = Integer.parseInt((context.getParameter("PUBLISHER_ACKS_TIMEOUT")));
//System.out.println("Publisher acks timeout: " + acksTimeout);
clientId = context.getParameter("CLIENT_ID");
if("TRUE".equalsIgnoreCase(context.getParameter("RANDOM_SUFFIX"))){
clientId= MqttPublisher.getClientId(clientId,Integer.parseInt(context.getParameter("SUFFIX_LENGTH")));
}
try {
log.debug("Host: " + host + "clientID: " + clientId);
if (!clientsMap.containsKey(clientId)) {
MqttAsyncClient cli = new MqttAsyncClient(host, clientId, new MemoryPersistence());
clientsMap.put(clientId, cli);
}
} catch (MqttException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//options.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
//options.setCleanSession(false);
options.setCleanSession(Boolean.parseBoolean((context.getParameter("CLEAN_SESSION"))));
//System.out.println("Pubs cleansession ====> " + context.getParameter("CLEAN_SESSION"));
options.setKeepAliveInterval(0);
timeout = Integer.parseInt((context.getParameter("CONNECTION_TIMEOUT")));
myname = context.getParameter("SAMPLER_NAME");
String user = context.getParameter("USER");
String pwd = context.getParameter("PASSWORD");
if (user != null) {
options.setUserName(user);
if ( pwd!=null ) {
options.setPassword(pwd.toCharArray());
}
}
clientConnect(timeout);
client().setCallback(this);
}