@@ -67,17 +67,18 @@ public Arguments getDefaultParameters() {
6767 @ Override
6868 public void setupTest (BackendListenerContext context ) throws Exception {
6969 try {
70- String host = context .getParameter (ES_HOST );
71- this .filters = new LinkedList <String >();
72- int port = Integer .parseInt (context .getParameter (ES_PORT ));
73- this .index = context .getParameter (ES_INDEX ).toLowerCase ();
74- this .bulkSize = Integer .parseInt (context .getParameter (ES_BULK_SIZE ));
75- this .timeoutMs = JMeterUtils .getPropDefault (ES_TIMEOUT_MS , DEFAULT_TIMEOUT_MS );
76- this .buildNumber = (JMeterUtils .getProperty (ElasticsearchBackend .BUILD_NUMBER ) != null && JMeterUtils .getProperty (ElasticsearchBackend .BUILD_NUMBER ).trim () != "" )
77- ? Integer .parseInt (JMeterUtils .getProperty (ElasticsearchBackend .BUILD_NUMBER )) : 0 ;
70+ String host = context .getParameter (ES_HOST );
71+ int port = Integer .parseInt (context .getParameter (ES_PORT ));
72+
73+ this .filters = new LinkedList <String >();
74+ this .bulkRequestList = new LinkedList <String >();
75+ this .index = context .getParameter (ES_INDEX ).toLowerCase ();
76+ this .bulkSize = Integer .parseInt (context .getParameter (ES_BULK_SIZE ));
77+ this .timeoutMs = JMeterUtils .getPropDefault (ES_TIMEOUT_MS , DEFAULT_TIMEOUT_MS );
78+ this .buildNumber = (JMeterUtils .getProperty (ElasticsearchBackend .BUILD_NUMBER ) != null && JMeterUtils .getProperty (ElasticsearchBackend .BUILD_NUMBER ).trim () != "" ) ? Integer .parseInt (JMeterUtils .getProperty (ElasticsearchBackend .BUILD_NUMBER )) : 0 ;
7879 this .client = RestClient .builder (new HttpHost (context .getParameter (ES_HOST ), port , context .getParameter (ES_SCHEME )))
7980 .setRequestConfigCallback (requestConfigBuilder -> requestConfigBuilder .setConnectTimeout (5000 )
80- .setSocketTimeout ((int ) timeoutMs ))
81+ .setSocketTimeout ((int ) timeoutMs ))
8182 .setFailureListener (new RestClient .FailureListener () {
8283 @ Override
8384 public void onFailure (HttpHost host ) {
@@ -86,7 +87,7 @@ public void onFailure(HttpHost host) {
8687 })
8788 .setMaxRetryTimeoutMillis (60000 )
8889 .build ();
89- this . bulkRequestList = new LinkedList < String >();
90+
9091 String [] filterArray = (context .getParameter (ES_SAMPLE_FILTER ).contains (";" )) ? context .getParameter (ES_SAMPLE_FILTER ).split (";" ) : new String [] {context .getParameter (ES_SAMPLE_FILTER )};
9192 if (filterArray .length >= 1 && filterArray [0 ].trim () != "" ) {
9293 for (String filter : filterArray ) {
@@ -123,11 +124,8 @@ public void handleSampleResults(List<SampleResult> results, BackendListenerConte
123124 }
124125 }
125126
126- if (validSample ) {
127- Gson gson = new Gson ();
128- String json = gson .toJson (this .getElasticData (sr , context ));
129- this .bulkRequestList .add (json );
130- }
127+ if (validSample )
128+ this .bulkRequestList .add (new Gson ().toJson (this .getElasticData (sr , context )));
131129 }
132130
133131 if (this .bulkRequestList .size () >= this .bulkSize ) {
0 commit comments