Java api: Remove unneeded getTookInMillis method (#23923)

Some response classes in the java api expose both `getTook()` which returns a `TimeValue` and `getTookInMillis` which returns a `long` value. `getTook()` is enough as one can do `getTook().millis()` to obtain the same result as `getTookInMillis()`, which can be removed.
This commit is contained in:
olcbean 2017-06-02 11:11:05 +02:00 committed by Luca Cavanna
parent 779fb9a1c0
commit 6dea5f14c3
9 changed files with 19 additions and 27 deletions

View File

@ -580,7 +580,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
BulkResponse bulkResponse = execute(bulkRequest, highLevelClient()::bulk, highLevelClient()::bulkAsync);
assertEquals(RestStatus.OK, bulkResponse.status());
assertTrue(bulkResponse.getTookInMillis() > 0);
assertTrue(bulkResponse.getTook().getMillis() > 0);
assertEquals(nbItems, bulkResponse.getItems().length);
validateBulkResponses(nbItems, errors, bulkResponse, bulkRequest);
@ -671,7 +671,7 @@ public class CrudIT extends ESRestHighLevelClientTestCase {
BulkRequest bulkRequest = requestRef.get();
assertEquals(RestStatus.OK, bulkResponse.status());
assertTrue(bulkResponse.getTookInMillis() > 0);
assertTrue(bulkResponse.getTook().getMillis() > 0);
assertEquals(nbItems, bulkResponse.getItems().length);
assertNull(error.get());

View File

@ -76,13 +76,6 @@ public class BulkResponse extends ActionResponse implements Iterable<BulkItemRes
return new TimeValue(tookInMillis);
}
/**
* How long the bulk execution took in milliseconds. Excluding ingest preprocessing.
*/
public long getTookInMillis() {
return tookInMillis;
}
/**
* If ingest is enabled returns the bulk ingest preprocessing time, otherwise 0 is returned.
*/

View File

@ -569,9 +569,9 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
ActionListener<BulkResponse> wrapActionListenerIfNeeded(long ingestTookInMillis, ActionListener<BulkResponse> actionListener) {
if (itemResponses.isEmpty()) {
return ActionListener.wrap(
response -> actionListener.onResponse(
new BulkResponse(response.getItems(), response.getTookInMillis(), ingestTookInMillis)),
actionListener::onFailure);
response -> actionListener.onResponse(new BulkResponse(response.getItems(),
response.getTook().getMillis(), ingestTookInMillis)),
actionListener::onFailure);
} else {
return new IngestBulkResponseListener(ingestTookInMillis, originalSlots, itemResponses, actionListener);
}
@ -610,7 +610,9 @@ public class TransportBulkAction extends HandledTransportAction<BulkRequest, Bul
for (int i = 0; i < items.length; i++) {
itemResponses.add(originalSlots[i], response.getItems()[i]);
}
actionListener.onResponse(new BulkResponse(itemResponses.toArray(new BulkItemResponse[itemResponses.size()]), response.getTookInMillis(), ingestTookInMillis));
actionListener.onResponse(new BulkResponse(
itemResponses.toArray(new BulkItemResponse[itemResponses.size()]),
response.getTook().getMillis(), ingestTookInMillis));
}
@Override

View File

@ -135,13 +135,6 @@ public class SearchResponse extends ActionResponse implements StatusToXContentOb
return new TimeValue(tookInMillis);
}
/**
* How long the search took in milliseconds.
*/
public long getTookInMillis() {
return tookInMillis;
}
/**
* The total number of shards the search was executed on.
*/

View File

@ -334,10 +334,6 @@ public class TermVectorsResponse extends ActionResponse implements ToXContentObj
return new TimeValue(tookInMillis);
}
public long getTookInMillis() {
return tookInMillis;
}
private void buildScore(XContentBuilder builder, BoostAttribute boostAtt) throws IOException {
if (hasScores) {
builder.field(FieldStrings.SCORE, boostAtt.getBoost());

View File

@ -95,7 +95,7 @@ public class BulkResponseTests extends ESTestCase {
assertNull(parser.nextToken());
}
assertEquals(took, parsedBulkResponse.getTookInMillis());
assertEquals(took, parsedBulkResponse.getTook().getMillis());
assertEquals(ingestTook, parsedBulkResponse.getIngestTookInMillis());
assertEquals(expectedBulkItems.length, parsedBulkResponse.getItems().length);

View File

@ -73,7 +73,8 @@ public class TermVectorsServiceTests extends ESSingleNodeTestCase {
TermVectorsResponse response = TermVectorsService.getTermVectors(shard, request, longs.iterator()::next);
assertThat(response, notNullValue());
assertThat(response.getTookInMillis(), equalTo(TimeUnit.NANOSECONDS.toMillis(longs.get(1) - longs.get(0))));
assertThat(response.getTook().getMillis(),
equalTo(TimeUnit.NANOSECONDS.toMillis(longs.get(1) - longs.get(0))));
}
public void testDocFreqs() throws IOException {

View File

@ -802,7 +802,8 @@ public class HighlighterSearchIT extends ESIntegTestCase {
* in the neighborhood of 300ms and the large phrase limit is in the
* neighborhood of 8 seconds.
*/
assertThat(defaultPhraseLimit.getTookInMillis(), lessThan(largePhraseLimit.getTookInMillis()));
assertThat(defaultPhraseLimit.getTook().getMillis(),
lessThan(largePhraseLimit.getTook().getMillis()));
}

View File

@ -35,3 +35,9 @@ code for ordering buckets. The `BucketOrder` class must be used instead of `Term
`Histogram.Order`. The `static` methods in the `BucketOrder` class must be called instead of directly
accessing internal order instances, e.g. `BucketOrder.count(boolean)` and `BucketOrder.aggregation(String, boolean)`.
Use `BucketOrder.key(boolean)` to order the `terms` aggregation buckets by `_term`.
=== `getTookInMillis()` removed in `BulkResponse`, `SearchResponse` and `TermVectorsResponse`
In `BulkResponse`, `SearchResponse` and `TermVectorsResponse` `getTookInMiilis()` method
has been removed in favor of `getTook` method. `getTookInMiilis()` is easily replaced by
`getTook().getMillis()`.