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

Number of bytes for subsamples not added to sample when sub samples are added #1917

Closed
asfimport opened this issue Apr 22, 2007 · 2 comments
Closed

Comments

@asfimport
Copy link
Collaborator

Alf Hogemark (Bug 42184):
When using HTTP Request sampler, for example, and ticking on the "Download
images" checkbox, the sample for the web page will get the images and other
resources downloaded for the page as subsamples.
The time elapsed for the sample for the web page includes the time it takes to
download the subsamples.
But the number of bytes downloaded for each subsample is not added to the
"parent" sample. Therefore the "number of bytes per second" in the "Summary
report" is incorrect.

I think the number of bytes for a sample should be updated to include the number
of bytes for subsamples added to the sample.

Severity: normal
OS: All

@asfimport
Copy link
Collaborator Author

Alf Hogemark (migrated from Bugzilla):
The suggested patch updates the number of bytes for the sample who receives
subsamples, so that the number of bytes is equal to the sum of bytes for its'
subsamples, plus the number of bytes for the sample itself.

I also think that it would be useful to show the number of bytes for the sample
in the "ViewResultsFullVisualizer" GUI, so I've included that in the patch.

And I have added some unit tests to TestSampleResults.

Created attachment patch_for_42184.patch: Suggested patch

patch_for_42184.patch
Index: C:/Documents and Settings/alf/workspace/Jmeter/test/src/org/apache/jmeter/samplers/TestSampleResult.java
===================================================================
--- C:/Documents and Settings/alf/workspace/Jmeter/test/src/org/apache/jmeter/samplers/TestSampleResult.java	(revision 531151)
+++ C:/Documents and Settings/alf/workspace/Jmeter/test/src/org/apache/jmeter/samplers/TestSampleResult.java	(working copy)
@@ -22,6 +22,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.jmeter.util.Calculator;
 import org.apache.log.LogTarget;
 import org.apache.log.format.Formatter;
 import org.apache.log.format.RawFormatter;
@@ -85,6 +86,88 @@
             res.samplePause();
             assertFalse(wr.toString().length() == 0);
         }
+        
+        public void testByteCount() throws Exception {
+            SampleResult res = new SampleResult();
+            
+            res.sampleStart();
+            res.setBytes(100);
+            res.setSampleLabel("sample of size 100 bytes");
+            res.sampleEnd();
+            assertEquals(100, res.getBytes());
+            assertEquals("sample of size 100 bytes", res.getSampleLabel());
+        }
+
+        public void testSubResults() throws Exception {
+        	// This test tries to emulate a http sample, with two
+        	// subsamples, representing images that are downloaded for the
+        	// page representing the first sample.
+        	
+            // Sample that will get two sub results, simulates a web page load 
+            SampleResult resWithSubResults = new SampleResult();            
+            resWithSubResults.sampleStart();
+            Thread.sleep(100);
+            resWithSubResults.setBytes(300);
+            resWithSubResults.setSampleLabel("sample with two subresults");
+            resWithSubResults.setSuccessful(true);
+            resWithSubResults.sampleEnd();
+            long sampleWithSubResultsTime = resWithSubResults.getTime();
+        	
+            // Sample with no sub results, simulates an image download
+            SampleResult resNoSubResults1 = new SampleResult();            
+            resNoSubResults1.sampleStart();
+            Thread.sleep(100);
+            resNoSubResults1.setBytes(100);
+            resNoSubResults1.setSampleLabel("sample with no subresults");
+            resNoSubResults1.setSuccessful(true);
+            resNoSubResults1.sampleEnd();
+            long sample1Time = resNoSubResults1.getTime();
+
+            assertTrue(resNoSubResults1.isSuccessful());
+            assertEquals(100, resNoSubResults1.getBytes());
+            assertEquals("sample with no subresults", resNoSubResults1.getSampleLabel());
+            assertEquals(1, resNoSubResults1.getSampleCount());
+            assertEquals(0, resNoSubResults1.getSubResults().length);
+            
+            // Sample with no sub results, simulates an image download 
+            SampleResult resNoSubResults2 = new SampleResult();            
+            resNoSubResults2.sampleStart();
+            Thread.sleep(100);
+            resNoSubResults2.setBytes(200);
+            resNoSubResults2.setSampleLabel("sample with no subresults");
+            resNoSubResults2.setSuccessful(true);
+            resNoSubResults2.sampleEnd();
+            long sample2Time = resNoSubResults2.getTime();
+
+            assertTrue(resNoSubResults2.isSuccessful());
+            assertEquals(200, resNoSubResults2.getBytes());
+            assertEquals("sample with no subresults", resNoSubResults2.getSampleLabel());
+            assertEquals(1, resNoSubResults2.getSampleCount());
+            assertEquals(0, resNoSubResults2.getSubResults().length);
+            
+            // Now add the subsamples to the sample
+            resWithSubResults.addSubResult(resNoSubResults1);
+            resWithSubResults.addSubResult(resNoSubResults2);
+            assertTrue(resWithSubResults.isSuccessful());
+            assertEquals(600, resWithSubResults.getBytes());
+            assertEquals("sample with two subresults", resWithSubResults.getSampleLabel());
+            assertEquals(1, resWithSubResults.getSampleCount());
+            assertEquals(2, resWithSubResults.getSubResults().length);
+            long totalTime = resWithSubResults.getTime();
+            
+            // Check the sample times
+            assertEquals(sampleWithSubResultsTime + sample1Time + sample2Time, totalTime);
+            
+            // Check that calculator gets the correct statistics from the sample
+            Calculator calculator = new Calculator();
+            calculator.addSample(resWithSubResults);
+            assertEquals(600, calculator.getTotalBytes());
+            assertEquals(1, calculator.getCount());
+            assertEquals(1d / (totalTime / 1000d), calculator.getRate());
+            // Check that the throughput uses the time elapsed for the sub results
+            assertFalse(1d / (sampleWithSubResultsTime / 1000d) <= calculator.getRate());
+        }
+
         // TODO some more invalid sequence tests needed
 }
 
Index: C:/Documents and Settings/alf/workspace/Jmeter/src/components/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java
===================================================================
--- C:/Documents and Settings/alf/workspace/Jmeter/src/components/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java	(revision 531151)
+++ C:/Documents and Settings/alf/workspace/Jmeter/src/components/org/apache/jmeter/visualizers/ViewResultsFullVisualizer.java	(working copy)
@@ -324,10 +324,11 @@
 							sampleDataField.setText(sd);
 						}
 
-						statsDoc.insertString(statsDoc.getLength(), "Thread Name: " + res.getThreadName() + "\n", null);
+						statsDoc.insertString(statsDoc.getLength(), "Thread Name: " + res.getThreadName() + "\n", null); // $NON-NLS-2$
 						String startTime = new Date(res.getStartTime()).toString();
-						statsDoc.insertString(statsDoc.getLength(), "Sample Start: " + startTime + "\n", null);
-						statsDoc.insertString(statsDoc.getLength(), "Load time: " + res.getTime() + "\n", null);
+						statsDoc.insertString(statsDoc.getLength(), "Sample Start: " + startTime + "\n", null); // $NON-NLS-2$
+						statsDoc.insertString(statsDoc.getLength(), "Load time: " + res.getTime() + "\n", null); // $NON-NLS-2$
+						statsDoc.insertString(statsDoc.getLength(), "Size in bytes: " + res.getBytes() + "\n", null); // $NON-NLS-2$
 
 						String responseCode = res.getResponseCode();
 						log.debug("valueChanged1 : response code - " + responseCode);
Index: C:/Documents and Settings/alf/workspace/Jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java
===================================================================
--- C:/Documents and Settings/alf/workspace/Jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java	(revision 531151)
+++ C:/Documents and Settings/alf/workspace/Jmeter/src/core/org/apache/jmeter/samplers/SampleResult.java	(working copy)
@@ -412,7 +412,10 @@
 			subResults = new ArrayList();
 		}
 		subResults.add(subResult);
-		setEndTime(subResult.getEndTime());// Extend the time to the end of the added sample
+		// Extend the time to the end of the added sample
+		setEndTime(subResult.getEndTime());
+		// Include the byte count for the added sample
+		setBytes(getBytes() + subResult.getBytes());
 		subResult.setParent(this);
 	}
 

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
Thanks, fixed in r531175.

By the way, I had to change

assertEquals(1d / (totalTime / 1000d), calculator.getRate());
to
assertEquals(1d / (totalTime / 1000d), calculator.getRate(),0d);

as assertEquals(double,double) does not exist in the version of JUnit used by
JMeter.

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