1919import org .apache .jmeter .visualizers .backend .AbstractBackendListenerClient ;
2020import org .apache .jmeter .visualizers .backend .BackendListenerContext ;
2121import org .elasticsearch .action .bulk .BulkRequestBuilder ;
22- import org .elasticsearch .client . Client ;
22+ import org .elasticsearch .action . bulk . BulkResponse ;
2323import org .elasticsearch .common .settings .Settings ;
2424import org .elasticsearch .common .transport .InetSocketTransportAddress ;
2525import org .elasticsearch .common .unit .TimeValue ;
@@ -48,7 +48,7 @@ public class ElasticsearchBackend extends AbstractBackendListenerClient {
4848 private static final long DEFAULT_TIMEOUT_MS = 200L ;
4949 private static final Logger logger = LoggerFactory .getLogger (ElasticsearchBackend .class );
5050
51- private Client client ;
51+ private PreBuiltTransportClient client ;
5252 private String index ;
5353 private int buildNumber ;
5454 private int bulkSize ;
@@ -81,7 +81,8 @@ public void setupTest(BackendListenerContext context) throws Exception {
8181 Settings settings = Settings .builder ().put ("cluster.name" , context .getParameter (ES_CLUSTER )).build ();
8282 String host = context .getParameter (ES_HOST );
8383 int port = Integer .parseInt (context .getParameter (ES_PORT ));
84- this .client = new PreBuiltTransportClient (settings ).addTransportAddress (
84+ this .client = new PreBuiltTransportClient (settings );
85+ this .client .addTransportAddress (
8586 new InetSocketTransportAddress (InetAddress .getByName (host ), port ));
8687 this .bulkRequest = this .client .prepareBulk ();
8788 super .setupTest (context );
@@ -98,7 +99,16 @@ public void handleSampleResults(List<SampleResult> results, BackendListenerConte
9899
99100 if (this .bulkRequest .numberOfActions () >= this .bulkSize ) {
100101 try {
101- this .bulkRequest .get (TimeValue .timeValueMillis (timeoutMs ));
102+ BulkResponse bulkResponse = this .bulkRequest .get (TimeValue .timeValueMillis (timeoutMs ));
103+ if (bulkResponse .hasFailures ()) {
104+ if (logger .isErrorEnabled ()) {
105+ logger .error ("Failed to write a result on {}: {}" ,
106+ index , bulkResponse .buildFailureMessage ());
107+ }
108+ } else {
109+ logger .debug ("Wrote {} results in {}." ,
110+ index );
111+ }
102112 } catch (Exception e ) {
103113 logger .error ("Error sending data to ES, data will be lost" , e );
104114 } finally {
0 commit comments