Skip to content

Commit 813d011

Browse files
author
Christoph Büscher
committed
Adding ccs testing
1 parent 11392de commit 813d011

File tree

2 files changed

+81
-3
lines changed

2 files changed

+81
-3
lines changed

qa/ccs-rolling-upgrade-remote-cluster/src/test/java/org/elasticsearch/upgrades/SearchStatesIT.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,26 @@
4242
import org.elasticsearch.client.RestHighLevelClient;
4343
import org.elasticsearch.client.indices.CreateIndexRequest;
4444
import org.elasticsearch.cluster.metadata.IndexMetadata;
45+
import org.elasticsearch.common.document.DocumentField;
4546
import org.elasticsearch.common.settings.Settings;
47+
import org.elasticsearch.common.settings.Settings.Builder;
4648
import org.elasticsearch.common.xcontent.DeprecationHandler;
4749
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
4850
import org.elasticsearch.common.xcontent.XContentParser;
4951
import org.elasticsearch.common.xcontent.json.JsonXContent;
5052
import org.elasticsearch.rest.action.document.RestIndexAction;
53+
import org.elasticsearch.search.SearchHit;
5154
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
5255
import org.elasticsearch.test.rest.ESRestTestCase;
5356
import org.elasticsearch.test.rest.yaml.ObjectPath;
5457

5558
import java.io.IOException;
5659
import java.io.UncheckedIOException;
5760
import java.util.ArrayList;
61+
import java.util.Collections;
5862
import java.util.List;
5963
import java.util.Map;
64+
import java.util.Optional;
6065
import java.util.concurrent.TimeUnit;
6166
import java.util.stream.Collectors;
6267

@@ -260,4 +265,80 @@ public void testBWCSearchStates() throws Exception {
260265
remoteClient.indices().delete(new DeleteIndexRequest(remoteIndex), RequestOptions.DEFAULT);
261266
}
262267
}
268+
269+
// TODO move test to its own module where local and remote conditions can be controlled better
270+
public void testFieldsOptionEmulation() throws Exception {
271+
String localIndex = "test_bwc_fields_index";
272+
String remoteIndex = "test_bwc_fields_remote_index";
273+
try (RestHighLevelClient localClient = newLocalClient();
274+
RestHighLevelClient remoteClient = newRemoteClient()) {
275+
localClient.indices().create(new CreateIndexRequest(localIndex)
276+
.settings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, between(1, 5))),
277+
RequestOptions.DEFAULT);
278+
int localNumDocs = indexDocs(localClient, localIndex, between(10, 20));
279+
// if not fully upgraded, we should find one node with older version
280+
Optional<Node> oldVersionNode = getNodes(remoteClient.getLowLevelClient()).stream().filter(n -> n.version.before(Version.CURRENT)).findFirst();
281+
if (oldVersionNode.isPresent()) {
282+
System.out.println(oldVersionNode.get());
283+
}
284+
Builder remoteIndexSettings = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, between(1, 5));
285+
if (oldVersionNode.isPresent()) {
286+
remoteIndexSettings.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._name", oldVersionNode.get().name);
287+
}
288+
remoteClient.indices().create(new CreateIndexRequest(remoteIndex)
289+
.settings(remoteIndexSettings),
290+
RequestOptions.DEFAULT);
291+
int remoteNumDocs = indexDocs(remoteClient, remoteIndex, between(10, 20));
292+
int expectedHitCount = localNumDocs + remoteNumDocs;
293+
294+
configureRemoteClusters(getNodes(remoteClient.getLowLevelClient()));
295+
// TODO other test uses 20 iterations, don't understand why, should this do as well?
296+
RestClient lowLevelClient = localClient.getLowLevelClient();
297+
List<Node> localNodes = getNodes(lowLevelClient);
298+
Node currentVersionNode = localNodes.stream().filter(n -> n.version.equals(Version.CURRENT)).findFirst().get();
299+
lowLevelClient
300+
.setNodes(
301+
Collections.singletonList(
302+
new org.elasticsearch.client.Node(
303+
HttpHost.create(currentVersionNode.httpAddress),
304+
null,
305+
null,
306+
currentVersionNode.version.toString(),
307+
null,
308+
null
309+
)
310+
)
311+
);
312+
313+
for (String minimizeRoundTrips : new String[] { "true", "false" }) {
314+
Request request = new Request("POST", "/_search");
315+
request.addParameter("index", localIndex + "," + CLUSTER_ALIAS + ":" + remoteIndex);
316+
if (UPGRADE_FROM_VERSION.onOrAfter(Version.V_7_0_0)) {
317+
request.addParameter("ccs_minimize_roundtrips", minimizeRoundTrips);
318+
}
319+
request.setJsonEntity("{\"_source\": false, \"fields\": [\"*\"] , \"size\": " + expectedHitCount + "}");
320+
Response response = lowLevelClient.performRequest(request);
321+
try (
322+
XContentParser parser = JsonXContent.jsonXContent.createParser(
323+
NamedXContentRegistry.EMPTY,
324+
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
325+
response.getEntity().getContent()
326+
)
327+
) {
328+
SearchResponse searchResponse = SearchResponse.fromXContent(parser);
329+
ElasticsearchAssertions.assertNoFailures(searchResponse);
330+
ElasticsearchAssertions.assertHitCount(searchResponse, expectedHitCount);
331+
SearchHit[] hits = searchResponse.getHits().getHits();
332+
for (SearchHit hit : hits) {
333+
assertFalse("No source in hit expected but was: " + hit.toString(), hit.hasSource());
334+
Map<String, DocumentField> fields = hit.getFields();
335+
assertNotNull(fields);
336+
assertNotNull("Field `f` not found, hit was: " + hit.toString(), fields.get("f"));
337+
}
338+
}
339+
}
340+
localClient.indices().delete(new DeleteIndexRequest(localIndex), RequestOptions.DEFAULT);
341+
remoteClient.indices().delete(new DeleteIndexRequest(remoteIndex), RequestOptions.DEFAULT);
342+
}
343+
}
263344
}

qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/FieldsOptionEmulationIT.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import org.elasticsearch.client.Response;
1616
import org.elasticsearch.client.RestClient;
1717
import org.elasticsearch.cluster.metadata.IndexMetadata;
18-
import org.elasticsearch.common.Strings;
1918
import org.elasticsearch.common.settings.Settings;
20-
import org.elasticsearch.common.xcontent.XContentType;
2119
import org.elasticsearch.test.rest.ESRestTestCase;
2220
import org.elasticsearch.test.rest.yaml.ObjectPath;
2321
import org.junit.Before;
@@ -83,7 +81,6 @@ public void testFieldOptionAdapter() throws Exception {
8381
) {
8482
Response response = client.performRequest(matchAllRequest);
8583
ObjectPath responseObject = ObjectPath.createFromResponse(response);
86-
System.out.println(Strings.toString(responseObject.toXContentBuilder(XContentType.JSON.xContent())));
8784
List<Map<String, Object>> hits = responseObject.evaluate("hits.hits");
8885
assertEquals(10, hits.size());
8986
for (Map<String, Object> hit : hits) {

0 commit comments

Comments
 (0)