Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Include Controller to test plan (made of Include Controllers) without saving TestPlan leads to included code not being taken into account until save #3176

Closed
asfimport opened this issue Jul 31, 2013 · 5 comments

Comments

@asfimport
Copy link
Collaborator

Soul Patch (Bug 55334):
In a Test Plan, add a Thread Group which has Include Controllers in it. Each Include controller has a valid Test Fragment file path specified. The Test Plan as a whole is Valid.
Run the Test Plan to completion. Now add another Include Controller to this Test Plan using Add -> Logic Controller -> Include Controller.
Add a valid file path of a Test Fragment (This could be a duplicate of one of the other Include Controllers already in the Test Plan)
Now run the Test Plan. The following exception is encountered in the logs.

ERROR - jmeter.threads.JMeterThread: Test failed! java.lang.ClassCastException: org.apache.jmeter.gui.tree.JMeterTreeNode cannot be cast to org.apache.jmeter.testelement.TestElement
at org.apache.jmeter.threads.TestCompiler.addNode(TestCompiler.java:140)
at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:1001)
at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:986)
at org.apache.jmeter.threads.JMeterThread.initRun(JMeterThread.java:532)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:252)
at java.lang.Thread.run(Unknown Source)

Severity: major
OS: All

@asfimport
Copy link
Collaborator Author

Soul Patch (migrated from Bugzilla):
On Investigation it was found that when traversing the testTree in the initRun() method in JMeterThread.java class the newly added Include Controller is passed as a JMeterTreeNode instead of an IncludeController type.

Following is the code flow :
JMeterThread.run() --> JMeterThread.initRun() --> Traverses the testTree using the HashTreeTraverser 'compiler'. --> HashTree.traverse() called where the data.keySet() function returns all the keys. The definition of 'data' says :


// N.B. The keys can be either JMeterTreeNode or TestElement
protected final Map<Object, HashTree> data;


TestCompiler.addNode() called which tries to cast the JMeterTreeNode received to TestElement and a ClassCastException is thrown.

Need to investigate why the data.keySet returns a JMeterTreeNode. If it is acceptable then a code should be in place to extract the TestElement from the JMeterTreeNode to avoid the ClassCastException.

@asfimport
Copy link
Collaborator Author

Soul Patch (migrated from Bugzilla):
Found a fix that works well. Don't know if this is the exact fix but it does nothing too radical.
Checking for the instance type of the 'node' received. If it is a JMeterTreeNode then extract the TestElement and set it to 'node' and then move ahead.
The TestCompiler.addNode() method now looks like this :

/** {@inheritdoc} */
@OverRide
public void addNode(Object node, HashTree subTree) {
if(node instanceof JMeterTreeNode){
stack.addLast(((JMeterTreeNode)node).getTestElement());
}else{
stack.addLast((TestElement) node);
}
}

@asfimport
Copy link
Collaborator Author

Soul Patch (migrated from Bugzilla):
The patch should be applied to the src/core directory in the source code. It contains the fix for the reported issue. The patch modifies the code in the org.apache.jmeter.threads.TestCompiler.addNode() method.

The method should look like this after adding the patch.

/** {@inheritdoc} */
@OverRide
public void addNode(Object node, HashTree subTree) {
if(node instanceof JMeterTreeNode){
stack.addLast(((JMeterTreeNode)node).getTestElement());
}else{
stack.addLast((TestElement) node);
}
}

Created attachment IncludeControllerBug_src_core.patch: proposed patch containing the fix for the issue.

IncludeControllerBug_src_core.patch
Index: org/apache/jmeter/threads/TestCompiler.java
===================================================================
--- org/apache/jmeter/threads/TestCompiler.java	(revision 1509349)
+++ org/apache/jmeter/threads/TestCompiler.java	(working copy)
@@ -137,7 +137,12 @@
     /** {@inheritDoc} */
     @Override
     public void addNode(Object node, HashTree subTree) {
+	//Added to resolve the bug Bug 55334 - https://issues.apache.org/bugzilla/show_bug.cgi?id=55334
+    	if(node instanceof JMeterTreeNode){
+    		stack.addLast(((JMeterTreeNode)node).getTestElement());
+    	}else{
         stack.addLast((TestElement) node);
+    	}
     }
 
     /** {@inheritDoc} */

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
Date: Fri Aug 2 12:02:03 2013
New Revision: 1509647

URL: http://svn.apache.org/r1509647
Log:
#3176 - Adding Include Controller to test plan (made of Include Controllers) without saving TestPlan leads to included code not being taken into account until save
#3176

Modified:
jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
jmeter/trunk/xdocs/changes.xml

@asfimport
Copy link
Collaborator Author

@pmouawad (migrated from Bugzilla):
Thanks for patch, but in fact it was not fixing root cause which was due to ReplaceableController not being loaded when in GUI mode and before saving Test Tree.

This should be fixed now.
Also removed invalid code in o instanceof TestElement branch code:

else { // null subTree
convertSubTree(tree.getTree(item));
}

in this branch, tree.getTree(item) can only be null, so calling convertSubTree would lead to NPE.

Thanks for reporting issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant