2727import org .elasticsearch .client .Client ;
2828import org .elasticsearch .client .Requests ;
2929import org .elasticsearch .cluster .metadata .IndexMetaData ;
30+ import org .elasticsearch .common .bytes .BytesArray ;
3031import org .elasticsearch .common .settings .Settings ;
3132import org .elasticsearch .common .unit .ByteSizeUnit ;
3233import org .elasticsearch .common .unit .ByteSizeValue ;
3334import org .elasticsearch .common .unit .TimeValue ;
35+ import org .elasticsearch .common .xcontent .XContentType ;
36+ import org .elasticsearch .common .xcontent .json .JsonXContent ;
3437import org .elasticsearch .env .Environment ;
3538import org .elasticsearch .test .ESIntegTestCase ;
3639import org .elasticsearch .transport .MockTransportClient ;
5457import static org .hamcrest .Matchers .lessThanOrEqualTo ;
5558
5659public class BulkProcessorIT extends ESIntegTestCase {
57- public void testThatBulkProcessorCountIsCorrect () throws InterruptedException {
60+ public void testThatBulkProcessorCountIsCorrect () throws Exception {
5861 final CountDownLatch latch = new CountDownLatch (1 );
5962 BulkProcessorTestListener listener = new BulkProcessorTestListener (latch );
6063
@@ -77,7 +80,7 @@ public void testThatBulkProcessorCountIsCorrect() throws InterruptedException {
7780 }
7881 }
7982
80- public void testBulkProcessorFlush () throws InterruptedException {
83+ public void testBulkProcessorFlush () throws Exception {
8184 final CountDownLatch latch = new CountDownLatch (1 );
8285 BulkProcessorTestListener listener = new BulkProcessorTestListener (latch );
8386
@@ -296,11 +299,18 @@ public void testBulkProcessorConcurrentRequestsReadOnlyIndex() throws Exception
296299 assertMultiGetResponse (multiGetRequestBuilder .get (), testDocs );
297300 }
298301
299- private static MultiGetRequestBuilder indexDocs (Client client , BulkProcessor processor , int numDocs ) {
302+ private static MultiGetRequestBuilder indexDocs (Client client , BulkProcessor processor , int numDocs ) throws Exception {
300303 MultiGetRequestBuilder multiGetRequestBuilder = client .prepareMultiGet ();
301304 for (int i = 1 ; i <= numDocs ; i ++) {
302- processor .add (new IndexRequest ("test" , "test" , Integer .toString (i ))
303- .source (Requests .INDEX_CONTENT_TYPE , "field" , randomRealisticUnicodeOfLengthBetween (1 , 30 )));
305+ if (randomBoolean ()) {
306+ processor .add (new IndexRequest ("test" , "test" , Integer .toString (i ))
307+ .source (Requests .INDEX_CONTENT_TYPE , "field" , randomRealisticUnicodeOfLengthBetween (1 , 30 )));
308+ } else {
309+ final String source = "{ \" index\" :{\" _index\" :\" test\" ,\" _type\" :\" test\" ,\" _id\" :\" " + Integer .toString (i ) + "\" } }\n "
310+ + JsonXContent .contentBuilder ()
311+ .startObject ().field ("field" , randomRealisticUnicodeOfLengthBetween (1 , 30 )).endObject ().string () + "\n " ;
312+ processor .add (new BytesArray (source ), null , null , XContentType .JSON );
313+ }
304314 multiGetRequestBuilder .add ("test" , "test" , Integer .toString (i ));
305315 }
306316 return multiGetRequestBuilder ;
@@ -313,7 +323,8 @@ private static void assertResponseItems(List<BulkItemResponse> bulkItemResponses
313323 assertThat (bulkItemResponse .getIndex (), equalTo ("test" ));
314324 assertThat (bulkItemResponse .getType (), equalTo ("test" ));
315325 assertThat (bulkItemResponse .getId (), equalTo (Integer .toString (i ++)));
316- assertThat (bulkItemResponse .isFailed (), equalTo (false ));
326+ assertThat ("item " + i + " failed with cause: " + bulkItemResponse .getFailureMessage (),
327+ bulkItemResponse .isFailed (), equalTo (false ));
317328 }
318329 }
319330
0 commit comments