本文整理汇总了Java中org.apache.jmeter.threads.JMeterVariables类的典型用法代码示例。如果您正苦于以下问题:Java JMeterVariables类的具体用法?Java JMeterVariables怎么用?Java JMeterVariables使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JMeterVariables类属于org.apache.jmeter.threads包,在下文中一共展示了JMeterVariables类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug54467
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
public void testBug54467() throws Exception {
JMeterContext jmctx = JMeterContextService.getContext();
LoopController loop = new LoopController();
Map<String, String> variables = new HashMap<String, String>();
ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
jmctx.setVariables(new JMeterVariables());
StringProperty prop = new StringProperty(LoopController.LOOPS,"${__Random(1,12,)}");
JMeterProperty newProp = transformer.transformValue(prop);
newProp.setRunningVersion(true);
loop.setProperty(newProp);
loop.addTestElement(new TestSampler("random run"));
loop.setRunningVersion(true);
loop.initialize();
int loops = loop.getLoops();
for (int i = 0; i < loops; i++) {
Sampler s = loop.next();
assertNotNull(s);
}
assertNull(loop.next());
}
示例2: send
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的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();
}
}
示例3: iterationStart
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {
boolean isIndependentListPerThread = getIndependentListPerThread();
if (!isIndependentListPerThread && directoryListingIterator == null) {
throw new JMeterStopThreadException("All files in the directory have been passed.");
}
if (getIterator().hasNext()) {
JMeterVariables variables = JMeterContextService.getContext().getVariables();
variables.put(
getStringOrDefault(getDestinationVariableName(), DEFAULT_DESTINATION_VARIABLE_NAME),
getFilePath(getIterator().next())
);
} else {
// TODO: interrupt iteration
directoryListingIterator = null;
throw new JMeterStopThreadException("All files in the directory have been passed.");
}
}
示例4: changeVariablesMap
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的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);
}
}
示例5: readRandom
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
private void readRandom() {
final RandomCSVReader reader = getReader();
long lineAddr;
synchronized (reader) {
if (reader.hasNextRecord()) {
lineAddr = reader.getNextLineAddr();
} else {
// TODO: interrupt iteration
randomCSVReader = null;
throw new JMeterStopThreadException("All records in the CSV file have been passed.");
}
}
JMeterVariables variables = JMeterContextService.getContext().getVariables();
putVariables(variables, getDestinationVariableKeys(), reader.readLineWithSeek(lineAddr));
}
示例6: testPutVariables1
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
@Test
public void testPutVariables1() throws Exception {
String path = this.getClass().getResource("/SpaceDelimiter.csv").getPath();
JMeterVariables jMeterVariables = new JMeterVariables();
JMeterContextService.getContext().setVariables(jMeterVariables);
RandomCSVDataSetConfig config = new RandomCSVDataSetConfig();
config.setFilename(path);
config.setFileEncoding("UTF-8");
config.setDelimiter(" ");
config.setVariableNames("column1,column2");
config.setRandomOrder(false);
config.setRewindOnTheEndOfList(false);
config.setIndependentListPerThread(false);
config.setIgnoreFirstLine(true);
config.testStarted();
config.iterationStart(null);
assertEquals(2, jMeterVariables.entrySet().size());
assertEquals("1", jMeterVariables.get("column1"));
assertEquals("2", jMeterVariables.get("column2"));
}
示例7: testPutVariables2
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
@Test
public void testPutVariables2() throws Exception {
String path = this.getClass().getResource("/SpaceDelimiter.csv").getPath();
JMeterVariables jMeterVariables = new JMeterVariables();
JMeterContextService.getContext().setVariables(jMeterVariables);
RandomCSVDataSetConfig config = new RandomCSVDataSetConfig();
config.setFilename(path);
config.setFileEncoding("UTF-8");
config.setDelimiter(" ");
config.setVariableNames("column1,column2,column3,column4");
config.setRandomOrder(false);
config.setRewindOnTheEndOfList(false);
config.setIndependentListPerThread(false);
config.setIgnoreFirstLine(true);
config.testStarted();
config.iterationStart(null);
assertEquals(3, jMeterVariables.entrySet().size());
assertEquals("1", jMeterVariables.get("column1"));
assertEquals("2", jMeterVariables.get("column2"));
assertEquals("3", jMeterVariables.get("column3"));
}
示例8: testPutVariables3
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
@Test
public void testPutVariables3() throws Exception {
String path = this.getClass().getResource("/SpaceDelimiter.csv").getPath();
JMeterVariables jMeterVariables = new JMeterVariables();
JMeterContextService.getContext().setVariables(jMeterVariables);
RandomCSVDataSetConfig config = new RandomCSVDataSetConfig();
config.setFilename(path);
config.setFileEncoding("UTF-8");
config.setDelimiter(" ");
config.setVariableNames("column1,column2,column3,column4");
config.setRandomOrder(false);
config.setRewindOnTheEndOfList(false);
config.setIndependentListPerThread(false);
config.setIgnoreFirstLine(true);
config.testStarted();
config.iterationStart(null);
assertEquals(3, jMeterVariables.entrySet().size());
assertEquals("1", jMeterVariables.get("column1"));
assertEquals("2", jMeterVariables.get("column2"));
assertEquals("3", jMeterVariables.get("column3"));
}
示例9: iterationStart
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
/**
* For every JMeter sample, iterationStart method gets invoked, it initializes load generator and for each iteration sets new message as JMeter variable
*
* @param loopIterationEvent
*/
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {
//Check if load generator is instantiated
if (generator == null) {
try {
//instantiate plaintext load generator
generator = new PlaintTextLoadGenerator(getJsonSchema());
} catch (Exception e) {
log.error("Failed to create PlaintTextLoadGenerator instance", e);
}
}
//For ever iteration put message in jmeter variables
JMeterVariables variables = JMeterContextService.getContext().getVariables();
variables.putObject(placeHolder, generator.nextMessage());
}
示例10: iterationStart
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
/**
* For every JMeter sample, iterationStart method gets invoked, it initializes load generator and for each iteration sets new message as JMeter variable
*
* @param loopIterationEvent
*/
@Override
public void iterationStart(LoopIterationEvent loopIterationEvent) {
try {
//Check if load generator is instantiated
if (generator == null) {
//instantiate serialized load generator
generator = new SerializedLoadGenerator(className, objProperties);
}
//For ever iteration put message in jmeter variables
JMeterVariables variables = JMeterContextService.getContext().getVariables();
variables.putObject(placeHolder, generator.nextMessage());
} catch (Exception e) {
log.error("Failed to create PlaintTextLoadGenerator instance", e);
}
}
示例11: setup
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
@Before
public void setup() throws IOException {
zkServer = new EmbeddedZookeeper();
String zkConnect = ZKHOST + ":" + zkServer.port();
zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
ZkUtils zkUtils = ZkUtils.apply(zkClient, false);
Properties brokerProps = new Properties();
brokerProps.setProperty("zookeeper.connect", zkConnect);
brokerProps.setProperty("broker.id", "0");
brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST +":" + BROKERPORT);
KafkaConfig config = new KafkaConfig(brokerProps);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
//AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
JMeterContext jmcx = JMeterContextService.getContext();
jmcx.setVariables(new JMeterVariables());
}
示例12: iterationStart
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
@Override
public void iterationStart(LoopIterationEvent event) {
TestElement source = event.getSource();
JMeterContext threadContext = source.getThreadContext();
JMeterVariables variables = threadContext.getVariables();
iterationStart(variables);
}
示例13: getApplicationContext
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的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);
}
示例14: isDone
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的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();
}
示例15: endOfLoop
import org.apache.jmeter.threads.JMeterVariables; //导入依赖的package包/类
private boolean endOfLoop(boolean loopEnd) {
String cnd = getCondition().trim();
if(log.isDebugEnabled()) {
log.debug("Condition string:" + cnd+".");
}
boolean res;
// If blank, only check previous sample when at end of loop
if ((loopEnd && cnd.length() == 0) || "LAST".equalsIgnoreCase(cnd)) {// $NON-NLS-1$
JMeterVariables threadVars = JMeterContextService.getContext().getVariables();
res = "false".equalsIgnoreCase(threadVars.get(JMeterThread.LAST_SAMPLE_OK));// $NON-NLS-1$
} else {
// cnd may be null if next() called us
res = "false".equalsIgnoreCase(cnd);// $NON-NLS-1$
}
if(log.isDebugEnabled()) {
log.debug("Condition value: " + res);
}
return res;
}