Hello,
Sorry for taking so long to get this patch ready -- things have been busy lately.


As we discussed a couple weeks ago, this patch will remove unused fields from SampleResult. It also uses lazy instantiation for some of the remaining fields so that extra memory won't be used when the fields aren't actually used. The accessors for these fields now return null where they used to return an empty collection -- I found two places in the JMeter code that could not handle this, and have fixed those two places. (Although the code changes were based on current CVS, the analysis to find the callers of these methods was done a couple weeks ago on an older snapshot of the code, so if you made any recent changes involving calls to SampleResult.getSubResults or getAssertions recently you might want to double-check that code to ensure it can handle a null return value.)

I've done a bit of testing on this code and it appears to work fine, but I don't have any test plans which use Assertions or SubResults, so I haven't tested cases where these are actually instantiated. The code is pretty straight-forward so there shouldn't be any problems, but you never know.

As always, let me know if you have any questions.

[Hopefully this is the right way to do a patch over multiple files -- let me know if I need to do something differently in the future.]

Jeremy

Jeremy Arnold
[EMAIL PROTECTED]
http://xirr.com/~jeremy_a

Index: jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java,v
retrieving revision 1.4
diff -u -r1.4 SampleResult.java
--- jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java        20 Feb 
2003 02:59:15 -0000      1.4
+++ jakarta-jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java        5 Mar 
2003 15:49:27 -0000
@@ -2,7 +2,7 @@
  *  ====================================================================
  *  The Apache Software License, Version 1.1
  *
- *  Copyright (c) 2001 The Apache Software Foundation.  All rights
+ *  Copyright (c) 2001,2003 The Apache Software Foundation.  All rights
  *  reserved.
  *
  *  Redistribution and use in source and binary forms, with or without
@@ -77,11 +77,22 @@
  */
 public class SampleResult implements Serializable
 {
-       //public final static String URL = "sampler.url";
-
-       public final static String TAG_NAME = "sampleResult";
+    /**
+     * Data type value indicating that the response data is text.
+     *
+     * @see #getDataType
+     * @see #setDataType(java.lang.String)
+     */
        public final static String TEXT = "text";
+
+    /**
+     * Data type value indicating that the response data is binary.
+     *
+     * @see #getDataType
+     * @see #setDataType(java.lang.String)
+     */
        public final static String BINARY = "bin";
+
        private byte[] responseData;
        private String responseCode;
        private String label;
@@ -89,65 +100,30 @@
        private String threadName;
        private String responseMessage;
        private long timeStamp = 0;
-       private List assertionResults = new ArrayList();
-       private List subResults = new ArrayList();
+       private List assertionResults;
+       private List subResults;
        private String dataType;
        private boolean success;
-       private boolean mark = false;
-       private Set files = new HashSet();
+       private Set files;
     private String dataEncoding;
-       
-
-       Map map;
-       long time;
-       /**
-        *  Description of the Field
-        */
-       private final static String SAMPLE_LABEL = "displayName";
-       private final static String SAMPLER_CONFIG = "samplerConfig";
-       private final static String DATA_TYPE = "dataType";
-       private final static String RESPONSE_CODE = "responseCode";
-       private final static String RESPONSE_MESSAGE = "responseMessage";
-       private final static String THREAD_NAME = "threadName";
-       private final static String TIME_STAMP = "timeStamp";
-       /**
-        *  Description of the Field
-        */
-       private final static String ASSERTION_RESULTS = "assertionResults";
-       /**
-        *  Description of the Field
-        */
-       private final static String RESPONSE_DATA = "responseData";
-       /**
-        *  Description of the Field
-        */
-       private final static String SUCCESS = "success";
+    private long time;
 
-       /**
-        *  Description of the Field
-        */
        private final static String TOTAL_TIME = "totalTime";
 
        transient private static Logger log = 
Hierarchy.getDefaultHierarchy().getLoggerFor("jmeter.engine");
 
 
-       /**
-        *  !ToDo (Constructor description)
-        */
-       public SampleResult()
-       {
-               map = new HashMap();
-               time = 0;
-       }
-       
        public void setMarked(String filename)
        {
+        if (files == null) {
+            files = new HashSet();
+        }
                files.add(filename);
        }
        
        public boolean isMarked(String filename)
        {
-               return files.contains(filename);
+        return files != null && files.contains(filename);
        }       
        
        public String getResponseCode()
@@ -202,29 +178,48 @@
 
        public void addAssertionResult(AssertionResult assertResult)
        {
+        if (assertionResults == null) {
+            assertionResults = new ArrayList();
+        }
                assertionResults.add(assertResult);
        }
 
+    /**
+     * Gets the assertion results associated with this sample.
+     *
+     * @return an array containing the assertion results for this sample.
+     *         Returns null if there are no assertion results.
+     */
        public AssertionResult[] getAssertionResults()
        {
+        if (assertionResults == null) {
+            return null;
+        }
                return (AssertionResult[])assertionResults.toArray(new 
AssertionResult[0]);
        }
 
        public void addSubResult(SampleResult subResult)
        {
+        if (subResults == null) {
+            subResults = new ArrayList();
+        }
                subResults.add(subResult);
        }
 
+    /**
+     * Gets the subresults associated with this sample.
+     *
+     * @return an array containing the subresults for this sample. Returns
+     *         null if there are no subresults.
+     */
        public SampleResult[] getSubResults()
        {
+        if (subResults == null) {
+            return null;
+        }
                return (SampleResult[])subResults.toArray(new SampleResult[0]);
        }
 
-       /**
-        *  Description of the Method
-        *
-        [EMAIL PROTECTED]  info  Description of the Parameter
-        */
        public void configure(Configuration info)
        {
                setTime(info.getAttributeAsLong(TOTAL_TIME,0L));
@@ -248,9 +243,6 @@
        public void setResponseData(byte[] response)
        {
                responseData = response;
-               /*DefaultConfiguration responseChild = new 
DefaultConfiguration(RESPONSE_DATA, "");
-               responseChild.setValue(getHexString(response));
-               addChild(responseChild);*/
        }
 
        
@@ -264,14 +256,6 @@
        public byte[] getResponseData()
        {
                return responseData;
-               /*Configuration responseChild = getChild(RESPONSE_DATA);
-               ByteArrayOutputStream bytes = new ByteArrayOutputStream();
-               String res = responseChild.getValue("");
-               for (int i = 0; i < res.length(); i+=2)
-               {
-                       bytes.write(Integer.parseInt(res.substring(i,i+2),16));
-               }
-               return bytes.toByteArray();*/
        }
 
        public void setSamplerData(TestElement s)
@@ -294,11 +278,6 @@
                return time;
        }
 
-       /**
-        *  !ToDoo (Method description)
-        *
-        [EMAIL PROTECTED]    !ToDo (Return description)
-        */
        public boolean isSuccessful()
        {
                return success;
Index: jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java,v
retrieving revision 1.16
diff -u -r1.16 SaveService.java
--- jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java     21 Feb 2003 
16:33:39 -0000      1.16
+++ jakarta-jmeter/src/core/org/apache/jmeter/save/SaveService.java     5 Mar 2003 
15:51:04 -0000
@@ -561,9 +561,11 @@
 
         SampleResult[] subResults = result.getSubResults();
 
-        for (int i = 0; i < subResults.length; i++)
-        {
-            config.addChild(getConfiguration(subResults[i], funcTest));
+        if (subResults != null) {
+            for (int i = 0; i < subResults.length; i++)
+            {
+                config.addChild(getConfiguration(subResults[i], funcTest));
+            }
         }
 
         AssertionResult[] assResults = result.getAssertionResults();
@@ -571,9 +573,11 @@
         if (funcTest)
         {
             config.addChild(getConfigForTestElement(null, result.getSamplerData()));
-            for (int i = 0; i < assResults.length; i++)
-            {
-                config.addChild(getConfiguration(assResults[i]));
+            if (assResults != null) {
+                for (int i = 0; i < assResults.length; i++)
+                {
+                    config.addChild(getConfiguration(assResults[i]));
+                }
             }
             config.addChild(getConfiguration(result.getResponseData()));
         }
@@ -584,12 +588,15 @@
             if (assertionsResultsToSave == SAVE_ALL_ASSERTIONS)
             {
                 config.addChild(getConfigForTestElement(null, 
result.getSamplerData()));
-                for (int i = 0; i < assResults.length; i++)
-                {
-                    config.addChild(getConfiguration(assResults[i]));
+                if (assResults != null) {
+                    for (int i = 0; i < assResults.length; i++)
+                    {
+                        config.addChild(getConfiguration(assResults[i]));
+                    }
                 }
             }
             else if ((assertionsResultsToSave == SAVE_FIRST_ASSERTION)
+                    && assResults != null
                     && assResults.length > 0)
             {
                 config.addChild(getConfiguration(assResults[0]));
Index: 
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/AssertionVisualizer.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jmeter/src/components/org/apache/jmeter/visualizers/AssertionVisualizer.java,v
retrieving revision 1.6
diff -u -r1.6 AssertionVisualizer.java
--- 
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/AssertionVisualizer.java   
     3 Feb 2003 14:29:01 -0000       1.6
+++ 
jakarta-jmeter/src/components/org/apache/jmeter/visualizers/AssertionVisualizer.java   
     5 Mar 2003 15:52:01 -0000
@@ -2,7 +2,7 @@
  * ====================================================================
  * The Apache Software License, Version 1.1
  *
- * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * Copyright (c) 2001,2003 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -134,15 +134,10 @@
         if (res != null)
         {
             StringBuffer display = new StringBuffer();
-            List assertionResults = Arrays.asList(res.getAssertionResults());
-
-            if (assertionResults != null)
-            {
-                Iterator iter = assertionResults.iterator();
-
-                while (iter.hasNext())
-                {
-                    AssertionResult item = (AssertionResult) iter.next();
+            AssertionResult assertionResults[] = res.getAssertionResults();
+            if (assertionResults != null) {
+                for (int i = 0; i < assertionResults.length; i++) {
+                    AssertionResult item = assertionResults[i];
 
                     if (item.isFailure() || item.isError())
                     {


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to