浏览代码

SearchWhileCreatingIndexIT: remove usage of _only_nodes

the only nodes preference was used as a replacement of `_primary` which was removed. Sadly, it's not the same as we also check that it makes sense - i.e., that the given node has a shard copy. Since the test uses indices with >1 shards, the primaries may be spread to multiple nodes. Using one (like it currently does) will fail for some primaries. Using all will probably end up hitting all nodes.

This commit removed the `_only_nodes` usage in favor a simple search

Relates to #26791
Boaz Leskes 8 年之前
父节点
当前提交
84742690cd
共有 1 个文件被更改,包括 5 次插入21 次删除
  1. 5 21
      core/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java

+ 5 - 21
core/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java

@@ -23,7 +23,6 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.cluster.health.ClusterHealthStatus;
-import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
 import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.test.ESIntegTestCase;
 import org.elasticsearch.test.junit.annotations.TestLogging;
@@ -74,21 +73,13 @@ public class SearchWhileCreatingIndexIT extends ESIntegTestCase {
 
         logger.info("using preference {}", preference);
         // we want to make sure that while recovery happens, and a replica gets recovered, its properly refreshed
-        ClusterHealthStatus status = client().admin().cluster().prepareHealth("test").get().getStatus();
-
+        ClusterHealthStatus status = client().admin().cluster().prepareHealth("test").get().getStatus();;
         while (status != ClusterHealthStatus.GREEN) {
-            // first, verify that search on the primary search works
-            for (IndexShardRoutingTable shardRoutingTable : clusterService().state().routingTable().index("test")) {
-                String primaryNode = shardRoutingTable.primaryShard().currentNodeId();
-                SearchResponse searchResponse = client().prepareSearch("test")
-                    .setPreference("_only_nodes:" + primaryNode)
-                    .setQuery(QueryBuilders.termQuery("field", "test"))
-                    .execute().actionGet();
-                assertHitCount(searchResponse, 1);
-                break;
-            }
+            // first, verify that search normal search works
+            SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
+            assertHitCount(searchResponse, 1);
             Client client = client();
-            SearchResponse searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
+            searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
             if (searchResponse.getHits().getTotalHits() != 1) {
                 refresh();
                 SearchResponse searchResponseAfterRefresh = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
@@ -102,13 +93,6 @@ public class SearchWhileCreatingIndexIT extends ESIntegTestCase {
             status = client().admin().cluster().prepareHealth("test").get().getStatus();
             internalCluster().ensureAtLeastNumDataNodes(numberOfReplicas + 1);
         }
-
-        for (String node : internalCluster().nodesInclude("test")) {
-            SearchResponse searchResponse = client().prepareSearch("test")
-                .setPreference("_prefer_nodes:" + node)
-                .setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
-            assertHitCount(searchResponse, 1);
-        }
         cluster().wipeIndices("test");
     }
 }