use of org.apache.jmeter.timers.Timer in project jmeter by apache.
the class TestCompiler method saveTransactionControllerConfigs.
private void saveTransactionControllerConfigs(TransactionController tc) {
List<ConfigTestElement> configs = new LinkedList<>();
List<Controller> controllers = new LinkedList<>();
List<SampleListener> listeners = new LinkedList<>();
List<Timer> timers = new LinkedList<>();
List<Assertion> assertions = new LinkedList<>();
LinkedList<PostProcessor> posts = new LinkedList<>();
LinkedList<PreProcessor> pres = new LinkedList<>();
for (int i = stack.size(); i > 0; i--) {
addDirectParentControllers(controllers, stack.get(i - 1));
for (Object item : testTree.list(stack.subList(0, i))) {
if (item instanceof SampleListener) {
listeners.add((SampleListener) item);
}
if (item instanceof Assertion) {
assertions.add((Assertion) item);
}
}
}
SamplePackage pack = new SamplePackage(configs, listeners, timers, assertions, posts, pres, controllers);
pack.setSampler(new TransactionSampler(tc, tc.getName()));
pack.setRunningVersion(true);
transactionControllerConfigMap.put(tc, pack);
}
use of org.apache.jmeter.timers.Timer in project jmeter by apache.
the class JMeterThread method delay.
private void delay(List<Timer> timers) {
long totalDelay = 0;
for (Timer timer : timers) {
TestBeanHelper.prepare((TestElement) timer);
long delay = timer.delay();
if (APPLY_TIMER_FACTOR && timer.isModifiable()) {
if (log.isDebugEnabled()) {
log.debug("Applying TIMER_FACTOR:{} on timer:{} for thread:{}", TIMER_FACTOR, ((TestElement) timer).getName(), getThreadName());
}
delay = Math.round(delay * TIMER_FACTOR);
}
totalDelay += delay;
}
if (totalDelay > 0) {
try {
if (scheduler) {
// We reduce pause to ensure end of test is not delayed by a sleep ending after test scheduled end
// See Bug 60049
totalDelay = TIMER_SERVICE.adjustDelay(totalDelay, endTime);
}
TimeUnit.MILLISECONDS.sleep(totalDelay);
} catch (InterruptedException e) {
log.warn("The delay timer was interrupted - probably did not wait as long as intended.");
Thread.currentThread().interrupt();
}
}
}
use of org.apache.jmeter.timers.Timer in project jmeter by apache.
the class ProxyControl method addTimers.
/**
* Helper method to replicate any timers found within the Proxy Controller
* into the provided sampler, while replacing any occurrences of string _T_
* in the timer's configuration with the provided deltaT.
* Called from AWT Event thread
* @param model
* Test component tree model
* @param node
* Sampler node in where we will add the timers
* @param deltaT
* Time interval from the previous request
*/
private void addTimers(JMeterTreeModel model, JMeterTreeNode node, long deltaT) {
TestPlan variables = new TestPlan();
// $NON-NLS-1$
variables.addParameter("T", Long.toString(deltaT));
ValueReplacer replacer = new ValueReplacer(variables);
JMeterTreeNode mySelf = model.getNodeOf(this);
Enumeration<JMeterTreeNode> children = mySelf.children();
while (children.hasMoreElements()) {
JMeterTreeNode templateNode = children.nextElement();
if (templateNode.isEnabled()) {
TestElement template = templateNode.getTestElement();
if (template instanceof Timer) {
TestElement timer = (TestElement) template.clone();
try {
timer.setComment("Recorded:" + Long.toString(deltaT) + "ms");
replacer.undoReverseReplace(timer);
model.addComponent(timer, node);
} catch (InvalidVariableException | IllegalUserActionException e) {
// Not 100% sure, but I believe this can't happen, so
// I'll log and throw an error:
log.error("Program error", e);
throw new Error(e);
}
}
}
}
}
use of org.apache.jmeter.timers.Timer in project jmeter by apache.
the class TreeClonerForValidation method addNodeToTree.
/**
* @see org.apache.jmeter.engine.TreeCloner#addNodeToTree(java.lang.Object)
*/
@Override
protected Object addNodeToTree(Object node) {
if ((VALIDATION_IGNORE_TIMERS && node instanceof Timer) || (VALIDATION_IGNORE_BACKENDS && node instanceof Backend)) {
// don't add timer or backend
return node;
} else {
Object clonedNode = super.addNodeToTree(node);
if (clonedNode instanceof org.apache.jmeter.threads.ThreadGroup) {
ThreadGroup tg = (ThreadGroup) clonedNode;
tg.setNumThreads(VALIDATION_NUMBER_OF_THREADS);
tg.setScheduler(false);
tg.setProperty(ThreadGroup.DELAY, 0);
if (((AbstractThreadGroup) clonedNode).getSamplerController() instanceof LoopController) {
((LoopController) ((AbstractThreadGroup) clonedNode).getSamplerController()).setLoops(VALIDATION_ITERATIONS);
}
}
return clonedNode;
}
}
Aggregations