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

It should be easier to plug a custom SampleSender in jmeter #2249

Closed
asfimport opened this issue Jun 19, 2009 · 6 comments
Closed

It should be easier to plug a custom SampleSender in jmeter #2249

asfimport opened this issue Jun 19, 2009 · 6 comments

Comments

@asfimport
Copy link
Collaborator

benoit.wiart (Bug 47394):
It's not possible to plug a custom SampleSender without making change in SampleSenderFactory and recompiling jmeter.

It should be possible to provide the implementation class in the config file

If the jmeter dev / comitters thing are willing to accept this change then I will provide a patch (keeping backward compatibility)

Severity: normal
OS: All

@asfimport
Copy link
Collaborator Author

benoit.wiart (migrated from Bugzilla):
How it will be done (open to discussion) :

add a new optionnal parameter in the config file (ex : sample.sender.class)
If the parameter is set
load the class and create a new instance of the samplesender
if it fails default to StandardSampleSender + log the exception
else
use the 'old' parameters 'mode' and 'hold_samples'

Benoit Wiart
Ubik Ingénierie
www.ubik-ingenierie.com

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
This is a good idea.

Regarding properties: I don't think it's necessary to add yet another property; just set hold=false and mode=classname.

If the class is not found, I think the run should fail rather than reverting to StandardSampler.

Please submit a patch. Ideally this should cover the factory class, jmeter.properties and the user documentation.

@asfimport
Copy link
Collaborator Author

benoit.wiart (migrated from Bugzilla):
Created attachment SampleSenderFactory.java.patch: sample sender factory patch

SampleSenderFactory.java.patch
Index: src/core/org/apache/jmeter/samplers/SampleSenderFactory.java
===================================================================
--- src/core/org/apache/jmeter/samplers/SampleSenderFactory.java	(revision 780105)
+++ src/core/org/apache/jmeter/samplers/SampleSenderFactory.java	(working copy)
@@ -18,10 +18,16 @@
 
 package org.apache.jmeter.samplers;
 
+import java.lang.reflect.Constructor;
+
 import org.apache.jmeter.util.JMeterUtils;
-import org.apache.jmeter.samplers.StatisticalSampleSender;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
 
 public class SampleSenderFactory {
+
+    private static final Logger log = LoggingManager.getLoggerForClass();
+    
     /**
      * Checks for the Jmeter property mode and returns the required class.
      *
@@ -45,9 +51,24 @@
         } else if (type.equalsIgnoreCase("Statistical")) {
             StatisticalSampleSender s = new StatisticalSampleSender(listener);
             return s;
-        } else {
+        } else if (type.equalsIgnoreCase("Standard")) {
             StandardSampleSender s = new StandardSampleSender(listener);
             return s;
+        } else {
+            // should be a user provided class name
+            SampleSender s = null;
+            try {
+                Class clazz = Class.forName(type);
+                Constructor cons = clazz.getConstructor(new Class[] {RemoteSampleListener.class});
+                s = (SampleSender) cons.newInstance(new Object [] {listener});
+            } catch (Exception e) {
+                // houston we have a problem !!
+                log.error("Unable to create a sample sender from class "+type, e);
+                throw new IllegalArgumentException(e.getMessage());
+            }
+
+            return s;
         }
+
     }
 }

@asfimport
Copy link
Collaborator Author

benoit.wiart (migrated from Bugzilla):
Created attachment jmeter.properties.patch: jmeter.properties patch

jmeter.properties.patch
Index: bin/jmeter.properties
===================================================================
--- bin/jmeter.properties	(revision 786693)
+++ bin/jmeter.properties	(working copy)
@@ -459,11 +459,13 @@
 # Batch returns samples in batches
 # Statistical returns sample stats
 # hold_samples was originally defined as a separate property,
-# but can now also be defined using remote.mode
+# but can now also be defined using mode=Hold
+# mode can also be the class name of an implementation of org.apache.jmeter.samplers.SampleSender
 #mode=Standard
 #mode=Batch
 #mode=Hold
 #mode=Statistical
+#mode=org.example.load.MySampleSender
 #hold_samples=true
 #num_sample_threshold=100
 #time_threshold=60000

@asfimport
Copy link
Collaborator Author

benoit.wiart (migrated from Bugzilla):
Created attachment remote-test.xml.patch: documentation patch

remote-test.xml.patch
Index: xdocs/usermanual/remote-test.xml
===================================================================
--- xdocs/usermanual/remote-test.xml	(revision 786693)
+++ xdocs/usermanual/remote-test.xml	(working copy)
@@ -216,6 +216,8 @@
     </ul>
     Other fields that vary between samples are lost. 
     </li>
+    <li>Custom implementation : set the mode parameter to your custom sample sender class name
+    </li>
     </ul>
 </ul>
 <p>The following properties apply to the Batch and Statistical modes:</p>

@asfimport
Copy link
Collaborator Author

Sebb (migrated from Bugzilla):
Thanks for the patches, which have been applied to SVN:

URL: http://svn.apache.org/viewvc?rev=786747&view=rev
Log:
#2249 - It should be easier to plug a custom SampleSender in jmeter

The updated code will be in nightly builds after r786747.

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