adapt to upstream java count api removal

Original commit: elastic/x-pack-elasticsearch@ea6c53b88e
This commit is contained in:
javanna 2015-10-19 15:10:59 +02:00 committed by Luca Cavanna
parent f523a476e1
commit baa36f7bae
11 changed files with 16 additions and 45 deletions

View File

@ -214,10 +214,6 @@ import org.elasticsearch.action.bulk.BulkAction;
import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.count.CountAction;
import org.elasticsearch.action.count.CountRequest;
import org.elasticsearch.action.count.CountRequestBuilder;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.delete.DeleteAction; import org.elasticsearch.action.delete.DeleteAction;
import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteRequestBuilder; import org.elasticsearch.action.delete.DeleteRequestBuilder;
@ -257,8 +253,6 @@ import org.elasticsearch.action.suggest.SuggestAction;
import org.elasticsearch.action.suggest.SuggestRequest; import org.elasticsearch.action.suggest.SuggestRequest;
import org.elasticsearch.action.suggest.SuggestRequestBuilder; import org.elasticsearch.action.suggest.SuggestRequestBuilder;
import org.elasticsearch.action.suggest.SuggestResponse; import org.elasticsearch.action.suggest.SuggestResponse;
import org.elasticsearch.action.support.AdapterActionFuture;
import org.elasticsearch.action.support.DelegatingActionListener;
import org.elasticsearch.action.termvectors.*; import org.elasticsearch.action.termvectors.*;
import org.elasticsearch.action.update.UpdateAction; import org.elasticsearch.action.update.UpdateAction;
import org.elasticsearch.action.update.UpdateRequest; import org.elasticsearch.action.update.UpdateRequest;
@ -506,28 +500,6 @@ public class SecuredClient implements Client {
return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE); return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE);
} }
public ActionFuture<CountResponse> count(CountRequest request) {
AdapterActionFuture actionFuture = new AdapterActionFuture<CountResponse, SearchResponse>() {
protected CountResponse convert(SearchResponse listenerResponse) {
return new CountResponse(listenerResponse);
}
};
this.execute(SearchAction.INSTANCE, request.toSearchRequest(), actionFuture);
return actionFuture;
}
public void count(CountRequest request, final ActionListener<CountResponse> listener) {
this.execute(SearchAction.INSTANCE, request.toSearchRequest(), new DelegatingActionListener<SearchResponse, CountResponse>(listener) {
protected CountResponse getDelegatedFromInstigator(SearchResponse response) {
return new CountResponse(response);
}
});
}
public CountRequestBuilder prepareCount(String... indices) {
return new CountRequestBuilder(this, CountAction.INSTANCE).setIndices(indices);
}
public ActionFuture<ExistsResponse> exists(ExistsRequest request) { public ActionFuture<ExistsResponse> exists(ExistsRequest request) {
return this.execute(ExistsAction.INSTANCE, request); return this.execute(ExistsAction.INSTANCE, request);
} }

View File

@ -57,7 +57,7 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
securedFlush(); securedFlush();
securedRefresh(); securedRefresh();
assertHitCount(client().prepareCount().get(), nbDocs); assertHitCount(client().prepareSearch().setSize(0).get(), nbDocs);
Collection<MarvelDoc> results = newClusterStateCollector().doCollect(); Collection<MarvelDoc> results = newClusterStateCollector().doCollect();
assertThat(results, hasSize(1)); assertThat(results, hasSize(1));
@ -99,7 +99,7 @@ public class ClusterStateCollectorTests extends AbstractCollectorTestCase {
securedFlush(); securedFlush();
securedRefresh(); securedRefresh();
for (int i = 0; i < nbIndices; i++) { for (int i = 0; i < nbIndices; i++) {
assertHitCount(client().prepareCount("test-" + i).get(), docsPerIndex[i]); assertHitCount(client().prepareSearch("test-" + i).setSize(0).get(), docsPerIndex[i]);
} }
Collection<MarvelDoc> results = newClusterStateCollector().doCollect(); Collection<MarvelDoc> results = newClusterStateCollector().doCollect();

View File

@ -70,8 +70,8 @@ public class IndexRecoveryCollectorTests extends AbstractCollectorTestCase {
client().prepareIndex("other", "bar").setSource("value", randomInt()).get(); client().prepareIndex("other", "bar").setSource("value", randomInt()).get();
flushAndRefresh(); flushAndRefresh();
assertHitCount(client().prepareCount(indexName).get(), numDocs); assertHitCount(client().prepareSearch(indexName).setSize(0).get(), numDocs);
assertHitCount(client().prepareCount("other").get(), 1L); assertHitCount(client().prepareSearch("other").setSize(0).get(), 1L);
logger.info("--> start second node"); logger.info("--> start second node");
final String node2 = internalCluster().startNode(); final String node2 = internalCluster().startNode();

View File

@ -48,7 +48,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
securedRefresh(); securedRefresh();
securedEnsureGreen(indexName); securedEnsureGreen(indexName);
assertHitCount(client().prepareCount().get(), nbDocs); assertHitCount(client().prepareSearch().setSize(0).get(), nbDocs);
Collection<MarvelDoc> results = newIndexStatsCollector().doCollect(); Collection<MarvelDoc> results = newIndexStatsCollector().doCollect();
assertThat(results, hasSize(1)); assertThat(results, hasSize(1));
@ -92,7 +92,7 @@ public class IndexStatsCollectorTests extends AbstractCollectorTestCase {
securedEnsureGreen(indexPrefix + "*"); securedEnsureGreen(indexPrefix + "*");
for (int i = 0; i < nbIndices; i++) { for (int i = 0; i < nbIndices; i++) {
assertHitCount(client().prepareCount(indexPrefix + i).get(), docsPerIndex[i]); assertHitCount(client().prepareSearch(indexPrefix + i).setSize(0).get(), docsPerIndex[i]);
} }
String clusterUUID = client().admin().cluster().prepareState().setMetaData(true).get().getState().metaData().clusterUUID(); String clusterUUID = client().admin().cluster().prepareState().setMetaData(true).get().getState().metaData().clusterUUID();

View File

@ -49,7 +49,7 @@ public class ShardsCollectorTests extends AbstractCollectorTestCase {
ensureGreen(); ensureGreen();
refresh(); refresh();
assertHitCount(client().prepareCount().get(), nbDocs); assertHitCount(client().prepareSearch().setSize(0).get(), nbDocs);
Collection<MarvelDoc> results = newShardsCollector().doCollect(); Collection<MarvelDoc> results = newShardsCollector().doCollect();
assertThat(results, hasSize(getNumShards("test-shards").totalNumShards)); assertThat(results, hasSize(getNumShards("test-shards").totalNumShards));
@ -117,7 +117,7 @@ public class ShardsCollectorTests extends AbstractCollectorTestCase {
refresh(); refresh();
for (int i = 0; i < nbIndices; i++) { for (int i = 0; i < nbIndices; i++) {
assertHitCount(client().prepareCount(indexPrefix + String.valueOf(i)).get(), nbDocsPerIndex[i]); assertHitCount(client().prepareSearch(indexPrefix + String.valueOf(i)).setSize(0).get(), nbDocsPerIndex[i]);
} }
Collection<MarvelDoc> results = newShardsCollector().doCollect(); Collection<MarvelDoc> results = newShardsCollector().doCollect();

View File

@ -116,7 +116,7 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
securedFlush(); securedFlush();
securedRefresh(); securedRefresh();
assertHitCount(client().prepareCount() assertHitCount(client().prepareSearch().setSize(0)
.setIndices(MarvelSettings.MARVEL_DATA_INDEX_NAME) .setIndices(MarvelSettings.MARVEL_DATA_INDEX_NAME)
.setTypes(ClusterInfoCollector.TYPE) .setTypes(ClusterInfoCollector.TYPE)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()

View File

@ -89,7 +89,7 @@ public class ClusterStateTests extends MarvelIntegTestCase {
DiscoveryNodes nodes = client().admin().cluster().prepareState().clear().setNodes(true).get().getState().nodes(); DiscoveryNodes nodes = client().admin().cluster().prepareState().clear().setNodes(true).get().getState().nodes();
logger.debug("--> ensure that the 'nodes' attributes of the cluster state document is not indexed"); logger.debug("--> ensure that the 'nodes' attributes of the cluster state document is not indexed");
assertHitCount(client().prepareCount() assertHitCount(client().prepareSearch().setSize(0)
.setTypes(ClusterStateCollector.TYPE) .setTypes(ClusterStateCollector.TYPE)
.setQuery(QueryBuilders.matchQuery("cluster_state.nodes." + nodes.masterNodeId() + ".name", nodes.masterNode().name())).get(), 0L); .setQuery(QueryBuilders.matchQuery("cluster_state.nodes." + nodes.masterNodeId() + ".name", nodes.masterNode().name())).get(), 0L);
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.marvel.agent.renderer.indices; package org.elasticsearch.marvel.agent.renderer.indices;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
@ -76,11 +75,12 @@ public class IndexStatsTests extends MarvelIntegTestCase {
securedFlush(indices); securedFlush(indices);
securedRefresh(); securedRefresh();
for (int i = 0; i < nbIndices; i++) { for (int i = 0; i < nbIndices; i++) {
CountResponse count = client().prepareCount() SearchResponse count = client().prepareSearch()
.setSize(0)
.setTypes(IndexStatsCollector.TYPE) .setTypes(IndexStatsCollector.TYPE)
.setQuery(QueryBuilders.termQuery("index_stats.index", indices[i])) .setQuery(QueryBuilders.termQuery("index_stats.index", indices[i]))
.get(); .get();
assertThat(count.getCount(), greaterThan(0L)); assertThat(count.getHits().totalHits(), greaterThan(0L));
} }
} }
}); });

View File

@ -177,8 +177,8 @@ public abstract class MarvelIntegTestCase extends ESIntegTestCase {
protected void assertMarvelDocsCount(Matcher<Long> matcher, String... types) { protected void assertMarvelDocsCount(Matcher<Long> matcher, String... types) {
try { try {
long count = client().prepareCount(MarvelSettings.MARVEL_INDICES_PREFIX + "*") long count = client().prepareSearch(MarvelSettings.MARVEL_INDICES_PREFIX + "*").setSize(0)
.setTypes(types).get().getCount(); .setTypes(types).get().getHits().totalHits();
logger.trace("--> searched for [{}] documents, found [{}]", Strings.arrayToCommaDelimitedString(types), count); logger.trace("--> searched for [{}] documents, found [{}]", Strings.arrayToCommaDelimitedString(types), count);
assertThat(count, matcher); assertThat(count, matcher);
} catch (IndexNotFoundException e) { } catch (IndexNotFoundException e) {

View File

@ -51,7 +51,6 @@ indices:monitor/settings/get
indices:monitor/shard_stores indices:monitor/shard_stores
indices:monitor/stats indices:monitor/stats
indices:monitor/upgrade indices:monitor/upgrade
indices:data/read/count
indices:data/read/exists indices:data/read/exists
indices:data/read/explain indices:data/read/explain
indices:data/read/field_stats indices:data/read/field_stats

View File

@ -157,7 +157,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
assertThat(deleteWatchResponse.isFound(), is(true)); assertThat(deleteWatchResponse.isFound(), is(true));
refresh(); refresh();
assertHitCount(client().prepareCount(WatchStore.INDEX).get(), 0l); assertHitCount(client().prepareSearch(WatchStore.INDEX).setSize(0).get(), 0l);
// Deleting the same watch for the second time // Deleting the same watch for the second time
deleteWatchResponse = watcherClient.prepareDeleteWatch("_name").get(); deleteWatchResponse = watcherClient.prepareDeleteWatch("_name").get();