2222import org .apache .jmeter .visualizers .backend .AbstractBackendListenerClient ;
2323import org .apache .jmeter .visualizers .backend .BackendListenerContext ;
2424import org .elasticsearch .action .bulk .BulkRequestBuilder ;
25- import org .elasticsearch .client . Client ;
25+ import org .elasticsearch .action . bulk . BulkResponse ;
2626import org .elasticsearch .common .settings .Settings ;
2727import org .elasticsearch .common .transport .InetSocketTransportAddress ;
2828import org .elasticsearch .common .unit .TimeValue ;
@@ -51,7 +51,7 @@ public class ElasticsearchBackend extends AbstractBackendListenerClient {
5151 private static final long DEFAULT_TIMEOUT_MS = 200L ;
5252 private static final Logger logger = LoggerFactory .getLogger (ElasticsearchBackend .class );
5353
54- private Client client ;
54+ private PreBuiltTransportClient client ;
5555 private String index ;
5656 private int buildNumber ;
5757 private int bulkSize ;
@@ -84,7 +84,8 @@ public void setupTest(BackendListenerContext context) throws Exception {
8484 Settings settings = Settings .builder ().put ("cluster.name" , context .getParameter (ES_CLUSTER )).build ();
8585 String host = context .getParameter (ES_HOST );
8686 int port = Integer .parseInt (context .getParameter (ES_PORT ));
87- this .client = new PreBuiltTransportClient (settings ).addTransportAddress (
87+ this .client = new PreBuiltTransportClient (settings );
88+ this .client .addTransportAddress (
8889 new InetSocketTransportAddress (InetAddress .getByName (host ), port ));
8990 this .bulkRequest = this .client .prepareBulk ();
9091 super .setupTest (context );
@@ -101,7 +102,16 @@ public void handleSampleResults(List<SampleResult> results, BackendListenerConte
101102
102103 if (this .bulkRequest .numberOfActions () >= this .bulkSize ) {
103104 try {
104- this .bulkRequest .get (TimeValue .timeValueMillis (timeoutMs ));
105+ BulkResponse bulkResponse = this .bulkRequest .get (TimeValue .timeValueMillis (timeoutMs ));
106+ if (bulkResponse .hasFailures ()) {
107+ if (logger .isErrorEnabled ()) {
108+ logger .error ("Failed to write a result on {}: {}" ,
109+ index , bulkResponse .buildFailureMessage ());
110+ }
111+ } else {
112+ logger .debug ("Wrote {} results in {}." ,
113+ index );
114+ }
105115 } catch (Exception e ) {
106116 logger .error ("Error sending data to ES, data will be lost" , e );
107117 } finally {
0 commit comments