use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ProxyControl method putSamplesIntoModel.
private void putSamplesIntoModel(ActionEvent e) {
// return early, as JMeterTreeModel might not been initialized yet
if (sampleQueue.isEmpty()) {
return;
}
final JMeterTreeModel treeModel = getJmeterTreeModel();
while (!sampleQueue.isEmpty()) {
SamplerInfo info = sampleQueue.poll();
try {
log.info("Add sample {} into controller {}", info.sampler.getName(), info.prefix);
try {
long now = info.recordedAt;
long deltaT = now - lastTime;
boolean firstInBatch = prepareTree(treeModel, deltaT, info);
if (lastTime == 0) {
// Decent value for timers
deltaT = 0;
}
lastTime = now;
if (info.groupingMode == GROUPING_STORE_FIRST_ONLY) {
if (!firstInBatch) {
// Huh! don't store this one!
return;
}
// If we're not storing subsequent samplers, we'll need the
// first sampler to do all the work...:
info.sampler.setFollowRedirects(true);
info.sampler.setImageParser(true);
}
final JMeterTreeNode targetNode = getTargetNode(info.target, info.groupingMode);
final JMeterTreeNode newNode = treeModel.addComponent(info.sampler, targetNode);
if (firstInBatch) {
if (addAssertions) {
addAssertion(treeModel, newNode);
}
addTimers(treeModel, newNode, deltaT);
}
addTestElements(treeModel, info.testElements, newNode);
} catch (IllegalUserActionException ex) {
log.error("Error placing sampler", ex);
JMeterUtils.reportErrorToUser(ex.getMessage());
}
} catch (Exception ex) {
log.error("Error placing sampler", ex);
JMeterUtils.reportErrorToUser(ex.getMessage());
}
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ProxyControl method notifySampleListeners.
/**
* This will notify sample listeners directly within the Proxy of the
* sampling that just occurred -- so that we have a means to record the
* server's responses as we go.
*
* @param event sampling event to be delivered
*/
@SuppressWarnings("JdkObsolete")
private void notifySampleListeners(SampleEvent event) {
JMeterTreeModel treeModel = getJmeterTreeModel();
JMeterTreeNode myNode = treeModel.getNodeOf(this);
if (myNode != null) {
Enumeration<?> kids = myNode.children();
while (kids.hasMoreElements()) {
JMeterTreeNode subNode = (JMeterTreeNode) kids.nextElement();
if (subNode.isEnabled()) {
TestElement testElement = subNode.getTestElement();
if (testElement instanceof SampleListener) {
((SampleListener) testElement).sampleOccurred(event);
}
}
}
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ProxyControl method prepareTree.
private boolean prepareTree(final JMeterTreeModel treeModel, long deltaT, SamplerInfo info) {
HTTPSamplerBase sampler = info.sampler;
JMeterTreeNode myTarget = info.target;
int cachedGroupingMode = info.groupingMode;
boolean prefixChanged = false;
if (oldPrefix == null || !oldPrefix.equals(info.prefix)) {
oldPrefix = info.prefix;
prefixChanged = true;
}
if (deltaT > sampleGap || prefixChanged) {
String controllerName = StringUtils.defaultString(getPrefixHTTPSampleName(), sampler.getName());
if (!myTarget.isLeaf() && cachedGroupingMode == GROUPING_ADD_SEPARATORS) {
addDivider(treeModel, myTarget);
}
if (cachedGroupingMode == GROUPING_IN_SIMPLE_CONTROLLERS) {
addSimpleController(treeModel, myTarget, controllerName);
}
if (cachedGroupingMode == GROUPING_IN_TRANSACTION_CONTROLLERS) {
addTransactionController(treeModel, myTarget, controllerName);
}
// Remember this was first in its batch
return true;
}
return false;
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class ApplyNamingConvention method applyNamingPolicyToCurrentNode.
/**
* Apply the naming policy of currentNode children
* @param guiPackage {@link GuiPackage}
* @param currentNode Parent node of elements on which we apply naming policy
*/
@SuppressWarnings("JdkObsolete")
private void applyNamingPolicyToCurrentNode(GuiPackage guiPackage, JMeterTreeNode currentNode) {
TreeNodeNamingPolicy namingPolicy = guiPackage.getNamingPolicy();
guiPackage.updateCurrentNode();
Enumeration<?> enumeration = currentNode.children();
int index = 0;
namingPolicy.resetState(currentNode);
while (enumeration.hasMoreElements()) {
JMeterTreeNode childNode = (JMeterTreeNode) enumeration.nextElement();
namingPolicy.rename(currentNode, childNode, index);
index++;
}
}
use of org.apache.jmeter.gui.tree.JMeterTreeNode in project jmeter by apache.
the class Clear method doAction.
@Override
public void doAction(ActionEvent e) {
GuiPackage guiPackage = GuiPackage.getInstance();
final String actionCommand = e.getActionCommand();
if (actionCommand.equals(ActionNames.CLEAR)) {
JMeterGUIComponent guiComp = guiPackage.getCurrentGui();
if (guiComp instanceof Clearable) {
((Clearable) guiComp).clearData();
}
} else {
guiPackage.getMainFrame().clearData();
for (JMeterTreeNode node : guiPackage.getTreeModel().getNodesOfType(Clearable.class)) {
JMeterGUIComponent guiComp = guiPackage.getGui(node.getTestElement());
if (guiComp instanceof Clearable) {
Clearable item = (Clearable) guiComp;
try {
item.clearData();
} catch (Exception ex) {
log.error("Can't clear: {} {}", node, guiComp, ex);
}
}
}
}
}
Aggregations