code:     private static void verify(ActionRequestBuilder requestBuilder, boolean fail, long expectedCount) {
          if (fail) {
              if (requestBuilder instanceof MultiSearchRequestBuilder) {
                  MultiSearchResponse multiSearchResponse = ((MultiSearchRequestBuilder) requestBuilder).get();
                  assertThat(multiSearchResponse.getResponses().length, equalTo(1));
                  assertThat(multiSearchResponse.getResponses()[0].getResponse(), nullValue());
              } else {
                  try {
                      requestBuilder.get();
                      fail("IndexMissingException or IndexClosedException was expected");
                  } catch (IndexMissingException | IndexClosedException e) {}
              }
          } else {
              if (requestBuilder instanceof SearchRequestBuilder) {
                  SearchRequestBuilder searchRequestBuilder = (SearchRequestBuilder) requestBuilder;
                  assertHitCount(searchRequestBuilder.get(), expectedCount);
              } else if (requestBuilder instanceof CountRequestBuilder) {
                  CountRequestBuilder countRequestBuilder = (CountRequestBuilder) requestBuilder;
                  assertHitCount(countRequestBuilder.get(), expectedCount);
              } else if (requestBuilder instanceof MultiSearchRequestBuilder) {
                  MultiSearchResponse multiSearchResponse = ((MultiSearchRequestBuilder) requestBuilder).get();
                  assertThat(multiSearchResponse.getResponses().length, equalTo(1));
                  assertThat(multiSearchResponse.getResponses()[0].getResponse(), notNullValue());
              } else {
                  requestBuilder.get();
              }
          }
      }
  
  