Skip to content

Commit 85d01c2

Browse files
committed
Make DocValueOnlyFieldsIT work for V7x
1 parent 2406751 commit 85d01c2

File tree

4 files changed

+23
-51
lines changed

4 files changed

+23
-51
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
package org.elasticsearch.test.rest;
1111

1212
import io.netty.handler.codec.http.HttpMethod;
13-
1413
import org.apache.http.Header;
1514
import org.apache.http.HttpEntity;
1615
import org.apache.http.HttpHost;
@@ -87,6 +86,7 @@
8786
import org.junit.AfterClass;
8887
import org.junit.Before;
8988

89+
import javax.net.ssl.SSLContext;
9090
import java.io.BufferedReader;
9191
import java.io.IOException;
9292
import java.io.InputStream;
@@ -118,14 +118,13 @@
118118
import java.util.Set;
119119
import java.util.concurrent.TimeUnit;
120120
import java.util.concurrent.atomic.AtomicBoolean;
121+
import java.util.function.BiFunction;
121122
import java.util.function.Consumer;
122123
import java.util.function.Predicate;
123124
import java.util.function.Supplier;
124125
import java.util.regex.Pattern;
125126
import java.util.stream.Collectors;
126127

127-
import javax.net.ssl.SSLContext;
128-
129128
import static java.util.Collections.sort;
130129
import static java.util.Collections.unmodifiableList;
131130
import static org.elasticsearch.client.RestClient.IGNORE_RESPONSE_CODES_PARAM;
@@ -408,6 +407,10 @@ protected static boolean has(ProductFeature feature) {
408407
}
409408

410409
protected List<HttpHost> parseClusterHosts(String hostsString) {
410+
return parseClusterHosts(hostsString, this::buildHttpHost);
411+
}
412+
413+
public static List<HttpHost> parseClusterHosts(String hostsString, BiFunction<String, Integer, HttpHost> httpHostSupplier) {
411414
String[] stringUrls = hostsString.split(",");
412415
List<HttpHost> hosts = new ArrayList<>(stringUrls.length);
413416
for (String stringUrl : stringUrls) {
@@ -417,7 +420,7 @@ protected List<HttpHost> parseClusterHosts(String hostsString) {
417420
}
418421
String host = stringUrl.substring(0, portSeparator);
419422
int port = Integer.valueOf(stringUrl.substring(portSeparator + 1));
420-
hosts.add(buildHttpHost(host, port));
423+
hosts.add(httpHostSupplier.apply(host, port));
421424
}
422425
return unmodifiableList(hosts);
423426
}

x-pack/qa/repository-old-versions-7x/src/javaRestTest/java/org/elasticsearch/oldrepos7x/DocValueOnlyFieldsIT.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.rules.TestRule;
3030

3131
import java.io.IOException;
32+
import java.util.List;
3233

3334
/**
3435
* Tests doc-value-based searches against indices imported from clusters older than N-1.
@@ -43,7 +44,7 @@
4344
public class DocValueOnlyFieldsIT extends ESClientYamlSuiteTestCase {
4445

4546
static final Version oldVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
46-
static boolean setupDone;
47+
static boolean repoRestored;
4748

4849
public static TemporaryFolder repoDirectory = new TemporaryFolder();
4950

@@ -54,8 +55,6 @@ public class DocValueOnlyFieldsIT extends ESClientYamlSuiteTestCase {
5455
.setting("xpack.license.self_generated.type", "trial")
5556
.setting("xpack.ml.enabled", "false")
5657
.setting("path.repo", () -> repoDirectory.getRoot().getPath())
57-
.setting("xpack.searchable.snapshot.shared_cache.size", "16MB")
58-
.setting("xpack.searchable.snapshot.shared_cache.region_size", "256KB")
5958
.build();
6059

6160
public static ElasticsearchCluster oldCluster = ElasticsearchCluster.local()
@@ -73,7 +72,6 @@ public class DocValueOnlyFieldsIT extends ESClientYamlSuiteTestCase {
7372
private static final String REPO_NAME = "doc_values_repo";
7473
private static final String INDEX_NAME = "test";
7574
private static final String snapshotName = "snap";
76-
7775
private static String repoLocation;
7876

7977
public DocValueOnlyFieldsIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {
@@ -111,9 +109,8 @@ public static void setupSnapshot() throws IOException {
111109
"keyword",
112110
"ip",
113111
"geo_point" }; // date is manually added as it need further configuration
114-
115-
int oldEsPort = Integer.parseInt(System.getProperty("tests.es.port"));
116-
try (RestClient oldEs = RestClient.builder(new HttpHost("127.0.0.1", oldEsPort)).build()) {
112+
List<HttpHost> oldClusterHosts = parseClusterHosts(oldCluster.getHttpAddresses(), (host, port) -> new HttpHost(host, port));
113+
try (RestClient oldEs = RestClient.builder(oldClusterHosts.toArray(new HttpHost[oldClusterHosts.size()])).build();) {
117114
Request createIndex = new Request("PUT", "/" + INDEX_NAME);
118115
int numberOfShards = randomIntBetween(1, 3);
119116

@@ -133,7 +130,7 @@ public static void setupSnapshot() throws IOException {
133130
createIndex.setJsonEntity(Strings.toString(settingsBuilder));
134131
assertOK(oldEs.performRequest(createIndex));
135132

136-
Request doc1 = new Request("PUT", "/" + INDEX_NAME + "/" + "doc" + "/" + "1");
133+
Request doc1 = new Request("PUT", "/" + INDEX_NAME + "/" + "_doc" + "/" + "1");
137134
doc1.addParameter("refresh", "true");
138135
XContentBuilder bodyDoc1 = XContentFactory.jsonBuilder()
139136
.startObject()
@@ -153,7 +150,7 @@ public static void setupSnapshot() throws IOException {
153150
doc1.setJsonEntity(Strings.toString(bodyDoc1));
154151
assertOK(oldEs.performRequest(doc1));
155152

156-
Request doc2 = new Request("PUT", "/" + INDEX_NAME + "/" + "doc" + "/" + "2");
153+
Request doc2 = new Request("PUT", "/" + INDEX_NAME + "/" + "_doc" + "/" + "2");
157154
doc2.addParameter("refresh", "true");
158155
XContentBuilder bodyDoc2 = XContentFactory.jsonBuilder()
159156
.startObject()
@@ -191,7 +188,7 @@ public static void setupSnapshot() throws IOException {
191188
public void registerAndRestoreRepo() throws IOException {
192189
// The following is bit of a hack. While we wish we could make this an @BeforeClass, it does not work because the client() is only
193190
// initialized later, so we do it when running the first test
194-
if (setupDone = false) {
191+
if (repoRestored == false) {
195192
// register repo on new ES and restore snapshot
196193
Request createRepoRequest2 = new Request("PUT", "/_snapshot/" + REPO_NAME);
197194
createRepoRequest2.setJsonEntity(Strings.format("""
@@ -204,7 +201,13 @@ public void registerAndRestoreRepo() throws IOException {
204201
createRestoreRequest.setJsonEntity("{\"indices\":\"" + INDEX_NAME + "\"}");
205202
assertOK(client().performRequest(createRestoreRequest));
206203

207-
setupDone = true;
204+
repoRestored = true;
208205
}
206+
logger.info("repo [" + REPO_NAME + "] restored");
207+
}
208+
209+
@Override
210+
protected String getTestRestCluster() {
211+
return currentCluster.getHttpAddresses();
209212
}
210213
}

x-pack/qa/repository-old-versions-7x/src/javaRestTest/java/org/elasticsearch/oldrepos7x/OldMappingsIT.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
import org.junit.rules.TestRule;
3131

3232
import java.io.IOException;
33-
import java.util.ArrayList;
3433
import java.util.Arrays;
3534
import java.util.List;
3635
import java.util.Map;
3736
import java.util.stream.Collectors;
3837

39-
import static java.util.Collections.unmodifiableList;
4038
import static org.hamcrest.Matchers.containsString;
4139
import static org.hamcrest.Matchers.hasKey;
4240
import static org.hamcrest.Matchers.hasSize;
@@ -103,7 +101,7 @@ public static void setupOldRepo() throws IOException {
103101
repoName = "old_mappings_repo";
104102
snapshotName = "snap";
105103

106-
List<HttpHost> oldClusterHosts = parseOldClusterHosts(oldCluster.getHttpAddresses());
104+
List<HttpHost> oldClusterHosts = parseClusterHosts(oldCluster.getHttpAddresses(), (host, port) -> new HttpHost(host, port));
107105
try (RestClient oldEsClient = RestClient.builder(oldClusterHosts.toArray(new HttpHost[oldClusterHosts.size()])).build();) {
108106
assertOK(oldEsClient.performRequest(createIndex("filebeat", "filebeat.json")));
109107

@@ -200,21 +198,6 @@ public void registerAndRestoreRepo() throws IOException {
200198
}
201199
}
202200

203-
private static List<HttpHost> parseOldClusterHosts(String hostsString) {
204-
String[] stringUrls = hostsString.split(",");
205-
List<HttpHost> hosts = new ArrayList<>(stringUrls.length);
206-
for (String stringUrl : stringUrls) {
207-
int portSeparator = stringUrl.lastIndexOf(':');
208-
if (portSeparator < 0) {
209-
throw new IllegalArgumentException("Illegal cluster url [" + stringUrl + "]");
210-
}
211-
String host = stringUrl.substring(0, portSeparator);
212-
int port = Integer.valueOf(stringUrl.substring(portSeparator + 1));
213-
hosts.add(new HttpHost(host, port));
214-
}
215-
return unmodifiableList(hosts);
216-
}
217-
218201
public void testFileBeatApache2MappingOk() throws IOException {
219202
Request mappingRequest = new Request("GET", "/" + "filebeat" + "/_mapping");
220203
Map<String, Object> mapping = entityAsMap(client().performRequest(mappingRequest));

x-pack/qa/repository-old-versions-7x/src/javaRestTest/java/org/elasticsearch/oldrepos7x/OldRepositoryAccessIT.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.junit.rules.TestRule;
4545

4646
import java.io.IOException;
47-
import java.util.ArrayList;
4847
import java.util.Arrays;
4948
import java.util.Comparator;
5049
import java.util.HashMap;
@@ -54,7 +53,6 @@
5453
import java.util.Set;
5554
import java.util.stream.Collectors;
5655

57-
import static java.util.Collections.unmodifiableList;
5856
import static org.hamcrest.Matchers.contains;
5957
import static org.hamcrest.Matchers.containsString;
6058
import static org.hamcrest.Matchers.empty;
@@ -106,7 +104,7 @@ public class OldRepositoryAccessIT extends ESRestTestCase {
106104
@BeforeClass
107105
public static void setupOldRepo() throws IOException {
108106
String repoLocationBase = repoDirectory.getRoot().getPath();
109-
List<HttpHost> oldClusterHosts = parseOldClusterHosts(oldCluster.getHttpAddresses());
107+
List<HttpHost> oldClusterHosts = parseClusterHosts(oldCluster.getHttpAddresses(), (host, port) -> new HttpHost(host, port));
110108
Version oldVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
111109
try (RestClient oldEs = RestClient.builder(oldClusterHosts.toArray(new HttpHost[oldClusterHosts.size()])).build()) {
112110
checkClusterVersion(oldEs, oldVersion);
@@ -524,19 +522,4 @@ private static void closeIndex(RestClient client, String index) throws IOExcepti
524522
ObjectPath doc = ObjectPath.createFromResponse(client.performRequest(request));
525523
assertTrue(doc.evaluate("shards_acknowledged"));
526524
}
527-
528-
private static List<HttpHost> parseOldClusterHosts(String hostsString) {
529-
String[] stringUrls = hostsString.split(",");
530-
List<HttpHost> hosts = new ArrayList<>(stringUrls.length);
531-
for (String stringUrl : stringUrls) {
532-
int portSeparator = stringUrl.lastIndexOf(':');
533-
if (portSeparator < 0) {
534-
throw new IllegalArgumentException("Illegal cluster url [" + stringUrl + "]");
535-
}
536-
String host = stringUrl.substring(0, portSeparator);
537-
int port = Integer.valueOf(stringUrl.substring(portSeparator + 1));
538-
hosts.add(new HttpHost(host, port));
539-
}
540-
return unmodifiableList(hosts);
541-
}
542525
}

0 commit comments

Comments
 (0)