本文整理汇总了Java中org.apache.jmeter.samplers.Sampler类的典型用法代码示例。如果您正苦于以下问题:Java Sampler类的具体用法?Java Sampler怎么用?Java Sampler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sampler类属于org.apache.jmeter.samplers包,在下文中一共展示了Sampler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
@Override
public void process(){
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
log.error("BeanShell not found");
return;
}
JMeterContext jmctx = JMeterContextService.getContext();
Sampler sam = jmctx.getCurrentSampler();
try {
// Add variables for access to context and variables
bshInterpreter.set("sampler", sam);//$NON-NLS-1$
processFileOrScript(bshInterpreter);
} catch (JMeterException e) {
log.warn("Problem in BeanShell script "+e);
}
}
示例2: testBug54467
import org.apache.jmeter.samplers.Sampler; //导入依赖的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());
}
示例3: next
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
@Override
public Sampler next() {
if (chosen) {
Sampler result = super.next();
if (result == null || currentCopy != current ||
(super.getSubControllers().get(current) instanceof TransactionController)) {
reset();
for (TestElement element : super.getSubControllers()) {
if (element instanceof Controller) {
((Controller) element).triggerEndOfLoop();
}
}
return null;
}
return result;
} else {
chosen = true;
choose();
return super.next();
}
}
示例4: getChildItems
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
private Map<JMeterTreeNode, Boolean> getChildItems(JMeterTreeNode root, WeightedSwitchController element) {
Map<JMeterTreeNode, Boolean> result = new LinkedHashMap<>();
for (int i = 0; i < root.getChildCount(); i++) {
JMeterTreeNode child = (JMeterTreeNode) root.getChildAt(i);
TestElement te = child.getTestElement();
if (element != root.getTestElement()) {
result.putAll(getChildItems(child, element));
} else {
if (te instanceof Sampler || te instanceof Controller) {
result.put(child, te.isEnabled());
}
}
}
return result;
}
示例5: testGeneric
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
@Test
public void testGeneric() {
WeightedSwitchController obj = new WeightedSwitchController();
obj.addTestElement(getSampler("0"));
obj.addTestElement(getSampler("1"));
obj.addTestElement(getSampler("2"));
obj.addTestElement(getSampler("5"));
PowerTableModel mdl = new PowerTableModel(new String[]{"name", WeightedSwitchController.WEIGHTS}, new Class[]{String.class, String.class});
mdl.addRow(new String[]{"0", "0"});
mdl.addRow(new String[]{"1", "1"});
mdl.addRow(new String[]{"2", "2"});
mdl.addRow(new String[]{"5", "5"});
obj.setData(mdl);
for (int n = 0; n < 800; n++) {
Sampler s = obj.next();
log.info("Sampler: " + s.getName());
Assert.assertNotNull(s);
Assert.assertNull(obj.next());
Assert.assertNotEquals(s.getName(), "0");
}
}
示例6: actionPerformed
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent actionEvent) {
result.clear();
if (exprField.getText().isEmpty()) {
return;
}
CompoundVariable masterFunction = new CompoundVariable(exprField.getText());
SampleResult previousResult = context.getPreviousResult();
Sampler currentSampler = context.getCurrentSampler();
try {
result.setText(masterFunction.execute(previousResult, currentSampler));
} catch (Throwable e) {
ByteArrayOutputStream text = new ByteArrayOutputStream(1024);
e.printStackTrace(new PrintStream(text));
result.setText(text.toString());
result.scrollToTop();
}
}
示例7: next
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
/**
* @see org.apache.jmeter.control.Controller#next()
*/
@Override
public Sampler next() {
// We should only evalute the condition if it is the first
// time ( first "iteration" ) we are called.
// For subsequent calls, we are inside the IfControllerGroup,
// so then we just pass the control to the next item inside the if control
boolean result = true;
if(isEvaluateAll() || isFirst()) {
result = isUseExpression() ?
evaluateExpression(getCondition())
:
evaluateCondition(getCondition());
}
if (result) {
return super.next();
}
// If-test is false, need to re-initialize indexes
try {
initializeSubControllers();
return nextIsNull();
} catch (NextIsNullException e1) {
return null;
}
}
示例8: nextIsAController
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected Sampler nextIsAController(Controller controller) throws NextIsNullException {
Sampler sampler = controller.next();
if (sampler == null) {
currentReturnedNull(controller);
return next();
}
currentReturnedAtLeastOne = true;
if (getStyle() == IGNORE_SUB_CONTROLLERS) {
incrementCurrent();
skipNext = true;
} else {
searchStart = null;
}
return sampler;
}
示例9: next
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
/**
* @see org.apache.jmeter.control.Controller#next()
*/
@Override
public Sampler next() {
if (StringUtils.isEmpty(getLockName())) {
log.warn("Empty lock name in Critical Section Controller:"
+ getName());
return super.next();
}
if (isFirst()) {
// Take the lock for first child element
long startTime = System.currentTimeMillis();
if (this.currentLock == null) {
this.currentLock = getOrCreateLock();
}
this.currentLock.lock();
long endTime = System.currentTimeMillis();
if (log.isDebugEnabled()) {
log.debug(Thread.currentThread().getName()
+ " acquired lock:'" + getLockName()
+ "' in Critical Section Controller " + getName()
+ " in:" + (endTime - startTime) + " ms");
}
}
return super.next();
}
示例10: nextIsAController
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
@Override
protected Sampler nextIsAController(Controller controller) throws NextIsNullException {
if (!isGenerateParentSample()) {
return super.nextIsAController(controller);
}
Sampler returnValue;
Sampler sampler = controller.next();
if (sampler == null) {
currentReturnedNull(controller);
// We need to call the super.next, instead of this.next, which is done in GenericController,
// because if we call this.next(), it will return the TransactionSampler, and we do not want that.
// We need to get the next real sampler or controller
returnValue = super.next();
} else {
returnValue = sampler;
}
return returnValue;
}
示例11: doEndTransactionSampler
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
private SampleResult doEndTransactionSampler(
TransactionSampler transactionSampler,
Sampler parent,
SamplePackage transactionPack,
JMeterContext threadContext) {
SampleResult transactionResult;
// Get the transaction sample result
transactionResult = transactionSampler.getTransactionResult();
transactionResult.setThreadName(threadName);
transactionResult.setGroupThreads(threadGroup.getNumberOfThreads());
transactionResult.setAllThreads(JMeterContextService.getNumberOfThreads());
// Check assertions for the transaction sample
checkAssertions(transactionPack.getAssertions(), transactionResult, threadContext);
// Notify listeners with the transaction sample result
if (!(parent instanceof TransactionSampler)) {
notifyListeners(transactionPack.getSampleListeners(), transactionResult);
}
compiler.done(transactionPack);
return transactionResult;
}
示例12: interrupt
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public boolean interrupt(){
try {
interruptLock.lock();
Sampler samp = currentSampler; // fetch once; must be done under lock
if (samp instanceof Interruptible){ // (also protects against null)
log.warn("Interrupting: " + threadName + " sampler: " +samp.getName());
try {
boolean found = ((Interruptible)samp).interrupt();
if (!found) {
log.warn("No operation pending");
}
return found;
} catch (Exception e) {
log.warn("Caught Exception interrupting sampler: "+e.toString());
}
} else if (samp != null){
log.warn("Sampler is not Interruptible: "+samp.getName());
}
} finally {
interruptLock.unlock();
}
return false;
}
示例13: configureWithConfigElements
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
private void configureWithConfigElements(Sampler sam, List<ConfigTestElement> configs) {
sam.clearTestElementChildren();
for (ConfigTestElement config : configs) {
if (!(config instanceof NoConfigMerge))
{
if(sam instanceof ConfigMergabilityIndicator) {
if(((ConfigMergabilityIndicator)sam).applies(config)) {
sam.addTestElement(config);
}
} else {
// Backward compatibility
sam.addTestElement(config);
}
}
}
}
示例14: execute
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler)
throws InvalidVariableException {
// return JMeterContextService.getContext().getCurrentSampler().getName();
String name = "";
if (currentSampler != null) { // will be null if function is used on TestPlan
name = currentSampler.getName();
}
if (values.length > 0){
JMeterVariables vars = getVariables();
if (vars != null) {// May be null if function is used on TestPlan
String varName = ((CompoundVariable) values[0]).execute().trim();
if (varName.length() > 0) {
vars.put(varName, name);
}
}
}
return name;
}
示例15: execute
import org.apache.jmeter.samplers.Sampler; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public String execute(SampleResult previousResult, Sampler currentSampler)
throws InvalidVariableException {
String stringToLog = ((CompoundVariable) values[0]).execute();
String priorityString;
if (values.length > 1) { // We have a default
priorityString = ((CompoundVariable) values[1]).execute();
if (priorityString.length() == 0) {
priorityString = DEFAULT_PRIORITY;
}
} else {
priorityString = DEFAULT_PRIORITY;
}
Throwable t = null;
if (values.length > 2) { // Throwable wanted
t = new Throwable(((CompoundVariable) values[2]).execute());
}
LogFunction.logDetails(log, stringToLog, priorityString, t, "");
return "";
}