jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1422660 - in /jmeter/trunk/src/components/org/apache/jmeter/extractor: Extractor.java HtmlExtractor.java JoddExtractor.java
Date Sun, 16 Dec 2012 18:26:44 GMT
Author: pmouawad
Date: Sun Dec 16 18:26:43 2012
New Revision: 1422660

URL: http://svn.apache.org/viewvc?rev=1422660&view=rev
Log:
Bug 54259 - Introduce a CSS or jquery-like based Extractor
Introduce parse caching to improve performances
Bugzilla Id: 54259

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/extractor/Extractor.java   (contents, props
changed)
    jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java   (contents,
props changed)
    jmeter/trunk/src/components/org/apache/jmeter/extractor/JoddExtractor.java   (contents,
props changed)

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/Extractor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/Extractor.java?rev=1422660&r1=1422659&r2=1422660&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/Extractor.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/Extractor.java Sun Dec 16 18:26:43
2012
@@ -34,7 +34,7 @@ public interface Extractor extends Seria
      * @param inputString Page or excerpt
      * @param result List<String> results
      * @param found current matches found
-     * @param cacheIfPossible Cache analysis if possibler
+     * @param cacheKey If not null, the implementation is encouraged to cache parsing result
and use this key as part of cache key
      * @return match found updated
      */
     int extract(
@@ -44,5 +44,5 @@ public interface Extractor extends Seria
             String inputString, 
             List<String> result,
             int found,
-            boolean cacheIfPossible);
+            String cacheKey);
 }

Propchange: jmeter/trunk/src/components/org/apache/jmeter/extractor/Extractor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java?rev=1422660&r1=1422659&r2=1422660&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java Sun Dec 16
18:26:43 2012
@@ -179,13 +179,14 @@ public class HtmlExtractor extends Abstr
         List<String> result = new ArrayList<String>();
         if (isScopeVariable()){
             String inputString=vars.get(getVariableName());
-            getExtractorImpl().extract(expression, attribute, matchNumber, inputString, result,
found, true);
+            getExtractorImpl().extract(expression, attribute, matchNumber, inputString, result,
found, "-1");
         } else {
             List<SampleResult> sampleList = getSampleList(previousResult);
             int i=0;
             for (SampleResult sr : sampleList) {
                 String inputString = sr.getResponseDataAsString();
-                found = getExtractorImpl().extract(expression, attribute, matchNumber, inputString,
result, found, i==0);
+                found = getExtractorImpl().extract(expression, attribute, matchNumber, inputString,
result, found,
+                        i>0 ? null : Integer.toString(i));
                 i++;
                 if (matchNumber > 0 && found == matchNumber){// no need to process
further
                     break;

Propchange: jmeter/trunk/src/components/org/apache/jmeter/extractor/HtmlExtractor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/JoddExtractor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/JoddExtractor.java?rev=1422660&r1=1422659&r2=1422660&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/JoddExtractor.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/JoddExtractor.java Sun Dec 16
18:26:43 2012
@@ -25,6 +25,7 @@ import jodd.lagarto.dom.LagartoDOMBuilde
 import jodd.lagarto.dom.Node;
 import jodd.lagarto.dom.NodeSelector;
 
+import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jorphan.util.JOrphanUtils;
 
 /**
@@ -39,6 +40,7 @@ public class JoddExtractor implements Ex
      */
     private static final long serialVersionUID = -7235814605293262972L;
 
+    private static final String CACHE_KEY_PREFIX = JoddExtractor.class.getName()+"_PARSED_BODY";
 
     /**
      * 
@@ -53,10 +55,22 @@ public class JoddExtractor implements Ex
     @Override
     public int extract(String expression, String attribute, int matchNumber,
             String inputString, List<String> result, int found,
-            boolean cacheIfPossible) {
-        LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
-        jodd.lagarto.dom.Document doc = domBuilder.parse(inputString);
-        NodeSelector nodeSelector = new NodeSelector(doc);
+            String cacheKey) {
+        NodeSelector nodeSelector = null;
+        if (cacheKey != null) {
+            nodeSelector = (NodeSelector) 
+                    JMeterContextService.getContext().getSamplerContext().get(CACHE_KEY_PREFIX+cacheKey);
+            if(nodeSelector==null) {
+                LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
+                jodd.lagarto.dom.Document doc = domBuilder.parse(inputString);
+                nodeSelector = new NodeSelector(doc);
+                JMeterContextService.getContext().getSamplerContext().put(CACHE_KEY_PREFIX+cacheKey,
nodeSelector);
+            }
+        } else {
+            LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
+            jodd.lagarto.dom.Document doc = domBuilder.parse(inputString);
+            nodeSelector = new NodeSelector(doc);
+        }
         LinkedList<Node> elements = nodeSelector.select(expression);
         int size = elements.size();
         for (int i = 0; i < size; i++) {

Propchange: jmeter/trunk/src/components/org/apache/jmeter/extractor/JoddExtractor.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message