<|start_filename|>resiliency-tests/testRunner.js<|end_filename|>
var scenarios = require('./scenarios');
var es = require('./elasticsearch.js');
var dateformat = require('dateformat');
var fs = require('fs');
var path = require('path');
var scpClient = require('scp2');
var async = require('async');
var childprocess = require('child_process');
var mkdirp = require('mkdirp');

module.exports = function(options) {
	
	var self = this;
	var elastic = es(options);

	var mkdirSync = function (path) {
		 try {
		 	mkdirp.sync(path);
		 } catch(e) {
		 	if ( e.code != 'EEXIST' ) throw e;
		 }
	};

	self.run = function(scenario) {
		var test = scenarios(self, options)[scenario];
		options.testName = test.name;
		console.log(`running ${options.testName}`);

		var now = new Date();
		var outputFileName = `${dateformat(now, 'yyyymmddHHMM')}-${options.testName}`;
		options.outputFileName = outputFileName;
		var outputDir = path.join(options.resultsPath, outputFileName);
		options.outputDir = outputDir;
		options.outputFilePath = path.join(outputDir, outputFileName);
		options.windows = process.platform === 'win32';

		mkdirSync(outputDir);

		test.run();
	};

	self.saveContextInfo = function(callback) {
		if(options.verbose) {console.log('saving test context info')}
		var outputFile = path.join(options.outputDir, options.outputFileName) + '.txt';
		elastic.getClusterHealth(function(err, res, body) {
			fs.writeFileSync(outputFile, body);
			elastic.getClusterStatus(function(err, res, body) {
				fs.appendFileSync(outputFile, body);
				elastic.getIndexSettings(function(err, res, body) {
					fs.appendFileSync(outputFile, body);
					elastic.getNodesSettings(function(err, res, body) {
						fs.appendFileSync(outputFile, body);
						callback();
					});
				});
			});
		});
	}

	self.wait = function(millis, callback) {
		if(options.verbose) {console.log(`waiting ${millis} milliseconds.`)}
		setTimeout(function() {callback();}, millis);
	}

	self.runScripts = function(scriptsPath, scriptsRemotePath, scriptsArgs, callback) {
				
		async.series([
			//Copy the script into the jumpbox machine.
			function(callback) {
				if(options.verbose) {console.log(`copying scripts ${scriptsPath} to remote machine ${options.cluster.jumpboxIp}`)}
				scpClient.scp(scriptsPath, {
					host: options.cluster.jumpboxIp,
					username: options.cluster.username,
					password: <PASSWORD>,
					path: `/home/${options.cluster.username}/`
				}, 
				function(err) {
					if (err) return callback(err);
					console.log('script copied to the remote machine');

					callback();
				});
			},
			//Execute script remotely.
			function(callback) {
				var jumpboxRemote = `${options.cluster.username}@${options.cluster.jumpboxIp}`;

				console.log('setting the remote script as executable');

				var plinkExecPath = path.join('lib', 'plink.exe');
				
				//make sure the script is marked as executable.
				if(options.windows) {
					childprocess.spawnSync(plinkExecPath, 
					[
						jumpboxRemote,
						'-l',
						options.cluster.username,
						'-pw',
						options.cluster.password,
						`chmod +x ${scriptsRemotePath}`
					]);
				} else {
					childprocess.execSync(`ssh -tt ${jumpboxRemote} chmod +x ${scriptsRemotePath}`);
				}

				var scenario;
				if(options.windows) {
					var args = [	
						'-ssh',
						jumpboxRemote,
						'-l',
						options.cluster.username,
						'-pw',
						options.cluster.password,
						scriptsRemotePath
					];

					var args = [].concat.apply(args, scriptsArgs);

					//run the script remotely.
					scenario = childprocess.spawn(plinkExecPath, args);
				} else {
					scenario = childprocess.exec(`ssh ${jumpboxRemote} ${scriptsRemotePath} ${scriptsArgs.join(" ")}`);
				}

				scenario.stdout.on('data', function (data) {
					console.log('test : ' + data);
				});

				scenario.stderr.on('data', function (data) {
					console.log('test :' + data);
				});

				if(options.windows) {
					scenario.stdin.write('y\n'); //this is to skip host confirmation from PLINK.
				}

				callback();
			}
		]);
		
	}

	return self;
}

<|start_filename|>resiliency-tests/scenarios/index.js<|end_filename|>
var scenario11 = require('./scenario11/scenario11.js');
var scenario12 = require('./scenario12/scenario12.js');
var scenario13 = require('./scenario13/scenario13.js');
var scenario21 = require('./scenario21/scenario21.js');

module.exports = function(self, options) {
	return {
		"11": scenario11(self, options),
		"12": scenario12(self, options),
		"13": scenario13(self, options),
		"21": scenario21(self, options)
	};
}

<|start_filename|>resiliency-tests/jmeter/tests/elasticsearch20/src/elasticsearchtest20/ElasticsearchTests20.java<|end_filename|>
package elasticsearchtest20;

import static org.junit.Assert.*;

import org.junit.*;

import java.util.*;
import java.io.*;
import java.net.*;

import org.elasticsearch.action.bulk.*;
import org.elasticsearch.common.transport.*;
import org.elasticsearch.client.transport.*;
import org.elasticsearch.common.settings.*;
import org.elasticsearch.common.xcontent.*;

public class ElasticsearchTests20 {
	
	private String [] names={"checkout","order","search","payment"};
	private String [] messages={"Incoming request from code","incoming operation succeeded with code","Operation completed time","transaction performed"};
	private String [] severity={"info","warning","transaction","verbose"};
	private String [] apps={"4D24BD62-20BF-4D74-B6DC-31313ABADB82","5D24BD62-20BF-4D74-B6DC-31313ABADB82","6D24BD62-20BF-4D74-B6DC-31313ABADB82","7D24BD62-20BF-4D74-B6DC-31313ABADB82"};

	private String hostName = "";
	private String indexName = "";
	private String typeName = "";
	private int port = 0;
	private int node = 0;
	private String clusterName = "";
	private int itemsPerBatch = 0;
	
	private static Random random = new Random();	

	@Before
	public void setUp() throws Exception {
	}
	
	public ElasticsearchTests20(String paras) {
		/* Paras is a string containing a set of comma separated values for:
		 
		   hostname
	       indexstr
	       typestr
	       port
	       clustername
	       node
	       itemsPerBatch
		 */
		
		// Note: No checking/validation is performed
		
		String delims = "[ ]*,[ ]*"; // comma surrounded by zero or more spaces
		String[] items = paras.split(delims);
		
		hostName = items[0];
		indexName = items[1];
		typeName = items[2];
		port = Integer.parseInt(items[3]);
		clusterName = items[4];
		node=Integer.parseInt(items[5]);
		
		if (node!=0) {
			port = port+(random.nextInt(node)+1);
		}
		
		itemsPerBatch = Integer.parseInt(items[6]);
		if(itemsPerBatch == 0)
		{
			itemsPerBatch = 1000;
		}
	}
	
	@Test
	public void BulkBigInsertTest20() throws IOException {
		
		Settings settings = Settings.settingsBuilder().put("cluster.name", clusterName).build();
		TransportClient client = TransportClient.builder().settings(settings).build();	                     
		
		try {
			
	        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), port));
			BulkRequestBuilder bulkRequest = client.prepareBulk();
	        Random random = new Random();
	        char[] exmarks = new char[2000];
	        Arrays.fill(exmarks, 'x');
	        String dataString = new String(exmarks);
	        
	        for(int i=1; i< itemsPerBatch ; i++){
		        random.nextInt(10);
		        int host=random.nextInt(20);
		   
		        bulkRequest.add(client.prepareIndex(indexName, typeName).setSource(XContentFactory.jsonBuilder()
			        .startObject()
			            .field("@timestamp", new Date())
    			        .field("name", names[random.nextInt(names.length)])
	    		        .field("message", messages[random.nextInt(messages.length)])
		    	        .field("severityCode", random.nextInt(10))
			            .field("severity", severity[random.nextInt(severity.length)])
			            .field("hostname", "Hostname"+host)
			            .field("hostip", "10.1.0."+host)
    			        .field("pid",random.nextInt(10))
	    		        .field("tid",random.nextInt(10))
		    	        .field("appId", apps[random.nextInt(apps.length)])
			            .field("appName", "application"+host)
			            .field("appVersion", random.nextInt(5))
			            .field("type", random.nextInt(6))
    			        .field("subtype", random.nextInt(6))
	    		        .field("correlationId", UUID.randomUUID().toString())
		    	        .field("os", "linux")
			            .field("osVersion", "14.1.5")
			            .field("parameters", "{ke:value,key:value}")
			            .field("data1",dataString)
			            .field("data2",dataString)
			        .endObject()
			        )
			    );
		    }
		    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
		    assertFalse(bulkResponse.buildFailureMessage(), bulkResponse.hasFailures());
	    }
        finally {
            client.close();
        }
    }
	
	@Test
	public void BulkDataInsertTest20() throws IOException {
		
		Settings settings = Settings.settingsBuilder().put("cluster.name", clusterName).build();
		TransportClient client = TransportClient.builder().settings(settings).build();	                     
		
		try {
			
	        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), port));
	        BulkRequestBuilder bulkRequest = client.prepareBulk();	     
	        
	        for(int i=1; i< itemsPerBatch; i++){
		        random.nextInt(10);
		        int host=random.nextInt(20);
		   
		        bulkRequest.add(client.prepareIndex(indexName, typeName).setSource(XContentFactory.jsonBuilder()
			        .startObject()
			            .field("@timestamp", new Date())
    			        .field("name", names[random.nextInt(names.length)])
	    		        .field("message", messages[random.nextInt(messages.length)])
		    	        .field("severityCode", random.nextInt(10))
			            .field("severity", severity[random.nextInt(severity.length)])
			            .field("hostname", "Hostname"+host)
			            .field("hostip", "10.1.0."+host)
    			        .field("pid",random.nextInt(10))
	    		        .field("tid",random.nextInt(10))
		    	        .field("appId", apps[random.nextInt(apps.length)])
			            .field("appName", "application"+host)
			            .field("appVersion", random.nextInt(5))
			            .field("type", random.nextInt(6))
    			        .field("subtype", random.nextInt(6))
	    		        .field("correlationId", UUID.randomUUID().toString())
		    	        .field("os", "linux")
			            .field("osVersion", "14.1.5")
			            .field("parameters", "{ke:value,key:value}")
			        .endObject()
			        )
			    );
		    }
		    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
		    assertFalse(bulkResponse.buildFailureMessage(), bulkResponse.hasFailures());
	    }
        finally {
            client.close();
        }
    }
	
	@Test
	public void BulkDataIdInsertTest20() throws IOException {
		
		Settings settings = Settings.settingsBuilder().put("cluster.name", clusterName).build();
		TransportClient client = TransportClient.builder().settings(settings).build();	                     
		
		try {
			
	        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostName), port));
	        BulkRequestBuilder bulkRequest = client.prepareBulk();	     
	        
	        for(int i=1; i< itemsPerBatch; i++){
		        random.nextInt(10);
		        int host=random.nextInt(20);
		   
		        bulkRequest.add(client.prepareIndex(indexName, typeName).setId(UUID.randomUUID().toString()).setSource(XContentFactory.jsonBuilder()
		        	
			        .startObject()			        			        			            		        
			            .field("@timestamp", new Date())
    			        .field("name", names[random.nextInt(names.length)])
	    		        .field("message", messages[random.nextInt(messages.length)])
		    	        .field("severityCode", random.nextInt(10))
			            .field("severity", severity[random.nextInt(severity.length)])
			            .field("hostname", "Hostname"+host)
			            .field("hostip", "10.1.0."+host)
    			        .field("pid",random.nextInt(10))
	    		        .field("tid",random.nextInt(10))
		    	        .field("appId", apps[random.nextInt(apps.length)])
			            .field("appName", "application"+host)
			            .field("appVersion", random.nextInt(5))
			            .field("type", random.nextInt(6))
    			        .field("subtype", random.nextInt(6))
	    		        .field("correlationId", UUID.randomUUID().toString())
		    	        .field("os", "linux")
			            .field("osVersion", "14.1.5")
			            .field("parameters", "{ke:value,key:value}")
			        .endObject()
			        )
			    );
		    }
		    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
		    assertFalse(bulkResponse.buildFailureMessage(), bulkResponse.hasFailures());
	    }
        finally {
            client.close();
        }
    }
	
	@After
	public void tearDown() throws Exception {
	}
}

<|start_filename|>resiliency-tests/config.js<|end_filename|>
'use strict';

var config = {};
config.jmeterPath = 'C:/apache-jmeter-2.13';
config.resultsPath = 'results';
config.verbose = true;
config.remote = false;

config.cluster = {};
config.cluster.clusterName = 'YOUR_ELASTIC_SEARCH_CLUSTER_NAME';
config.cluster.jumpboxIp = 'YOUR_JUMPBOX_IP';
config.cluster.username = 'YOUR_USER';
config.cluster.password = '<PASSWORD>';

config.cluster.loadBalancer = {};
config.cluster.loadBalancer.ip = 'YOUR_LOADBALANCER_IP';
config.cluster.loadBalancer.url = 'http://YOUR_LOADBALANCER_IP:9200';

config.testIndex = {};
config.testIndex.indexName = 'systwo';  //default you can change your index here
config.testIndex.replicas = 1;          // # of Replicas for this Index
config.testIndex.shards = 5;            // # of Shards for this Index

config.testIndex.template = {};
config.testIndex.template.templateName = 'perftemplate';
config.testIndex.template.templateBody = {
  "template": "sys*",
  "order": 1,
  "settings": {
    "refresh_interval": "30s"
  },
  "mappings": {
    "_default_": {
      "_all": {"enabled": false},
      "dynamic_templates": [
        {
        "notanalyzed": {
              "match": "*", 
              "match_mapping_type": "string",
              "mapping": {
                  "type": "string",
                  "index": "not_analyzed"
              }
           }
        }
      ]
    }
  }
};

module.exports = config;

<|start_filename|>resiliency-tests/elasticsearch.js<|end_filename|>
'use strict';

var request = require('request');
var _ = require('lodash');

module.exports = function(config) {
	return {
		deleteIndex: function(indexName, callback) {
			if(config.verbose) { console.log(`deleting index ${indexName}`)}
			request({
				uri: `${config.cluster.loadBalancer.url}/${indexName}`,
				method: 'DELETE'
			}, callback);
		},
		createIndex: function(indexName, callback) {
			if(config.verbose) { console.log(`creating index ${indexName}`)}
			request({
				uri: `${config.cluster.loadBalancer.url}/${indexName}`,
				method: 'PUT',
				json: {
					"settings": {
						"index.number_of_replicas": config.testIndex.replicas,
						"index.number_of_shards": config.testIndex.shards
					}
				}
			}, callback);
		},
		applyTemplate: function(callback) {
			if(config.verbose) { console.log(`applying custom index settings`)}
			request({
				uri: `${config.cluster.loadBalancer.url}/_template/${config.testIndex.template.templateName}`,
				method: 'PUT',
				json: config.testIndex.template.templateBody
			}, callback);
		},
		getClusterHealth: function(callback) {
			if(config.verbose) { console.log(`getting cluster health of ${config.cluster.clusterName}`)}
			request({
				uri: `${config.cluster.loadBalancer.url}/_cluster/health?pretty`,
				method: 'GET'
			}, callback);
		},
		getClusterStatus: function(callback) {
			if(config.verbose) { console.log(`getting cluster status of ${config.cluster.clusterName}`)}
			request({
				uri: `${config.cluster.loadBalancer.url}?pretty`,
				method: 'GET'
			}, callback);
		},
		getIndexSettings: function(callback) {
			if(config.verbose) { console.log(`getting settings of index ${config.testIndex.indexName}`)}
			request({
				uri: `${config.cluster.loadBalancer.url}/${config.testIndex.indexName}/_settings?pretty`,
				method: 'GET'
			}, callback);
		},
		getNodesSettings: function(callback) {
			if(config.verbose) { console.log(`getting cluster node settings of ${config.cluster.clusterName}`)}
			request({
				uri: `${config.cluster.loadBalancer.url}/_nodes/process?pretty`,
				method: 'GET'
			}, callback);
		},
		setReallocationTimeout: function(indexName, timeout, callback) {
			request({
				uri: `${config.cluster.loadBalancer.url}/${indexName}/_settings`,
				method: 'PUT',
				json: {
					"settings": {
						"index.unassigned.node_left.delayed_timeout": timeout
					}
				}
			}, callback);
		},
		getAllNodes: function(callback) {
			 
			request({
				uri: `${config.cluster.loadBalancer.url}/_cat/nodes?v=&h=host,node.role`,
				method: 'GET'
			}, callback);
		},
		getDataNodeNames: function(callback) {
			if(config.verbose) { console.log(`getting data nodes of cluster ${config.cluster.clusterName}`)}
			request({
				uri: `${config.cluster.loadBalancer.url}/_nodes`,
				method: 'GET'
			}, function(err, res, body)
			{
				body = JSON.parse(body);
				var dataNodes = _.filter(body.nodes, function(n) {
  					return n.settings.node.data == 'true'
				});

				var names = _.pluck(dataNodes, 'host');
				names = _.sortBy(names, function(n) {
					return n;
				});

				callback(err, res, names);
			});
		}
	}
}

<|start_filename|>ingestion-and-query-tests/junitcode/elasticsearch1.73/src/elasticsearchtest2/ElasticSearchLoadTest2.java<|end_filename|>
package elasticsearchtest2;

import static org.junit.Assert.*;

import org.junit.*;

import java.util.*;
import java.io.*;

import org.elasticsearch.action.bulk.*;
import org.elasticsearch.common.transport.*;
import org.elasticsearch.client.transport.*;
import org.elasticsearch.common.settings.*;
import org.elasticsearch.common.xcontent.*;

public class ElasticSearchLoadTest2 {
  
  private String [] names={"checkout","order","search","payment"};
  private String [] messages={"Incoming request from code","incoming operation succeeded with code","Operation completed time","transaction performed"};
  private String [] severity={"info","warning","transaction","verbose"};
  private String [] apps={"4D24BD62-20BF-4D74-B6DC-31313ABADB82","5D24BD62-20BF-4D74-B6DC-31313ABADB82","6D24BD62-20BF-4D74-B6DC-31313ABADB82","7D24BD62-20BF-4D74-B6DC-31313ABADB82"};

  private String hostname = "";
  private String indexstr = "";
  private String typestr = "";
  private int port = 0;
  private int node=0;
  private int itemsPerInsert = 0;
  private String clustername = "";
  private static Random rand=new Random();
  

  @Before
  public void setUp() throws Exception {

  }
  
  public ElasticSearchLoadTest2(String paras) {
    /* Paras is a string containing a set of comma separated values for:
     
      hostname
      indexstr
      typestr
      port
      clustername
      node
      itemsPerInsert
    */
    
    // Note: No checking/validation is performed
    
    String delims = "[ ]*,[ ]*"; // comma surrounded by zero or more spaces
    String[] items = paras.split(delims);
    
    
    
    hostname = items[0];
    indexstr = items[1];
    typestr = items[2];
    port = Integer.parseInt(items[3]);
    clustername = items[4];
    node=Integer.parseInt(items[5]);
    
    if (node!=0)
      port = port+(rand.nextInt(node)+1);
    
    itemsPerInsert = Integer.parseInt(items[6]);
    if (itemsPerInsert == 0)
      itemsPerInsert = 1000;
  }

  @After
  public void tearDown() throws Exception {
  }

  @Test
  public void BulkBigInsertTest() throws IOException {
    
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clustername).build();
    TransportClient client;
    client = new TransportClient(settings);
    
    try {
      
          client.addTransportAddress(new InetSocketTransportAddress(hostname, port));   
          BulkRequestBuilder bulkRequest = client.prepareBulk();
          Random random = new Random();
          char[] exmarks = new char[12000];
          Arrays.fill(exmarks, 'x');
          String dataString = new String(exmarks);
          
          for(int i=1; i < itemsPerInsert; i++){
            random.nextInt(10);
            int host=random.nextInt(20);
       
            bulkRequest.add(client.prepareIndex(indexstr, typestr).setSource(XContentFactory.jsonBuilder()
              .startObject()
                  .field("@timestamp", new Date())
                  .field("name", names[random.nextInt(names.length)])
                  .field("message", messages[random.nextInt(messages.length)])
                  .field("severityCode", random.nextInt(10))
                  .field("severity", severity[random.nextInt(severity.length)])
                  .field("hostname", "Hostname"+host)
                  .field("hostip", "10.1.0."+host)
                  .field("pid",random.nextInt(10))
                  .field("tid",random.nextInt(10))
                  .field("appId", apps[random.nextInt(apps.length)])
                  .field("appName", "application"+host)
                  .field("appVersion", random.nextInt(5))
                  .field("type", random.nextInt(6))
                  .field("subtype", random.nextInt(6))
                  .field("correlationId", UUID.randomUUID().toString())
                  .field("os", "linux")
                  .field("osVersion", "14.1.5")
                  .field("parameters", "{ke:value,key:value}")
                  .field("data1",dataString)
                  .field("data2",dataString)
              .endObject()
              )
          );
        }
        BulkResponse bulkResponse = bulkRequest.execute().actionGet();
        assertFalse(bulkResponse.hasFailures());
      }
        finally {
            client.close();
        }
    }
  
  @Test
  public void BulkDataInsertTest() throws IOException {
    
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", clustername).build();
    TransportClient client;
    client = new TransportClient(settings);
    
    try {        
          client.addTransportAddress(new InetSocketTransportAddress(hostname, port));   
          BulkRequestBuilder bulkRequest = client.prepareBulk();
          //Random random = new Random();
       
          for(int i=1; i< itemsPerInsert; i++){
            rand.nextInt(10);
            int host=rand.nextInt(20);
       
            bulkRequest.add(client.prepareIndex(indexstr, typestr).setSource(XContentFactory.jsonBuilder()
              .startObject()
                  .field("@timestamp", new Date())
                  .field("name", names[rand.nextInt(names.length)])
                  .field("message", messages[rand.nextInt(messages.length)])
                  .field("severityCode", rand.nextInt(10))
                  .field("severity", severity[rand.nextInt(severity.length)])
                  .field("hostname", "Hostname"+host)
                  .field("hostip", "10.1.0."+host)
                  .field("pid",rand.nextInt(10))
                  .field("tid",rand.nextInt(10))
                  .field("appId", apps[rand.nextInt(apps.length)])
                  .field("appName", "application"+host)
                  .field("appVersion", rand.nextInt(5))
                  .field("type", rand.nextInt(6))
                  .field("subtype", rand.nextInt(6))
                  .field("correlationId", UUID.randomUUID().toString())
                  .field("os", "linux")
                  .field("osVersion", "14.1.5")
                  .field("parameters", "{ke:value,key:value}")
              .endObject()
              )
          );
        }
        BulkResponse bulkResponse = bulkRequest.execute().actionGet();
        assertFalse(bulkResponse.hasFailures());
      }
        finally {
            client.close();
        }
    }  
}


<|start_filename|>resiliency-tests/export.bat<|end_filename|>
SET testname=%1
SET extpath=%2
SET testdir=results/%testname%
SET testPathNoExtension=%testdir%/%testname%

ECHO %1
ECHO %2
ECHO %testdir%
ECHO %testPathNoExtension%

java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-csv %testPathNoExtension%.csv --input-jtl %testPathNoExtension%.jtl --plugin-type AggregateReport

java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-csv %testPathNoExtension%-transactions.csv --input-jtl %testPathNoExtension%.jtl --plugin-type TransactionsPerSecond
java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-png %testPathNoExtension%-transactions.png --input-jtl %testPathNoExtension%.jtl --plugin-type TransactionsPerSecond

java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-csv %testPathNoExtension%-responses.csv --input-jtl %testPathNoExtension%.jtl --plugin-type ResponseTimesOverTime
java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-png %testPathNoExtension%-responses.png --input-jtl %testPathNoExtension%.jtl --plugin-type ResponseTimesOverTime

java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-csv %testPathNoExtension%-cpu.csv --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*CPU.*" --include-label-regex true
java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-png %testPathNoExtension%-cpu.png --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*CPU.*" --include-label-regex true

java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-csv %testPathNoExtension%-disk.csv --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*Disk.*" --include-label-regex true
java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-png %testPathNoExtension%-disk.png --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*Disk.*" --include-label-regex true

java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-csv %testPathNoExtension%-memory.csv --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*Memory.*" --include-label-regex true
java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-png %testPathNoExtension%-memory.png --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*Memory.*" --include-label-regex true

java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-csv %testPathNoExtension%-network.csv --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*Network.*" --include-label-regex true
java -jar %extpath%/CMDRunner.jar --tool Reporter --generate-png %testPathNoExtension%-network.png --input-jtl %testPathNoExtension%-perf.jtl --plugin-type PerfMon --include-labels ".*Network.*" --include-label-regex true

<|start_filename|>resiliency-tests/setup.js<|end_filename|>
var elasticsearch = require('./elasticsearch.js');
var config = require('./config.js');

console.log('configuring cluster to run the scripts');

elasticsearch = elasticsearch(config);

elasticsearch.getDataNodeNames(function(err, res, dataNodes) {
	console.log(dataNodes);
});

<|start_filename|>resiliency-tests/jmeterRunner.js<|end_filename|>
var childprocess = require('child_process');
var path = require('path');

module.exports = function(options) {

	var self = this;

	var runJmeterLinux = function(testOptions) {
		var jmeterExecPath = path.join(options.jmeterPath, 'bin/jmeter.sh');
		testOptions.unshift(jmeterExecPath);
		return childprocess.spawn('sh', testOptions);
	};

	var runJmeterWindows = function(testOptions) {
		var jmeterExecPath = path.join(options.jmeterPath, 'bin/jmeter.bat');
		return childprocess.spawn(jmeterExecPath, testOptions);
	};

	self.run = function(templatePath, args, callback) {
			
		var testOptions = [];

		if(options.remote) {
			testOptions.push('-r'); //run on the remote servers specified in jmeter.properties.
		}

		testOptions.push('-n'); //non-gui mode.

		for(var key in args) {
			testOptions.push(`-G${key}=${args[key]}`); //send as global parameter
			testOptions.push(`-J${key}=${args[key]}`); //send as local parameter
		}

		testOptions.push('-t');
		testOptions.push(templatePath);

		console.log('starting jmeter test');
		
		var test = null;
		if(options.windows) {
			test = runJmeterWindows(testOptions);
		} else {
			test = runJmeterLinux(testOptions);
		}

		test.stdout.on('data', function (data) {
    		console.log('jmeter: ' + data);
		});

		test.stderr.on('data', function (data) {
    		console.log('jmeter: ' + data);
    		process.exit();
		});

		test.on('close', function (code) {
    
    		if (code !== 0) {
        		console.log('testRun process exited with code ' + code);
    		}
    
    		console.log('exporting results...');

    		var jmeterExtPath = path.join(options.jmeterPath, 'lib/ext');

    		if(options.windows) {
    			childprocess.spawnSync('export.bat', [options.outputFileName, jmeterExtPath]);
    		}
    		else {
    			childprocess.spawnSync('export.sh', [options.outputFileName, jmeterExtPath]);
    		}
   			
   			console.log('export finished.');
		});

		callback();
	}

	return self;
};

<|start_filename|>resiliency-tests/scenarios/scenario12/scenario12.js<|end_filename|>
'use strict';

var elasticsearch = require('../../elasticsearch.js');
var jmeter = require('../../jmeterRunner.js');
var async = require('async');
var config = require('../../config.js');

module.exports = function(runner, options) {

	elasticsearch = elasticsearch(options);
	jmeter = jmeter(options);
	
	var scriptsArgs = [
		2400, //40 min initial wait time.
		300, //5 min node down.
		options.cluster.username,
		config.cluster.clusterName,
		'su0nvm0' //Name of the cluster to restart.
	];

	var index1 = "sysone";
	var index2 = "systwo";

	return {
		name: "scenario12",
		run: function() {
			async.series([
				//prepare cluster.
				async.apply(elasticsearch.deleteIndex, index1),
				async.apply(elasticsearch.deleteIndex, index2),
				async.apply(elasticsearch.createIndex, index1),
				async.apply(elasticsearch.createIndex, index2),
				elasticsearch.applyTemplate,
				async.apply(elasticsearch.setReallocationTimeout, index1,'15m'),
				async.apply(elasticsearch.setReallocationTimeout, index2,'15m'),
				async.apply(runner.wait, 2000),
				runner.saveContextInfo,
				//run jmeter test.
				async.apply(jmeter.run, 'jmeter/plans/insert_query.jmx', {
					outputfile: options.outputFilePath,
					stage1duration: 900, //15 min pre-populate duration (inserts)
					stage2duration: 4200, //70 min run (inserts + queries),
					elasticip: options.cluster.loadBalancer.ip,
					index1name: index1,
					index2name: index2,
					clustername: options.cluster.clusterName,
					insertthreads: 1,
					querythreads: 6
				}),
				//run scripts.
				async.apply(
				  runner.runScripts,
				  'scenarios/scenario12/scenario12.sh',
				  `/home/${options.cluster.username}/scenario12.sh`,
				  scriptsArgs
				)
			],
			function (err, result) {
    			console.log(result);
			});
		}
	};
}

<|start_filename|>resiliency-tests/app.js<|end_filename|>
﻿'use strict';

var program = require('commander');
var prompt = require('prompt');
var config = require('./config.js');
var testRunner = require('./testRunner.js');
var _ = require('lodash');

program
  .version('0.0.1')
  .option('-s, --scenario [number]', 'Run the specified scenario')
  .parse(process.argv);

if (!program.scenario) {
    
    console.log('choose an scenario to run:');
    console.log('----------------------------------------------------');
    console.log('Reliability Testing Scenarios');
    console.log('----------------------------------------------------');
    console.log('[11] Scenario 1.1 -> No re-allocation w/o data loss');
    console.log('[12] Scenario 1.2 -> No re-allocation w data loss');
    console.log('[13] Scenario 1.3 -> Re-allocation w/o data loss');
    console.log('[21] Scenario 2.1 -> Rolling updates');
    console.log('----------------------------------------------------');
    
    prompt.start();
    prompt.get(['scenario'], function (err, result) {
        
        if (err) {
            console.log(err);
            process.exit();
        }

        testRunner(config).run(result.scenario);
        
    });
}
else {
    testRunner(config).run(program.scenario);
}