├── websocket ├── README.md └── src │ ├── test │ ├── resources │ │ └── mockito-extensions │ │ │ └── org.mockito.plugins.MockMaker │ └── java │ │ └── blazemeter │ │ └── jmeter │ │ └── plugins │ │ └── websocket │ │ └── test │ │ └── MqttCallBackImplTest.java │ └── main │ └── java │ └── blazemeter │ └── jmeter │ └── plugins │ └── websocket │ └── sampler │ ├── Handler.java │ ├── Factory.java │ └── gui │ ├── WebSocketSendSamplerGui.java │ └── WebSocketCollectorSamplerGui.java ├── xmpp ├── xmpp.png ├── xzibit.jpg ├── xmpp-sampler.png ├── xmpp-connection.png ├── XMPPConnection.md ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── blazemeter │ │ │ └── jmeter │ │ │ └── xmpp │ │ │ ├── JMeterXMPPSamplerMock.java │ │ │ ├── JMeterXMPPConnectionTest.java │ │ │ ├── actions │ │ │ ├── DisconnectTest.java │ │ │ ├── RawXMLTest.java │ │ │ ├── SendMessageTest.java │ │ │ └── GetBookmarksTest.java │ │ │ ├── JMeterXMPPSamplerGuiTest.java │ │ │ ├── XMPPConnectionMock.java │ │ │ └── JMeterXMPPConnectionGuiTest.java │ └── main │ │ └── java │ │ └── com │ │ └── blazemeter │ │ └── jmeter │ │ └── xmpp │ │ ├── actions │ │ ├── Connect.java │ │ ├── Disconnect.java │ │ ├── GetBookmarks.java │ │ ├── RawXML.java │ │ ├── MUC.java │ │ ├── ServiceDiscovery.java │ │ ├── Login.java │ │ ├── AbstractXMPPAction.java │ │ ├── RosterAction.java │ │ └── NoOp.java │ │ ├── Loggers.java │ │ └── JMeterXMPPSampler.java └── XMPPSampler.md ├── random-csv-data-set ├── src │ ├── test │ │ ├── resources │ │ │ ├── SpaceDelimiter.csv │ │ │ ├── EmptyLastLine.csv │ │ │ ├── text.csv │ │ │ ├── JMeterCsvResults.csv │ │ │ └── TabDelimiter.csv │ │ └── java │ │ │ └── com │ │ │ └── blazemeter │ │ │ └── jmeter │ │ │ ├── TestRandomCSVActionTest.java │ │ │ └── RandomCSVDataSetConfigGuiTest.java │ └── main │ │ └── java │ │ └── com │ │ └── blazemeter │ │ ├── csv │ │ ├── RandomBufferedReader.java │ │ └── BufferedReaderExt.java │ │ └── jmeter │ │ └── TestRandomCSVAction.java ├── randomCSVDataSetConfig.png └── RandomCSVDataSetConfig.md ├── parallel ├── ParallelSampler.png ├── ParallelController.png ├── src │ ├── main │ │ └── java │ │ │ ├── org │ │ │ └── apache │ │ │ │ └── jmeter │ │ │ │ ├── threads │ │ │ │ └── JMeterContextServiceAccessorParallel.java │ │ │ │ └── protocol │ │ │ │ └── http │ │ │ │ ├── sampler │ │ │ │ └── HCAccessor.java │ │ │ │ └── control │ │ │ │ └── ThreadSafeCookieManager.java │ │ │ └── com │ │ │ └── blazemeter │ │ │ └── jmeter │ │ │ └── controller │ │ │ ├── traverse │ │ │ └── CustomTreeCloner.java │ │ │ ├── ParallelListenerNotifier.java │ │ │ ├── DummyThreadGroup.java │ │ │ └── TestCompilerParallel.java │ └── test │ │ └── java │ │ └── com │ │ └── blazemeter │ │ └── jmeter │ │ ├── http │ │ ├── ParallelHTTPSamplerMock.java │ │ └── ParallelHTTPSamplerTest.java │ │ └── controller │ │ ├── ParallelControllerGuiTest.java │ │ ├── traverse │ │ └── CustomTreeClonerTest.java │ │ ├── JMeterThreadParallelTest.java │ │ └── ParallelListenerNotifierTest.java └── Parallel.md ├── wsc ├── WeightedSwitchController.png ├── WeightedSwitchController.md └── pom.xml ├── sense-uploader ├── BlazeMeterPlugin.png ├── blazemeter_uploader.png ├── loadosophia_uploader.png ├── src │ ├── main │ │ └── java │ │ │ ├── kg │ │ │ └── apc │ │ │ │ └── jmeter │ │ │ │ └── notifier │ │ │ │ └── StatusNotifierCallback.java │ │ │ ├── org │ │ │ └── loadosophia │ │ │ │ └── jmeter │ │ │ │ └── LoadosophiaUploadResults.java │ │ │ └── com │ │ │ └── blazemeter │ │ │ └── api │ │ │ ├── BlazeMeterReport.java │ │ │ ├── explorer │ │ │ ├── BZAObject.java │ │ │ ├── Master.java │ │ │ ├── User.java │ │ │ ├── Workspace.java │ │ │ ├── Account.java │ │ │ ├── Project.java │ │ │ ├── Test.java │ │ │ └── Session.java │ │ │ └── http │ │ │ └── BlazeMeterHttpUtils.java │ └── test │ │ └── java │ │ ├── com │ │ └── blazemeter │ │ │ └── api │ │ │ ├── BlazemeterReportTest.java │ │ │ ├── explorer │ │ │ ├── BZAObjectTest.java │ │ │ ├── UserTest.java │ │ │ ├── MasterTest.java │ │ │ ├── ProjectTest.java │ │ │ ├── WorkspaceTest.java │ │ │ ├── AccountTest.java │ │ │ ├── SessionTest.java │ │ │ └── TestTest.java │ │ │ ├── http │ │ │ ├── BlazeMeterHttpUtilsEmul.java │ │ │ └── BlazeMeterHttpUtilsTest.java │ │ │ └── data │ │ │ └── JSONConverterTest.java │ │ ├── org │ │ └── loadosophia │ │ │ └── jmeter │ │ │ ├── LoadosophiaAPIClientEmul.java │ │ │ └── LoadosophiaAPIClientTest.java │ │ └── kg │ │ └── apc │ │ └── jmeter │ │ ├── reporters │ │ ├── bzm │ │ │ ├── BLCEmul.java │ │ │ ├── BlazemeterUploaderTest.java │ │ │ ├── BlazemeterUploaderGuiTest.java │ │ │ └── BlazemeterBackendListenerClientTest.java │ │ └── notifier │ │ │ └── StatusNotifierCallbackTest.java │ │ └── http │ │ └── HttpUtilsEmul.java ├── BlazemeterPlugin.md ├── LoadosophiaUploader.md ├── BlazeMeterUploader.md └── pom.xml ├── directory-listing ├── directoryListing.png ├── DirectoryListing.md ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── blazemeter │ │ │ └── jmeter │ │ │ ├── DirectoryListingIteratorTest.java │ │ │ └── DirectoryListingConfigGuiTest.java │ └── main │ │ └── java │ │ └── com │ │ └── blazemeter │ │ └── jmeter │ │ ├── TestDirectoryListingAction.java │ │ └── DirectoryListingIterator.java └── pom.xml ├── rotating-listener ├── rotatingListener.png ├── RotatingListener.md ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── blazemeter │ │ │ └── jmeter │ │ │ └── RotatingResultCollectorGui.java │ └── test │ │ └── java │ │ └── com │ │ └── blazemeter │ │ └── jmeter │ │ └── RotatingResultCollectorGuiTest.java └── pom.xml ├── .travis └── install-maven-dependency.sh ├── pom.xml ├── .travis.yml ├── README.md └── .gitignore /websocket/README.md: -------------------------------------------------------------------------------- 1 | # Web Socket PLUGIN 2 | Repo for Web Socket plugin 3 | 4 | 5 | -------------------------------------------------------------------------------- /xmpp/xmpp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/xmpp/xmpp.png -------------------------------------------------------------------------------- /websocket/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker: -------------------------------------------------------------------------------- 1 | mock-maker-inline -------------------------------------------------------------------------------- /xmpp/xzibit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/xmpp/xzibit.jpg -------------------------------------------------------------------------------- /random-csv-data-set/src/test/resources/SpaceDelimiter.csv: -------------------------------------------------------------------------------- 1 | first second third 2 | 1 2 3 3 | 4 5 6 4 | 7 8 9 -------------------------------------------------------------------------------- /random-csv-data-set/src/test/resources/EmptyLastLine.csv: -------------------------------------------------------------------------------- 1 | first second third 2 | 1 2 3 3 | 4 5 6 4 | 7 8 9 5 | -------------------------------------------------------------------------------- /xmpp/xmpp-sampler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/xmpp/xmpp-sampler.png -------------------------------------------------------------------------------- /xmpp/xmpp-connection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/xmpp/xmpp-connection.png -------------------------------------------------------------------------------- /parallel/ParallelSampler.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/parallel/ParallelSampler.png -------------------------------------------------------------------------------- /parallel/ParallelController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/parallel/ParallelController.png -------------------------------------------------------------------------------- /wsc/WeightedSwitchController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/wsc/WeightedSwitchController.png -------------------------------------------------------------------------------- /sense-uploader/BlazeMeterPlugin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/sense-uploader/BlazeMeterPlugin.png -------------------------------------------------------------------------------- /directory-listing/directoryListing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/directory-listing/directoryListing.png -------------------------------------------------------------------------------- /rotating-listener/rotatingListener.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/rotating-listener/rotatingListener.png -------------------------------------------------------------------------------- /sense-uploader/blazemeter_uploader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/sense-uploader/blazemeter_uploader.png -------------------------------------------------------------------------------- /sense-uploader/loadosophia_uploader.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/sense-uploader/loadosophia_uploader.png -------------------------------------------------------------------------------- /random-csv-data-set/randomCSVDataSetConfig.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blazemeter/jmeter-bzm-plugins/master/random-csv-data-set/randomCSVDataSetConfig.png -------------------------------------------------------------------------------- /sense-uploader/src/main/java/kg/apc/jmeter/notifier/StatusNotifierCallback.java: -------------------------------------------------------------------------------- 1 | package kg.apc.jmeter.notifier; 2 | 3 | public interface StatusNotifierCallback { 4 | 5 | void notifyAbout(String info); 6 | } 7 | -------------------------------------------------------------------------------- /random-csv-data-set/src/test/resources/text.csv: -------------------------------------------------------------------------------- 1 | firstname;lastname;street;city 2 | Hänsel;Mustermann;Einbahnstraße;Hamburg 3 | André;Lecompte;Rue du marché;Moÿ-de-l'Aisne 4 | Ἀλέξανδρος;Павлов;Большая Пироговская улица;Москва́ 5 | בנימין;يعقوب;Street;Megapolis -------------------------------------------------------------------------------- /.travis/install-maven-dependency.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | set -ex 3 | 4 | if !(mvn dependency:get -Dartifact=$2:$3:$4); then 5 | mvn com.googlecode.maven-download-plugin:download-maven-plugin:1.4.0:wget -Ddownload.url=$1 6 | mvn install:install-file -Dfile=target/${1##*/} -DgroupId=$2 -DartifactId=$3 -Dversion=$4 -Dpackaging=jar 7 | fi 8 | -------------------------------------------------------------------------------- /sense-uploader/BlazemeterPlugin.md: -------------------------------------------------------------------------------- 1 | # Reporters 2 | [BlazeMeter Uploader](BlazeMeterUploader.md) for uploading result to [BlazeMeter](https://a.blazemeter.com/) during the test running. 3 | 4 | [BM. Sense Uploader](LoadosophiaUploader.md) for uploading results to [BlazeMeter Sense](https://sense.blazemeter.com/?utm_source=jpgc&utm_medium=link&utm_campaign=wiki) immediately after test end. -------------------------------------------------------------------------------- /random-csv-data-set/src/test/resources/JMeterCsvResults.csv: -------------------------------------------------------------------------------- 1 | timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,bytes 2 | 1393227741256,1425,GET /ordermgmt/login - Login Page,200,OK,Thread Group 1-1,text,true,3478 3 | 1393227741257,2204,GET /ordermgmt/pre-logout,200,OK,"Thread Group 1-1{ 4 | asdasdasdd 5 | fds 6 | fs 7 | sds}",text,true,19714 8 | 1393227741258,2204,GET /ordermgmt/pre-logout,200,OK,Thread Group 1-1,text,true,19714 -------------------------------------------------------------------------------- /xmpp/XMPPConnection.md: -------------------------------------------------------------------------------- 1 | # XMPP Connection Config 2 | ![](xmpp.png) 3 | 4 | XMPP Connection Config item is required for any XMPP testing script. [XMPP Samplers](XMPPSampler.md) takes connection context from this element. 5 | 6 | TCP tansport is fully functional and tested with common XMPP servers, like `ejabberd`, `openfire` and `hipchat`. 7 | 8 | Please note that `BOSH` protocol option is experimental and may be not fully functional. 9 | 10 | ![](xmpp-connection.png) -------------------------------------------------------------------------------- /rotating-listener/RotatingListener.md: -------------------------------------------------------------------------------- 1 | # Rotating JTL Listener 2 | 3 | Rotating JTL Listener is a Listener that allows writing sequence of JTL files, limited by number of samples per file. 4 | 5 | This enables recorded file to be handled by some background cleanup process, 6 | to be archived/deleted for saving disk space during soak tests and long duration/hight throughput tests. 7 | 8 | File names form sequence like `result.jtl => result.1.jtl => result.2.jtl`. 9 | 10 | ![](rotatingListener.png) 11 | -------------------------------------------------------------------------------- /parallel/src/main/java/org/apache/jmeter/threads/JMeterContextServiceAccessorParallel.java: -------------------------------------------------------------------------------- 1 | package org.apache.jmeter.threads; 2 | 3 | // you did not see this, ok? 4 | public class JMeterContextServiceAccessorParallel { // "Parallel" is to not clash with Debugger's class 5 | public static void decrNumberOfThreads() { 6 | JMeterContextService.decrNumberOfThreads(); 7 | } 8 | 9 | public static void incrNumberOfThreads() { 10 | JMeterContextService.incrNumberOfThreads(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /parallel/src/main/java/org/apache/jmeter/protocol/http/sampler/HCAccessor.java: -------------------------------------------------------------------------------- 1 | package org.apache.jmeter.protocol.http.sampler; 2 | 3 | import java.net.URL; 4 | 5 | // due to JMeter's closed namespaces we have to have this class to access it 6 | public class HCAccessor { 7 | public static HTTPAbstractImpl getInstance(HTTPSamplerBase sampler) { 8 | return new HTTPHC4Impl(sampler); 9 | } 10 | 11 | public static HTTPSampleResult sample(HTTPAbstractImpl impl, URL u, String method, boolean areFollowingRedirect, int depth) { 12 | return impl.sample(u, method, areFollowingRedirect, depth); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/JMeterXMPPSamplerMock.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp; 2 | 3 | import org.jivesoftware.smack.SmackException; 4 | import org.jivesoftware.smack.XMPPConnection; 5 | 6 | import java.security.KeyManagementException; 7 | import java.security.NoSuchAlgorithmException; 8 | 9 | public class JMeterXMPPSamplerMock extends JMeterXMPPSampler { 10 | 11 | public XMPPConnectionMock conn = new XMPPConnectionMock(); 12 | 13 | @Override 14 | public XMPPConnection getXMPPConnection() throws KeyManagementException, NoSuchAlgorithmException, SmackException { 15 | return conn; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/JMeterXMPPConnectionTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp; 2 | 3 | import junit.framework.TestCase; 4 | import org.jivesoftware.smack.SmackException; 5 | 6 | import java.security.KeyManagementException; 7 | import java.security.NoSuchAlgorithmException; 8 | 9 | public class JMeterXMPPConnectionTest extends TestCase { 10 | 11 | public void testTestStarted() throws NoSuchAlgorithmException, KeyManagementException, SmackException, InterruptedException { 12 | JMeterXMPPConnection obj = new JMeterXMPPConnection(); 13 | obj.setAddress("localhost"); 14 | obj.testStarted(""); 15 | obj.getConnection(); 16 | obj.testEnded(""); 17 | } 18 | } -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/actions/DisconnectTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSamplerMock; 4 | import org.apache.jmeter.samplers.SampleResult; 5 | import org.junit.Test; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | public class DisconnectTest { 11 | 12 | @Test 13 | public void testPerform() throws Exception { 14 | Disconnect obj = new Disconnect(); 15 | obj.perform(new JMeterXMPPSamplerMock(), new SampleResult()); 16 | } 17 | 18 | @Test 19 | public void testAddUI() throws Exception { 20 | Disconnect obj = new Disconnect(); 21 | obj.addUI(new JPanel(), new GridBagConstraints(), new GridBagConstraints()); 22 | } 23 | } -------------------------------------------------------------------------------- /sense-uploader/src/main/java/org/loadosophia/jmeter/LoadosophiaUploadResults.java: -------------------------------------------------------------------------------- 1 | package org.loadosophia.jmeter; 2 | 3 | public class LoadosophiaUploadResults { 4 | 5 | private String redirect = ""; 6 | private int testID; 7 | private int queueID; 8 | 9 | public String getRedirectLink() { 10 | return redirect; 11 | } 12 | 13 | public void setRedirectLink(String string) { 14 | redirect = string; 15 | } 16 | 17 | public void setQueueID(int aQueueID) { 18 | queueID = aQueueID; 19 | } 20 | 21 | public void setTestID(int aTestID) { 22 | testID = aTestID; 23 | } 24 | 25 | public int getTestID() { 26 | return testID; 27 | } 28 | 29 | public int getQueueID() { 30 | return queueID; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blazemeter.jmeter 8 | jmeter-bzm-plugins 9 | 0.0 10 | pom 11 | 12 | 13 | 14 | directory-listing 15 | parallel 16 | rotating-listener 17 | sense-uploader 18 | wsc 19 | xmpp 20 | websocket 21 | random-csv-data-set 22 | 23 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/BlazemeterReportTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertTrue; 7 | 8 | public class BlazemeterReportTest { 9 | 10 | @Test 11 | public void test() throws Exception { 12 | BlazeMeterReport report = new BlazeMeterReport(); 13 | 14 | String project = "project"; 15 | report.setProject(project); 16 | assertEquals(project, report.getProject()); 17 | 18 | String title = "title"; 19 | report.setTitle(title); 20 | assertEquals(title, report.getTitle()); 21 | 22 | String token = "token"; 23 | report.setToken(token); 24 | assertEquals(token, report.getToken()); 25 | 26 | report.setShareTest(true); 27 | assertTrue(report.isShareTest()); 28 | } 29 | } -------------------------------------------------------------------------------- /wsc/WeightedSwitchController.md: -------------------------------------------------------------------------------- 1 | # Weighted Switch Controller 2 | 3 | This controller takes the information about child elements and offers managing relative weights for them. Relative weight means how frequently the child element will be executed during thread iterations. Please note that each thread has independent counter of iterations. 4 | 5 | Relative weights mapped to child names and it save values even if the order of the child has changed. In the case of adding a new child or rename existing child will be set the default value of the relative weight for this child. If the child element is disabled, the relative weight of this element will not be counted in the test. 6 | 7 | * `Random Choice` - on each iteration plugin will choose a random item. This check box can not guarantee that actual percent of child elements execution will equals with expected (delta in tests not more than 0.5%) 8 | 9 | ![](WeightedSwitchController.png) -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/BZAObjectTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 5 | 6 | import static org.junit.Assert.*; 7 | 8 | public class BZAObjectTest { 9 | 10 | @org.junit.Test 11 | public void test() throws Exception { 12 | HttpUtils httpUtils = new HttpUtils(new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(), "", ""); 13 | BZAObject entity = new BZAObject(httpUtils, "id", "name"); 14 | assertEquals(httpUtils, entity.getHttpUtils()); 15 | assertEquals("id", entity.getId()); 16 | assertEquals("name", entity.getName()); 17 | entity.setHttpUtils(null); 18 | entity.setId("id1"); 19 | entity.setName("name1"); 20 | assertNull(entity.getHttpUtils()); 21 | assertEquals("id1", entity.getId()); 22 | assertEquals("name1", entity.getName()); 23 | } 24 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | env: 2 | global: 3 | - MAVEN_OPTS=-Dmaven.repo.local=.m2/repository 4 | - MQTT_WEBSOCKET_VERSION=1.0.1 5 | 6 | cache: 7 | directories: 8 | - .jmeter 9 | - .m2 10 | 11 | language: java 12 | 13 | jdk: 14 | - openjdk8 15 | 16 | before_install: 17 | - sudo apt-get -y update 18 | - sudo apt-get -y install python3 default-jre-headless python3-tk python3-setuptools python3-pip python3-dev libxml2-dev libxslt-dev zlib1g-dev net-tools 19 | - chmod -R +x ./.travis 20 | - "sh ./.travis/install-maven-dependency.sh https://github.com/inventit/mqtt-websocket-java/releases/download/$MQTT_WEBSOCKET_VERSION/mqtt-websocket-java-$MQTT_WEBSOCKET_VERSION.jar io.inventit.dev mqtt-websocket-java $MQTT_WEBSOCKET_VERSION" 21 | 22 | script: 23 | - "mvn -DskipTests=true clean install --batch-mode" 24 | - "mvn -Djava.awt.headless=true -Dmaven.test.redirectTestOutputToFile=true -Dcobertura.report.format=xml --fail-at-end --batch-mode cobertura:cobertura test" 25 | 26 | after_success: 27 | - bash <(curl -s https://codecov.io/bash) 28 | -------------------------------------------------------------------------------- /parallel/src/main/java/org/apache/jmeter/protocol/http/control/ThreadSafeCookieManager.java: -------------------------------------------------------------------------------- 1 | package org.apache.jmeter.protocol.http.control; 2 | 3 | import org.apache.jmeter.testelement.property.PropertyIterator; 4 | 5 | public class ThreadSafeCookieManager extends CookieManager { 6 | 7 | 8 | public ThreadSafeCookieManager() { 9 | this(new CookieManager()); 10 | } 11 | 12 | public ThreadSafeCookieManager(CookieManager manager) { 13 | PropertyIterator iter = manager.propertyIterator(); 14 | while (iter.hasNext()) { 15 | setProperty(iter.next().clone()); 16 | } 17 | setRunningVersion(manager.isRunningVersion()); 18 | testStarted(); 19 | } 20 | 21 | @Override 22 | public synchronized void add(Cookie c) { 23 | super.add(c); 24 | } 25 | 26 | @Override 27 | synchronized void removeMatchingCookies(Cookie newCookie) { 28 | super.removeMatchingCookies(newCookie); 29 | } 30 | 31 | @Override 32 | public Object clone() { 33 | return super.clone(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /parallel/src/test/java/com/blazemeter/jmeter/http/ParallelHTTPSamplerMock.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.http; 2 | 3 | import org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl; 4 | import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult; 5 | import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; 6 | 7 | import java.net.URL; 8 | 9 | public class ParallelHTTPSamplerMock extends ParallelHTTPSampler { 10 | public ParallelHTTPSamplerMock() { 11 | super(); 12 | impl = new HCMock(this); 13 | } 14 | 15 | public class HCMock extends HTTPAbstractImpl { 16 | public HCMock(HTTPSamplerBase testElement) { 17 | super(testElement); 18 | } 19 | 20 | @Override 21 | protected HTTPSampleResult sample(URL url, String s, boolean b, int i) { 22 | HTTPSampleResult res = new HTTPSampleResult(); 23 | res.setSuccessful(true); 24 | return res; 25 | } 26 | 27 | @Override 28 | public boolean interrupt() { 29 | return false; 30 | } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/BlazeMeterReport.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api; 2 | 3 | public class BlazeMeterReport { 4 | 5 | protected boolean isShareTest; 6 | protected String project; 7 | protected String title; 8 | protected String token; 9 | 10 | public boolean isAnonymousTest() { 11 | return (token == null || token.isEmpty()); 12 | } 13 | 14 | public boolean isShareTest() { 15 | return isShareTest; 16 | } 17 | 18 | public void setShareTest(boolean shareTest) { 19 | isShareTest = shareTest; 20 | } 21 | 22 | public String getProject() { 23 | return project; 24 | } 25 | 26 | public void setProject(String project) { 27 | this.project = project; 28 | } 29 | 30 | public String getTitle() { 31 | return title; 32 | } 33 | 34 | public void setTitle(String title) { 35 | this.title = title; 36 | } 37 | 38 | public String getToken() { 39 | return token; 40 | } 41 | 42 | public void setToken(String token) { 43 | this.token = token; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /directory-listing/DirectoryListing.md: -------------------------------------------------------------------------------- 1 | # Directory Listing Config 2 | 3 | Directory listing config plugin offers capabilities list files from source directory and iterate over this list with JMeter variable. This is convenient for data-driven testing when you have, for example, 1000 files to upload into server. 4 | 5 | This plugin has following options that affect the behavior: 6 | * "Use full path" - is this flag does not selected plugin will be set sub-path from source path into destination variable; 7 | * "Random order" - shuffle listing in random order; 8 | * "Recursive listing" - meaning, that plugin will be looking for all sub-folders in source directory; 9 | * "Rewind on end of list" - if the flag is selected and an iteration loop has reached the end, the new loop will be started; 10 | * "Re-read directory on the end of list" - re-read directory before starting new iteration loop; 11 | * "Independent list per thread" - determines that listing will be shared for all threads or each thread will be having own local copy. 12 | 13 | _Default value of destination variable name is "filename"._ 14 | 15 | ![](directoryListing.png) 16 | -------------------------------------------------------------------------------- /random-csv-data-set/src/test/resources/TabDelimiter.csv: -------------------------------------------------------------------------------- 1 | timeStamp elapsed label responseCode responseMessage threadName dataType success failureMessage bytes sentBytes grpThreads allThreads Latency IdleTime Connect 2 | 1509464779128 131 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 33 0 4 3 | 1509464779260 478 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 27 0 2 4 | 1509464779738 175 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 22 0 1 5 | 1509464779913 186 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 25 0 5 6 | 1509464780099 87 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 40 0 4 7 | 1509464780186 484 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 19 0 5 8 | 1509464780671 480 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 38 0 1 9 | 1509464781152 207 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 29 0 1 10 | 1509464781359 102 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 14 0 4 11 | 1509464781461 407 jp@gc - Dummy Sampler 200 OK Thread Group 1-1 text true 114 0 1 1 26 0 5 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Plugins for Apache JMeter by CA BlazeMeter 2 | Consolidated repository with all CA BlazeMeter's plugins for JMeter. All of the plugins are available through [Plugins Manager](https://jmeter-plugins.org/wiki/PluginsManager/). 3 | 4 | Contents: 5 | - [Directory Listing Data Source](directory-listing/DirectoryListing.md) 6 | - [HTTP/2 Protocol](http2/README.md) 7 | - [Parallel Controller](parallel/Parallel.md) 8 | - [Random CSV Data Set Config ](random-csv-data-set/RandomCSVDataSetConfig.md) 9 | - [Rotating JTL File Listener](rotating-listener/RotatingListener.md) 10 | - [Weighted Switch Controller](wsc/WeightedSwitchController.md) 11 | - [XMPP Connection](xmpp/XMPPConnection.md) and [XMPP Sampler](xmpp/XMPPSampler.md) 12 | - [BlazeMeter Uploader](sense-uploader/BlazeMeterUploader.md) and [BM.Sense Uploader](sense-uploader/LoadosophiaUploader.md) 13 | 14 | ## Support 15 | 16 | To get support on these plugins, please use regular [JMeter Plugins support forums](https://groups.google.com/forum/#!forum/jmeter-plugins) 17 | 18 | ## License 19 | 20 | The plugins are proudly contributed to community as Open Source, under [Apache 2.0 License](LICENSE). 21 | -------------------------------------------------------------------------------- /parallel/src/test/java/com/blazemeter/jmeter/controller/ParallelControllerGuiTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.junit.BeforeClass; 5 | import org.junit.Test; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | 11 | public class ParallelControllerGuiTest { 12 | 13 | @BeforeClass 14 | public static void setUpClass() 15 | throws Exception { 16 | TestJMeterUtils.createJmeterEnv(); 17 | } 18 | 19 | 20 | @Test 21 | public void showGui() throws Exception { 22 | if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) { 23 | ParallelControllerGui gui = new ParallelControllerGui(); 24 | JDialog frame = new JDialog(); 25 | frame.add(gui); 26 | 27 | frame.setPreferredSize(new Dimension(800, 600)); 28 | frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 29 | frame.pack(); 30 | frame.setVisible(true); 31 | while (frame.isVisible()) { 32 | Thread.sleep(100); 33 | } 34 | } 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /websocket/src/main/java/blazemeter/jmeter/plugins/websocket/sampler/Handler.java: -------------------------------------------------------------------------------- 1 | package blazemeter.jmeter.plugins.websocket.sampler; 2 | 3 | import java.io.IOException; 4 | import java.io.Serializable; 5 | import java.util.LinkedList; 6 | import java.util.Queue; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | public abstract class Handler implements Serializable{ 10 | 11 | private String encoding; 12 | protected Queue messages = new LinkedList(); 13 | 14 | Handler (){} 15 | 16 | Handler (String enconding){ 17 | this.encoding = encoding; 18 | } 19 | 20 | public String getContentEncoding(){ 21 | return this.encoding; 22 | } 23 | 24 | public abstract void close(); 25 | 26 | public abstract boolean awaitMessage(int duration, TimeUnit unit, String waitResponsePatter) throws InterruptedException; 27 | 28 | public String getMessages(){ 29 | String ret = ""; 30 | for (String s : messages){ 31 | ret = ret + s + "\n"; 32 | } 33 | messages.clear(); 34 | return ret; 35 | } 36 | 37 | public abstract void initialize(); 38 | 39 | public abstract boolean isConnected(); 40 | 41 | public abstract void sendMessage(String message) throws IOException; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/BZAObject.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import org.apache.jorphan.logging.LoggingManager; 5 | import org.apache.log.Logger; 6 | 7 | /** 8 | * Base entity for BlazeMeter explorer classes 9 | */ 10 | public class BZAObject { 11 | 12 | protected static final Logger log = LoggingManager.getLoggerForClass(); 13 | 14 | protected String id; 15 | protected String name; 16 | protected HttpUtils httpUtils; 17 | 18 | public BZAObject(HttpUtils httpUtils, String id, String name) { 19 | this.httpUtils = httpUtils; 20 | this.id = id; 21 | this.name = name; 22 | } 23 | 24 | public HttpUtils getHttpUtils() { 25 | return httpUtils; 26 | } 27 | 28 | public void setHttpUtils(HttpUtils httpUtils) { 29 | this.httpUtils = httpUtils; 30 | } 31 | 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public void setId(String id) { 41 | this.id = id; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/actions/RawXMLTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSamplerMock; 4 | import org.apache.jmeter.samplers.Sampler; 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | import static org.junit.Assert.assertFalse; 12 | 13 | public class RawXMLTest { 14 | 15 | private RawXML obj; 16 | 17 | @Before 18 | public void setUp() throws Exception { 19 | this.obj = new RawXML(); 20 | } 21 | 22 | @Test 23 | public void testGetLabel() throws Exception { 24 | assertFalse(obj.getLabel().isEmpty()); 25 | } 26 | 27 | @Test 28 | public void testPerform() throws Exception { 29 | Sampler s = new JMeterXMPPSamplerMock(); 30 | s.setProperty(RawXML.XML, ""); 31 | } 32 | 33 | @Test 34 | public void testAddUI() throws Exception { 35 | obj.addUI(new JPanel(), new GridBagConstraints(), new GridBagConstraints()); 36 | obj.setSamplerProperties(new JMeterXMPPSamplerMock()); 37 | obj.setGuiFieldsFromSampler(new JMeterXMPPSamplerMock()); 38 | obj.clearGui(); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/Connect.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | 4 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 5 | import org.apache.jmeter.samplers.SampleResult; 6 | import org.jivesoftware.smack.AbstractXMPPConnection; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | public class Connect extends AbstractXMPPAction { 12 | @Override 13 | public String getLabel() { 14 | return "Connect to Server"; 15 | } 16 | 17 | @Override 18 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 19 | AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection(); 20 | conn.connect(); 21 | res.setResponseData(sampler.getXMPPConnection().getConnectionID().getBytes()); 22 | return res; 23 | } 24 | 25 | @Override 26 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 27 | 28 | } 29 | 30 | @Override 31 | public void clearGui() { 32 | 33 | } 34 | 35 | @Override 36 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 37 | 38 | } 39 | 40 | @Override 41 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/org/loadosophia/jmeter/LoadosophiaAPIClientEmul.java: -------------------------------------------------------------------------------- 1 | package org.loadosophia.jmeter; 2 | 3 | import kg.apc.jmeter.notifier.StatusNotifierCallback; 4 | import net.sf.json.JSON; 5 | import org.apache.http.client.methods.HttpRequestBase; 6 | import org.apache.jorphan.logging.LoggingManager; 7 | import org.apache.log.Logger; 8 | 9 | import java.io.IOException; 10 | import java.util.LinkedList; 11 | 12 | 13 | public class LoadosophiaAPIClientEmul extends LoadosophiaAPIClient { 14 | private static final Logger log = LoggingManager.getLoggerForClass(); 15 | 16 | private LinkedList responses = new LinkedList<>(); 17 | 18 | public LoadosophiaAPIClientEmul(StatusNotifierCallback aThis) { 19 | super(aThis, "http://localhost/", "TEST", COLOR_NONE, "TEST", "TEST"); 20 | } 21 | 22 | public void addEmul(JSON response) { 23 | responses.add(response); 24 | } 25 | 26 | @Override 27 | public JSON query(HttpRequestBase request, int expectedCode) throws IOException { 28 | log.info("Simulating request: " + request); 29 | if (responses.size()>0) { 30 | JSON resp = responses.remove(); 31 | log.info("Response: " + resp); 32 | return resp; 33 | } else { 34 | throw new IOException("No responses to emulate"); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/Master.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import net.sf.json.JSONObject; 5 | 6 | import java.io.IOException; 7 | 8 | public class Master extends BZAObject { 9 | 10 | public Master(HttpUtils httpUtils, String id, String name) { 11 | super(httpUtils, id, name); 12 | } 13 | 14 | /** 15 | * Makes a private user report public 16 | * @return public link to the report 17 | */ 18 | public String makeReportPublic() throws IOException { 19 | String uri = httpUtils.getAddress() + String.format("/api/v4/masters/%s/public-token", getId()); 20 | JSONObject obj = new JSONObject(); 21 | obj.put("publicToken", "None"); 22 | JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, obj.toString()), 201); 23 | 24 | return httpUtils.getAddress() + String.format("/app/?public-token=%s#/masters/%s/summary", 25 | extractPublicToken(response.getJSONObject("result")), getId()); 26 | } 27 | 28 | private String extractPublicToken(JSONObject result) { 29 | return result.getString("publicToken"); 30 | } 31 | 32 | public static Master fromJSON(HttpUtils httpUtils, JSONObject obj) { 33 | return new Master(httpUtils, obj.getString("id"), obj.getString("name")); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/User.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import net.sf.json.JSONArray; 5 | import net.sf.json.JSONObject; 6 | 7 | import java.io.IOException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class User extends BZAObject { 12 | 13 | 14 | public User(HttpUtils httpUtils) { 15 | super(httpUtils, "", ""); 16 | } 17 | 18 | /** 19 | * Quick check if we can access the service 20 | */ 21 | public void ping() throws IOException { 22 | String uri = httpUtils.getAddress() + "/api/v4/web/version"; 23 | httpUtils.query(httpUtils.createGet(uri), 200); 24 | } 25 | 26 | /** 27 | * @return list of Account for user token 28 | */ 29 | public List getAccounts() throws IOException { 30 | String uri = httpUtils.getAddress()+ "/api/v4/accounts"; 31 | JSONObject response = httpUtils.queryObject(httpUtils.createGet(uri), 200); 32 | return extractAccounts(response.getJSONArray("result")); 33 | } 34 | 35 | private List extractAccounts(JSONArray result) { 36 | List accounts = new ArrayList<>(); 37 | 38 | for (Object obj : result) { 39 | accounts.add(Account.fromJSON(httpUtils, (JSONObject) obj)); 40 | } 41 | 42 | return accounts; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/kg/apc/jmeter/reporters/bzm/BLCEmul.java: -------------------------------------------------------------------------------- 1 | package kg.apc.jmeter.reporters.bzm; 2 | 3 | import com.blazemeter.api.BlazeMeterAPIClient; 4 | import kg.apc.jmeter.http.HttpUtilsEmul; 5 | 6 | import java.io.IOException; 7 | 8 | public class BLCEmul extends BlazeMeterBackendListenerClient { 9 | @Override 10 | public void initiateOnline() { 11 | HttpUtilsEmul httpUtils = new HttpUtilsEmul(informer, "https://a.blazemeter.com/", "https://a.blazemeter.com/"); 12 | httpUtils.addEmul("{}"); 13 | httpUtils.addEmul("{\"result\": {" + 14 | "\"test\": {\"id\": 1, \"name\": \"atest\"}, " + 15 | "\"master\": {\"id\": 1, \"name\": \"atest\"}, " + 16 | "\"session\": {\"id\": 1, \"name\": \"atest\", \"userId\": \"atest\"}, " + 17 | "\"publicTokenUrl\": \"http://\", " + 18 | "\"signature\": \"sign\"" + 19 | "}}"); 20 | httpUtils.addEmul("{\"result\": {" + 21 | "\"session\": {\"id\": 1, \"name\": \"atest\", \"userId\": \"atest\", \"statusCode\": \"50\"} " + 22 | "}}"); 23 | httpUtils.addEmul("{}"); 24 | apiClient = new BlazeMeterAPIClient(httpUtils, informer, report); 25 | apiClient.prepare(); 26 | try { 27 | apiClient.startOnline(); 28 | } catch (IOException e) { 29 | throw new RuntimeException("", e); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /websocket/src/main/java/blazemeter/jmeter/plugins/websocket/sampler/Factory.java: -------------------------------------------------------------------------------- 1 | package blazemeter.jmeter.plugins.websocket.sampler; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.eclipse.jetty.websocket.client.WebSocketClient; 6 | import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; 7 | import org.eclipse.paho.client.mqttv3.MqttAsyncClient; 8 | import org.eclipse.paho.client.mqttv3.MqttException; 9 | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; 10 | 11 | import io.inventit.dev.mqtt.paho.MqttWebSocketAsyncClient; 12 | 13 | public class Factory implements Serializable{ 14 | 15 | public MqttCallBackImpl getMqttHandler (IMqttAsyncClient client, String clientID, String logLevel, String encoding){ 16 | return new MqttCallBackImpl(client, clientID, logLevel, encoding); 17 | } 18 | 19 | public WebSocketConnection getWebSocketHandler (WebSocketClient client, String closeConnectionPattern, String encoding){ 20 | return new WebSocketConnection(client, closeConnectionPattern, encoding); 21 | } 22 | 23 | public IMqttAsyncClient getMqttAsyncClient (String protocol, String mqttUrl, String clientID, MemoryPersistence persistence) throws MqttException { 24 | if(protocol.equals("tcp")) 25 | return new MqttAsyncClient(mqttUrl, clientID, persistence); 26 | else if (protocol.equals("ws") || protocol.equals("wss")) 27 | return new MqttWebSocketAsyncClient (mqttUrl, clientID, persistence); 28 | else 29 | return null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/Disconnect.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 4 | import org.apache.jmeter.samplers.SampleResult; 5 | import org.jivesoftware.smack.AbstractXMPPConnection; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | public class Disconnect extends AbstractXMPPAction { 11 | 12 | @Override 13 | public String getLabel() { 14 | return "Disconnect from Server"; 15 | } 16 | 17 | @Override 18 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 19 | if (!sampler.getXMPPConnection().isConnected()) { 20 | return res; 21 | } 22 | AbstractXMPPConnection conn = (AbstractXMPPConnection)sampler.getXMPPConnection(); 23 | conn.disconnect(); 24 | if (sampler.getXMPPConnectionConfig() != null) 25 | sampler.getXMPPConnectionConfig().resetConnection(); 26 | return res; 27 | } 28 | 29 | @Override 30 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 31 | } 32 | 33 | @Override 34 | public void clearGui() { 35 | 36 | } 37 | 38 | @Override 39 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 40 | 41 | } 42 | 43 | @Override 44 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/actions/SendMessageTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 4 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSamplerMock; 5 | import com.blazemeter.jmeter.xmpp.XMPPConnectionMock; 6 | import org.apache.jmeter.samplers.SampleResult; 7 | import org.jivesoftware.smack.XMPPConnection; 8 | import org.jivesoftware.smack.packet.Message; 9 | import org.junit.Assert; 10 | import org.junit.Test; 11 | 12 | 13 | public class SendMessageTest { 14 | @Test 15 | public void perform() throws Exception { 16 | SendMessage action = new SendMessage(); 17 | XMPPConnectionMock connection = new XMPPConnectionMock(); 18 | action.connected(connection); 19 | Message resp = new Message(); 20 | resp.setFrom("test@test.com"); 21 | resp.setBody(SendMessage.RESPONSE_MARKER); 22 | action.processPacket(resp); 23 | JMeterXMPPSampler sampler = new JMeterXMPPSamplerMock(); 24 | sampler.getXMPPConnection().setFromMode(XMPPConnection.FromMode.USER); 25 | sampler.setProperty(SendMessage.RECIPIENT, "test@test.com"); 26 | sampler.setProperty(SendMessage.WAIT_RESPONSE, true); 27 | SampleResult res = new SampleResult(); 28 | action.perform(sampler, res); 29 | Assert.assertTrue(res.getResponseDataAsString().contains(SendMessage.RESPONSE_MARKER)); 30 | Assert.assertTrue(res.getSamplerData().contains("from")); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /random-csv-data-set/src/test/java/com/blazemeter/jmeter/TestRandomCSVActionTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.junit.BeforeClass; 5 | import org.junit.Test; 6 | 7 | 8 | import static org.junit.Assert.*; 9 | 10 | 11 | public class TestRandomCSVActionTest { 12 | 13 | @BeforeClass 14 | public static void setUpClass() 15 | throws Exception { 16 | TestJMeterUtils.createJmeterEnv(); 17 | } 18 | 19 | @Test 20 | public void testAction() throws Exception { 21 | String path = this.getClass().getResource("/JMeterCsvResults.csv").getPath(); 22 | 23 | RandomCSVDataSetConfig config = new RandomCSVDataSetConfig(); 24 | config.setFilename(path); 25 | config.setFileEncoding("UTF-8"); 26 | config.setDelimiter(","); 27 | // special check for skip first line. It must no skip and return all lines in file. 28 | config.setVariableNames("aaa,aaa1"); 29 | config.setIgnoreFirstLine(false); 30 | 31 | RandomCSVDataSetConfigGui gui = new RandomCSVDataSetConfigGui(); 32 | 33 | gui.configure(config); 34 | 35 | TestRandomCSVAction action = new TestRandomCSVAction(gui); 36 | 37 | action.actionPerformed(null); 38 | assertTrue(gui.getCheckArea().getText().startsWith("Reading CSV successfully finished, 4 records found")); 39 | 40 | config.setFilename(""); 41 | gui.configure(config); 42 | action.actionPerformed(null); 43 | assertTrue(gui.getCheckArea().getText().contains("Is a directory")); 44 | } 45 | } -------------------------------------------------------------------------------- /parallel/src/main/java/com/blazemeter/jmeter/controller/traverse/CustomTreeCloner.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller.traverse; 2 | 3 | import org.apache.jmeter.protocol.http.control.CookieManager; 4 | import org.apache.jmeter.protocol.http.control.ThreadSafeCookieManager; 5 | import org.apache.jorphan.collections.HashTree; 6 | import org.apache.jorphan.collections.HashTreeTraverser; 7 | import org.apache.jorphan.collections.ListedHashTree; 8 | 9 | import java.util.LinkedList; 10 | 11 | public class CustomTreeCloner implements HashTreeTraverser { 12 | 13 | private final ListedHashTree newTree; 14 | 15 | private final LinkedList objects = new LinkedList<>(); 16 | 17 | public CustomTreeCloner() { 18 | newTree = new ListedHashTree(); 19 | } 20 | 21 | /** 22 | * {@inheritDoc} 23 | */ 24 | @Override 25 | public final void addNode(Object node, HashTree subTree) { 26 | if (node instanceof CookieManager) { 27 | node = new ThreadSafeCookieManager((CookieManager) node); 28 | } 29 | newTree.add(objects, node); 30 | addLast(node); 31 | } 32 | 33 | 34 | /** 35 | * add node to objects LinkedList 36 | * @param node Object 37 | */ 38 | private void addLast(Object node) { 39 | objects.addLast(node); 40 | } 41 | 42 | @Override 43 | public void subtractNode() { 44 | objects.removeLast(); 45 | } 46 | 47 | public ListedHashTree getClonedTree() { 48 | return newTree; 49 | } 50 | 51 | @Override 52 | public void processPath() { 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /random-csv-data-set/src/main/java/com/blazemeter/csv/RandomBufferedReader.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.csv; 2 | 3 | import java.io.*; 4 | import java.nio.channels.Channels; 5 | 6 | public class RandomBufferedReader extends BufferedReader { 7 | 8 | private final RandomAccessFile raf; 9 | 10 | private InputStream is; 11 | private BufferedReader reader; 12 | private String encoding; 13 | private long markedPosition; 14 | 15 | public RandomBufferedReader(Reader in, RandomAccessFile raf, String encoding) throws UnsupportedEncodingException { 16 | super(in); 17 | this.raf = raf; 18 | this.encoding = encoding; 19 | this.is = Channels.newInputStream(raf.getChannel()); 20 | initBufferedReader(); 21 | } 22 | 23 | private void initBufferedReader() throws UnsupportedEncodingException { 24 | InputStreamReader isr = new InputStreamReader(is, encoding); 25 | reader = new BufferedReader(isr); 26 | } 27 | 28 | public void seek(long pos) throws IOException { 29 | this.raf.seek(pos); 30 | initBufferedReader(); 31 | } 32 | 33 | @Override 34 | public int read() throws IOException { 35 | return reader.read(); 36 | } 37 | 38 | @Override 39 | public void mark(int readAheadLimit) throws IOException { 40 | markedPosition = raf.getFilePointer(); 41 | } 42 | 43 | @Override 44 | public void reset() throws IOException { 45 | raf.seek(markedPosition); 46 | } 47 | 48 | @Override 49 | public void close() throws IOException { 50 | super.close(); 51 | is.close(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /random-csv-data-set/RandomCSVDataSetConfig.md: -------------------------------------------------------------------------------- 1 | # Random CSV Data Set Config 2 | 3 | Random CSV Data Set Config is used to read CSV rows from file, split and put them into JMeter variables in random order. 4 | 5 | This plugin has following options that affect the behavior: 6 | * `Filename` - path to CSV file. Relative path are resolved with respect to the path of the active test plan. For distributed testing, the CSV file must be stored on the server host system in the correct relative directory to where the JMeter server is started.; 7 | * `File encoding` - encoding of this CSV file; 8 | * `Delimiter` - delimiter that be used to split records in the file; 9 | * `Variable Names` - list (comma-separated) of variable names; 10 | * `Random order` - The plugin will get records from the file in random order. This is the part that provides this element’s added value. If you don’t select this option, the element will work like the regular CSV Data Set Config.; 11 | * `Rewind on end of list` - if the flag is selected and an iteration loop has reached the end, the new loop will be started; 12 | * `First line is CSV header` - select this flag to skip header(used only if `Variable Names` is not empty); 13 | * `Independent list per thread` - When this is checked with “Random order”, each thread runs its own copy of CSV values with random order. When unchecked, all of threads go over the same randomized list of values. 14 | 15 | _***At the beginning of the test, the config reads file. There are a delay and a large memory consumption for large files.***_ 16 | 17 | _In preview area shows only 20 records from CSV file._ 18 | 19 | ![](randomCSVDataSetConfig.png) 20 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/kg/apc/jmeter/http/HttpUtilsEmul.java: -------------------------------------------------------------------------------- 1 | package kg.apc.jmeter.http; 2 | 3 | import kg.apc.jmeter.notifier.StatusNotifierCallback; 4 | import net.sf.json.JSON; 5 | import net.sf.json.JSONObject; 6 | import net.sf.json.JSONSerializer; 7 | import org.apache.http.client.methods.HttpRequestBase; 8 | 9 | import java.io.IOException; 10 | import java.util.LinkedList; 11 | 12 | public class HttpUtilsEmul extends HttpUtils { 13 | 14 | private LinkedList responses = new LinkedList<>(); 15 | 16 | 17 | public HttpUtilsEmul(StatusNotifierCallback notifier, String address, String dataAddress) { 18 | super(notifier, address, dataAddress); 19 | } 20 | 21 | public void addEmul(JSON response) { 22 | responses.add(response); 23 | } 24 | 25 | @Override 26 | public JSON query(HttpRequestBase request, int expectedCode) throws IOException { 27 | return getResponse(request); 28 | } 29 | 30 | @Override 31 | public JSONObject queryObject(HttpRequestBase request, int expectedCode) throws IOException { 32 | return (JSONObject) getResponse(request); 33 | } 34 | 35 | public JSON getResponse(HttpRequestBase request) throws IOException { 36 | log.info("Simulating request: " + request); 37 | if (responses.size() > 0) { 38 | JSON resp = responses.remove(); 39 | log.info("Response: " + resp); 40 | return resp; 41 | } else { 42 | throw new IOException("No responses to emulate"); 43 | } 44 | } 45 | 46 | public void addEmul(String s) { 47 | addEmul(JSONSerializer.toJSON(s)); 48 | } 49 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/UserTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import com.blazemeter.api.http.BlazeMeterHttpUtilsEmul; 5 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 6 | import net.sf.json.JSONArray; 7 | import net.sf.json.JSONObject; 8 | 9 | import java.util.List; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | public class UserTest { 14 | 15 | @org.junit.Test 16 | public void testFlow() throws Exception { 17 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 18 | BlazeMeterReport report = new BlazeMeterReport(); 19 | 20 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", report); 21 | 22 | User user = new User(emul); 23 | emul.addEmul(new JSONObject()); 24 | user.ping(); 25 | 26 | JSONObject acc = new JSONObject(); 27 | acc.put("id", "accountId"); 28 | acc.put("name", "accountName"); 29 | JSONArray result = new JSONArray(); 30 | result.add(acc); 31 | result.add(acc); 32 | JSONObject response = new JSONObject(); 33 | response.put("result", result); 34 | emul.addEmul(response); 35 | 36 | List accounts = user.getAccounts(); 37 | assertEquals(2, accounts.size()); 38 | for (Account account : accounts) { 39 | assertEquals("accountId", account.getId()); 40 | assertEquals("accountName", account.getName()); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /parallel/src/main/java/com/blazemeter/jmeter/controller/ParallelListenerNotifier.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller; 2 | 3 | 4 | import org.apache.jmeter.samplers.SampleEvent; 5 | import org.apache.jmeter.samplers.SampleListener; 6 | import org.apache.jmeter.samplers.SampleResult; 7 | import org.apache.jmeter.threads.ListenerNotifier; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.Serializable; 12 | import java.util.List; 13 | 14 | public class ParallelListenerNotifier extends ListenerNotifier implements Serializable { 15 | private static final Logger log = LoggerFactory.getLogger(ParallelListenerNotifier.class); 16 | private SampleResult container = new SampleResult(); 17 | 18 | @Override 19 | public void notifyListeners(SampleEvent res, List listeners) { 20 | log.debug("Adding subresult " + res.getResult()); 21 | SampleResult result = res.getResult(); 22 | String label = result.getSampleLabel(); 23 | synchronized (this) { 24 | container.addSubResult(result); 25 | if (!res.getResult().isSuccessful()) { 26 | container.setSuccessful(false); 27 | } 28 | } 29 | // because https://bz.apache.org/bugzilla/show_bug.cgi?id=62550 in JMeter 5.0 30 | result.setSampleLabel(label); 31 | super.notifyListeners(res, listeners); 32 | log.debug("Added subresult " + res.getResult()); 33 | } 34 | 35 | public void setContainer(SampleResult container) { 36 | this.container = container; 37 | } 38 | 39 | public SampleResult getContainer() { 40 | return container; 41 | } 42 | } -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/GetBookmarks.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 4 | import org.apache.jmeter.samplers.SampleResult; 5 | import org.jivesoftware.smackx.bookmarks.BookmarkManager; 6 | import org.jivesoftware.smackx.bookmarks.BookmarkedConference; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | import java.util.Collection; 11 | 12 | public class GetBookmarks extends AbstractXMPPAction { 13 | @Override 14 | public String getLabel() { 15 | return "Get Bookmarked Conferences (XEP-0048)"; 16 | } 17 | 18 | @Override 19 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 20 | BookmarkManager manager = BookmarkManager.getBookmarkManager(sampler.getXMPPConnection()); 21 | Collection confs = manager.getBookmarkedConferences(); 22 | StringBuilder text = new StringBuilder(); 23 | for (BookmarkedConference room : confs) { 24 | text.append(room.getJid()); 25 | text.append("\r\n"); 26 | } 27 | res.setResponseData(text.toString().getBytes()); 28 | return res; 29 | } 30 | 31 | @Override 32 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 33 | panel.add(new JLabel("Request list of bookmarked chat rooms from the server")); 34 | } 35 | 36 | @Override 37 | public void clearGui() { 38 | 39 | } 40 | 41 | @Override 42 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 43 | 44 | } 45 | 46 | @Override 47 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/kg/apc/jmeter/reporters/bzm/BlazemeterUploaderTest.java: -------------------------------------------------------------------------------- 1 | package kg.apc.jmeter.reporters.bzm; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.apache.jmeter.util.JMeterUtils; 5 | import org.junit.After; 6 | import org.junit.BeforeClass; 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class BlazemeterUploaderTest { 12 | 13 | @BeforeClass 14 | public static void setUpClass() 15 | throws Exception { 16 | TestJMeterUtils.createJmeterEnv(); 17 | } 18 | 19 | @After 20 | public void tearDown() { 21 | JMeterUtils.getJMeterProperties().remove("blazemeter.client"); 22 | } 23 | 24 | @Test 25 | public void testFlow() throws Exception { 26 | JMeterUtils.setProperty("blazemeter.client", BLCEmul.class.getName()); 27 | BlazeMeterUploader uploader = new BlazeMeterUploader(); 28 | uploader.setGui(new BlazeMeterUploaderGui()); 29 | uploader.setShareTest(true); 30 | uploader.setProject("project"); 31 | uploader.setTitle("title"); 32 | uploader.testStarted(); 33 | uploader.testEnded(); 34 | 35 | assertEquals(true, uploader.isShareTest()); 36 | assertEquals("project", uploader.getProject()); 37 | assertEquals("title", uploader.getTitle()); 38 | assertEquals("", uploader.getUploadToken()); 39 | } 40 | 41 | @Test 42 | public void testClone() throws Exception { 43 | BlazeMeterUploader uploader = new BlazeMeterUploader(); 44 | BlazeMeterUploaderGui gui = new BlazeMeterUploaderGui(); 45 | uploader.setGui(gui); 46 | BlazeMeterUploader clone = (BlazeMeterUploader) uploader.clone(); 47 | assertEquals(gui, clone.gui); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/RawXML.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | 4 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 5 | import org.apache.jmeter.samplers.SampleResult; 6 | import org.jivesoftware.smack.packet.Packet; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | public class RawXML extends AbstractXMPPAction { 12 | public static final java.lang.String XML = "xml"; 13 | private JTextArea msgBody; 14 | 15 | @Override 16 | public String getLabel() { 17 | return "Send Raw XML"; 18 | } 19 | 20 | @Override 21 | public SampleResult perform(final JMeterXMPPSampler sampler, SampleResult res) throws Exception { 22 | final String xml = sampler.getPropertyAsString(XML); 23 | res.setSamplerData(xml); 24 | sampler.getXMPPConnection().sendPacket(new Packet() { 25 | @Override 26 | public CharSequence toXML() { 27 | return xml; 28 | } 29 | }); 30 | return res; 31 | } 32 | 33 | @Override 34 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 35 | addToPanel(panel, labelConstraints, 0, 2, new JLabel("XML to Send: ", JLabel.RIGHT)); 36 | addToPanel(panel, editConstraints, 1, 2, msgBody = new JTextArea(5, 20)); 37 | } 38 | 39 | @Override 40 | public void clearGui() { 41 | msgBody.setText(""); 42 | } 43 | 44 | @Override 45 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 46 | sampler.setProperty(XML, msgBody.getText()); 47 | } 48 | 49 | @Override 50 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 51 | msgBody.setText(sampler.getPropertyAsString(XML)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/JMeterXMPPSamplerGuiTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp; 2 | 3 | import com.blazemeter.jmeter.xmpp.actions.AbstractXMPPAction; 4 | import kg.apc.emulators.TestJMeterUtils; 5 | import org.junit.BeforeClass; 6 | import org.junit.Test; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | import static org.junit.Assert.assertTrue; 12 | 13 | 14 | public class JMeterXMPPSamplerGuiTest { 15 | @BeforeClass 16 | public static void setUpClass() 17 | throws Exception { 18 | TestJMeterUtils.createJmeterEnv(); 19 | } 20 | 21 | @Test 22 | public void testCreateTestElement() throws Exception { 23 | JMeterXMPPSamplerGui obj = new JMeterXMPPSamplerGuiEmul(); 24 | assertTrue(obj.createTestElement() instanceof JMeterXMPPSampler); 25 | } 26 | 27 | @Test 28 | public void testConfigure() throws Exception { 29 | JMeterXMPPSamplerGui obj = new JMeterXMPPSamplerGuiEmul(); 30 | obj.configure(obj.createTestElement()); 31 | } 32 | 33 | @Test 34 | public void testModifyTestElement() throws Exception { 35 | JMeterXMPPSamplerGui obj = new JMeterXMPPSamplerGuiEmul(); 36 | obj.modifyTestElement(obj.createTestElement()); 37 | } 38 | 39 | @Test 40 | public void testClearGui() throws Exception { 41 | JMeterXMPPSamplerGui obj = new JMeterXMPPSamplerGuiEmul(); 42 | obj.clearGui(); 43 | } 44 | 45 | private class JMeterXMPPSamplerGuiEmul extends JMeterXMPPSamplerGui { 46 | @Override 47 | protected Map getActions() { 48 | Map list = new HashMap<>(); 49 | JMeterXMPPSamplerTest.fillActionClasses(list); 50 | return list; 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /sense-uploader/LoadosophiaUploader.md: -------------------------------------------------------------------------------- 1 | # BM.Sense Uploader 2 | 3 | This is special plugin for uploading results to 4 | [BlazeMeter Sense](https://sense.blazemeter.com/?utm_source=jpgc&utm_medium=link&utm_campaign=wiki) 5 | immediately after test end. It was previously known as "Loadosophia Uploader" and has changed the name following service rename. 6 | 7 | ![](loadosophia_uploader.png) 8 | 9 | ## Fields 10 | 11 | You need to receive special string token at sense.blazemeter.com 12 | to use as your upload identifier with this plugin. 13 | Please, treat the token as confidential, everyone who knows it 14 | may upload files to your projects. 15 | 16 | _Upload to Project_ field specifies project name in which you will upload results. 17 | 18 | _Test Title_ may be used to customize test title displayed on report pages. 19 | 20 | _Color Flag_ sets test to have color mark in BlazeMeter Sense interface. 21 | 22 | 23 | # Usage 24 | 25 | 1. Go to sense.blazemeter.com and [issue an upload token](https://sense.blazemeter.com/gui/settings/?utm_source=jpgc&utm_medium=link&utm_campaign=wikitoken) 26 | 2. Copy & paste it into _Upload Token_ field of BM.Sense Uploader 27 | 3. Run your test, verify in _Info Area_ that results uploaded successfully 28 | 4. Wait for uploaded file to be processed at [uploads page](https://sense.blazemeter.com/gui/upload/?utm_source=jpgc&utm_medium=link&utm_campaign=wikiupload) 29 | 5. Analyze performance report and organize your tests at [BlazeMeter Sense](https://sense.blazemeter.com) 30 | 31 | Please copy the token carefully, don't miss any chars or add extra. 32 | 33 | Make note that BlazeMeter Sense has limits for uploaded file size, which differs according to your plan. 34 | 35 | If you get "Cannot send empty" log messages or uploaded files seems to be incomplete, consider setting `jmeter.save.saveservice.autoflush=true` in `jmeter.properties` file. 36 | 37 | -------------------------------------------------------------------------------- /sense-uploader/BlazeMeterUploader.md: -------------------------------------------------------------------------------- 1 | # BlazeMeter Uploader 2 | 3 | This is special plugin for uploading results to 4 | [BlazeMeter](https://a.blazemeter.com/) 5 | during the test running. 6 | 7 | ![](blazemeter_uploader.png) 8 | 9 | ## Fields 10 | 11 | _Anonymous test_ will enable result feeding to service without any other settings required. You will receive the link for your report in the Info Area, and the link will be automatically opened in your system browser. Anonymous reports are kept for 7 days. 12 | 13 | _Share test_ if is enabled, anyone with the link can access the report. 14 | 15 | _Project Workspace_ field specifies workspace name or Id in which you will upload results. 16 | 17 | _Upload to Project_ field specifies project name or Id in which you will upload results. 18 | 19 | _Test Title_ may be used to customize test title displayed on report pages. 20 | 21 | You need to receive special string token at [a.blazemeter.com](https://a.blazemeter.com/) 22 | to use as your upload identifier with this plugin. You can find it under your [Settings => API Keys](https://a.blazemeter.com/app/#/settings/api-keys). 23 | Please, treat the token as confidential, everyone who knows it 24 | may upload files to your projects. Join key ID and secret with single colon: `TDknBxu0hmVnJ7NrqtG1F:DFddfgdsljasdfkKSKSDDFKSDFJKSDJFKSDJFsdjfksjfjsSF` 25 | 26 | # Usage 27 | 28 | 1. Go to a.blazemeter.com and [issue an upload token](https://a.blazemeter.com/app/#/settings/api-keys) 29 | 2. Copy & paste it into _Upload Token_ field of BlazeMeter Uploader 30 | 3. Run your test, verify in _Info Area_ that results uploaded successfully 31 | 4. Analyze performance report and organize your tests at a.blazemeter.com 32 | 33 | Please copy the token carefully, don't miss any chars or add extra. 34 | 35 | Make note that BlazeMeter has limits for uploaded tests, projects, workspaces, which differs according to your plan. 36 | 37 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/MasterTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import com.blazemeter.api.http.BlazeMeterHttpUtilsEmul; 5 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 6 | import net.sf.json.JSONObject; 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class MasterTest { 12 | 13 | @Test 14 | public void testFlow() throws Exception { 15 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 16 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 17 | 18 | JSONObject result = new JSONObject(); 19 | result.put("publicToken", "test_token"); 20 | JSONObject response = new JSONObject(); 21 | response.put("result", result); 22 | 23 | Master master = new Master(emul, "master_id", "master_name"); 24 | emul.addEmul(response); 25 | String url = master.makeReportPublic(); 26 | assertEquals("test_address/app/?public-token=test_token#/masters/master_id/summary", url); 27 | } 28 | 29 | @Test 30 | public void testFromJSON() throws Exception { 31 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 32 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 33 | JSONObject object = new JSONObject(); 34 | object.put("id", "masterId"); 35 | object.put("name", "masterName"); 36 | Master master = Master.fromJSON(emul, object); 37 | assertEquals("masterId", master.getId()); 38 | assertEquals("masterName", master.getName()); 39 | } 40 | } -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/Workspace.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import net.sf.json.JSONArray; 5 | import net.sf.json.JSONObject; 6 | 7 | import java.io.IOException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class Workspace extends BZAObject { 12 | 13 | public Workspace(HttpUtils httpUtils, String id, String name) { 14 | super(httpUtils, id, name); 15 | } 16 | 17 | /** 18 | * Create Project in current Workspace 19 | * @param name - Name of the new Project 20 | */ 21 | public Project createProject(String name) throws IOException { 22 | String uri = httpUtils.getAddress() + "/api/v4/projects"; 23 | JSONObject data = new JSONObject(); 24 | data.put("name", name); 25 | data.put("workspaceId", Long.parseLong(getId())); 26 | JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, data.toString()), 201); 27 | return Project.fromJSON(httpUtils, response.getJSONObject("result")); 28 | } 29 | 30 | /** 31 | * @return list of Projects in current Workspace 32 | */ 33 | public List getProjects() throws IOException { 34 | String uri = httpUtils.getAddress() + String.format("/api/v4/projects?workspaceId=%s&limit=99999", getId()); 35 | JSONObject response = httpUtils.queryObject(httpUtils.createGet(uri), 200); 36 | return extractProjects(response.getJSONArray("result")); 37 | } 38 | 39 | private List extractProjects(JSONArray result) { 40 | List projects = new ArrayList<>(); 41 | 42 | for (Object obj : result) { 43 | projects.add(Project.fromJSON(httpUtils, (JSONObject) obj)); 44 | } 45 | 46 | return projects; 47 | } 48 | 49 | public static Workspace fromJSON(HttpUtils httpUtils, JSONObject obj) { 50 | return new Workspace(httpUtils, obj.getString("id"), obj.getString("name")); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/Account.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import net.sf.json.JSONArray; 5 | import net.sf.json.JSONObject; 6 | 7 | import java.io.IOException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class Account extends BZAObject { 12 | 13 | public Account(HttpUtils httpUtils, String id, String name) { 14 | super(httpUtils, id, name); 15 | } 16 | 17 | /** 18 | * Create Workspace in current Account 19 | * @param name - Name of the new Workspace 20 | */ 21 | public Workspace createWorkspace(String name) throws IOException { 22 | String uri = httpUtils.getAddress() + "/api/v4/workspaces"; 23 | JSONObject data = new JSONObject(); 24 | data.put("name", name); 25 | data.put("accountId", Long.parseLong(getId())); 26 | JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, data.toString()), 201); 27 | return Workspace.fromJSON(httpUtils, response.getJSONObject("result")); 28 | } 29 | 30 | /** 31 | * @return list of Workspace in current Account 32 | */ 33 | public List getWorkspaces() throws IOException { 34 | String uri = httpUtils.getAddress() + String.format("/api/v4/workspaces?accountId=%s&enabled=true&limit=100", getId()); 35 | JSONObject response = httpUtils.queryObject(httpUtils.createGet(uri), 200); 36 | return extractWorkspaces(response.getJSONArray("result")); 37 | } 38 | 39 | private List extractWorkspaces(JSONArray result) { 40 | List workspaces = new ArrayList<>(); 41 | 42 | for (Object obj : result) { 43 | workspaces.add(Workspace.fromJSON(httpUtils, (JSONObject) obj)); 44 | } 45 | 46 | return workspaces; 47 | } 48 | 49 | public static Account fromJSON(HttpUtils httpUtils, JSONObject obj) { 50 | return new Account(httpUtils, obj.getString("id"), obj.getString("name")); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /parallel/src/main/java/com/blazemeter/jmeter/controller/DummyThreadGroup.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller; 2 | 3 | import org.apache.jmeter.engine.StandardJMeterEngine; 4 | import org.apache.jmeter.threads.AbstractThreadGroup; 5 | import org.apache.jmeter.threads.JMeterThread; 6 | import org.apache.jmeter.threads.ListenerNotifier; 7 | import org.apache.jorphan.collections.ListedHashTree; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.LinkedList; 12 | import java.util.List; 13 | 14 | public class DummyThreadGroup extends AbstractThreadGroup { 15 | private static final Logger log = LoggerFactory.getLogger(ParallelSampler.class); 16 | private final List jMeterThreads = new LinkedList<>(); 17 | 18 | public void reset() { 19 | this.jMeterThreads.clear(); 20 | } 21 | 22 | public void addThread(JMeterThread thread) { 23 | this.jMeterThreads.add(thread); 24 | } 25 | 26 | public void stopAllThreads() { 27 | for (JMeterThread thread : jMeterThreads) { 28 | thread.stop(); 29 | } 30 | } 31 | 32 | @Override 33 | public boolean stopThread(String s, boolean b) { 34 | return false; 35 | } 36 | 37 | @Override 38 | public int numberOfActiveThreads() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public void start(int i, ListenerNotifier listenerNotifier, ListedHashTree listedHashTree, StandardJMeterEngine standardJMeterEngine) { 44 | 45 | } 46 | 47 | @Override 48 | public boolean verifyThreadsStopped() { 49 | return false; 50 | } 51 | 52 | @Override 53 | public void waitThreadsStopped() { 54 | 55 | } 56 | 57 | @Override 58 | public void tellThreadsToStop() { 59 | stopAllThreads(); 60 | } 61 | 62 | @Override 63 | public void stop() { 64 | stopAllThreads(); 65 | } 66 | 67 | @Override 68 | public void threadFinished(JMeterThread jMeterThread) { 69 | log.debug("BG thread finished"); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /random-csv-data-set/src/main/java/com/blazemeter/csv/BufferedReaderExt.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.csv; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.Reader; 6 | import java.nio.CharBuffer; 7 | import java.nio.charset.Charset; 8 | 9 | public class BufferedReaderExt extends BufferedReader { 10 | 11 | private int pos; 12 | private Charset charset; 13 | 14 | 15 | public BufferedReaderExt(Reader in, String encoding) { 16 | super(in); 17 | charset = Charset.forName(encoding); 18 | } 19 | 20 | public int getPos() { 21 | return pos; 22 | } 23 | 24 | // JMeter used just this read() method. 25 | @Override 26 | public int read() throws IOException { 27 | int res = super.read(); 28 | if (res <= Byte.MAX_VALUE) { 29 | pos++; 30 | } else { 31 | byte[] buf = new String(new char[]{(char) res}).getBytes(charset); 32 | pos += buf.length; 33 | } 34 | return res; 35 | } 36 | 37 | @Override 38 | public int read(char[] cbuf, int off, int len) throws IOException { 39 | int count = super.read(cbuf, off, len); 40 | pos += count; 41 | return count; 42 | } 43 | 44 | @Override 45 | public String readLine() throws IOException { 46 | String res = super.readLine(); 47 | pos += res.length(); 48 | return res; 49 | } 50 | 51 | @Override 52 | public long skip(long n) throws IOException { 53 | long res = super.skip(n); 54 | pos += res; 55 | return res; 56 | } 57 | 58 | @Override 59 | public void reset() throws IOException { 60 | super.reset(); 61 | pos = 0; 62 | } 63 | 64 | @Override 65 | public int read(CharBuffer target) throws IOException { 66 | int res = super.read(target); 67 | pos += res; 68 | return res; 69 | } 70 | 71 | 72 | 73 | @Override 74 | public int read(char[] cbuf) throws IOException { 75 | int res = super.read(cbuf); 76 | pos += res; 77 | return res; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /xmpp/XMPPSampler.md: -------------------------------------------------------------------------------- 1 | # XMPP Sampler 2 | ![](xmpp.png) 3 | 4 | XMPP Samlper uses [XMPP Connection](XMPPConnection.md) to obtain connection context, then it performs one of available XMPP actions. Action is selected in the UI from the list of available actions. To use the plugin properly, you need to have at least basic knowledge of [XMPP protocol](http://xmpp.org/xmpp-protocols/) and its client-server interaction. 5 | 6 | ![](xmpp-sampler.png) 7 | 8 | ## Actions 9 | 10 | * Connect - every XMPP session must start with connecting to server 11 | * Log In - log into service with username/password/resource 12 | * Roster Actions - allows getting/adding/deleting items from roster 13 | * Send Presence - send available/away status 14 | * Send Message - send messages to individual and group recipients 15 | * Send Raw XML - send raw XML packet to server 16 | * Collect Incoming Packets - very important action, collects all asynchronous incoming packets from connection input queue 17 | * Disconnect - finish XMPP session with this action 18 | * Get Bookmarked Conferences ([XEP-0048](http://xmpp.org/extensions/xep-0048.html)) 19 | * Join Multi-User Chat ([XEP-0045](http://xmpp.org/extensions/xep-0045.html)) 20 | * Send File ([XEP-0096](http://xmpp.org/extensions/xep-0096.html)) 21 | * Service Discovery ([XEP-0030](http://xmpp.org/extensions/xep-0030.html)) 22 | 23 | ## Resource Consumption Notice 24 | 25 | This plugin uses [Smack API](http://www.igniterealtime.org/projects/smack/) as underlying library. This library uses approach when every client can create two more threads for its functioning (sending and receiving). Users should keep that in mind and monitor factual count of the threads for JMeter process. 26 | 27 | ## Extensibility 28 | ![](xzibit.jpg) 29 | 30 | Yeah, just like that. You can implement your own action and put JAR with it under lib/ext, so XMPP sampler will detect it and display in the list of available actions in XMPP Sampler. 31 | 32 | You'll need to inherit from class `com.blazemeter.jmeter.xmpp.actions.AbstractXMPPAction` and implement all required methods. There are plenty of examples in existing actions' source code. -------------------------------------------------------------------------------- /parallel/src/test/java/com/blazemeter/jmeter/controller/traverse/CustomTreeClonerTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller.traverse; 2 | 3 | import org.apache.jmeter.config.ConfigTestElement; 4 | import org.apache.jmeter.control.LoopController; 5 | import org.apache.jmeter.control.ThroughputController; 6 | import org.apache.jmeter.protocol.http.control.CookieManager; 7 | import org.apache.jmeter.protocol.http.control.ThreadSafeCookieManager; 8 | import org.apache.jorphan.collections.HashTree; 9 | import org.apache.jorphan.collections.ListedHashTree; 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class CustomTreeClonerTest { 15 | 16 | @Test 17 | public void testFlow() throws Exception { 18 | final CookieManager manager = new CookieManager(); 19 | final ThroughputController controller = new ThroughputController(); 20 | 21 | CustomTreeCloner cloner = new CustomTreeCloner(); 22 | HashTree tree = createTestTree(controller, manager); 23 | tree.traverse(cloner); 24 | 25 | ListedHashTree clonedTree = cloner.getClonedTree(); 26 | ListedHashTree loop = (ListedHashTree) clonedTree.values().toArray()[0]; 27 | 28 | Object actualController = loop.keySet().toArray()[0]; 29 | assertTrue("This links should be to the same instance", controller == actualController); 30 | 31 | Object actualManager = loop.get(actualController).keySet().toArray()[0]; 32 | assertTrue("Cookie manager should be changed to ThreadSafe instance", actualManager instanceof ThreadSafeCookieManager); 33 | } 34 | 35 | private HashTree createTestTree(ThroughputController controller, ConfigTestElement configTestElement) { 36 | HashTree controllerNode = new HashTree(); 37 | controllerNode.add(controller, configTestElement); 38 | 39 | 40 | LoopController loopController = new LoopController(); 41 | HashTree loopNode = new HashTree(); 42 | loopNode.add(loopController, controllerNode); 43 | 44 | HashTree hashTree = new HashTree(); 45 | hashTree.add(loopNode); 46 | return hashTree; 47 | } 48 | } -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/Project.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import net.sf.json.JSONArray; 5 | import net.sf.json.JSONObject; 6 | 7 | import java.io.IOException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class Project extends BZAObject { 12 | 13 | public static final String DEFAULT_PROJECT = "Default project"; 14 | 15 | public Project(HttpUtils httpUtils, String id, String name) { 16 | super(httpUtils, id, name); 17 | } 18 | 19 | /** 20 | * Create Test in current Project 21 | * @param name - title of the new Test 22 | */ 23 | public Test createTest(String name) throws IOException { 24 | String uri = httpUtils.getAddress() + "/api/v4/tests"; 25 | JSONObject data = new JSONObject(); 26 | data.put("projectId", Long.parseLong(getId())); 27 | JSONObject configuration = new JSONObject(); 28 | configuration.put("type", "external"); 29 | data.put("configuration", configuration); 30 | data.put("name", name); 31 | JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, data.toString()), 201); 32 | return Test.fromJSON(httpUtils, response.getJSONObject("result")); 33 | } 34 | 35 | /** 36 | * @return list of Tests in current Project 37 | */ 38 | public List getTests() throws IOException { 39 | String uri = httpUtils.getAddress() + "/api/v4/tests?projectId=" + getId(); 40 | JSONObject response = httpUtils.queryObject(httpUtils.createGet(uri), 200); 41 | return extractTests(response.getJSONArray("result")); 42 | } 43 | 44 | private List extractTests(JSONArray result) { 45 | List accounts = new ArrayList<>(); 46 | 47 | for (Object obj : result) { 48 | accounts.add(Test.fromJSON(httpUtils, (JSONObject) obj)); 49 | } 50 | 51 | return accounts; 52 | } 53 | 54 | public static Project fromJSON(HttpUtils httpUtils, JSONObject obj) { 55 | return new Project(httpUtils, obj.getString("id"), obj.getString("name")); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /parallel/src/test/java/com/blazemeter/jmeter/controller/JMeterThreadParallelTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller; 2 | 3 | import org.apache.jmeter.control.LoopController; 4 | import org.apache.jmeter.samplers.Sampler; 5 | import org.apache.jmeter.threads.JMeterContextService; 6 | import org.apache.jmeter.threads.JMeterThread; 7 | import org.apache.jmeter.threads.JMeterThreadMonitor; 8 | import org.apache.jmeter.threads.ListenerNotifier; 9 | import org.apache.jorphan.collections.HashTree; 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.*; 13 | 14 | public class JMeterThreadParallelTest { 15 | 16 | @Test 17 | public void testStopParentThread() { 18 | DummyThreadGroup monitor = new DummyThreadGroup(); 19 | ListenerNotifier listenerNotifier = new ListenerNotifier(); 20 | 21 | HashTree tree = new HashTree(); 22 | LoopControllerExt loopControllerExt = new LoopControllerExt(); 23 | tree.add(loopControllerExt); 24 | 25 | JMeterThreadExt parentThread = new JMeterThreadExt(tree, monitor, listenerNotifier); 26 | parentThread.setThreadGroup(monitor); 27 | JMeterContextService.getContext().setThread(parentThread); 28 | 29 | JMeterThreadParallel parallel = new JMeterThreadParallel(tree, monitor, listenerNotifier, true); 30 | parallel.setThreadGroup(monitor); 31 | loopControllerExt.thread = parallel; 32 | parallel.run(); 33 | 34 | assertTrue(parentThread.isStopped); 35 | } 36 | 37 | private static class LoopControllerExt extends LoopController { 38 | JMeterThread thread; 39 | 40 | @Override 41 | public Sampler next() { 42 | thread.stop(); 43 | return super.next(); 44 | } 45 | } 46 | 47 | private static class JMeterThreadExt extends JMeterThread { 48 | boolean isStopped = false; 49 | 50 | public JMeterThreadExt(HashTree test, JMeterThreadMonitor monitor, ListenerNotifier note) { 51 | super(test, monitor, note); 52 | } 53 | 54 | @Override 55 | public void stop() { 56 | isStopped = true; 57 | super.stop(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /parallel/src/test/java/com/blazemeter/jmeter/controller/ParallelListenerNotifierTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller; 2 | 3 | import org.apache.jmeter.samplers.SampleEvent; 4 | import org.apache.jmeter.samplers.SampleListener; 5 | import org.apache.jmeter.samplers.SampleResult; 6 | import org.apache.jmeter.testelement.AbstractTestElement; 7 | import org.junit.Test; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | public class ParallelListenerNotifierTest { 15 | 16 | @Test 17 | public void testSubResultsLabels() { 18 | ParallelListenerNotifier notifier = new ParallelListenerNotifier(); 19 | SampleResult container = new SampleResult() { 20 | @Override 21 | public void addSubResult(SampleResult subResult) { 22 | // generate JMeter 5.0 behaviour 23 | // https://bz.apache.org/bugzilla/show_bug.cgi?id=62550 24 | subResult.setSampleLabel("new Label"); 25 | } 26 | }; 27 | 28 | 29 | notifier.setContainer(container); 30 | 31 | SampleResult subSampler = new SampleResult(); 32 | subSampler.setSampleLabel("label"); 33 | 34 | SampleListenerExt sampleListenerExt = new SampleListenerExt(); 35 | List list = new ArrayList<>(); 36 | list.add(sampleListenerExt); 37 | 38 | 39 | notifier.notifyListeners(new SampleEvent(subSampler, ""), list); 40 | assertEquals("label", subSampler.getSampleLabel()); 41 | assertEquals(1, sampleListenerExt.count); 42 | } 43 | 44 | private static class SampleListenerExt extends AbstractTestElement implements SampleListener { 45 | int count = 0; 46 | @Override 47 | public void sampleOccurred(SampleEvent sampleEvent) { 48 | assertEquals("label", sampleEvent.getResult().getSampleLabel()); 49 | count++; 50 | } 51 | 52 | @Override 53 | public void sampleStarted(SampleEvent sampleEvent) { 54 | 55 | } 56 | 57 | @Override 58 | public void sampleStopped(SampleEvent sampleEvent) { 59 | 60 | } 61 | } 62 | 63 | 64 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/kg/apc/jmeter/reporters/notifier/StatusNotifierCallbackTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 undera. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package kg.apc.jmeter.reporters.notifier; 17 | 18 | import kg.apc.jmeter.notifier.StatusNotifierCallback; 19 | import org.junit.After; 20 | import org.junit.AfterClass; 21 | import org.junit.Before; 22 | import org.junit.BeforeClass; 23 | import org.junit.Test; 24 | 25 | public class StatusNotifierCallbackTest { 26 | 27 | public StatusNotifierCallbackTest() { 28 | } 29 | 30 | @BeforeClass 31 | public static void setUpClass() { 32 | } 33 | 34 | @AfterClass 35 | public static void tearDownClass() { 36 | } 37 | 38 | @Before 39 | public void setUp() { 40 | } 41 | 42 | @After 43 | public void tearDown() { 44 | } 45 | 46 | /** 47 | * Test of notifyAbout method, of class StatusNotifierCallback. 48 | */ 49 | @Test 50 | public void testNotifyAbout() { 51 | System.out.println("notifyAbout"); 52 | String info = ""; 53 | StatusNotifierCallback instance = new StatusNotifierCallbackImpl(); 54 | instance.notifyAbout(info); 55 | // TODO review the generated test code and remove the default call to fail. 56 | 57 | } 58 | 59 | public static class StatusNotifierCallbackImpl implements StatusNotifierCallback { 60 | private StringBuilder buffer = new StringBuilder(); 61 | 62 | public void notifyAbout(String info) { 63 | buffer.append(info); 64 | } 65 | 66 | public StringBuilder getBuffer() { 67 | return buffer; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/MUC.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 4 | import org.apache.jmeter.samplers.SampleResult; 5 | import org.jivesoftware.smackx.muc.MultiUserChat; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | public class MUC extends AbstractXMPPAction { 11 | private static final java.lang.String ROOM = "muc_room"; 12 | private static final java.lang.String NICKNAME = "muc_nickname"; 13 | private JTextField roomname; 14 | private JTextField nickname; 15 | 16 | @Override 17 | public String getLabel() { 18 | return "Join Multi-User Chat (XEP-0045)"; 19 | } 20 | 21 | @Override 22 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 23 | String room = sampler.getPropertyAsString(ROOM); 24 | String nick = sampler.getPropertyAsString(NICKNAME); 25 | res.setSamplerData("Join Room: " + room + "/" + nick); 26 | MultiUserChat muc = new MultiUserChat(sampler.getXMPPConnection(), room); 27 | muc.join(nick); 28 | return res; 29 | } 30 | 31 | @Override 32 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 33 | addToPanel(panel, labelConstraints, 0, 0, new JLabel("Room: ", JLabel.RIGHT)); 34 | addToPanel(panel, editConstraints, 1, 0, roomname = new JTextField(20)); 35 | 36 | addToPanel(panel, labelConstraints, 0, 1, new JLabel("Nickname: ", JLabel.RIGHT)); 37 | addToPanel(panel, editConstraints, 1, 1, nickname = new JTextField(20)); 38 | } 39 | 40 | @Override 41 | public void clearGui() { 42 | roomname.setText(""); 43 | nickname.setText(""); 44 | } 45 | 46 | @Override 47 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 48 | sampler.setProperty(ROOM, roomname.getText()); 49 | sampler.setProperty(NICKNAME, nickname.getText()); 50 | } 51 | 52 | @Override 53 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 54 | roomname.setText(sampler.getPropertyAsString(ROOM)); 55 | nickname.setText(sampler.getPropertyAsString(NICKNAME)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/http/BlazeMeterHttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.http; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import kg.apc.jmeter.http.HttpUtils; 5 | import kg.apc.jmeter.notifier.StatusNotifierCallback; 6 | import net.sf.json.JSON; 7 | import net.sf.json.JSONException; 8 | import net.sf.json.JSONObject; 9 | import net.sf.json.JSONSerializer; 10 | import net.sf.json.JsonConfig; 11 | import org.apache.commons.codec.binary.Base64; 12 | import org.apache.http.client.methods.HttpRequestBase; 13 | 14 | 15 | public class BlazeMeterHttpUtils extends HttpUtils { 16 | 17 | protected final BlazeMeterReport report; 18 | 19 | public BlazeMeterHttpUtils(StatusNotifierCallback notifier, String address, String dataAddress, BlazeMeterReport report) { 20 | super(notifier, address, dataAddress); 21 | this.report = report; 22 | } 23 | 24 | @Override 25 | protected void addRequiredHeader(HttpRequestBase httpRequestBase) { 26 | if (!report.isAnonymousTest()) { 27 | String token = report.getToken(); 28 | if (token != null && token.contains(":")) { 29 | httpRequestBase.setHeader("Authorization", "Basic " + new String(Base64.encodeBase64(token.getBytes()))); 30 | } else { 31 | httpRequestBase.setHeader("X-Api-Key", token); 32 | } 33 | } 34 | } 35 | 36 | @Override 37 | protected String extractErrorMessage(String response) { 38 | if (response != null && !response.isEmpty()) { 39 | try { 40 | JSON jsonResponse = JSONSerializer.toJSON(response, new JsonConfig()); 41 | if (jsonResponse instanceof JSONObject) { 42 | JSONObject object = (JSONObject) jsonResponse; 43 | JSONObject errorObj = object.getJSONObject("error"); 44 | if (errorObj.containsKey("message")) { 45 | return errorObj.getString("message"); 46 | } 47 | } 48 | } catch (JSONException ex) { 49 | log.debug("Cannot parse JSON error response: " + response); 50 | } 51 | } 52 | return response; 53 | } 54 | 55 | public BlazeMeterReport getReport() { 56 | return report; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /parallel/Parallel.md: -------------------------------------------------------------------------------- 1 | # Parallel Sampling for JMeter 2 | 3 | ## Parallel Controller 4 | 5 | Parallel Controller is a Controller that allows execute child elements parallel. 6 | Can be used to simulate a load using AJAX, download resources and many other different variants. 7 | 8 | ![](ParallelController.png) 9 | 10 | Use option _Generate parent sample_ to generate one parent sample that unite all child elements 11 | 12 | Use option _Limit max thread number_ to limit the concurrent thread simultaneosly active. 13 | 14 | If _Limit max thread number_ is select it's possible to specify thread number (by default 6) 15 | 16 | If _Limit max thread number_ is not selected, no limit will be set. 17 | 18 | ### Limitations 19 | 20 | Parallel Controller does **not** support work with **Transaction Controller** so if used you can get an unexpected results. 21 | If you decide to use these controllers together familiarize yourself with already known problems that described in [roadmap](#roadmap) 22 | 23 | [Download Example Test Plan](ParallelController.jmx) 24 | 25 | ## Parallel Sampler 26 | 27 | Parallel Sampler allows make requests like embedded resources for URLs from list in GUI, without making request for main page. 28 | 29 | ![](ParallelSampler.png) 30 | 31 | Click `Add Row` for added new row in URL list and then enter the URL into row. 32 | 33 | [Download Example Test Plan](ParallelSampler.jmx) 34 | 35 | ## Roadmap 36 | 37 | * test, test, test 38 | * Known issues with Transaction Controller: 39 | * If Transaction Controller put in Parallel Controller and option `Generate parent sample` is enabled in two controllers 40 | than you'll see parent sample of Transaction Controller and sub-sampler of this parent in parent sample of Parallel Controller ([fix]()) 41 | * If Transaction Controller put in Parallel Controller and option `Generate parent sample` is enabled in Parallel Controller and disable in Transaction Controller 42 | than you'll not see the result sample of transaction (_with number of samples and fails in transaction_) in parent sample of Parallel Controller 43 | * If Parallel Controller put in Transaction Controller and option `Generate parent sample` is disable in Parallel Controller and enabled in Transaction Controller 44 | than you'll see that samples from Parallel Controller will have the same nesting as parent sample of Transaction Controller, and parent sample will be empty 45 | -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/actions/GetBookmarksTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSamplerMock; 4 | import org.apache.jmeter.samplers.SampleResult; 5 | import org.apache.jorphan.logging.LoggingManager; 6 | import org.apache.log.Logger; 7 | import org.jivesoftware.smack.packet.IQ; 8 | import org.jivesoftware.smackx.bookmarks.Bookmarks; 9 | import org.jivesoftware.smackx.iqprivate.packet.PrivateData; 10 | import org.junit.Test; 11 | 12 | import javax.swing.*; 13 | import java.awt.*; 14 | 15 | public class GetBookmarksTest { 16 | private static final Logger log = LoggingManager.getLoggerForClass(); 17 | 18 | 19 | public void testPerform() throws Exception { 20 | GetBookmarks obj = new GetBookmarks(); 21 | final JMeterXMPPSamplerMock sampler = new JMeterXMPPSamplerMock(); 22 | Thread thr = new Thread() { 23 | @Override 24 | public void run() { 25 | while (true) { 26 | if (!sampler.conn.getCollectors().isEmpty()) 27 | sampler.conn.processPacket(new PrivateDataResult(new Bookmarks())); 28 | } 29 | } 30 | }; 31 | thr.start(); 32 | Thread.sleep(sampler.conn.getPacketReplyTimeout() / 10); 33 | obj.perform(sampler, new SampleResult()); 34 | 35 | } 36 | 37 | @Test 38 | public void testAddUI() throws Exception { 39 | GetBookmarks obj = new GetBookmarks(); 40 | obj.addUI(new JPanel(), new GridBagConstraints(), new GridBagConstraints()); 41 | } 42 | 43 | /** 44 | * An IQ packet to hold PrivateData GET results. 45 | */ 46 | private static class PrivateDataResult extends IQ { 47 | 48 | private PrivateData privateData; 49 | 50 | PrivateDataResult(PrivateData privateData) { 51 | this.privateData = privateData; 52 | } 53 | 54 | public PrivateData getPrivateData() { 55 | return privateData; 56 | } 57 | 58 | public String getChildElementXML() { 59 | StringBuilder buf = new StringBuilder(); 60 | buf.append(""); 61 | if (privateData != null) { 62 | buf.append(privateData.toXML()); 63 | } 64 | buf.append(""); 65 | return buf.toString(); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/ProjectTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import com.blazemeter.api.http.BlazeMeterHttpUtilsEmul; 5 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 6 | import net.sf.json.JSONArray; 7 | import net.sf.json.JSONObject; 8 | 9 | import java.util.List; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | public class ProjectTest { 14 | @org.junit.Test 15 | public void testFlow() throws Exception { 16 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 17 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 18 | 19 | JSONObject result = new JSONObject(); 20 | result.put("id", "100"); 21 | result.put("name", "NEW_TEST"); 22 | JSONObject response = new JSONObject(); 23 | response.put("result", result); 24 | 25 | Project project = new Project(emul, "10", "projectName"); 26 | emul.addEmul(response); 27 | Test test = project.createTest("NEW_WORKSPACE"); 28 | assertEquals("100", test.getId()); 29 | assertEquals("NEW_TEST", test.getName()); 30 | 31 | response.clear(); 32 | JSONArray results = new JSONArray(); 33 | results.add(result); 34 | results.add(result); 35 | response.put("result", results); 36 | emul.addEmul(response); 37 | 38 | List tests = project.getTests(); 39 | assertEquals(2, tests.size()); 40 | for (Test t :tests) { 41 | assertEquals("100", t.getId()); 42 | assertEquals("NEW_TEST", t.getName()); 43 | } 44 | } 45 | 46 | @org.junit.Test 47 | public void testFromJSON() throws Exception { 48 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 49 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 50 | JSONObject object = new JSONObject(); 51 | object.put("id", "projectId"); 52 | object.put("name", "projectName"); 53 | Project project = Project.fromJSON(emul, object); 54 | assertEquals("projectId", project.getId()); 55 | assertEquals("projectName", project.getName()); 56 | } 57 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/http/BlazeMeterHttpUtilsEmul.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.http; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import kg.apc.jmeter.notifier.StatusNotifierCallback; 5 | import net.sf.json.JSON; 6 | import net.sf.json.JSONObject; 7 | import org.apache.commons.io.IOUtils; 8 | import org.apache.http.client.methods.HttpPost; 9 | import org.apache.http.client.methods.HttpRequestBase; 10 | 11 | import java.io.ByteArrayOutputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.util.LinkedList; 15 | 16 | public class BlazeMeterHttpUtilsEmul extends BlazeMeterHttpUtils { 17 | 18 | private LinkedList responses = new LinkedList<>(); 19 | private LinkedList requests = new LinkedList<>(); 20 | 21 | public BlazeMeterHttpUtilsEmul(StatusNotifierCallback notifier, String address, String dataAddress, BlazeMeterReport report) { 22 | super(notifier, address, dataAddress, report); 23 | } 24 | 25 | public void addEmul(JSON response) { 26 | responses.add(response); 27 | } 28 | 29 | public void clean() { 30 | requests.clear(); 31 | } 32 | 33 | public LinkedList getRequests() { 34 | return requests; 35 | } 36 | 37 | @Override 38 | public JSON query(HttpRequestBase request, int expectedCode) throws IOException { 39 | extractBody(request); 40 | return getResponse(request); 41 | } 42 | 43 | @Override 44 | public JSONObject queryObject(HttpRequestBase request, int expectedCode) throws IOException { 45 | extractBody(request); 46 | return (JSONObject) getResponse(request); 47 | } 48 | 49 | public void extractBody(HttpRequestBase request) throws IOException { 50 | if (request instanceof HttpPost) { 51 | HttpPost post = (HttpPost) request; 52 | InputStream inputStream = post.getEntity().getContent(); 53 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 54 | IOUtils.copy(inputStream, outputStream); 55 | requests.add(outputStream.toString()); 56 | } 57 | } 58 | 59 | public JSON getResponse(HttpRequestBase request) throws IOException { 60 | log.info("Simulating request: " + request); 61 | if (responses.size() > 0) { 62 | JSON resp = responses.remove(); 63 | log.info("Response: " + resp); 64 | return resp; 65 | } else { 66 | throw new IOException("No responses to emulate"); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /rotating-listener/src/main/java/com/blazemeter/jmeter/RotatingResultCollectorGui.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import kg.apc.jmeter.JMeterPluginsUtils; 4 | import org.apache.jmeter.gui.util.HorizontalPanel; 5 | import org.apache.jmeter.testelement.TestElement; 6 | import org.apache.jmeter.visualizers.SimpleDataWriter; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | public class RotatingResultCollectorGui extends SimpleDataWriter { 12 | public static final String WIKIPAGE = "RotatingListener"; 13 | 14 | private JTextField maxSamplesCount; 15 | 16 | public RotatingResultCollectorGui() { 17 | super(); 18 | init(); 19 | } 20 | 21 | private void init() { 22 | setLayout(new BorderLayout(0, 5)); 23 | setBorder(makeBorder()); 24 | 25 | Container topPanel = makeTitlePanel(); 26 | 27 | add(JMeterPluginsUtils.addHelpLinkToPanel(topPanel, WIKIPAGE), BorderLayout.NORTH); 28 | add(topPanel, BorderLayout.NORTH); 29 | 30 | JPanel mainPanel = new HorizontalPanel(); 31 | 32 | mainPanel.setBorder(BorderFactory.createTitledBorder("File Rotating Rules")); 33 | mainPanel.add(new JLabel("Limit samples count in file: ", JLabel.RIGHT)); 34 | maxSamplesCount = new JTextField(20); 35 | mainPanel.add(maxSamplesCount); 36 | 37 | topPanel.add(mainPanel); 38 | } 39 | 40 | @Override 41 | public String getStaticLabel() { 42 | return JMeterPluginsUtils.prefixLabel("Rotating Simple Data Writer"); 43 | } 44 | 45 | public TestElement createTestElement() { 46 | RotatingResultCollector element = new RotatingResultCollector(); 47 | modifyTestElement(element); 48 | return element; 49 | } 50 | 51 | public void modifyTestElement(TestElement element) { 52 | super.modifyTestElement(element); 53 | 54 | if (element instanceof RotatingResultCollector) { 55 | RotatingResultCollector rotatingCollector = (RotatingResultCollector) element; 56 | rotatingCollector.setMaxSamplesCount(this.maxSamplesCount.getText()); 57 | } 58 | } 59 | 60 | @Override 61 | public void configure(TestElement element) { 62 | super.configure(element); 63 | 64 | if (element instanceof RotatingResultCollector) { 65 | maxSamplesCount.setText(((RotatingResultCollector) element).getMaxSamplesCount()); 66 | } 67 | } 68 | 69 | @Override 70 | public void clearGui() { 71 | super.clearGui(); 72 | maxSamplesCount.setText(""); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /rotating-listener/src/test/java/com/blazemeter/jmeter/RotatingResultCollectorGuiTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.junit.BeforeClass; 5 | import org.junit.Test; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | import static org.junit.Assert.assertNotEquals; 12 | import static org.junit.Assert.assertTrue; 13 | 14 | /** 15 | * 16 | */ 17 | public class RotatingResultCollectorGuiTest { 18 | 19 | @BeforeClass 20 | public static void setUpClass() 21 | throws Exception { 22 | TestJMeterUtils.createJmeterEnv(); 23 | } 24 | 25 | //@Test 26 | public void testGui() throws Exception { 27 | if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) { 28 | RotatingResultCollectorGui gui = new RotatingResultCollectorGui(); 29 | RotatingResultCollector te1 = (RotatingResultCollector) gui.createTestElement(); 30 | RotatingResultCollector te2 = (RotatingResultCollector) gui.createTestElement(); 31 | assertNotEquals("", te1.getName()); 32 | 33 | te1.setMaxSamplesCount("7"); 34 | gui.configure(te1); 35 | gui.modifyTestElement(te2); 36 | 37 | assertTrue(te1.equals(te2)); 38 | assertEquals(7, te2.getMaxSamplesCountAsInt()); 39 | 40 | JDialog frame = new JDialog(); 41 | frame.add(gui); 42 | 43 | frame.setPreferredSize(new Dimension(800, 600)); 44 | frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 45 | frame.pack(); 46 | frame.setVisible(true); 47 | while (frame.isVisible()) { 48 | Thread.sleep(100); 49 | } 50 | } 51 | } 52 | 53 | @Test 54 | public void testGuiForm() throws Exception { 55 | RotatingResultCollectorGui gui = new RotatingResultCollectorGui(); 56 | RotatingResultCollector te1 = (RotatingResultCollector) gui.createTestElement(); 57 | RotatingResultCollector te2 = (RotatingResultCollector) gui.createTestElement(); 58 | assertNotEquals("", te1.getName()); 59 | 60 | te1.setMaxSamplesCount("7"); 61 | gui.configure(te1); 62 | gui.modifyTestElement(te2); 63 | 64 | assertTrue(te1.equals(te2)); 65 | assertEquals(7, te2.getMaxSamplesCountAsInt()); 66 | 67 | gui.clearGui(); 68 | gui.modifyTestElement(te1); 69 | assertEquals("", te1.getMaxSamplesCount()); 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/WorkspaceTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import com.blazemeter.api.http.BlazeMeterHttpUtilsEmul; 5 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 6 | import net.sf.json.JSONArray; 7 | import net.sf.json.JSONObject; 8 | 9 | import java.util.List; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | public class WorkspaceTest { 14 | @org.junit.Test 15 | public void testFlow() throws Exception { 16 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 17 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 18 | 19 | JSONObject result = new JSONObject(); 20 | result.put("id", "999"); 21 | result.put("name", "NEW_PROJECT"); 22 | JSONObject response = new JSONObject(); 23 | response.put("result", result); 24 | 25 | Workspace workspace = new Workspace(emul, "888", "workspace_name"); 26 | emul.addEmul(response); 27 | Project project = workspace.createProject("NEW_PROJECT"); 28 | assertEquals("999", project.getId()); 29 | assertEquals("NEW_PROJECT", project.getName()); 30 | 31 | response.clear(); 32 | JSONArray results = new JSONArray(); 33 | results.add(result); 34 | results.add(result); 35 | response.put("result", results); 36 | emul.addEmul(response); 37 | 38 | List projects = workspace.getProjects(); 39 | assertEquals(2, projects.size()); 40 | for (Project p :projects) { 41 | assertEquals("999", p.getId()); 42 | assertEquals("NEW_PROJECT", p.getName()); 43 | } 44 | } 45 | 46 | @org.junit.Test 47 | public void testFromJSON() throws Exception { 48 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 49 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 50 | JSONObject object = new JSONObject(); 51 | object.put("id", "workspaceId"); 52 | object.put("name", "workspaceName"); 53 | Workspace workspace = Workspace.fromJSON(emul, object); 54 | assertEquals("workspaceId", workspace.getId()); 55 | assertEquals("workspaceName", workspace.getName()); 56 | } 57 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/AccountTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import com.blazemeter.api.http.BlazeMeterHttpUtilsEmul; 5 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 6 | import net.sf.json.JSONArray; 7 | import net.sf.json.JSONObject; 8 | import org.junit.Test; 9 | 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | public class AccountTest { 15 | 16 | @Test 17 | public void testFlow() throws Exception { 18 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 19 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 20 | 21 | JSONObject result = new JSONObject(); 22 | result.put("id", "100"); 23 | result.put("name", "NEW_WORKSPACE"); 24 | JSONObject response = new JSONObject(); 25 | response.put("result", result); 26 | 27 | Account account = new Account(emul, "777", "account_name"); 28 | emul.addEmul(response); 29 | Workspace workspace = account.createWorkspace("NEW_WORKSPACE"); 30 | assertEquals("100", workspace.getId()); 31 | assertEquals("NEW_WORKSPACE", workspace.getName()); 32 | 33 | response.clear(); 34 | JSONArray results = new JSONArray(); 35 | results.add(result); 36 | results.add(result); 37 | response.put("result", results); 38 | emul.addEmul(response); 39 | 40 | List workspaces = account.getWorkspaces(); 41 | assertEquals(2, workspaces.size()); 42 | for (Workspace wsp :workspaces) { 43 | assertEquals("100", wsp.getId()); 44 | assertEquals("NEW_WORKSPACE", wsp.getName()); 45 | } 46 | } 47 | 48 | @Test 49 | public void testFromJSON() throws Exception { 50 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 51 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 52 | JSONObject object = new JSONObject(); 53 | object.put("id", "accountId"); 54 | object.put("name", "accountName"); 55 | Account account = Account.fromJSON(emul, object); 56 | assertEquals("accountId", account.getId()); 57 | assertEquals("accountName", account.getName()); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /parallel/src/test/java/com/blazemeter/jmeter/http/ParallelHTTPSamplerTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.http; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import kg.apc.jmeter.JMeterPluginsUtils; 5 | import org.apache.jmeter.gui.util.PowerTableModel; 6 | import org.apache.jmeter.protocol.http.sampler.HTTPAbstractImpl; 7 | import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult; 8 | import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase; 9 | import org.apache.jmeter.samplers.SampleResult; 10 | import org.apache.jmeter.testelement.property.CollectionProperty; 11 | import org.apache.jmeter.util.JMeterUtils; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test; 14 | 15 | import java.net.URL; 16 | 17 | import static org.junit.Assert.assertEquals; 18 | import static org.junit.Assert.assertTrue; 19 | 20 | public class ParallelHTTPSamplerTest { 21 | @BeforeClass 22 | public static void setUp() throws Exception { 23 | TestJMeterUtils.createJmeterEnv(); 24 | JMeterUtils.setProperty("HTTPResponse.parsers", "htmlParser"); 25 | JMeterUtils.setProperty("htmlParser.types", "text/html"); 26 | JMeterUtils.setProperty("htmlParser.className", "org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser"); 27 | } 28 | 29 | @Test 30 | public void sample() throws Exception { 31 | ParallelHTTPSampler obj = new ParallelHTTPSamplerMock(); 32 | obj.setName("parent"); 33 | //obj.setConcurrentDwn(false); //FIXME: remove or comment this 34 | PowerTableModel dataModel = new PowerTableModel(ParallelHTTPSampler.columnIdentifiers, ParallelHTTPSampler.columnClasses); 35 | dataModel.addRow(new String[]{"http://localhost:8000/rtimes/const?delay=1"}); 36 | dataModel.addRow(new String[]{"http://localhost:8000/rtimes/const?delay=2"}); 37 | CollectionProperty prop = JMeterPluginsUtils.tableModelRowsToCollectionProperty(dataModel, ParallelHTTPSampler.DATA_PROPERTY); 38 | obj.setData(prop); 39 | SampleResult res = obj.sample(); 40 | assertTrue(res.isSuccessful()); 41 | assertEquals(2, res.getSubResults().length); 42 | } 43 | 44 | @Test 45 | public void empty_list_call() throws Exception { 46 | ParallelHTTPSampler obj = new ParallelHTTPSamplerMock(); 47 | obj.setName("parent"); 48 | obj.addURL("http://localhost:8000/rtimes/const?delay=1"); 49 | obj.addURL("http://localhost:8000/rtimes/const?delay=2"); 50 | SampleResult res = obj.sample(); 51 | assertTrue(res.isSuccessful()); 52 | assertEquals(2, res.getSubResults().length); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/Test.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | 4 | import kg.apc.jmeter.http.HttpUtils; 5 | import net.sf.json.JSONObject; 6 | 7 | import java.io.IOException; 8 | 9 | public class Test extends BZAObject { 10 | 11 | public static final String DEFAULT_TEST = "Default test"; 12 | 13 | private Session session; 14 | private Master master; 15 | private String signature; 16 | private String reportURL; 17 | 18 | public Test(HttpUtils httpUtils) { 19 | super(httpUtils, "", ""); 20 | } 21 | 22 | public Test(HttpUtils httpUtils, String id, String name) { 23 | super(httpUtils, id, name); 24 | } 25 | 26 | /** 27 | * Start External test for user token 28 | */ 29 | public void startExternal() throws IOException { 30 | JSONObject result = sendStartTest(httpUtils.getAddress() + String.format("/api/v4/tests/%s/start-external", getId()), 202); 31 | fillFields(result); 32 | } 33 | 34 | /** 35 | * Start Anonymous External test 36 | * @return public link to the report 37 | */ 38 | public String startAnonymousExternal() throws IOException { 39 | JSONObject result = sendStartTest(httpUtils.getAddress() + "/api/v4/sessions", 201); 40 | setTestFields(result.getJSONObject("test")); 41 | reportURL = result.getString("publicTokenUrl"); 42 | fillFields(result); 43 | return reportURL; 44 | } 45 | 46 | private JSONObject sendStartTest(String uri, int expectedRC) throws IOException { 47 | JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, ""), expectedRC); 48 | return response.getJSONObject("result"); 49 | } 50 | 51 | private void fillFields(JSONObject result) { 52 | this.signature = result.getString("signature"); 53 | this.session = Session.fromJSON(httpUtils, getId(), signature, result.getJSONObject("session")); 54 | this.master = Master.fromJSON(httpUtils, result.getJSONObject("master")); 55 | } 56 | 57 | private void setTestFields(JSONObject obj) { 58 | setId(obj.getString("id")); 59 | setName(obj.getString("name")); 60 | } 61 | 62 | public Session getSession() { 63 | return session; 64 | } 65 | 66 | public Master getMaster() { 67 | return master; 68 | } 69 | 70 | public String getSignature() { 71 | return signature; 72 | } 73 | 74 | public String getReportURL() { 75 | return reportURL; 76 | } 77 | 78 | public static Test fromJSON(HttpUtils httpUtils, JSONObject obj) { 79 | return new Test(httpUtils, obj.getString("id"), obj.getString("name")); 80 | } 81 | } -------------------------------------------------------------------------------- /sense-uploader/src/main/java/com/blazemeter/api/explorer/Session.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import kg.apc.jmeter.http.HttpUtils; 4 | import net.sf.json.JSONObject; 5 | 6 | import java.io.IOException; 7 | 8 | public class Session extends BZAObject { 9 | 10 | private final String userId; 11 | private final String testId; 12 | private final String signature; 13 | 14 | public Session(HttpUtils httpUtils, String id, String name, String userId, String testId, String signature) { 15 | super(httpUtils, id, name); 16 | this.userId = userId; 17 | this.testId = testId; 18 | this.signature = signature; 19 | } 20 | 21 | /** 22 | * Send test json data for the report 23 | * @return session in JSONObject 24 | */ 25 | public JSONObject sendData(JSONObject data) throws IOException { 26 | String uri = httpUtils.getDataAddress() + 27 | String.format("/submit.php?session_id=%s&signature=%s&test_id=%s&user_id=%s", 28 | getId(), signature, testId, userId); 29 | uri += "&pq=0&target=labels_bulk&update=1"; //TODO: % self.kpi_target 30 | String dataStr = data.toString(); 31 | log.debug("Sending active test data: " + dataStr); 32 | JSONObject response = httpUtils.queryObject(httpUtils.createPost(uri, dataStr), 200); 33 | return response.getJSONObject("result").getJSONObject("session"); 34 | } 35 | 36 | /** 37 | * Stop session for user token 38 | */ 39 | public void stop() throws IOException { 40 | String uri = httpUtils.getAddress() + String.format("/api/v4/sessions/%s/stop", getId()); 41 | httpUtils.query(httpUtils.createPost(uri, ""), 202); 42 | } 43 | 44 | /** 45 | * Stop anonymous session 46 | */ 47 | public void stopAnonymous() throws IOException { 48 | String uri = httpUtils.getAddress() + String.format("/api/v4/sessions/%s/terminate-external", getId()); 49 | JSONObject data = new JSONObject(); 50 | data.put("signature", signature); 51 | data.put("testId", testId); 52 | data.put("sessionId", getId()); 53 | httpUtils.query(httpUtils.createPost(uri, data.toString()), 200); 54 | } 55 | 56 | public String getUserId() { 57 | return userId; 58 | } 59 | 60 | public String getTestId() { 61 | return testId; 62 | } 63 | 64 | public String getSignature() { 65 | return signature; 66 | } 67 | 68 | public static Session fromJSON(HttpUtils httpUtils, String testId, String signature, JSONObject session) { 69 | return new Session(httpUtils, session.getString("id"), session.getString("name"), session.getString("userId"), testId, signature); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/XMPPConnectionMock.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp; 2 | 3 | import org.apache.jorphan.logging.LoggingManager; 4 | import org.apache.log.Logger; 5 | import org.jivesoftware.smack.*; 6 | import org.jivesoftware.smack.packet.Packet; 7 | import org.jivesoftware.smack.packet.PlainStreamElement; 8 | 9 | import java.io.IOException; 10 | 11 | public class XMPPConnectionMock extends AbstractXMPPConnection { 12 | private static final Logger log = LoggingManager.getLoggerForClass(); 13 | 14 | public boolean isConnected = true; 15 | public boolean isAuthenticated = true; 16 | 17 | public XMPPConnectionMock() { 18 | super(new ConnectionConfiguration("unitTest")); 19 | } 20 | 21 | @Override 22 | public String getUser() { 23 | return "test@unitTest"; 24 | } 25 | 26 | @Override 27 | public String getConnectionID() { 28 | return "ConnID"; 29 | } 30 | 31 | @Override 32 | public boolean isConnected() { 33 | return isConnected; 34 | } 35 | 36 | @Override 37 | public boolean isAuthenticated() { 38 | return isAuthenticated; 39 | } 40 | 41 | @Override 42 | public boolean isAnonymous() { 43 | return false; 44 | } 45 | 46 | @Override 47 | public boolean isSecureConnection() { 48 | return false; 49 | } 50 | 51 | @Override 52 | protected void sendPacketInternal(Packet packet) throws SmackException.NotConnectedException { 53 | log.debug("Emul sending packet: " + packet.toXML()); 54 | } 55 | 56 | @Override 57 | public void send(PlainStreamElement element) throws SmackException.NotConnectedException { 58 | log.debug("Emul sending packet: " + element.toXML()); 59 | } 60 | 61 | @Override 62 | public boolean isUsingCompression() { 63 | return false; 64 | } 65 | 66 | @Override 67 | protected void connectInternal() throws SmackException, IOException, XMPPException { 68 | log.debug("Emul connect"); 69 | } 70 | 71 | @Override 72 | public void login(String username, String password, String resource) throws XMPPException, SmackException, IOException { 73 | log.debug("Emul login"); 74 | } 75 | 76 | @Override 77 | public void loginAnonymously() throws XMPPException, SmackException, IOException { 78 | log.debug("Emul login"); 79 | } 80 | 81 | @Override 82 | protected void shutdown() { 83 | log.debug("Emul Shutdown"); 84 | } 85 | 86 | @Override 87 | public void processPacket(Packet packet) { 88 | super.processPacket(packet); 89 | } 90 | 91 | 92 | public java.util.Collection getCollectors() { 93 | return collectors; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /directory-listing/src/test/java/com/blazemeter/jmeter/DirectoryListingIteratorTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import org.junit.Test; 4 | 5 | import java.io.File; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | public class DirectoryListingIteratorTest { 12 | 13 | @Test 14 | public void testReRead() throws Exception { 15 | File rootDir = TestDirectoryListingConfigActionTest.createFileTree(); 16 | 17 | List etalonList = DirectoryListingIterator.getDirectoryListing(rootDir.getAbsoluteFile(), true); 18 | 19 | DirectoryListingIterator iterator = new DirectoryListingIterator( 20 | rootDir.getAbsolutePath(), 21 | false, 22 | true, 23 | true, 24 | true 25 | ); 26 | 27 | testFlow(etalonList, iterator); 28 | 29 | File.createTempFile("tmpFile3_", ".csv", rootDir); 30 | 31 | etalonList = DirectoryListingIterator.getDirectoryListing(rootDir.getAbsoluteFile(), true); 32 | testFlow(etalonList, iterator); 33 | } 34 | 35 | @Test 36 | public void testRewindWithRandom() throws Exception { 37 | File rootDir = TestDirectoryListingConfigActionTest.createFileTree(); 38 | 39 | List etalonList = DirectoryListingIterator.getDirectoryListing(rootDir.getAbsoluteFile(), true); 40 | 41 | DirectoryListingIterator iterator = new DirectoryListingIterator( 42 | rootDir.getAbsolutePath(), 43 | true, 44 | true, 45 | true, 46 | false 47 | ); 48 | 49 | testRandomFlow(etalonList, iterator); 50 | testRandomFlow(etalonList, iterator); 51 | } 52 | 53 | private void testRandomFlow(List etalonList, DirectoryListingIterator iterator) { 54 | List filesNames = new ArrayList<>(etalonList.size()); 55 | 56 | for (File f : etalonList) { 57 | filesNames.add(f.getAbsolutePath()); 58 | } 59 | 60 | for (int i = 0; i < etalonList.size(); i++) { 61 | assertTrue(iterator.hasNext()); 62 | String fname = iterator.next().getAbsolutePath(); 63 | assertTrue(filesNames.contains(fname)); 64 | filesNames.remove(fname); 65 | } 66 | 67 | assertEquals(0, filesNames.size()); 68 | } 69 | 70 | private void testFlow(List etalonList, DirectoryListingIterator iterator) { 71 | assertNotNull(etalonList); 72 | 73 | for (File etalonFile : etalonList) { 74 | assertTrue(iterator.hasNext()); 75 | 76 | assertEquals(etalonFile.getAbsolutePath(), iterator.next().getAbsolutePath()); 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/kg/apc/jmeter/reporters/bzm/BlazemeterUploaderGuiTest.java: -------------------------------------------------------------------------------- 1 | package kg.apc.jmeter.reporters.bzm; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.apache.jmeter.testelement.TestElement; 5 | import org.junit.BeforeClass; 6 | import org.junit.Test; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | 13 | public class BlazemeterUploaderGuiTest { 14 | 15 | @BeforeClass 16 | public static void setUpClass() throws Exception { 17 | TestJMeterUtils.createJmeterEnv(); 18 | } 19 | 20 | // @Test 21 | public void displayGUI() throws InterruptedException { 22 | if (!GraphicsEnvironment.isHeadless()) { 23 | BlazeMeterUploaderGui obj = new BlazeMeterUploaderGui(); 24 | TestElement te = obj.createTestElement(); 25 | obj.configure(te); 26 | obj.clearGui(); 27 | obj.modifyTestElement(te); 28 | 29 | JFrame frame = new JFrame(obj.getStaticLabel()); 30 | frame.setPreferredSize(new Dimension(800, 600)); 31 | frame.getContentPane().add(obj, BorderLayout.CENTER); 32 | frame.pack(); 33 | frame.setVisible(true); 34 | 35 | while (frame.isVisible()) { 36 | Thread.sleep(1000); 37 | } 38 | } 39 | } 40 | 41 | @Test 42 | public void testGui() throws Exception { 43 | BlazeMeterUploaderGui gui = new BlazeMeterUploaderGui(); 44 | 45 | assertEquals(BlazeMeterUploaderGui.class.getCanonicalName(), gui.getLabelResource()); 46 | assertEquals("bzm - BlazeMeter Uploader", gui.getStaticLabel()); 47 | 48 | BlazeMeterUploader element1 = (BlazeMeterUploader) gui.createTestElement(); 49 | BlazeMeterUploader element2 = (BlazeMeterUploader) gui.createTestElement(); 50 | 51 | element1.setProject("test_project"); 52 | element1.setTitle("test_title"); 53 | element1.setUploadToken("test_token"); 54 | element1.setShareTest(true); 55 | 56 | gui.configure(element1); 57 | gui.modifyTestElement(element2); 58 | 59 | assertEquals(element1.getProject(), element2.getProject()); 60 | assertEquals(element1.getTitle(), element2.getTitle()); 61 | assertEquals(element1.getUploadToken(), element2.getUploadToken()); 62 | assertEquals(element1.isShareTest(), element2.isShareTest()); 63 | 64 | gui.clearGui(); 65 | gui.modifyTestElement(element2); 66 | 67 | assertEquals("", element2.getTitle()); 68 | assertEquals("Default project", element2.getProject()); 69 | assertEquals(BlazeMeterUploaderGui.UPLOAD_TOKEN_PLACEHOLDER, element2.getUploadToken()); 70 | assertEquals(false, element2.isShareTest()); 71 | } 72 | } -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/ServiceDiscovery.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 4 | import org.apache.jmeter.samplers.SampleResult; 5 | import org.jivesoftware.smack.packet.IQ; 6 | import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | public class ServiceDiscovery extends AbstractXMPPAction { 12 | private static final java.lang.String ENTITY_ID = "entity_id"; 13 | private static final java.lang.String TYPE = "discovery_type"; 14 | private JTextField entityID; 15 | private JComboBox discoType; 16 | 17 | @Override 18 | public String getLabel() { 19 | return "Service Discovery (XEP-0030)"; 20 | } 21 | 22 | @Override 23 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 24 | String entID = sampler.getPropertyAsString(ENTITY_ID); 25 | res.setSamplerData("Entity ID: " + entID); 26 | ServiceDiscoveryManager discoMgr = ServiceDiscoveryManager.getInstanceFor(sampler.getXMPPConnection()); 27 | IQ info; 28 | if (Type.valueOf(sampler.getPropertyAsString(TYPE)) == Type.info) { 29 | info = discoMgr.discoverInfo(entID); 30 | } else { 31 | info = discoMgr.discoverItems(entID); 32 | } 33 | res.setResponseData(info.toXML().toString().getBytes()); 34 | return res; 35 | } 36 | 37 | @Override 38 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 39 | addToPanel(panel, labelConstraints, 0, 0, new JLabel("Entity ID: ", JLabel.RIGHT)); 40 | addToPanel(panel, editConstraints, 1, 0, entityID = new JTextField(20)); 41 | 42 | addToPanel(panel, labelConstraints, 0, 1, new JLabel("Type: ", JLabel.RIGHT)); 43 | addToPanel(panel, editConstraints, 1, 1, discoType = new JComboBox<>()); 44 | discoType.addItem(Type.items.toString()); 45 | discoType.addItem(Type.info.toString()); 46 | } 47 | 48 | @Override 49 | public void clearGui() { 50 | entityID.setText(""); 51 | discoType.setSelectedIndex(0); 52 | } 53 | 54 | @Override 55 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 56 | sampler.setProperty(ENTITY_ID, entityID.getText()); 57 | sampler.setProperty(TYPE, discoType.getSelectedItem().toString()); 58 | } 59 | 60 | @Override 61 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 62 | entityID.setText(sampler.getPropertyAsString(ENTITY_ID)); 63 | discoType.setSelectedItem(Type.valueOf(sampler.getPropertyAsString(TYPE, Type.items.toString()))); 64 | } 65 | 66 | public enum Type {info, items} 67 | } 68 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/SessionTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import com.blazemeter.api.http.BlazeMeterHttpUtilsEmul; 5 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 6 | import net.sf.json.JSONObject; 7 | import net.sf.json.JSONSerializer; 8 | import net.sf.json.JsonConfig; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class SessionTest { 13 | 14 | @org.junit.Test 15 | public void testFlow() throws Exception { 16 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 17 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 18 | 19 | JSONObject data = new JSONObject(); 20 | data.put("data", "Hello, World!"); 21 | 22 | Session session = new Session(emul, "sessionId", "sessionName", "userId", "testId", "testSignature"); 23 | 24 | emul.addEmul(JSONSerializer.toJSON("{\"result\":{\"session\":{\"statusCode\":15}}}", new JsonConfig())); 25 | session.sendData(data); 26 | assertEquals(1, emul.getRequests().size()); 27 | assertEquals("{\"data\":\"Hello, World!\"}", emul.getRequests().get(0)); 28 | emul.clean(); 29 | 30 | emul.addEmul(new JSONObject()); 31 | session.stop(); 32 | assertEquals(1, emul.getRequests().size()); 33 | assertEquals("", emul.getRequests().get(0)); 34 | emul.clean(); 35 | 36 | emul.addEmul(new JSONObject()); 37 | session.stopAnonymous(); 38 | assertEquals(1, emul.getRequests().size()); 39 | assertEquals("{\"signature\":\"testSignature\",\"testId\":\"testId\",\"sessionId\":\"sessionId\"}", emul.getRequests().get(0)); 40 | emul.clean(); 41 | } 42 | 43 | @org.junit.Test 44 | public void testFromJSON() throws Exception { 45 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 46 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 47 | JSONObject object = new JSONObject(); 48 | object.put("id", "sessionId"); 49 | object.put("name", "sessionName"); 50 | object.put("userId", "testUserId"); 51 | Session session = Session.fromJSON(emul, "testId", "testSignature", object); 52 | assertEquals("sessionId", session.getId()); 53 | assertEquals("sessionName", session.getName()); 54 | assertEquals("testId", session.getTestId()); 55 | assertEquals("testSignature", session.getSignature()); 56 | assertEquals("testUserId", session.getUserId()); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/org/loadosophia/jmeter/LoadosophiaAPIClientTest.java: -------------------------------------------------------------------------------- 1 | package org.loadosophia.jmeter; 2 | 3 | import kg.apc.jmeter.notifier.StatusNotifierCallback; 4 | import net.sf.json.JSONArray; 5 | import net.sf.json.JSONObject; 6 | import org.junit.Assert; 7 | import org.junit.Test; 8 | 9 | import java.io.File; 10 | import java.io.PrintStream; 11 | import java.util.LinkedList; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | 15 | public class LoadosophiaAPIClientTest implements StatusNotifierCallback { 16 | @Test 17 | public void testSendFiles() throws Exception { 18 | System.out.println("sendFiles"); 19 | File targetFile = File.createTempFile(".jtl", "temp"); 20 | PrintStream ps = new PrintStream(targetFile); 21 | ps.print("test"); 22 | ps.close(); 23 | LinkedList perfMonFiles = new LinkedList<>(); 24 | LoadosophiaAPIClientEmul instance = new LoadosophiaAPIClientEmul(this); 25 | 26 | JSONObject resp1 = new JSONObject(); 27 | resp1.put("QueueID", 1); 28 | instance.addEmul(resp1); 29 | 30 | JSONObject resp2 = new JSONObject(); 31 | resp2.put("status", 0); 32 | instance.addEmul(resp2); 33 | 34 | JSONObject resp3 = new JSONObject(); 35 | resp3.put("status", 4); 36 | resp3.put("TestID", 2); 37 | instance.addEmul(resp3); 38 | 39 | JSONObject resp4 = new JSONObject(); 40 | instance.addEmul(resp4); 41 | 42 | LoadosophiaUploadResults result = instance.sendFiles(targetFile, perfMonFiles); 43 | assertEquals(1, result.getQueueID()); 44 | } 45 | 46 | @Test 47 | public void testStartOnline() throws Exception { 48 | System.out.println("startOnline"); 49 | LoadosophiaAPIClientEmul instance = new LoadosophiaAPIClientEmul(this); 50 | JSONObject resp = new JSONObject(); 51 | resp.put("OnlineID", "123123"); 52 | instance.addEmul(resp); 53 | String expResult = "http://localhost/gui/active/123123/"; 54 | String result = instance.startOnline(); 55 | Assert.assertEquals(expResult, result); 56 | } 57 | 58 | @Test 59 | public void testEndOnline() throws Exception { 60 | System.out.println("endOnline"); 61 | LoadosophiaAPIClientEmul instance = new LoadosophiaAPIClientEmul(this); 62 | instance.addEmul(new JSONObject()); 63 | instance.endOnline(""); 64 | } 65 | 66 | @Test 67 | public void testSendOnlineData() throws Exception { 68 | System.out.println("sendOnlineData"); 69 | JSONArray data = new JSONArray(); 70 | LoadosophiaAPIClientEmul instance = new LoadosophiaAPIClientEmul(this); 71 | instance.addEmul(new JSONObject()); 72 | instance.sendOnlineData(data); 73 | } 74 | 75 | @Override 76 | public void notifyAbout(String info) { 77 | 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/kg/apc/jmeter/reporters/bzm/BlazemeterBackendListenerClientTest.java: -------------------------------------------------------------------------------- 1 | package kg.apc.jmeter.reporters.bzm; 2 | 3 | import com.blazemeter.api.BlazeMeterAPIClient; 4 | import com.blazemeter.api.BlazemeterAPIClientTest; 5 | import com.blazemeter.api.BlazeMeterReport; 6 | import kg.apc.jmeter.http.HttpUtils; 7 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 8 | import org.apache.jmeter.config.Arguments; 9 | import org.apache.jmeter.visualizers.backend.BackendListenerContext; 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.assertNotNull; 14 | import static org.junit.Assert.assertNull; 15 | import static org.junit.Assert.assertTrue; 16 | 17 | public class BlazemeterBackendListenerClientTest { 18 | 19 | @Test 20 | public void testGetAndSet() throws Exception { 21 | BlazeMeterBackendListenerClient client = new BlazeMeterBackendListenerClient(); 22 | 23 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl informer = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 24 | client.setInformer(informer); 25 | assertEquals(informer, client.getInformer()); 26 | HttpUtils httpUtils = new HttpUtils(informer, "http://a.blazemeter.com", "http://data.blazemeter.com"); 27 | BlazeMeterReport report = new BlazeMeterReport(); 28 | BlazeMeterAPIClient apiClient = new BlazeMeterAPIClient(httpUtils, informer, report); 29 | client.setApiClient(apiClient); 30 | assertEquals(apiClient, client.getApiClient()); 31 | 32 | BlazeMeterReport report1 = new BlazeMeterReport(); 33 | client.setReport(report1); 34 | assertEquals(report1, client.getReport()); 35 | 36 | assertNull(client.getDefaultParameters()); 37 | assertNull(client.createSampleResult(null, null)); 38 | } 39 | 40 | @Test 41 | public void testFlow() throws Exception { 42 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 43 | BlazeMeterBackendListenerClient client = new BLCEmul(); 44 | final Arguments arguments = new Arguments(); 45 | arguments.addArgument(BlazeMeterUploader.SHARE_TEST, Boolean.toString(false)); 46 | arguments.addArgument(BlazeMeterUploader.PROJECT, "project"); 47 | arguments.addArgument(BlazeMeterUploader.TITLE, "title"); 48 | client.setupTest(new BackendListenerContext(arguments)); 49 | client.setInformer(notifier); 50 | client.initiateOnline(); 51 | assertNotNull(client.getApiClient()); 52 | 53 | client.handleSampleResults(BlazemeterAPIClientTest.generateResults(), null); 54 | 55 | client.teardownTest(null); 56 | 57 | String output = notifier.getBuffer().toString(); 58 | assertTrue(output.contains("No BlazeMeter API key provided, will upload anonymously")); 59 | } 60 | } -------------------------------------------------------------------------------- /xmpp/src/test/java/com/blazemeter/jmeter/xmpp/JMeterXMPPConnectionGuiTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.apache.jmeter.util.JMeterUtils; 5 | import org.jivesoftware.smack.XMPPConnection; 6 | import org.junit.BeforeClass; 7 | import org.junit.Test; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.net.URL; 12 | import java.net.URLClassLoader; 13 | 14 | import static org.junit.Assert.assertTrue; 15 | 16 | public class JMeterXMPPConnectionGuiTest { 17 | @BeforeClass 18 | public static void setUpClass() 19 | throws Exception { 20 | TestJMeterUtils.createJmeterEnv(); 21 | } 22 | 23 | @Test 24 | public void testCreateTestElement() throws Exception { 25 | JMeterXMPPConnectionGui obj = new JMeterXMPPConnectionGui(); 26 | assertTrue(obj.createTestElement() instanceof JMeterXMPPConnection); 27 | } 28 | 29 | @Test 30 | public void testConfigure() throws Exception { 31 | JMeterXMPPConnectionGui obj = new JMeterXMPPConnectionGui(); 32 | obj.configure(obj.createTestElement()); 33 | } 34 | 35 | @Test 36 | public void testClearGui() throws Exception { 37 | JMeterXMPPConnectionGui obj = new JMeterXMPPConnectionGui(); 38 | obj.clearGui(); 39 | } 40 | 41 | @Test 42 | public void testModifyTestElement() throws Exception { 43 | JMeterXMPPConnectionGui obj = new JMeterXMPPConnectionGui(); 44 | obj.modifyTestElement(obj.createTestElement()); 45 | } 46 | 47 | //@Test 48 | public void displayGUI() throws Throwable { 49 | setSearchPaths(); 50 | 51 | if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) { 52 | JMeterXMPPConnection te = new JMeterXMPPConnection(); 53 | te.setFromMode(XMPPConnection.FromMode.OMITTED.toString()); 54 | 55 | JMeterXMPPConnectionGui gui = new JMeterXMPPConnectionGui(); 56 | gui.configure(te); 57 | JDialog dialog = new JDialog(); 58 | dialog.add(gui); 59 | 60 | dialog.setPreferredSize(new Dimension(800, 600)); 61 | dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 62 | dialog.pack(); 63 | dialog.setVisible(true); 64 | while (dialog.isVisible()) { 65 | Thread.sleep(1000); 66 | } 67 | } 68 | } 69 | 70 | private void setSearchPaths() { 71 | ClassLoader cl = ClassLoader.getSystemClassLoader(); 72 | URL[] urls = ((URLClassLoader) cl).getURLs(); 73 | String classes = "."; 74 | for (URL url : urls) { 75 | if (url.getFile().contains("bouncy") || !url.getFile().contains("jmeter")) { 76 | continue; 77 | } 78 | 79 | classes += ";" + url.getFile(); 80 | } 81 | JMeterUtils.setProperty("search_paths", classes); 82 | } 83 | 84 | 85 | } -------------------------------------------------------------------------------- /rotating-listener/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | com.blazemeter 7 | jmeter-plugins-rotating-listener 8 | 0.2 9 | 10 | Rotating JTL listener 11 | Rotating JTL listener 12 | 13 | 14 | The Apache Software License, Version 2.0 15 | http://www.apache.org/licenses/LICENSE-2.0.txt 16 | repo 17 | 18 | 19 | http://jmeter-plugins.org/ 20 | 21 | https://github.com/undera/jmeter-plugins 22 | https://github.com/undera/jmeter-plugins.git 23 | git@github.com:undera/jmeter-plugins.git 24 | 25 | 26 | 27 | team 28 | jmeter-plugins.org 29 | jmeter-plugins@googlegroups.com 30 | 31 | 32 | 33 | 34 | 35 | 36 | org.sonatype.plugins 37 | nexus-staging-maven-plugin 38 | 1.6.7 39 | true 40 | 41 | sonatype-nexus-staging 42 | https://oss.sonatype.org/ 43 | true 44 | 45 | 46 | 47 | 48 | 49 | 50 | UTF-8 51 | 1.7 52 | 1.7 53 | 54 | 55 | 56 | org.apache.jmeter 57 | ApacheJMeter_components 58 | 3.1 59 | 60 | 61 | kg.apc 62 | jmeter-plugins-emulators 63 | 0.4 64 | test 65 | 66 | 67 | kg.apc 68 | jmeter-plugins-cmn-jmeter 69 | 0.3 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /directory-listing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blazemeter 8 | jmeter-plugins-directory-listing 9 | 0.3 10 | 11 | Directory listing data source 12 | Directory listing data source 13 | 14 | 15 | The Apache Software License, Version 2.0 16 | http://www.apache.org/licenses/LICENSE-2.0.txt 17 | repo 18 | 19 | 20 | http://jmeter-plugins.org/ 21 | 22 | https://github.com/undera/jmeter-plugins 23 | https://github.com/undera/jmeter-plugins.git 24 | git@github.com:undera/jmeter-plugins.git 25 | 26 | 27 | 28 | team 29 | jmeter-plugins.org 30 | jmeter-plugins@googlegroups.com 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.sonatype.plugins 38 | nexus-staging-maven-plugin 39 | 1.6.7 40 | true 41 | 42 | sonatype-nexus-staging 43 | https://oss.sonatype.org/ 44 | true 45 | 46 | 47 | 48 | 49 | 50 | 51 | UTF-8 52 | 1.7 53 | 1.7 54 | 55 | 56 | 57 | 58 | kg.apc 59 | jmeter-plugins-cmn-jmeter 60 | 0.3 61 | 62 | 63 | org.apache.jmeter 64 | ApacheJMeter_components 65 | 3.1 66 | 67 | 68 | kg.apc 69 | jmeter-plugins-emulators 70 | 0.4 71 | test 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/Loggers.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp; 2 | 3 | import org.apache.jorphan.logging.LoggingManager; 4 | import org.apache.log.Logger; 5 | import org.jivesoftware.smack.ConnectionListener; 6 | import org.jivesoftware.smack.PacketListener; 7 | import org.jivesoftware.smack.SmackException; 8 | import org.jivesoftware.smack.XMPPConnection; 9 | import org.jivesoftware.smack.packet.Packet; 10 | 11 | public class Loggers { 12 | private static final Logger log = LoggingManager.getLoggerForClass(); 13 | 14 | public static class LogRecv implements PacketListener { 15 | private final XMPPConnection conn; 16 | 17 | public LogRecv(XMPPConnection conn) { 18 | this.conn = conn; 19 | } 20 | 21 | @Override 22 | public void processPacket(Packet packet) throws SmackException.NotConnectedException { 23 | try { 24 | log.debug("Packet recv [" + conn.getConnectionID() + "]: " + packet.toXML()); 25 | } catch (IllegalArgumentException e) { 26 | log.debug("Failed to log packet", e); 27 | log.debug("Packet recv [" + conn.getConnectionID() + "]: " + packet.getError()); 28 | } 29 | } 30 | } 31 | 32 | public static class LogSent implements PacketListener { 33 | private final XMPPConnection conn; 34 | 35 | public LogSent(XMPPConnection conn) { 36 | this.conn = conn; 37 | } 38 | 39 | @Override 40 | public void processPacket(Packet packet) throws SmackException.NotConnectedException { 41 | log.debug("Packet sent [" + conn.getConnectionID() + "]: " + packet.toXML()); 42 | } 43 | } 44 | 45 | public static class LogConn implements ConnectionListener { 46 | private final XMPPConnection conn; 47 | 48 | public LogConn(XMPPConnection conn) { 49 | this.conn = conn; 50 | } 51 | 52 | @Override 53 | public void connected(XMPPConnection connection) { 54 | log.debug("Connected: " + connection.getConnectionID()); 55 | } 56 | 57 | @Override 58 | public void authenticated(XMPPConnection connection) { 59 | log.debug("Authenticated: " + connection.getConnectionID()); 60 | } 61 | 62 | @Override 63 | public void connectionClosed() { 64 | log.debug("Connection closed: " + conn.getConnectionID()); 65 | } 66 | 67 | @Override 68 | public void connectionClosedOnError(Exception e) { 69 | log.error("Connection closed with error: " + conn.getConnectionID(), e); 70 | } 71 | 72 | @Override 73 | public void reconnectingIn(int seconds) { 74 | log.debug("Reconnecting in: " + seconds); 75 | } 76 | 77 | @Override 78 | public void reconnectionSuccessful() { 79 | log.debug("Reconnection successfull"); 80 | } 81 | 82 | @Override 83 | public void reconnectionFailed(Exception e) { 84 | log.error("Reconnection failed: ", e); 85 | 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /random-csv-data-set/src/test/java/com/blazemeter/jmeter/RandomCSVDataSetConfigGuiTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.junit.BeforeClass; 5 | import org.junit.Test; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | 13 | public class RandomCSVDataSetConfigGuiTest { 14 | 15 | @BeforeClass 16 | public static void setUpClass() 17 | throws Exception { 18 | TestJMeterUtils.createJmeterEnv(); 19 | } 20 | 21 | 22 | @Test 23 | public void showGui() throws Exception { 24 | if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) { 25 | RandomCSVDataSetConfigGui gui = new RandomCSVDataSetConfigGui(); 26 | JDialog frame = new JDialog(); 27 | frame.add(gui); 28 | 29 | frame.setPreferredSize(new Dimension(800, 600)); 30 | frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 31 | frame.pack(); 32 | frame.setVisible(true); 33 | while (frame.isVisible()) { 34 | Thread.sleep(100); 35 | } 36 | } 37 | } 38 | 39 | @Test 40 | public void testGui() throws Exception { 41 | RandomCSVDataSetConfigGui gui = new RandomCSVDataSetConfigGui(); 42 | 43 | RandomCSVDataSetConfig element1 = (RandomCSVDataSetConfig) gui.createTestElement(); 44 | RandomCSVDataSetConfig element2 = (RandomCSVDataSetConfig) gui.createTestElement(); 45 | 46 | element1.setFilename("filename"); 47 | element1.setFileEncoding("fileEncoding"); 48 | element1.setDelimiter("delimiter"); 49 | element1.setVariableNames("vars"); 50 | 51 | element1.setIgnoreFirstLine(true); 52 | element1.setRandomOrder(true); 53 | element1.setRewindOnTheEndOfList(true); 54 | element1.setIndependentListPerThread(true); 55 | 56 | gui.configure(element1); 57 | gui.modifyTestElement(element2); 58 | 59 | assertEquals(element1.getFilename(), element2.getFilename()); 60 | assertEquals(element1.getFileEncoding(), element2.getFileEncoding()); 61 | assertEquals(element1.getDelimiter(), element2.getDelimiter()); 62 | assertEquals(element1.getVariableNames(), element2.getVariableNames()); 63 | 64 | assertEquals(element1.isRandomOrder(), element2.isRandomOrder()); 65 | assertEquals(element1.isIndependentListPerThread(), element2.isIndependentListPerThread()); 66 | assertEquals(element1.isIgnoreFirstLine(), element2.isIgnoreFirstLine()); 67 | assertEquals(element1.isRewindOnTheEndOfList(), element2.isRewindOnTheEndOfList()); 68 | 69 | gui.clearGui(); 70 | gui.modifyTestElement(element2); 71 | 72 | assertEquals("", element2.getFilename()); 73 | assertEquals("UTF-8", element2.getFileEncoding()); 74 | assertEquals(",", element2.getDelimiter()); 75 | assertEquals("", element2.getVariableNames()); 76 | assertEquals(true, element2.isRandomOrder()); 77 | assertEquals(false, element2.isIgnoreFirstLine()); 78 | assertEquals(false, element2.isIndependentListPerThread()); 79 | assertEquals(true, element2.isRewindOnTheEndOfList()); 80 | } 81 | } -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/Login.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 4 | import java.awt.GridBagConstraints; 5 | import javax.swing.JComponent; 6 | import javax.swing.JLabel; 7 | import javax.swing.JTextField; 8 | import org.apache.jmeter.samplers.SampleResult; 9 | import org.apache.jorphan.logging.LoggingManager; 10 | import org.apache.log.Logger; 11 | import org.jivesoftware.smack.AbstractXMPPConnection; 12 | import org.jivesoftware.smack.XMPPConnection; 13 | 14 | public class Login extends AbstractXMPPAction { 15 | 16 | private static final Logger log = LoggingManager.getLoggerForClass(); 17 | 18 | public static final String LOGIN = "login"; 19 | public static final String PASSWORD = "password"; 20 | public static final String RESOURCE = "resource"; 21 | private JTextField login; 22 | private JTextField password; 23 | private JTextField resource; 24 | 25 | @Override 26 | public String getLabel() { 27 | return "Log In"; 28 | } 29 | 30 | @Override 31 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 32 | addToPanel(panel, labelConstraints, 0, 0, new JLabel("Username: ", JLabel.RIGHT)); 33 | addToPanel(panel, editConstraints, 1, 0, login = new JTextField(20)); 34 | 35 | addToPanel(panel, labelConstraints, 0, 1, new JLabel("Password: ", JLabel.RIGHT)); 36 | addToPanel(panel, editConstraints, 1, 1, password = new JTextField(20)); 37 | 38 | addToPanel(panel, labelConstraints, 0, 2, new JLabel("Resource: ", JLabel.RIGHT)); 39 | addToPanel(panel, editConstraints, 1, 2, resource = new JTextField(20)); 40 | } 41 | 42 | @Override 43 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 44 | XMPPConnection conn = sampler.getXMPPConnection(); 45 | String loginStr = sampler.getPropertyAsString(LOGIN); 46 | String pwdStr = sampler.getPropertyAsString(PASSWORD); 47 | String resStr = sampler.getPropertyAsString(RESOURCE); 48 | res.setSamplerData("Username: " + loginStr + "\nPassword: " + pwdStr + "\nResource: " + resStr); 49 | AbstractXMPPConnection absConn = (AbstractXMPPConnection) conn; 50 | if (loginStr.isEmpty()) { 51 | absConn.loginAnonymously(); 52 | } else { 53 | absConn.login(loginStr, pwdStr, resStr); 54 | } 55 | return res; 56 | } 57 | 58 | @Override 59 | public void clearGui() { 60 | login.setText(""); 61 | password.setText(""); 62 | resource.setText("JMeter"); 63 | } 64 | 65 | @Override 66 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 67 | sampler.setProperty(LOGIN, login.getText()); 68 | sampler.setProperty(PASSWORD, password.getText()); 69 | sampler.setProperty(RESOURCE, resource.getText()); 70 | } 71 | 72 | @Override 73 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 74 | login.setText(sampler.getPropertyAsString(LOGIN)); 75 | password.setText(sampler.getPropertyAsString(PASSWORD)); 76 | resource.setText(sampler.getPropertyAsString(RESOURCE)); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/AbstractXMPPAction.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | 4 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 5 | import org.apache.jmeter.samplers.SampleResult; 6 | import org.jivesoftware.smack.filter.AndFilter; 7 | import org.jivesoftware.smack.filter.PacketFilter; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.io.Serializable; 12 | 13 | /** 14 | * All subclasses of this class will be displayed as actions in XMPP Sampler. 15 | * You can just create JAR with such subclasses and put it into lib/ext of JMeter and they will become available. 16 | * If class will implement PacketListener, it will be added as listener to XMPPConnection. 17 | * Every JMeterXMPPConnection has its own set of available actions 18 | */ 19 | public abstract class AbstractXMPPAction implements Cloneable, Serializable { 20 | /** 21 | * @return label that will be shown in action block title, near radio button 22 | */ 23 | public abstract String getLabel(); 24 | 25 | /** 26 | * Perfrom action, fill necessary SampleResult fields 27 | * 28 | * @param sampler sampler instance 29 | * @param res sample to fill fields. Note: do not call sampleEnd, it will be called automatically 30 | * @return if SampleResult present, it will be used. If null returned, sampler will not generate sample 31 | * @throws Exception 32 | */ 33 | public abstract SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception; 34 | 35 | /** 36 | * GUI initialization method. Create and add to panel UI elements for action 37 | * 38 | * @param panel container panel, has GridBagLayout 39 | * @param labelConstraints Constraints for labels in GridBagLayout 40 | * @param editConstraints Constraints for edit controls in GridBagLayout 41 | */ 42 | public abstract void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints); 43 | 44 | /** 45 | * Helper method to add Component to panel with GridBagLayout 46 | * 47 | * @param panel container panel 48 | * @param constraints constraints to use when adding 49 | * @param col column number 50 | * @param row row number 51 | * @param component component to add 52 | */ 53 | protected void addToPanel(JComponent panel, GridBagConstraints constraints, int col, int row, JComponent component) { 54 | constraints.gridx = col; 55 | constraints.gridy = row; 56 | panel.add(component, constraints); 57 | } 58 | 59 | /** 60 | * Resets controls to default state (empty fields) 61 | */ 62 | public abstract void clearGui(); 63 | 64 | /** 65 | * Record data from UI controls into Sampler. You must use Sampler.setPropery* methods to record it. 66 | * 67 | * @param sampler Sampler instance 68 | */ 69 | public abstract void setSamplerProperties(JMeterXMPPSampler sampler); 70 | 71 | /** 72 | * Fill UI controls from Sampler properties 73 | * 74 | * @param sampler Sampler instance 75 | */ 76 | public abstract void setGuiFieldsFromSampler(JMeterXMPPSampler sampler); 77 | 78 | public PacketFilter getPacketFilter() { 79 | return new AndFilter(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /directory-listing/src/test/java/com/blazemeter/jmeter/DirectoryListingConfigGuiTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import kg.apc.emulators.TestJMeterUtils; 4 | import org.junit.BeforeClass; 5 | import org.junit.Test; 6 | 7 | import javax.swing.*; 8 | import java.awt.*; 9 | 10 | import static org.junit.Assert.assertEquals; 11 | 12 | public class DirectoryListingConfigGuiTest { 13 | 14 | @BeforeClass 15 | public static void setUpClass() 16 | throws Exception { 17 | TestJMeterUtils.createJmeterEnv(); 18 | } 19 | 20 | // @Test 21 | public void showGui() throws Exception { 22 | if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) { 23 | DirectoryListingConfigGui gui = new DirectoryListingConfigGui(); 24 | JDialog frame = new JDialog(); 25 | frame.add(gui); 26 | 27 | frame.setPreferredSize(new Dimension(800, 600)); 28 | frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); 29 | frame.pack(); 30 | frame.setVisible(true); 31 | while (frame.isVisible()) { 32 | Thread.sleep(100); 33 | } 34 | } 35 | } 36 | 37 | @Test 38 | public void testGui() throws Exception { 39 | DirectoryListingConfigGui gui = new DirectoryListingConfigGui(); 40 | 41 | DirectoryListingConfig element1 = (DirectoryListingConfig) gui.createTestElement(); 42 | DirectoryListingConfig element2 = (DirectoryListingConfig) gui.createTestElement(); 43 | 44 | element1.setSourceDirectory("/tmp/csv/"); 45 | element1.setDestinationVariableName("fname"); 46 | element1.setUseFullPath(true); 47 | element1.setRandomOrder(true); 48 | element1.setRecursiveListing(true); 49 | element1.setRewindOnTheEnd(true); 50 | element1.setIndependentListPerThread(true); 51 | element1.setReReadDirectoryOnTheEndOfList(true); 52 | 53 | gui.configure(element1); 54 | gui.modifyTestElement(element2); 55 | 56 | assertEquals(element1.getSourceDirectory(), element2.getSourceDirectory()); 57 | assertEquals(element1.getDestinationVariableName(), element2.getDestinationVariableName()); 58 | assertEquals(element1.getUseFullPath(), element2.getUseFullPath()); 59 | assertEquals(element1.getRandomOrder(), element2.getRandomOrder()); 60 | assertEquals(element1.getRecursiveListing(), element2.getRecursiveListing()); 61 | assertEquals(element1.getRewindOnTheEnd(), element2.getRewindOnTheEnd()); 62 | assertEquals(element1.getIndependentListPerThread(), element2.getIndependentListPerThread()); 63 | assertEquals(element1.getReReadDirectoryOnTheEndOfList(), element2.getReReadDirectoryOnTheEndOfList()); 64 | 65 | gui.clearGui(); 66 | gui.modifyTestElement(element2); 67 | 68 | assertEquals("", element2.getSourceDirectory()); 69 | assertEquals("", element2.getDestinationVariableName()); 70 | assertEquals(false, element2.getUseFullPath()); 71 | assertEquals(false, element2.getRandomOrder()); 72 | assertEquals(false, element2.getRecursiveListing()); 73 | assertEquals(true, element2.getRewindOnTheEnd()); 74 | assertEquals(false, element2.getIndependentListPerThread()); 75 | assertEquals(false, element2.getReReadDirectoryOnTheEndOfList()); 76 | } 77 | } -------------------------------------------------------------------------------- /directory-listing/src/main/java/com/blazemeter/jmeter/TestDirectoryListingAction.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import org.apache.jmeter.engine.util.CompoundVariable; 4 | import org.apache.jmeter.functions.InvalidVariableException; 5 | import org.apache.jmeter.threads.JMeterContextService; 6 | import org.apache.jmeter.threads.JMeterVariables; 7 | import org.apache.jorphan.util.JMeterStopThreadException; 8 | 9 | import javax.swing.*; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | import java.io.File; 13 | import java.io.FileNotFoundException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | public class TestDirectoryListingAction implements ActionListener { 18 | 19 | private final DirectoryListingConfigGui directoryListingConfigGui; 20 | 21 | public TestDirectoryListingAction(DirectoryListingConfigGui fileListingGui) { 22 | this.directoryListingConfigGui = fileListingGui; 23 | } 24 | 25 | @Override 26 | public void actionPerformed(ActionEvent event) { 27 | final DirectoryListingConfig config = (DirectoryListingConfig) directoryListingConfigGui.createTestElement(); 28 | 29 | config.setRewindOnTheEnd(false); 30 | config.setIndependentListPerThread(false); 31 | 32 | JTextArea checkArea = directoryListingConfigGui.getCheckArea(); 33 | 34 | try { 35 | final CompoundVariable compVarSrcDir = new CompoundVariable(); 36 | compVarSrcDir.setParameters(config.getSourceDirectory()); 37 | config.setSourceDirectory(compVarSrcDir.execute()); 38 | 39 | final CompoundVariable compVarDestVar = new CompoundVariable(); 40 | compVarDestVar.setParameters(config.getDestinationVariableName()); 41 | config.setDestinationVariableName(compVarDestVar.execute()); 42 | 43 | String variableName = DirectoryListingConfig.getStringOrDefault( 44 | config.getDestinationVariableName(), 45 | DirectoryListingConfig.DEFAULT_DESTINATION_VARIABLE_NAME 46 | ); 47 | 48 | JMeterVariables variables = new JMeterVariables(); 49 | JMeterContextService.getContext().setVariables(variables); 50 | 51 | final List filePaths = new ArrayList<>(); 52 | 53 | config.testStarted(); 54 | 55 | try { 56 | while (true) { 57 | config.iterationStart(null); 58 | filePaths.add(variables.get(variableName)); 59 | } 60 | } catch (JMeterStopThreadException ex) { 61 | // OK 62 | } 63 | 64 | config.testEnded(); 65 | 66 | final StringBuilder builder = new StringBuilder(); 67 | 68 | builder.append("Listing of directory successfully finished, ").append(filePaths.size()).append(" files found:\r\n"); 69 | for (String filePath : filePaths) { 70 | builder.append("${").append(variableName).append("} = "); 71 | builder.append(filePath); 72 | builder.append("\r\n"); 73 | } 74 | 75 | checkArea.setText(builder.toString()); 76 | // move scroll to top 77 | checkArea.setCaretPosition(0); 78 | } catch (RuntimeException | InvalidVariableException e) { 79 | checkArea.setText(e.getMessage()); 80 | } 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /websocket/src/main/java/blazemeter/jmeter/plugins/websocket/sampler/gui/WebSocketSendSamplerGui.java: -------------------------------------------------------------------------------- 1 | 2 | package blazemeter.jmeter.plugins.websocket.sampler.gui; 3 | 4 | import java.awt.BorderLayout; 5 | import org.apache.jmeter.config.Arguments; 6 | import org.apache.jmeter.config.gui.ArgumentsPanel; 7 | import org.apache.jmeter.samplers.gui.AbstractSamplerGui; 8 | import org.apache.jmeter.testelement.TestElement; 9 | import org.apache.jorphan.logging.LoggingManager; 10 | import org.apache.log.Logger; 11 | 12 | import blazemeter.jmeter.plugins.websocket.sampler.WebSocketSendSampler; 13 | 14 | 15 | public class WebSocketSendSamplerGui extends AbstractSamplerGui { 16 | 17 | private WebSocketSendSamplerPanel webSocketSendSamplerPanel; 18 | 19 | public WebSocketSendSamplerGui() { 20 | super(); 21 | init(); 22 | initFields(); 23 | 24 | setLayout(new BorderLayout(0, 5)); 25 | setBorder(makeBorder()); 26 | 27 | add(makeTitlePanel(), BorderLayout.NORTH); 28 | add(webSocketSendSamplerPanel, BorderLayout.CENTER); 29 | } 30 | 31 | @Override 32 | public String getStaticLabel() { 33 | return "WebSocket Send Sampler"; 34 | } 35 | 36 | @Override 37 | public String getLabelResource() { 38 | throw new IllegalStateException("This shouldn't be called"); //$NON-NLS-1$ 39 | } 40 | 41 | @Override 42 | public void configure(TestElement element) { 43 | super.configure(element); 44 | if (element instanceof WebSocketSendSampler) { 45 | WebSocketSendSampler WebSocketSendSamplerTestElement = (WebSocketSendSampler) element; 46 | webSocketSendSamplerPanel.setPayloadContent(WebSocketSendSamplerTestElement.getPayloadContent()); 47 | webSocketSendSamplerPanel.setWaitUntilResponse(WebSocketSendSamplerTestElement.getWaitUntilResponse()); 48 | webSocketSendSamplerPanel.setResponsePattern(WebSocketSendSamplerTestElement.getResponsePattern()); 49 | webSocketSendSamplerPanel.setResponseTimeout(WebSocketSendSamplerTestElement.getResponseTimeout()); 50 | } 51 | } 52 | 53 | @Override 54 | public TestElement createTestElement() { 55 | WebSocketSendSampler preproc = new WebSocketSendSampler(); 56 | configureTestElement(preproc); 57 | return preproc; 58 | } 59 | 60 | @Override 61 | public void modifyTestElement(TestElement te) { 62 | configureTestElement(te); 63 | if (te instanceof WebSocketSendSampler) { 64 | WebSocketSendSampler WebSocketSendSamplerTestElement = (WebSocketSendSampler) te; 65 | WebSocketSendSamplerTestElement.setPayloadContent(webSocketSendSamplerPanel.getPayloadContent()); 66 | WebSocketSendSamplerTestElement.setWaitUntilResponse(webSocketSendSamplerPanel.getWaitUntilResponse()); 67 | WebSocketSendSamplerTestElement.setResponsePattern(webSocketSendSamplerPanel.getResponsePattern()); 68 | WebSocketSendSamplerTestElement.setResponseTimeout(webSocketSendSamplerPanel.getResponseTimeout()); 69 | } 70 | } 71 | 72 | @Override 73 | public void clearGui() { 74 | super.clearGui(); 75 | initFields(); 76 | } 77 | 78 | private void init() { 79 | webSocketSendSamplerPanel = new WebSocketSendSamplerPanel(); 80 | } 81 | 82 | private void initFields() { 83 | webSocketSendSamplerPanel.initFields(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /wsc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blazemeter 8 | jmeter-plugins-wsc 9 | 0.7 10 | 11 | Weighted Switch Controller 12 | Weighted switch controller plugin 13 | 14 | 15 | The Apache Software License, Version 2.0 16 | http://www.apache.org/licenses/LICENSE-2.0.txt 17 | repo 18 | 19 | 20 | http://jmeter-plugins.org/ 21 | 22 | https://github.com/undera/jmeter-plugins 23 | https://github.com/undera/jmeter-plugins.git 24 | git@github.com:undera/jmeter-plugins.git 25 | 26 | 27 | 28 | team 29 | jmeter-plugins.org 30 | jmeter-plugins@googlegroups.com 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.sonatype.plugins 38 | nexus-staging-maven-plugin 39 | 1.6.7 40 | true 41 | 42 | sonatype-nexus-staging 43 | https://oss.sonatype.org/ 44 | true 45 | 46 | 47 | 48 | 49 | 50 | 51 | UTF-8 52 | 1.7 53 | 1.7 54 | 55 | 56 | 57 | 58 | kg.apc 59 | jmeter-plugins-cmn-jmeter 60 | 0.5 61 | 62 | 63 | org.apache.jmeter 64 | ApacheJMeter_components 65 | 2.13 66 | test 67 | 68 | 69 | commons-math3 70 | commons-math3 71 | 72 | 73 | commons-pool2 74 | commons-pool2 75 | 76 | 77 | 78 | 79 | kg.apc 80 | jmeter-plugins-emulators 81 | 0.4 82 | test 83 | 84 | 85 | -------------------------------------------------------------------------------- /websocket/src/main/java/blazemeter/jmeter/plugins/websocket/sampler/gui/WebSocketCollectorSamplerGui.java: -------------------------------------------------------------------------------- 1 | 2 | package blazemeter.jmeter.plugins.websocket.sampler.gui; 3 | 4 | import java.awt.BorderLayout; 5 | 6 | import org.apache.jmeter.samplers.gui.AbstractSamplerGui; 7 | import org.apache.jmeter.testelement.TestElement; 8 | 9 | import blazemeter.jmeter.plugins.websocket.sampler.WebSocketCollectorSampler; 10 | 11 | 12 | 13 | 14 | public class WebSocketCollectorSamplerGui extends AbstractSamplerGui { 15 | 16 | /** 17 | * 18 | */ 19 | private static final long serialVersionUID = -5507578136184456991L; 20 | private WebSocketCollectorSamplerPanel WebSocketCollectorSamplerPanel; 21 | 22 | public WebSocketCollectorSamplerGui() { 23 | super(); 24 | init(); 25 | initFields(); 26 | 27 | setLayout(new BorderLayout(0, 5)); 28 | setBorder(makeBorder()); 29 | 30 | add(makeTitlePanel(), BorderLayout.NORTH); 31 | add(WebSocketCollectorSamplerPanel, BorderLayout.CENTER); 32 | } 33 | 34 | @Override 35 | public String getStaticLabel() { 36 | return "WebSocket Collector Sampler"; 37 | } 38 | 39 | @Override 40 | public String getLabelResource() { 41 | throw new IllegalStateException("This shouldn't be called"); //$NON-NLS-1$ 42 | } 43 | 44 | @Override 45 | public void configure(TestElement element) { 46 | super.configure(element); 47 | if (element instanceof WebSocketCollectorSampler) { 48 | WebSocketCollectorSampler WebSocketCollectorSamplerTestElement = (WebSocketCollectorSampler) element; 49 | WebSocketCollectorSamplerPanel.setWaitUntilMessage(WebSocketCollectorSamplerTestElement.getWaitUntilMessage()); 50 | WebSocketCollectorSamplerPanel.setCloseConnection(WebSocketCollectorSamplerTestElement.getCloseConnection()); 51 | WebSocketCollectorSamplerPanel.setResponsePattern(WebSocketCollectorSamplerTestElement.getResponsePattern()); 52 | WebSocketCollectorSamplerPanel.setResponseTimeout(WebSocketCollectorSamplerTestElement.getResponseTimeout()); 53 | } 54 | } 55 | 56 | @Override 57 | public TestElement createTestElement() { 58 | WebSocketCollectorSampler preproc = new WebSocketCollectorSampler(); 59 | configureTestElement(preproc); 60 | return preproc; 61 | } 62 | 63 | @Override 64 | public void modifyTestElement(TestElement te) { 65 | configureTestElement(te); 66 | if (te instanceof WebSocketCollectorSampler) { 67 | WebSocketCollectorSampler WebSocketCollectorSamplerTestElement = (WebSocketCollectorSampler) te; 68 | WebSocketCollectorSamplerTestElement.setWaitUntilMessage(WebSocketCollectorSamplerPanel.getWaitUntilResponse()); 69 | WebSocketCollectorSamplerTestElement.setCloseConnection(WebSocketCollectorSamplerPanel.getCloseConnection()); 70 | WebSocketCollectorSamplerTestElement.setResponsePattern(WebSocketCollectorSamplerPanel.getResponsePattern()); 71 | WebSocketCollectorSamplerTestElement.setResponseTimeout(WebSocketCollectorSamplerPanel.getResponseTimeout()); 72 | } 73 | } 74 | 75 | @Override 76 | public void clearGui() { 77 | super.clearGui(); 78 | initFields(); 79 | } 80 | 81 | private void init() { 82 | WebSocketCollectorSamplerPanel = new WebSocketCollectorSamplerPanel(); 83 | } 84 | 85 | private void initFields() { 86 | WebSocketCollectorSamplerPanel.initFields(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */target/ 2 | */.idea/ 3 | /.idea/ 4 | *.iml 5 | 6 | 7 | # Compiled class file 8 | *.class 9 | 10 | # Log file 11 | *.log 12 | 13 | # BlueJ files 14 | *.ctxt 15 | 16 | # Mobile Tools for Java (J2ME) 17 | .mtj.tmp/ 18 | 19 | # Package Files # 20 | *.jar 21 | *.war 22 | *.ear 23 | *.zip 24 | *.tar.gz 25 | *.rar 26 | 27 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 28 | hs_err_pid* 29 | /http2/datawriter 30 | 31 | ### Eclipse ### 32 | 33 | .metadata 34 | bin/ 35 | tmp/ 36 | *.tmp 37 | *.bak 38 | *.swp 39 | *~.nib 40 | local.properties 41 | .settings/ 42 | .loadpath 43 | .recommenders 44 | 45 | # External tool builders 46 | .externalToolBuilders/ 47 | 48 | # Locally stored "Eclipse launch configurations" 49 | *.launch 50 | 51 | # PyDev specific (Python IDE for Eclipse) 52 | *.pydevproject 53 | 54 | # CDT-specific (C/C++ Development Tooling) 55 | .cproject 56 | 57 | # Java annotation processor (APT) 58 | .factorypath 59 | 60 | # PDT-specific (PHP Development Tools) 61 | .buildpath 62 | 63 | # sbteclipse plugin 64 | .target 65 | 66 | # Tern plugin 67 | .tern-project 68 | 69 | # TeXlipse plugin 70 | .texlipse 71 | 72 | # STS (Spring Tool Suite) 73 | .springBeans 74 | 75 | # Code Recommenders 76 | .recommenders/ 77 | 78 | # Scala IDE specific (Scala & Java development for Eclipse) 79 | .cache-main 80 | .scala_dependencies 81 | .worksheet 82 | 83 | ### Eclipse Patch ### 84 | # Eclipse Core 85 | .project 86 | 87 | # JDT-specific (Eclipse Java Development Tools) 88 | .classpath 89 | 90 | ### Intellij ### 91 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 92 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 93 | 94 | # User-specific stuff: 95 | .idea/**/workspace.xml 96 | .idea/**/tasks.xml 97 | .idea/dictionaries 98 | 99 | # Sensitive or high-churn files: 100 | .idea/**/dataSources/ 101 | .idea/**/dataSources.ids 102 | .idea/**/dataSources.xml 103 | .idea/**/dataSources.local.xml 104 | .idea/**/sqlDataSources.xml 105 | .idea/**/dynamic.xml 106 | .idea/**/uiDesigner.xml 107 | 108 | # Gradle: 109 | .idea/**/gradle.xml 110 | .idea/**/libraries 111 | 112 | # CMake 113 | cmake-build-debug/ 114 | 115 | # Mongo Explorer plugin: 116 | .idea/**/mongoSettings.xml 117 | 118 | ## File-based project format: 119 | *.iws 120 | 121 | ## Plugin-specific files: 122 | 123 | # IntelliJ 124 | /out/ 125 | 126 | # mpeltonen/sbt-idea plugin 127 | .idea_modules/ 128 | 129 | # JIRA plugin 130 | atlassian-ide-plugin.xml 131 | 132 | # Cursive Clojure plugin 133 | .idea/replstate.xml 134 | 135 | # Ruby plugin and RubyMine 136 | /.rakeTasks 137 | 138 | # Crashlytics plugin (for Android Studio and IntelliJ) 139 | com_crashlytics_export_strings.xml 140 | crashlytics.properties 141 | crashlytics-build.properties 142 | fabric.properties 143 | 144 | ### Intellij Patch ### 145 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 146 | 147 | # *.iml 148 | # modules.xml 149 | # .idea/misc.xml 150 | # *.ipr 151 | 152 | # Sonarlint plugin 153 | .idea/sonarlint 154 | 155 | ### Maven ### 156 | target/ 157 | pom.xml.tag 158 | pom.xml.releaseBackup 159 | pom.xml.versionsBackup 160 | pom.xml.next 161 | release.properties 162 | dependency-reduced-pom.xml 163 | buildNumber.properties 164 | .mvn/timing.properties 165 | 166 | # Avoid ignoring Maven wrapper jar file (.jar files are usually ignored) 167 | !/.mvn/wrapper/maven-wrapper.jar 168 | -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/RosterAction.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 4 | import org.apache.jmeter.samplers.SampleResult; 5 | import org.jivesoftware.smack.Roster; 6 | import org.jivesoftware.smack.RosterEntry; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | public class RosterAction extends AbstractXMPPAction { 12 | private static final java.lang.String ENTRY = "roster_entry"; 13 | private static final java.lang.String ACTION = "roster_action"; 14 | private JComboBox rosterAction; 15 | private JTextField rosterItem; 16 | 17 | @Override 18 | public String getLabel() { 19 | return "Roster Actions"; 20 | } 21 | 22 | @Override 23 | public void addUI(JComponent mainPanel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 24 | addToPanel(mainPanel, labelConstraints, 0, 0, new JLabel("Type: ", JLabel.RIGHT)); 25 | addToPanel(mainPanel, editConstraints, 1, 0, rosterAction = new JComboBox<>()); 26 | rosterAction.addItem(Action.get_roster); 27 | rosterAction.addItem(Action.add_item); 28 | rosterAction.addItem(Action.delete_item); 29 | 30 | addToPanel(mainPanel, labelConstraints, 0, 1, new JLabel("JID: ", JLabel.RIGHT)); 31 | addToPanel(mainPanel, editConstraints, 1, 1, rosterItem = new JTextField(20)); 32 | } 33 | 34 | @Override 35 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 36 | Action action = Action.valueOf(sampler.getPropertyAsString(ACTION, Action.get_roster.toString())); 37 | Roster roster = sampler.getXMPPConnection().getRoster(); 38 | String entry = sampler.getPropertyAsString(ENTRY); 39 | res.setSamplerData(action.toString() + ": " + entry); 40 | if (action == Action.get_roster) { 41 | res.setResponseData(rosterToString(roster).getBytes()); 42 | } else if (action == Action.add_item) { 43 | roster.createEntry(entry, entry, new String[0]); 44 | } else if (action == Action.delete_item) { 45 | RosterEntry rosterEntry = roster.getEntry(entry); 46 | if (rosterEntry != null) { 47 | roster.removeEntry(rosterEntry); 48 | } 49 | } 50 | 51 | return res; 52 | } 53 | 54 | @Override 55 | public void clearGui() { 56 | rosterAction.setSelectedIndex(0); 57 | rosterItem.setText(""); 58 | } 59 | 60 | @Override 61 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 62 | sampler.setProperty(ACTION, rosterAction.getSelectedItem().toString()); 63 | sampler.setProperty(ENTRY, rosterItem.getText()); 64 | } 65 | 66 | @Override 67 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 68 | rosterItem.setText(sampler.getPropertyAsString(ENTRY)); 69 | rosterAction.setSelectedItem(Action.valueOf(sampler.getPropertyAsString(ACTION, Action.get_roster.toString()))); 70 | } 71 | 72 | private String rosterToString(Roster roster) { 73 | StringBuilder res = new StringBuilder(); 74 | for (RosterEntry entry : roster.getEntries()) { 75 | res.append(entry.toString()); 76 | res.append(':'); 77 | res.append(roster.getPresence(entry.getUser()).toString()); 78 | res.append('\n'); 79 | } 80 | return res.toString(); 81 | } 82 | 83 | public enum Action { 84 | get_roster, add_item, delete_item 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /websocket/src/test/java/blazemeter/jmeter/plugins/websocket/test/MqttCallBackImplTest.java: -------------------------------------------------------------------------------- 1 | package blazemeter.jmeter.plugins.websocket.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.net.URL; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | import java.util.regex.Pattern; 11 | 12 | import org.apache.jmeter.samplers.SampleResult; 13 | import org.eclipse.paho.client.mqttv3.IMqttAsyncClient; 14 | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; 15 | import org.eclipse.paho.client.mqttv3.MqttMessage; 16 | import org.junit.Assert; 17 | import org.junit.BeforeClass; 18 | import org.junit.Test; 19 | import org.mockito.Mockito; 20 | 21 | import blazemeter.jmeter.plugins.websocket.sampler.Handler; 22 | import blazemeter.jmeter.plugins.websocket.sampler.MqttCallBackImpl; 23 | 24 | 25 | public class MqttCallBackImplTest { 26 | 27 | private static IMqttAsyncClient clientMock; 28 | private static MqttMessage messageMock; 29 | private static IMqttDeliveryToken tokenMock; 30 | private static Throwable causeMock; 31 | 32 | @BeforeClass 33 | public static void setUpClass() 34 | throws Exception { 35 | clientMock = Mockito.mock(IMqttAsyncClient.class); 36 | messageMock = Mockito.mock(MqttMessage.class); 37 | tokenMock = Mockito.mock(IMqttDeliveryToken.class); 38 | causeMock = Mockito.mock(Throwable.class); 39 | } 40 | 41 | @Test 42 | public void test1() throws Exception{ 43 | 44 | 45 | 46 | MqttCallBackImpl mqtt = new MqttCallBackImpl (clientMock, "clientID", "info" , "utf-8"); 47 | 48 | Mockito.when(messageMock.toString()).thenReturn("message2"); 49 | Mockito.when(tokenMock.toString()).thenReturn("token"); 50 | Mockito.when(causeMock.toString()).thenReturn("cause"); 51 | Mockito.when(clientMock.isConnected()).thenReturn(true); 52 | 53 | mqtt.addMessage("message1"); 54 | mqtt.messageArrived("topic1", messageMock); 55 | mqtt.deliveryComplete(tokenMock); 56 | mqtt.close(); 57 | mqtt.connectionLost(causeMock); 58 | 59 | 60 | String messages = mqtt.getMessages(); 61 | String expectedMessage = "message1\\n" 62 | + "\\[RECIVED at (\\d+?)\\] -- clientID -- TOPIC: topic1 NEW MESSAGE ARRIVED: message2\\n" 63 | + "CLIENT DISCONNECTION\\n" 64 | + "CLIENT CLOSING\\n" 65 | + "-- clientID-- CONNECTION LOST: cause\\n"; 66 | 67 | 68 | Assert.assertTrue(Pattern.matches(expectedMessage,messages)); 69 | } 70 | 71 | @Test 72 | public void test2() throws Exception{ 73 | 74 | MqttCallBackImpl mqtt = new MqttCallBackImpl (clientMock, "clientID", "debug" , "utf-8"); 75 | 76 | Mockito.when(messageMock.toString()).thenReturn("message2"); 77 | Mockito.when(tokenMock.toString()).thenReturn("token"); 78 | Mockito.when(causeMock.toString()).thenReturn("cause"); 79 | Mockito.when(clientMock.isConnected()).thenReturn(true); 80 | 81 | mqtt.addMessage("message1"); 82 | mqtt.messageArrived("topic1", messageMock); 83 | mqtt.deliveryComplete(tokenMock); 84 | mqtt.close(); 85 | 86 | 87 | String messages = mqtt.getMessages(); 88 | String expectedMessage = "message1\\n" 89 | + "\\[RECIVED at (\\d+?)\\] -- clientID -- TOPIC: topic1 NEW MESSAGE ARRIVED: message2\\n" 90 | + "CLIENT DISCONNECTION\\n" 91 | + "CLIENT CLOSING\\n"; 92 | 93 | 94 | System.out.println(expectedMessage); 95 | System.out.println(messages); 96 | 97 | Assert.assertTrue(Pattern.matches(expectedMessage,messages)); 98 | 99 | 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /directory-listing/src/main/java/com/blazemeter/jmeter/DirectoryListingIterator.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | 4 | import java.io.File; 5 | import java.io.FileNotFoundException; 6 | import java.util.*; 7 | 8 | public class DirectoryListingIterator implements Iterator{ 9 | 10 | private final String srcDir; 11 | private final boolean isRandomOrder; 12 | private final boolean isRecursiveListing; 13 | private final boolean isRewindOnEndOfList; 14 | private final boolean isReReadDirectory; 15 | 16 | 17 | public DirectoryListingIterator(String srcDir, 18 | boolean isRandomOrder, 19 | boolean isRecursiveListing, 20 | boolean isRewindOnEndOfList, 21 | boolean isReReadDirectory) { 22 | this.srcDir = srcDir; 23 | this.isRandomOrder = isRandomOrder; 24 | this.isRecursiveListing = isRecursiveListing; 25 | this.isRewindOnEndOfList = isRewindOnEndOfList; 26 | this.isReReadDirectory = isReReadDirectory; 27 | 28 | this.list = getDirectoryListing(); 29 | if (isRandomOrder) { 30 | shuffleList(list); 31 | } 32 | this.iterator = this.list.iterator(); 33 | } 34 | 35 | private Iterator iterator; 36 | private List list; 37 | 38 | synchronized public boolean hasNext() { 39 | if (!iterator.hasNext()) { 40 | if (isRewindOnEndOfList) { 41 | if (isReReadDirectory) { 42 | list = getDirectoryListing(); 43 | } 44 | 45 | if (isRandomOrder) { 46 | shuffleList(list); 47 | } 48 | 49 | iterator = list.iterator(); 50 | } 51 | } 52 | return iterator.hasNext(); 53 | } 54 | 55 | synchronized public File next() { 56 | return iterator.next(); 57 | } 58 | 59 | @Override 60 | public void remove() { 61 | throw new UnsupportedOperationException("Removing is not supported for this iterator"); 62 | } 63 | 64 | protected List getDirectoryListing() { 65 | try { 66 | return getDirectoryListing(new File(srcDir), isRecursiveListing); 67 | } catch (FileNotFoundException ex) { 68 | throw new RuntimeException(ex); 69 | } 70 | } 71 | 72 | public static void shuffleList(List list) { 73 | Collections.shuffle(list, new Random(System.currentTimeMillis())); 74 | } 75 | 76 | public static List getDirectoryListing(File baseDir, boolean isRecursiveListing) throws FileNotFoundException { 77 | final List resultList = new ArrayList<>(); 78 | 79 | if (!baseDir.exists()) { 80 | throw new FileNotFoundException("Directory does not exists: " + baseDir.getAbsolutePath()); 81 | } 82 | 83 | File[] files = baseDir.listFiles(); 84 | 85 | if (files == null) { 86 | return resultList; 87 | } 88 | 89 | 90 | for (File file : files) { 91 | boolean isDirectory = file.isDirectory(); 92 | if (isRecursiveListing && isDirectory) { 93 | List nestedListing = getDirectoryListing(file, true); 94 | if (!nestedListing.isEmpty()) { 95 | resultList.addAll(nestedListing); 96 | } 97 | } else if (!isDirectory) { 98 | resultList.add(file); 99 | } 100 | } 101 | 102 | return resultList; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/JMeterXMPPSampler.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp; 2 | 3 | import com.blazemeter.jmeter.xmpp.actions.AbstractXMPPAction; 4 | import com.blazemeter.jmeter.xmpp.actions.Connect; 5 | import org.apache.commons.lang3.exception.ExceptionUtils; 6 | import org.apache.jmeter.samplers.AbstractSampler; 7 | import org.apache.jmeter.samplers.Entry; 8 | import org.apache.jmeter.samplers.SampleResult; 9 | import org.apache.jmeter.testelement.TestElement; 10 | import org.apache.jorphan.logging.LoggingManager; 11 | import org.apache.log.Logger; 12 | import org.jivesoftware.smack.SmackException; 13 | import org.jivesoftware.smack.XMPPConnection; 14 | 15 | import java.security.KeyManagementException; 16 | import java.security.NoSuchAlgorithmException; 17 | 18 | public class JMeterXMPPSampler extends AbstractSampler { 19 | private static final Logger log = LoggingManager.getLoggerForClass(); 20 | private static final String ACTION = "action"; 21 | protected JMeterXMPPConnection connConfig; 22 | 23 | @Override 24 | public SampleResult sample(Entry entry) { 25 | SampleResult res = new SampleResult(); 26 | res.setSampleLabel(getName()); 27 | res.setDataType(SampleResult.TEXT); 28 | res.setSuccessful(true); 29 | res.setResponseCode("200"); 30 | res.setResponseMessage("OK"); 31 | 32 | res.sampleStart(); 33 | try { 34 | if (connConfig == null) { 35 | throw new RuntimeException("Cannot sample XMPP without XMPP Connection component"); 36 | } 37 | 38 | XMPPConnection conn = getXMPPConnection(); 39 | 40 | if (conn == null) { 41 | throw new RuntimeException("No XMPP Connection available"); 42 | } 43 | 44 | String headers = "Connection ID: " + conn.getConnectionID() + "\r\n"; 45 | 46 | String action = getAction(); 47 | if (!conn.isConnected() && !action.equals(Connect.class.getCanonicalName())) { 48 | log.error("Please call Connect before calling other actions"); 49 | throw new SmackException.NotConnectedException(); 50 | } 51 | 52 | headers += "User: " + conn.getUser() + "\r\n"; 53 | 54 | res.setRequestHeaders(headers); 55 | 56 | AbstractXMPPAction actObject = connConfig.getActions().get(action); 57 | if (actObject.perform(this, res) == null) { 58 | return null; 59 | } 60 | } catch (Exception e) { 61 | log.error("Error in XMPP Sampler: ", e); 62 | res.setSuccessful(false); 63 | res.setResponseCode("500"); 64 | res.setResponseMessage((e.getMessage() == null || e.getMessage().isEmpty()) ? e.toString() : e.getMessage()); 65 | res.setResponseData(ExceptionUtils.getStackTrace(e).getBytes()); 66 | } 67 | 68 | res.sampleEnd(); 69 | return res; 70 | } 71 | 72 | public String getAction() { 73 | return getPropertyAsString(ACTION); 74 | } 75 | 76 | public void setAction(String value) { 77 | setProperty(ACTION, value); 78 | } 79 | 80 | public XMPPConnection getXMPPConnection() throws KeyManagementException, NoSuchAlgorithmException, SmackException, InterruptedException { 81 | return connConfig.getConnection(); 82 | } 83 | 84 | @Override 85 | public void addTestElement(TestElement el) { 86 | super.addTestElement(el); 87 | 88 | if (el instanceof JMeterXMPPConnection) { 89 | this.connConfig = (JMeterXMPPConnection) el; 90 | } 91 | } 92 | 93 | public JMeterXMPPConnection getXMPPConnectionConfig() { 94 | return connConfig; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/data/JSONConverterTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.data; 2 | 3 | import net.sf.json.JSONArray; 4 | import net.sf.json.JSONObject; 5 | import org.apache.jmeter.assertions.AssertionResult; 6 | import org.apache.jmeter.samplers.SampleResult; 7 | import org.junit.Test; 8 | 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.fail; 14 | 15 | public class JSONConverterTest { 16 | 17 | 18 | @Test 19 | public void testConvert() throws Exception { 20 | List list = new LinkedList<>(); 21 | list.add(new SampleResult(System.currentTimeMillis(), 1)); 22 | list.add(new SampleResult(System.currentTimeMillis() + 1000, 1)); 23 | list.add(new SampleResult(System.currentTimeMillis() + 2000, 1)); 24 | list.add(new SampleResult(System.currentTimeMillis() + 3000, 1)); 25 | 26 | SampleResult res = new SampleResult(System.currentTimeMillis() + 3000, 3); 27 | res.setSuccessful(true); 28 | res.setSampleLabel("L2"); 29 | list.add(res); 30 | 31 | res = new SampleResult(System.currentTimeMillis() + 3000, 3); 32 | res.setSuccessful(true); 33 | res.setSampleLabel("L2"); 34 | list.add(res); 35 | 36 | res = new SampleResult(System.currentTimeMillis() + 5000, 2); 37 | res.setSuccessful(false); 38 | AssertionResult assertionResult = new AssertionResult("ops"); 39 | assertionResult.setFailureMessage("assertion failed"); 40 | res.addAssertionResult(assertionResult); 41 | res.setSampleLabel("L2"); 42 | list.add(res); 43 | 44 | res = new SampleResult(System.currentTimeMillis() + 4000, 3); 45 | res.setSampleLabel("L2"); 46 | res.setSuccessful(false); 47 | res.setResponseMessage("Some error message"); 48 | res.setResponseCode("Some error code"); 49 | list.add(res); 50 | 51 | 52 | JSONObject result = JSONConverter.convertToJSON(list, list); 53 | JSONArray labels = result.getJSONArray("labels"); 54 | assertEquals(3, labels.size()); 55 | 56 | for (Object obj : labels) { 57 | JSONObject label = (JSONObject) obj; 58 | String name = label.getString("name"); 59 | if ("ALL".equals(name)) { 60 | assertEquals("8", label.getString("n")); 61 | } else if ("".equals(name)) { 62 | assertEquals("4", label.getString("n")); 63 | } else if ("L2".equals(name)) { 64 | assertEquals("4", label.getString("n")); 65 | assertErrors(label); 66 | assertAssertions(label); 67 | } else { 68 | fail("Unexpected label name: " + name); 69 | } 70 | } 71 | } 72 | 73 | private void assertAssertions(JSONObject label) { 74 | JSONArray assertions = label.getJSONArray("assertions"); 75 | assertEquals(1, assertions.size()); 76 | JSONObject jsonObject = assertions.getJSONObject(0); 77 | assertEquals("1", jsonObject.getString("failures")); 78 | assertEquals("All Assertions", jsonObject.getString("name")); 79 | assertEquals("assertion failed", jsonObject.getString("failureMessage")); 80 | } 81 | 82 | private void assertErrors(JSONObject label) { 83 | JSONArray errors = label.getJSONArray("errors"); 84 | assertEquals(1, errors.size()); 85 | JSONObject jsonObject = errors.getJSONObject(0); 86 | assertEquals("1", jsonObject.getString("count")); 87 | assertEquals("Some error message", jsonObject.getString("m")); 88 | assertEquals("Some error code", jsonObject.getString("rc")); 89 | } 90 | } -------------------------------------------------------------------------------- /parallel/src/main/java/com/blazemeter/jmeter/controller/TestCompilerParallel.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.controller; 2 | 3 | import org.apache.jmeter.assertions.Assertion; 4 | import org.apache.jmeter.config.ConfigTestElement; 5 | import org.apache.jmeter.control.TransactionSampler; 6 | import org.apache.jmeter.processor.PostProcessor; 7 | import org.apache.jmeter.processor.PreProcessor; 8 | import org.apache.jmeter.samplers.Sampler; 9 | import org.apache.jmeter.testelement.AbstractTestElement; 10 | import org.apache.jmeter.threads.SamplePackage; 11 | import org.apache.jmeter.threads.TestCompiler; 12 | import org.apache.jmeter.timers.Timer; 13 | import org.apache.jorphan.collections.HashTree; 14 | 15 | import java.util.HashSet; 16 | import java.util.Set; 17 | 18 | public class TestCompilerParallel extends TestCompiler { 19 | private final boolean suppressListeners; 20 | private Set knownElements = new HashSet<>(); 21 | 22 | public TestCompilerParallel(HashTree hashTree, boolean suppressListeners) { 23 | super(hashTree); 24 | this.suppressListeners = suppressListeners; 25 | } 26 | 27 | @Override 28 | public SamplePackage configureSampler(Sampler sampler) { 29 | SamplePackage samplePackage = super.configureSampler(sampler); 30 | addSamplePackage(sampler, samplePackage); 31 | if (suppressListeners) { 32 | samplePackage.getSampleListeners().clear(); 33 | } 34 | return samplePackage; 35 | } 36 | 37 | private void addSamplePackage(Sampler sampler, SamplePackage samplePackage) { 38 | if (sampler instanceof AbstractTestElement) { 39 | knownElements.add((AbstractTestElement) sampler); 40 | } 41 | 42 | for (Assertion assertion : samplePackage.getAssertions()) { 43 | if (assertion instanceof AbstractTestElement) { 44 | knownElements.add((AbstractTestElement) assertion); 45 | } 46 | } 47 | 48 | for (ConfigTestElement config : samplePackage.getConfigs()) { 49 | knownElements.add(config); 50 | } 51 | 52 | for (PostProcessor postProcessor : samplePackage.getPostProcessors()) { 53 | if (postProcessor instanceof AbstractTestElement) { 54 | knownElements.add((AbstractTestElement) postProcessor); 55 | } 56 | } 57 | 58 | for (PreProcessor preProcessor : samplePackage.getPreProcessors()) { 59 | if (preProcessor instanceof AbstractTestElement) { 60 | knownElements.add((AbstractTestElement) preProcessor); 61 | } 62 | } 63 | 64 | for (Timer timer : samplePackage.getTimers()) { 65 | if (timer instanceof AbstractTestElement) { 66 | knownElements.add((AbstractTestElement) timer); 67 | } 68 | } 69 | } 70 | 71 | 72 | @Override 73 | public SamplePackage configureTransactionSampler(TransactionSampler transactionSampler) { 74 | SamplePackage samplePackage = super.configureTransactionSampler(transactionSampler); 75 | addSamplePackage(transactionSampler, samplePackage); 76 | if (suppressListeners) { 77 | samplePackage.getSampleListeners().clear(); 78 | } 79 | return samplePackage; 80 | } 81 | 82 | public Set getKnownElements() { 83 | return knownElements; 84 | } 85 | 86 | @Override 87 | public void addNode(Object node, HashTree subTree) { 88 | // Override, because in JMeterThread.run().initRun() 89 | // it will break SamplePackage config 90 | } 91 | 92 | @Override 93 | public void subtractNode() { 94 | // Override, because in JMeterThread.run().initRun() 95 | // it will break SamplePackage config 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /sense-uploader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.blazemeter 8 | jmeter-plugins-senseuploader 9 | 3.5 10 | 11 | BlazeMeter Sense Uploader 12 | BlazeMeter Sense Uploader 13 | 14 | 15 | The Apache Software License, Version 2.0 16 | http://www.apache.org/licenses/LICENSE-2.0.txt 17 | repo 18 | 19 | 20 | http://jmeter-plugins.org/ 21 | 22 | https://github.com/undera/jmeter-plugins 23 | https://github.com/undera/jmeter-plugins.git 24 | git@github.com:undera/jmeter-plugins.git 25 | 26 | 27 | 28 | team 29 | jmeter-plugins.org 30 | jmeter-plugins@googlegroups.com 31 | 32 | 33 | 34 | 35 | UTF-8 36 | 1.7 37 | 1.7 38 | 39 | 40 | 41 | 42 | 43 | org.sonatype.plugins 44 | nexus-staging-maven-plugin 45 | 1.6.7 46 | true 47 | 48 | sonatype-nexus-staging 49 | https://oss.sonatype.org/ 50 | true 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.apache.jmeter 59 | ApacheJMeter_components 60 | 2.13 61 | 62 | 63 | commons-math3 64 | commons-math3 65 | 66 | 67 | commons-pool2 68 | commons-pool2 69 | 70 | 71 | 72 | 73 | net.sf.json-lib 74 | json-lib 75 | 2.4 76 | jdk15 77 | 78 | 79 | 80 | kg.apc 81 | jmeter-plugins-cmn-jmeter 82 | 0.3 83 | 84 | 85 | 86 | kg.apc 87 | jmeter-plugins-perfmon 88 | 2.0 89 | 90 | 91 | kg.apc 92 | jmeter-plugins-emulators 93 | 0.2 94 | test 95 | 96 | 97 | -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/http/BlazeMeterHttpUtilsTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.http; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 5 | import net.sf.json.JSON; 6 | import net.sf.json.JSONObject; 7 | import net.sf.json.JSONSerializer; 8 | import net.sf.json.JsonConfig; 9 | import org.apache.http.client.methods.HttpGet; 10 | import org.apache.http.client.methods.HttpPost; 11 | import org.apache.http.client.methods.HttpRequestBase; 12 | import org.junit.Test; 13 | 14 | import java.io.IOException; 15 | 16 | import static org.junit.Assert.*; 17 | 18 | 19 | public class BlazeMeterHttpUtilsTest { 20 | 21 | @Test 22 | public void testFlow() throws Exception { 23 | final StatusNotifierCallbackTest.StatusNotifierCallbackImpl callbackTest = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 24 | final String address = "empty_host"; 25 | BlazeMeterReport report = new BlazeMeterReport(); 26 | report.setToken("test_token"); 27 | BlazeMeterHttpUtils entity = createMockUtils(callbackTest, address, report); 28 | 29 | assertEquals(callbackTest, entity.getNotifier()); 30 | assertEquals(address, entity.getAddress()); 31 | assertEquals(address, entity.getDataAddress()); 32 | assertEquals(report, entity.getReport()); 33 | assertNotNull(entity.getHttpClient()); 34 | 35 | HttpGet get = entity.createGet(address); 36 | JSONObject response = entity.queryObject(get, 200); 37 | assertEquals("test_token", get.getHeaders("X-Api-Key")[0].getValue()); 38 | assertTrue(response.containsKey("message")); 39 | assertEquals("ok", response.get("message")); 40 | 41 | report.setToken("test:token"); 42 | entity = createMockUtils(callbackTest, address, report); 43 | HttpPost post = entity.createPost(address, ""); 44 | entity.queryObject(post, 200); 45 | assertTrue(post.getHeaders("Authorization")[0].getValue().startsWith("Basic ")); 46 | assertTrue(response.containsKey("message")); 47 | assertEquals("ok", response.get("message")); 48 | } 49 | 50 | private BlazeMeterHttpUtils createMockUtils(StatusNotifierCallbackTest.StatusNotifierCallbackImpl callbackTest, 51 | String address, BlazeMeterReport report) { 52 | return new BlazeMeterHttpUtils(callbackTest, address, address, report) { 53 | @Override 54 | public JSON query(HttpRequestBase request, int expectedCode) throws IOException { 55 | try { 56 | super.query(request, expectedCode); 57 | fail("Cannot send request to " + address); 58 | } catch (IllegalStateException ex) { 59 | assertEquals("Target host must not be null, or set in parameters.", ex.getMessage()); 60 | } 61 | return JSONSerializer.toJSON("{\"message\" : \"ok\"}", new JsonConfig()); 62 | } 63 | }; 64 | } 65 | 66 | @Test 67 | public void extractErrorMessageTest() throws Exception { 68 | final StatusNotifierCallbackTest.StatusNotifierCallbackImpl callbackTest = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 69 | final String address = "localhost"; 70 | BlazeMeterReport report = new BlazeMeterReport(); 71 | report.setToken("test_token"); 72 | BlazeMeterHttpUtils entity = new BlazeMeterHttpUtils(callbackTest, address, address, report); 73 | 74 | String errorResponse = "{\"error\":{\"message\":\"Please, try later!\"}}"; 75 | String message = entity.extractErrorMessage(errorResponse); 76 | 77 | assertEquals("Please, try later!", message); 78 | 79 | errorResponse = "Please, try later!"; 80 | assertEquals(errorResponse, entity.extractErrorMessage(errorResponse)); 81 | } 82 | } -------------------------------------------------------------------------------- /sense-uploader/src/test/java/com/blazemeter/api/explorer/TestTest.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.api.explorer; 2 | 3 | import com.blazemeter.api.BlazeMeterReport; 4 | import com.blazemeter.api.http.BlazeMeterHttpUtilsEmul; 5 | import kg.apc.jmeter.reporters.notifier.StatusNotifierCallbackTest; 6 | import net.sf.json.JSONObject; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | import static org.junit.Assert.assertNull; 10 | 11 | public class TestTest { 12 | 13 | @org.junit.Test 14 | public void testFlow() throws Exception { 15 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 16 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 17 | 18 | JSONObject testResponse = new JSONObject(); 19 | testResponse.put("id", "responseTestId"); 20 | testResponse.put("name", "responseTestName"); 21 | 22 | JSONObject sessionResponse = new JSONObject(); 23 | sessionResponse.put("id", "responseSessionId"); 24 | sessionResponse.put("name", "responseSessionName"); 25 | sessionResponse.put("userId", "responseUserId"); 26 | 27 | JSONObject masterResponse = new JSONObject(); 28 | masterResponse.put("id", "responseMasterId"); 29 | masterResponse.put("name", "responseMasterName"); 30 | 31 | final String expectedURL = "localhost:7777/report"; 32 | JSONObject result = new JSONObject(); 33 | result.put("publicTokenUrl", expectedURL); 34 | result.put("test", testResponse); 35 | result.put("signature", "responseSignature"); 36 | result.put("session", sessionResponse); 37 | result.put("master", masterResponse); 38 | 39 | JSONObject response = new JSONObject(); 40 | response.put("result", result); 41 | 42 | Test test = new Test(emul, "testId", "testName"); 43 | emul.addEmul(response); 44 | test.startExternal(); 45 | assertEquals(1, emul.getRequests().size()); 46 | assertEquals("", emul.getRequests().get(0)); 47 | assertNull(test.getReportURL()); 48 | checkTest(test, false); 49 | emul.clean(); 50 | 51 | test = new Test(emul); 52 | 53 | emul.addEmul(response); 54 | String url = test.startAnonymousExternal(); 55 | 56 | assertEquals(expectedURL, url); 57 | assertEquals(expectedURL, test.getReportURL()); 58 | checkTest(test, true); 59 | } 60 | 61 | private void checkTest(Test test, boolean isStartAnonymous) { 62 | Master master = test.getMaster(); 63 | assertEquals("responseMasterId", master.getId()); 64 | assertEquals("responseMasterName", master.getName()); 65 | 66 | Session session = test.getSession(); 67 | assertEquals("responseSessionId", session.getId()); 68 | assertEquals("responseSessionName", session.getName()); 69 | assertEquals("responseUserId", session.getUserId()); 70 | if (!isStartAnonymous) { 71 | assertEquals("testId", session.getTestId()); 72 | } else { 73 | assertEquals("responseTestId", session.getTestId()); 74 | } 75 | assertEquals("responseSignature", session.getSignature()); 76 | 77 | assertEquals("responseSignature", test.getSignature()); 78 | } 79 | 80 | @org.junit.Test 81 | public void testFromJSON() throws Exception { 82 | StatusNotifierCallbackTest.StatusNotifierCallbackImpl notifier = new StatusNotifierCallbackTest.StatusNotifierCallbackImpl(); 83 | BlazeMeterHttpUtilsEmul emul = new BlazeMeterHttpUtilsEmul(notifier, "test_address", "test_data_address", new BlazeMeterReport()); 84 | JSONObject object = new JSONObject(); 85 | object.put("id", "testId"); 86 | object.put("name", "testName"); 87 | Test test = Test.fromJSON(emul, object); 88 | assertEquals("testId", test.getId()); 89 | assertEquals("testName", test.getName()); 90 | } 91 | } -------------------------------------------------------------------------------- /xmpp/src/main/java/com/blazemeter/jmeter/xmpp/actions/NoOp.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter.xmpp.actions; 2 | 3 | 4 | import com.blazemeter.jmeter.xmpp.JMeterXMPPSampler; 5 | import org.apache.jmeter.samplers.SampleResult; 6 | import org.apache.jorphan.logging.LoggingManager; 7 | import org.apache.log.Logger; 8 | import org.jivesoftware.smack.PacketListener; 9 | import org.jivesoftware.smack.SmackException; 10 | import org.jivesoftware.smack.filter.OrFilter; 11 | import org.jivesoftware.smack.filter.PacketFilter; 12 | import org.jivesoftware.smack.filter.PacketTypeFilter; 13 | import org.jivesoftware.smack.packet.IQ; 14 | import org.jivesoftware.smack.packet.Message; 15 | import org.jivesoftware.smack.packet.Packet; 16 | import org.jivesoftware.smack.packet.Presence; 17 | 18 | import javax.swing.*; 19 | import java.awt.*; 20 | import java.util.Queue; 21 | import java.util.concurrent.LinkedBlockingQueue; 22 | 23 | public class NoOp extends AbstractXMPPAction implements PacketListener { 24 | private static final Logger log = LoggingManager.getLoggerForClass(); 25 | private Queue incomingPackets = new LinkedBlockingQueue<>(); 26 | 27 | @Override 28 | public String getLabel() { 29 | return "Collect Incoming Packets"; 30 | } 31 | 32 | @Override 33 | public void addUI(JComponent panel, GridBagConstraints labelConstraints, GridBagConstraints editConstraints) { 34 | panel.add(new JLabel("Generates no sample if there was no incoming packets.")); 35 | } 36 | 37 | @Override 38 | public SampleResult perform(JMeterXMPPSampler sampler, SampleResult res) throws Exception { 39 | long counter = 0; 40 | for (Packet packet : incomingPackets) { 41 | incomingPackets.remove(packet); 42 | SampleResult subRes = new SampleResult(); 43 | subRes.setSuccessful(true); 44 | subRes.setResponseCode("200"); 45 | subRes.setResponseMessage("OK"); 46 | subRes.setSampleLabel(packet.getClass().getSimpleName().isEmpty() ? packet.getClass().getName() : packet.getClass().getSimpleName()); 47 | subRes.setResponseData(packet.toXML().toString().getBytes()); 48 | 49 | if ((packet instanceof Presence) && (((Presence) packet).getType() == Presence.Type.error)) { 50 | subRes.setSuccessful(false); 51 | subRes.setResponseCode("500"); 52 | subRes.setResponseMessage(packet.getError().toString()); 53 | } else if ((packet instanceof Message) && (((Message) packet).getType() == Message.Type.error)) { 54 | subRes.setSuccessful(false); 55 | subRes.setResponseCode("500"); 56 | subRes.setResponseMessage(packet.getError().toString()); 57 | } else if ((packet instanceof IQ) && (((IQ) packet).getType() == IQ.Type.error)) { 58 | subRes.setSuccessful(false); 59 | subRes.setResponseCode("500"); 60 | subRes.setResponseMessage(packet.getError().toString()); 61 | } 62 | 63 | res.addSubResult(subRes); 64 | counter++; 65 | } 66 | res.setResponseData(("Received packets: " + counter).getBytes()); 67 | return counter > 0 ? res : null; 68 | } 69 | 70 | @Override 71 | public void clearGui() { 72 | 73 | } 74 | 75 | @Override 76 | public void setSamplerProperties(JMeterXMPPSampler sampler) { 77 | 78 | } 79 | 80 | @Override 81 | public void setGuiFieldsFromSampler(JMeterXMPPSampler sampler) { 82 | 83 | } 84 | 85 | @Override 86 | public void processPacket(Packet packet) throws SmackException.NotConnectedException { 87 | log.debug("Adding pending packet: " + packet.toXML()); 88 | //log.debug("Extensions: " + Arrays.toString(packet.getExtensions().toArray())); 89 | incomingPackets.add(packet); 90 | } 91 | 92 | @Override 93 | public PacketFilter getPacketFilter() { 94 | return new OrFilter(PacketTypeFilter.MESSAGE, PacketTypeFilter.PRESENCE, new PacketTypeFilter(IQ.class)); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /random-csv-data-set/src/main/java/com/blazemeter/jmeter/TestRandomCSVAction.java: -------------------------------------------------------------------------------- 1 | package com.blazemeter.jmeter; 2 | 3 | import org.apache.jmeter.engine.util.CompoundVariable; 4 | import org.apache.jmeter.functions.InvalidVariableException; 5 | import org.apache.jmeter.threads.JMeterContextService; 6 | import org.apache.jmeter.threads.JMeterVariables; 7 | import org.apache.jorphan.logging.LoggingManager; 8 | import org.apache.jorphan.util.JMeterStopThreadException; 9 | import org.apache.log.Logger; 10 | 11 | import javax.swing.*; 12 | import java.awt.event.ActionEvent; 13 | import java.awt.event.ActionListener; 14 | import java.util.ArrayList; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | public class TestRandomCSVAction implements ActionListener { 20 | 21 | private static final Logger LOGGER = LoggingManager.getLoggerForClass(); 22 | private static final int PREVIEW_MAX_SIZE = 20; 23 | private final RandomCSVDataSetConfigGui randomCSVConfigGui; 24 | 25 | public TestRandomCSVAction(RandomCSVDataSetConfigGui randomCSVConfigGui) { 26 | this.randomCSVConfigGui = randomCSVConfigGui; 27 | } 28 | 29 | @Override 30 | public void actionPerformed(ActionEvent event) { 31 | final RandomCSVDataSetConfig config = (RandomCSVDataSetConfig) randomCSVConfigGui.createTestElement(); 32 | 33 | config.setRewindOnTheEndOfList(false); 34 | config.setIndependentListPerThread(false); 35 | 36 | JTextArea checkArea = randomCSVConfigGui.getCheckArea(); 37 | 38 | try { 39 | config.setFilename(compoundValue(config.getFilename())); 40 | config.setVariableNames(compoundValue(config.getVariableNames())); 41 | config.setFileEncoding(compoundValue(config.getFileEncoding())); 42 | config.setDelimiter(compoundValue(config.getDelimiter())); 43 | 44 | JMeterVariables jMeterVariables = new JMeterVariables(); 45 | JMeterContextService.getContext().setVariables(jMeterVariables); 46 | 47 | final List> result = new ArrayList<>(); 48 | 49 | config.trySetFinalFilename(); 50 | config.testStarted(); 51 | 52 | String[] destinationVariableKeys = config.getDestinationVariableKeys(); 53 | 54 | try { 55 | for (int i = 0; i < PREVIEW_MAX_SIZE; i++) { 56 | config.iterationStart(null); 57 | Map record = new HashMap<>(); 58 | for (String var : destinationVariableKeys) { 59 | record.put(var, jMeterVariables.get(var)); 60 | } 61 | result.add(record); 62 | } 63 | } catch (JMeterStopThreadException ex) { 64 | // OK 65 | } 66 | 67 | config.testEnded(); 68 | 69 | final StringBuilder builder = new StringBuilder(); 70 | 71 | builder.append("Reading CSV successfully finished, ").append(result.size()).append(" records found:\r\n"); 72 | for (Map record : result) { 73 | for (String key : record.keySet()) { 74 | builder.append("${").append(key).append("} = "); 75 | builder.append(record.get(key)); 76 | builder.append("\r\n"); 77 | } 78 | builder.append("------------\r\n"); 79 | } 80 | 81 | checkArea.setText(builder.toString()); 82 | // move scroll to top 83 | checkArea.setCaretPosition(0); 84 | } catch (RuntimeException | InvalidVariableException ex) { 85 | checkArea.setText(ex.getMessage()); 86 | LOGGER.warn("Failed to test CSV Reading ", ex); 87 | } 88 | } 89 | 90 | 91 | private String compoundValue(String val) throws InvalidVariableException { 92 | CompoundVariable compoundVariable = new CompoundVariable(); 93 | compoundVariable.setParameters(val); 94 | return compoundVariable.execute(); 95 | } 96 | } 97 | --------------------------------------------------------------------------------