ruby-jmeter 2.13.8 → 2.13.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/basic_header.rb +7 -0
- data/examples/real_redis_data_set_with_setup.rb +123 -0
- data/lib/ruby-jmeter/dsl.rb +5 -0
- data/lib/ruby-jmeter/plugins/redis_data_set.rb +39 -0
- data/lib/ruby-jmeter/version.rb +1 -1
- data/spec/dsl_spec.rb +53 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b08a9495536489abe43055bcaefb8b00ae1d688
|
4
|
+
data.tar.gz: 117ffddedc4e3fda6f25b9e2d2c77d7717672a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9857ead6edff27a4ae5577d019d265ca11499777256a2ffd39b2f3f4f6c04f441dc129ca1507079ea1bf48fa6b8a0796502759ac922f562959c018dbcdf74b99
|
7
|
+
data.tar.gz: a7f89263182930d51b6388e99f2b6631f071c7aa2b3687251980410daac18812dc24050b353c4f0b83e348e6e137ca45a045dcfa47723efd09c9f638c3a0af90
|
data/examples/basic_header.rb
CHANGED
@@ -0,0 +1,123 @@
|
|
1
|
+
################################################################################
|
2
|
+
# This is an example of how to use a Redis data set with CSV data.
|
3
|
+
# The test plan defines a setup thread group with a JSR223 sampler (scripted in
|
4
|
+
# Groovy), which pre-populates Redis with the data used for the actual test.
|
5
|
+
# The test itself simply calls a REST API with data seeded from Redis.
|
6
|
+
#
|
7
|
+
# The redis key is "test_data" and the format of the CSV data is:
|
8
|
+
# user_id,start_date,end_date
|
9
|
+
#
|
10
|
+
# Requires:
|
11
|
+
# JMeter (recommended version: 2.13 or later)
|
12
|
+
# jmeter-plugins extras with libs (this gives us the redis data set config)
|
13
|
+
# Groovy 2.4 or later (put the groovy-all jar into $JMETER_HOME/lib)
|
14
|
+
################################################################################
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
+
require 'ruby-jmeter'
|
18
|
+
|
19
|
+
# For redis dataset config.
|
20
|
+
redis_host = 'localhost'
|
21
|
+
redis_port = 6379
|
22
|
+
redis_key = 'test_data'
|
23
|
+
num_records = 1000 # how many rows of test data to generate
|
24
|
+
|
25
|
+
# for HTTP request defaults
|
26
|
+
protocol = 'http'
|
27
|
+
host = 'localhost'
|
28
|
+
port = 8080
|
29
|
+
|
30
|
+
# JMeter test plan begins here.
|
31
|
+
test do
|
32
|
+
|
33
|
+
# Setup the data set we will use to run the tests.
|
34
|
+
setup_thread_group name: 'Redis Fill',
|
35
|
+
loops: 1 do
|
36
|
+
jsr223_sampler name: 'redis fill',
|
37
|
+
scriptLanguage: 'groovy',
|
38
|
+
cacheKey: 'prefill_user_ids',
|
39
|
+
script: <<-EOS.strip_heredoc
|
40
|
+
import redis.clients.jedis.JedisPoolConfig;
|
41
|
+
import redis.clients.jedis.JedisPool;
|
42
|
+
import redis.clients.jedis.Jedis;
|
43
|
+
|
44
|
+
import java.util.Random;
|
45
|
+
import java.util.Date;
|
46
|
+
import java.text.DateFormat;
|
47
|
+
import java.text.SimpleDateFormat;
|
48
|
+
|
49
|
+
JedisPoolConfig config = new JedisPoolConfig();
|
50
|
+
JedisPool pool = new JedisPool(config, "#{redis_host}", #{redis_port});
|
51
|
+
Jedis jedis = null;
|
52
|
+
try {
|
53
|
+
jedis = pool.getResource();
|
54
|
+
|
55
|
+
//delete old data, if it exists
|
56
|
+
jedis.del("#{redis_key}");
|
57
|
+
|
58
|
+
// Create a list of the last 90 days. We will seed our test data from this.
|
59
|
+
Date now = new Date();
|
60
|
+
Date oldest = now - 90;
|
61
|
+
Range days = oldest..now;
|
62
|
+
|
63
|
+
Random random = new Random();
|
64
|
+
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
65
|
+
|
66
|
+
/*
|
67
|
+
* Generate CSV data in the form of:
|
68
|
+
* user_id,start_date,end_date
|
69
|
+
*/
|
70
|
+
for (int i = 1; i <= #{num_records}; i++) {
|
71
|
+
Date day = days[random.nextInt(days.size())]
|
72
|
+
String data = [i, df.format(day), df.format(day)].join(',')
|
73
|
+
jedis.sadd("#{redis_key}", data);
|
74
|
+
}
|
75
|
+
}finally {
|
76
|
+
if(jedis != null) {
|
77
|
+
pool.returnResource(jedis);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
EOS
|
81
|
+
end
|
82
|
+
|
83
|
+
# Defines a thread group. We allow certain parameters to be passed in
|
84
|
+
# as system properties.
|
85
|
+
threads name: 'Test Scenario - REST API query',
|
86
|
+
count: '${__P(threads,1)}',
|
87
|
+
rampup: '${__P(rampup,600)}',
|
88
|
+
duration: '${__P(duration, 600)}' do
|
89
|
+
|
90
|
+
# HTTP request defaults
|
91
|
+
defaults domain: host, # default domain if not specified in URL
|
92
|
+
protocol: protocol, # default protocol if not specified in URL
|
93
|
+
port: port,
|
94
|
+
download_resources: false # download images/CSS/JS (no)
|
95
|
+
|
96
|
+
cookies # om nom nom
|
97
|
+
|
98
|
+
cache clear_each_iteration: true # each thread iteration mimics a new user with an empty browser cache
|
99
|
+
|
100
|
+
with_gzip # add HTTP request headers to allow GZIP compression. Most sites support this nowadays.
|
101
|
+
|
102
|
+
# Test data. Note how the variableNames match the variables used by the
|
103
|
+
# sampler below.
|
104
|
+
redis_data_set 'test data',
|
105
|
+
redisKey: redis_key,
|
106
|
+
host: redis_host,
|
107
|
+
port: redis_port,
|
108
|
+
variableNames: 'user_id,start_date,end_date'
|
109
|
+
|
110
|
+
# User workflow begins here.
|
111
|
+
visit name: 'REST API query',
|
112
|
+
url: '/rest/query',
|
113
|
+
always_encode: true,
|
114
|
+
fill_in: {
|
115
|
+
'user_id' => '${user_id}',
|
116
|
+
'start' => '${start_date}',
|
117
|
+
'end' => '${end_date}'
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
response_time_graph
|
122
|
+
view_results_tree
|
123
|
+
end.jmx(file: 'real_redis_data_set_with_setup.jmx')
|
data/lib/ruby-jmeter/dsl.rb
CHANGED
@@ -519,6 +519,11 @@ module RubyJmeter
|
|
519
519
|
|
520
520
|
alias_method :loadosophia, :loadosophia_uploader
|
521
521
|
|
522
|
+
def redis_data_set(params = {}, &block)
|
523
|
+
node = RubyJmeter::Plugins::RedisDataSet.new(params)
|
524
|
+
attach_node(node, &block)
|
525
|
+
end
|
526
|
+
|
522
527
|
|
523
528
|
|
524
529
|
# API Methods
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RubyJmeter
|
2
|
+
module Plugins
|
3
|
+
class RedisDataSet
|
4
|
+
attr_accessor :doc
|
5
|
+
include Helper
|
6
|
+
def initialize(params={})
|
7
|
+
testname = params.kind_of?(Array) ? 'Redis Data Set Config' : (params[:name] || 'Redis Data Set Config')
|
8
|
+
params[:getMode] ||= "1" unless params[:remove] == true
|
9
|
+
@doc = Nokogiri::XML(<<-XML.strip_heredoc)
|
10
|
+
<kg.apc.jmeter.config.redis.RedisDataSet guiclass="TestBeanGUI" testclass="kg.apc.jmeter.config.redis.RedisDataSet" testname="#{testname}" enabled="true">
|
11
|
+
<stringProp name="database">0</stringProp>
|
12
|
+
<stringProp name="delimiter">,</stringProp>
|
13
|
+
<intProp name="getMode">0</intProp>
|
14
|
+
<stringProp name="host"></stringProp
|
15
|
+
<intProp name="maxActive">20</intProp>
|
16
|
+
<intProp name="maxIdle">10</intProp>
|
17
|
+
<longProp name="maxWait">30000</longProp>
|
18
|
+
<longProp name="minEvictableIdleTimeMillis">60000</longProp>
|
19
|
+
<intProp name="minIdle">0</intProp>
|
20
|
+
<intProp name="numTestsPerEvictionRun">0</intProp>
|
21
|
+
<stringProp name="password"></stringProp>
|
22
|
+
<stringProp name="port">6379</stringProp>
|
23
|
+
<stringProp name="redisKey"></stringProp>
|
24
|
+
<longProp name="softMinEvictableIdleTimeMillis">60000</longProp>
|
25
|
+
<boolProp name="testOnBorrow">false</boolProp>
|
26
|
+
<boolProp name="testOnReturn">false</boolProp>
|
27
|
+
<boolProp name="testWhileIdle">false</boolProp>
|
28
|
+
<longProp name="timeBetweenEvictionRunsMillis">30000</longProp>
|
29
|
+
<stringProp name="timeout">2000</stringProp>
|
30
|
+
<stringProp name="variableNames"></stringProp>
|
31
|
+
<intProp name="whenExhaustedAction">2</intProp>
|
32
|
+
</kg.apc.jmeter.config.redis.RedisDataSet>
|
33
|
+
XML
|
34
|
+
update params
|
35
|
+
update_at_xpath params if params.is_a?(Hash) && params[:update_at_xpath]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ruby-jmeter/version.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -1101,4 +1101,57 @@ describe 'DSL' do
|
|
1101
1101
|
metric_connections.search("//stringProp[@name='']").first.text.should == '1.1.1.1'
|
1102
1102
|
end
|
1103
1103
|
end
|
1104
|
+
|
1105
|
+
describe 'redis data set' do
|
1106
|
+
describe 'random keep' do
|
1107
|
+
let(:doc) do
|
1108
|
+
test do
|
1109
|
+
threads do
|
1110
|
+
redis_data_set name: 'redis data set name',
|
1111
|
+
host: 'the_host',
|
1112
|
+
port: 1234
|
1113
|
+
|
1114
|
+
end
|
1115
|
+
end.to_doc
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
let(:fragment) { doc.search("//kg.apc.jmeter.config.redis.RedisDataSet").first }
|
1119
|
+
|
1120
|
+
it 'should have a name' do
|
1121
|
+
fragment.attributes['testname'].value.should == 'redis data set name'
|
1122
|
+
end
|
1123
|
+
|
1124
|
+
it 'should be configured for random keep' do
|
1125
|
+
fragment.search("//intProp[@name='getMode']").text.should == '1'
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
it 'should point to the host' do
|
1129
|
+
fragment.search("//stringProp[@name='host']").text.should == 'the_host'
|
1130
|
+
end
|
1131
|
+
|
1132
|
+
it 'should configure a port' do
|
1133
|
+
fragment.search("//stringProp[@name='port']").text.should == '1234'
|
1134
|
+
end
|
1135
|
+
end
|
1136
|
+
|
1137
|
+
describe 'random remove' do
|
1138
|
+
let(:doc) do
|
1139
|
+
test do
|
1140
|
+
threads do
|
1141
|
+
redis_data_set remove: true
|
1142
|
+
end
|
1143
|
+
end.to_doc
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
let(:fragment) { doc.search("//kg.apc.jmeter.config.redis.RedisDataSet").first }
|
1147
|
+
|
1148
|
+
it 'should have a default name' do
|
1149
|
+
fragment.attributes['testname'].value.should == 'Redis Data Set Config'
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
it 'should be configured for random remove' do
|
1153
|
+
fragment.search("//intProp[@name='getMode']").text.should == '0'
|
1154
|
+
end
|
1155
|
+
end
|
1156
|
+
end
|
1104
1157
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-jmeter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.13.
|
4
|
+
version: 2.13.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Koopmans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- examples/real_flood_test_data.rb
|
110
110
|
- examples/real_immi.gov.au_visa.rb
|
111
111
|
- examples/real_page_objects.rb
|
112
|
+
- examples/real_redis_data_set_with_setup.rb
|
112
113
|
- examples/real_user_objects_github.rb
|
113
114
|
- lib/ruby-jmeter.rb
|
114
115
|
- lib/ruby-jmeter/DSL.md
|
@@ -248,6 +249,7 @@ files:
|
|
248
249
|
- lib/ruby-jmeter/plugins/latencies_over_time.rb
|
249
250
|
- lib/ruby-jmeter/plugins/loadosophia_uploader.rb
|
250
251
|
- lib/ruby-jmeter/plugins/perfmon_collector.rb
|
252
|
+
- lib/ruby-jmeter/plugins/redis_data_set.rb
|
251
253
|
- lib/ruby-jmeter/plugins/response_codes_per_second.rb
|
252
254
|
- lib/ruby-jmeter/plugins/response_times_distribution.rb
|
253
255
|
- lib/ruby-jmeter/plugins/response_times_over_time.rb
|