本文整理汇总了Java中org.apache.jmeter.threads.JMeterContext.getVariables方法的典型用法代码示例。如果您正苦于以下问题:Java JMeterContext.getVariables方法的具体用法?Java JMeterContext.getVariables怎么用?Java JMeterContext.getVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jmeter.threads.JMeterContext
的用法示例。
在下文中一共展示了JMeterContext.getVariables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
@Override
public void send(JMeterContext context, SampleResult result) {
JMeterVariables variables = context.getVariables();
ConcurrentHashMap<String, MockLwM2mClient> clients = (ConcurrentHashMap<String, MockLwM2mClient>) variables.getObject("lwm2mClients");
MockLwM2mClient client = clients.get(endpoint);
if (client != null) {
SimpleResource resource = (SimpleResource) client.getObject(objectId).getChild(instanceId).getChild(resourceId);
result.sampleStart();
if (resource != null) {
resource.setResourceValue(Float.toString(rng.nextInt(100)));
result.setSuccessful(true);
log.debug("Sent observation for " + objectId + "/" + instanceId + "/" + resourceId);
} else {
result.setSuccessful(false);
log.debug("Could not send observation for " + objectId + "/" + instanceId + "/" + resourceId);
}
result.sampleEnd();
}
}
示例2: changeVariablesMap
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
private void changeVariablesMap() {
try {
JMeterContext context = this.getThreadContext();
if (context != null && context.getVariables() != null) {
JMeterVariables jMeterVariables = context.getVariables();
Class<JMeterVariables> cls = JMeterVariables.class;
Field variablesField = cls.getDeclaredField("variables");
variablesField.setAccessible(true);
Object obj = variablesField.get(jMeterVariables);
synchronized (obj) {
if (obj instanceof Map) {
Map variables = (Map) obj;
if (!(variables instanceof ConcurrentHashMap)) {
variablesField.set(jMeterVariables, new ConcurrentHashMap(variables));
}
} else {
log.warn("Unexpected variables map type " + obj.getClass().getName());
}
}
}
} catch (Throwable ex) {
log.warn("Cannot change variables map ", ex);
}
}
示例3: iterationStart
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
@Override
public void iterationStart(LoopIterationEvent event) {
TestElement source = event.getSource();
JMeterContext threadContext = source.getThreadContext();
JMeterVariables variables = threadContext.getVariables();
iterationStart(variables);
}
示例4: getApplicationContext
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
public static ApplicationContext getApplicationContext() {
JMeterContext context = JMeterContextService.getContext();
JMeterVariables variables = context.getVariables();
Object o = variables.getObject(VARIABLE);
checkNotNull(o, "variable %s not found", VARIABLE);
return ApplicationContext.class.cast(o);
}
示例5: isDone
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean isDone() {
if (loopCount >= getEndIndex()) {
return true;
}
JMeterContext context = getThreadContext();
StringBuilder builder = new StringBuilder(
getInputVal().length()+getSeparator().length()+3);
String inputVariable =
builder.append(getInputVal())
.append(getSeparator())
.append(Integer.toString(loopCount+1)).toString();
final JMeterVariables variables = context.getVariables();
final Object currentVariable = variables.getObject(inputVariable);
if (currentVariable != null) {
variables.putObject(getReturnVal(), currentVariable);
if (log.isDebugEnabled()) {
log.debug("ForEach resultstring isDone=" + variables.get(getReturnVal()));
}
return false;
}
return super.isDone();
}
示例6: notifyListeners
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
/**
* Create additional SampleEvent in NON Parent Mode
*/
protected void notifyListeners() {
// TODO could these be done earlier (or just once?)
JMeterContext threadContext = getThreadContext();
JMeterVariables threadVars = threadContext.getVariables();
SamplePackage pack = (SamplePackage) threadVars.getObject(JMeterThread.PACKAGE_OBJECT);
if (pack == null) {
// If child of TransactionController is a ThroughputController and TPC does
// not sample its children, then we will have this
// TODO Should this be at warn level ?
log.warn("Could not fetch SamplePackage");
} else {
SampleEvent event = new SampleEvent(res, threadContext.getThreadGroup().getName(),threadVars, true);
// We must set res to null now, before sending the event for the transaction,
// so that we can ignore that event in our sampleOccured method
res = null;
lnf.notifyListeners(event, pack.getSampleListeners());
}
}
示例7: getStringValue
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
/**
* Executes the function (and caches the value for the duration of the test
* iteration) if the property is a running version. Otherwise, the raw
* string representation of the function is provided.
*
* @see JMeterProperty#getStringValue()
*/
@Override
public String getStringValue() {
JMeterContext ctx = JMeterContextService.getContext();// Expensive, so
// do
// once
if (!isRunningVersion() /*|| !ctx.isSamplingStarted()*/) {
log.debug("Not running version, return raw function string");
return function.getRawParameters();
}
if(!ctx.isSamplingStarted()) {
return function.execute();
}
log.debug("Running version, executing function");
int iter = ctx.getVariables() != null ? ctx.getVariables().getIteration() : -1;
if (iter < testIteration) {
testIteration = -1;
}
if (iter > testIteration || cacheValue == null) {
testIteration = iter;
cacheValue = function.execute();
}
return cacheValue;
}
示例8: execute
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler)
throws InvalidVariableException {
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
String script = ((CompoundVariable) values[0]).execute();
// Allow variable to be omitted
String varName = values.length < 2 ? null : ((CompoundVariable) values[1]).execute().trim();
String resultStr = "";
if(USE_RHINO_ENGINE) {
resultStr = executeWithRhino(previousResult, currentSampler, jmctx,
vars, script, varName);
} else {
resultStr = executeWithNashorn(previousResult, currentSampler, jmctx,
vars, script, varName);
}
return resultStr;
}
示例9: notifyListeners
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
/**
* Create additional SampleEvent in NON Parent Mode
*/
protected void notifyListeners() {
// TODO could these be done earlier (or just once?)
JMeterContext threadContext = getThreadContext();
JMeterVariables threadVars = threadContext.getVariables();
SamplePackage pack = (SamplePackage) threadVars.getObject(JMeterThread.PACKAGE_OBJECT);
if (pack == null) {
// If child of TransactionController is a ThroughputController and TPC does
// not sample its children, then we will have this
// TODO Should this be at warn level ?
log.warn("Could not fetch SamplePackage");
} else {
SampleEvent event = new SampleEvent(res, threadContext.getThreadGroup().getName(),threadVars, true);
// We must set res to null now, before sending the event for the transaction,
// so that we can ignore that event in our sampleOccured method
res = null;
// bug 50032
if (!getThreadContext().isReinitializingSubControllers()) {
lnf.notifyListeners(event, pack.getSampleListeners());
}
}
}
示例10: injectVariables
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
private void injectVariables(JMeterThread jmThread, JMeterContext threadContext) {
if (threadContext != null && threadContext.getVariables() != null) {
try {
Class<JMeterThread> cls = JMeterThread.class;
Field vars = cls.getDeclaredField("threadVars");
vars.setAccessible(true);
vars.set(jmThread, threadContext.getVariables());
} catch (Throwable ex) {
log.warn("Cannot inject variables into parallel thread ", ex);
}
}
}
示例11: iterationStart
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {
JMeterContext context = JMeterContextService.getContext();
MartiniResult result;
Martini next = getNext();
JMeterVariables variables = context.getVariables();
if (null == next) {
variables.remove(VARIABLE);
}
else {
variables.putObject(VARIABLE, next);
}
}
示例12: populateBindings
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
/**
* Populate variables to be passed to scripts
* @param bindings Bindings
*/
protected void populateBindings(Bindings bindings) {
final String label = getName();
final String fileName = getFilename();
final String scriptParameters = getParameters();
// Use actual class name for log
final Logger logger = LoggerFactory.getLogger(JSR223TestElement.class);
bindings.put("log", logger); // $NON-NLS-1$ (this name is fixed)
bindings.put("Label", label); // $NON-NLS-1$ (this name is fixed)
bindings.put("FileName", fileName); // $NON-NLS-1$ (this name is fixed)
bindings.put("Parameters", scriptParameters); // $NON-NLS-1$ (this name is fixed)
String [] args=JOrphanUtils.split(scriptParameters, " ");//$NON-NLS-1$
bindings.put("args", args); // $NON-NLS-1$ (this name is fixed)
// Add variables for access to context and variables
JMeterContext jmctx = JMeterContextService.getContext();
bindings.put("ctx", jmctx); // $NON-NLS-1$ (this name is fixed)
JMeterVariables vars = jmctx.getVariables();
bindings.put("vars", vars); // $NON-NLS-1$ (this name is fixed)
Properties props = JMeterUtils.getJMeterProperties();
bindings.put("props", props); // $NON-NLS-1$ (this name is fixed)
// For use in debugging:
bindings.put("OUT", System.out); // $NON-NLS-1$ (this name is fixed)
// Most subclasses will need these:
Sampler sampler = jmctx.getCurrentSampler();
bindings.put("sampler", sampler); // $NON-NLS-1$ (this name is fixed)
SampleResult prev = jmctx.getPreviousResult();
bindings.put("prev", prev); // $NON-NLS-1$ (this name is fixed)
}
示例13: initManager
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
protected void initManager(BSFManager mgr) throws BSFException{
final String label = getName();
final String fileName = getFilename();
final String scriptParameters = getParameters();
// Use actual class name for log
// final Logger logger = LoggingManager.getLoggerForShortName(getClass().getName());
mgr.declareBean("log", log, Logger.class); // $NON-NLS-1$
mgr.declareBean("Label",label, String.class); // $NON-NLS-1$
mgr.declareBean("FileName",fileName, String.class); // $NON-NLS-1$
mgr.declareBean("Parameters", scriptParameters, String.class); // $NON-NLS-1$
String [] args=JOrphanUtils.split(scriptParameters, " ");//$NON-NLS-1$
mgr.declareBean("args",args,args.getClass());//$NON-NLS-1$
// Add variables for access to context and variables
JMeterContext jmctx = JMeterContextService.getContext();
JMeterVariables vars = jmctx.getVariables();
Properties props = JMeterUtils.getJMeterProperties();
mgr.declareBean("ctx", jmctx, jmctx.getClass()); // $NON-NLS-1$
mgr.declareBean("vars", vars, vars.getClass()); // $NON-NLS-1$
mgr.declareBean("props", props, props.getClass()); // $NON-NLS-1$
// For use in debugging:
mgr.declareBean("OUT", System.out, PrintStream.class); // $NON-NLS-1$
// Most subclasses will need these:
Sampler sampler = jmctx.getCurrentSampler();
mgr.declareBean("sampler", sampler, Sampler.class);
SampleResult prev = jmctx.getPreviousResult();
mgr.declareBean("prev", prev, SampleResult.class);
}
示例14: testStarted
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
@Override
public void testStarted() {
started = true;
JMeterContext context = getThreadContext();
JMeterVariables vars = context.getVariables();
String startTimeString = vars.get("TIMESTAMPTIMER_START");
if (startTimeString != null)
{
startTime = Long.parseLong(startTimeString);
} else {
startTime = System.currentTimeMillis();
vars.put("TIMESTAMPTIMER_START", Long.toString(startTime));
vars.put("TIMESTAMP_TOTAL", Long.toString(timestampList.size()));
}
}
示例15: populateBindings
import org.apache.jmeter.threads.JMeterContext; //导入方法依赖的package包/类
/**
* Populate variables to be passed to scripts
* @param bindings Bindings
*/
protected void populateBindings(Bindings bindings) {
final String label = getName();
final String fileName = getFilename();
final String scriptParameters = getParameters();
// Use actual class name for log
final Logger logger = LoggingManager.getLoggerForShortName(getClass().getName());
bindings.put("log", logger);
bindings.put("Label", label);
bindings.put("FileName", fileName);
bindings.put("Parameters", scriptParameters);
String [] args=JOrphanUtils.split(scriptParameters, " ");//$NON-NLS-1$
bindings.put("args", args);
// Add variables for access to context and variables
JMeterContext jmctx = JMeterContextService.getContext();
bindings.put("ctx", jmctx);
JMeterVariables vars = jmctx.getVariables();
bindings.put("vars", vars);
Properties props = JMeterUtils.getJMeterProperties();
bindings.put("props", props);
// For use in debugging:
bindings.put("OUT", System.out);
// Most subclasses will need these:
Sampler sampler = jmctx.getCurrentSampler();
bindings.put("sampler", sampler);
SampleResult prev = jmctx.getPreviousResult();
bindings.put("prev", prev);
}