Skip to content

Commit 9f2d1e4

Browse files
authored
Test/add custom analyzer old versions (#119759)
Tsts to cover archive-indices and searchable-snapshots created for versions v5/v6 containing a custom analyzer with standard-token-filter.
1 parent 4ac8d55 commit 9f2d1e4

15 files changed

+476
-18
lines changed

x-pack/qa/repository-old-versions-compatibility/src/javaRestTest/java/org/elasticsearch/oldrepos/AbstractUpgradeCompatibilityTestCase.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
import java.nio.file.Path;
3737
import java.nio.file.Paths;
3838
import java.util.Comparator;
39+
import java.util.List;
3940
import java.util.Objects;
41+
import java.util.function.Consumer;
4042
import java.util.stream.Stream;
4143
import java.util.zip.ZipEntry;
4244
import java.util.zip.ZipInputStream;
@@ -74,10 +76,16 @@ public abstract class AbstractUpgradeCompatibilityTestCase extends ESRestTestCas
7476

7577
private final Version clusterVersion;
7678
private final String indexCreatedVersion;
79+
private final Consumer<List<String>> warningsConsumer;
7780

78-
public AbstractUpgradeCompatibilityTestCase(@Name("cluster") Version clusterVersion, String indexCreatedVersion) {
81+
public AbstractUpgradeCompatibilityTestCase(
82+
@Name("cluster") Version clusterVersion,
83+
String indexCreatedVersion,
84+
Consumer<List<String>> warningsConsumer
85+
) {
7986
this.clusterVersion = clusterVersion;
8087
this.indexCreatedVersion = indexCreatedVersion;
88+
this.warningsConsumer = warningsConsumer;
8189
}
8290

8391
@ParametersFactory
@@ -143,7 +151,7 @@ public int compare(TestMethodAndParams o1, TestMethodAndParams o2) {
143151
}
144152
}
145153

146-
public final void verifyCompatibility(String version) throws Exception {
154+
protected final void verifyCompatibility(String version, Consumer<List<String>> warningsConsumer) throws Exception {
147155
final String repository = "repository";
148156
final String snapshot = "snapshot";
149157
final String index = "index";
@@ -158,7 +166,7 @@ public final void verifyCompatibility(String version) throws Exception {
158166
// Copy a snapshot of an index with 5 documents
159167
copySnapshotFromResources(repositoryPath, version);
160168
registerRepository(client(), repository, FsRepository.TYPE, true, Settings.builder().put("location", repositoryPath).build());
161-
recover(client(), repository, snapshot, index);
169+
recover(client(), repository, snapshot, index, warningsConsumer);
162170

163171
assertTrue(getIndices(client()).contains(index));
164172
assertDocCount(client(), index, numDocs);
@@ -173,7 +181,13 @@ public final void verifyCompatibility(String version) throws Exception {
173181
}
174182
}
175183

176-
public abstract void recover(RestClient restClient, String repository, String snapshot, String index) throws Exception;
184+
protected abstract void recover(
185+
RestClient restClient,
186+
String repository,
187+
String snapshot,
188+
String index,
189+
Consumer<List<String>> warningsConsumer
190+
) throws Exception;
177191

178192
private static String getIndices(RestClient client) throws IOException {
179193
final Request request = new Request("GET", "_cat/indices");
@@ -212,6 +226,6 @@ private static void unzip(Path zipFilePath, Path outputDir) throws IOException {
212226
}
213227

214228
public final void testArchiveIndex() throws Exception {
215-
verifyCompatibility(indexCreatedVersion);
229+
verifyCompatibility(indexCreatedVersion, warningsConsumer);
216230
}
217231
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.oldrepos;
9+
10+
/**
11+
* Snapshot zip file names for archive and searchable snapshot tests
12+
*/
13+
public final class TestSnapshotCases {
14+
// Index created in vES_5 - Basic mapping
15+
public static final String ES_VERSION_5 = "5";
16+
17+
// Index created in vES_5 - Custom-Analyzer - standard token filter
18+
public static final String ES_VERSION_5_STANDARD_TOKEN_FILTER = "5_custom_analyzer";
19+
20+
// Index created in vES_5 - Basic mapping
21+
public static final String ES_VERSION_6 = "5";
22+
23+
// Index created in vES_5 - Custom-Analyzer - standard token filter
24+
public static final String ES_VERSION_6_STANDARD_TOKEN_FILTER = "5_custom_analyzer";
25+
26+
}

x-pack/qa/repository-old-versions-compatibility/src/javaRestTest/java/org/elasticsearch/oldrepos/archiveindex/ArchiveIndexTestCase.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
package org.elasticsearch.oldrepos.archiveindex;
99

1010
import org.elasticsearch.client.Request;
11+
import org.elasticsearch.client.RequestOptions;
12+
import org.elasticsearch.client.Response;
1113
import org.elasticsearch.client.RestClient;
14+
import org.elasticsearch.client.WarningsHandler;
1215
import org.elasticsearch.common.Strings;
1316
import org.elasticsearch.oldrepos.AbstractUpgradeCompatibilityTestCase;
1417
import org.elasticsearch.test.cluster.util.Version;
1518

16-
import static org.elasticsearch.test.rest.ObjectPath.createFromResponse;
19+
import java.util.List;
20+
import java.util.function.Consumer;
1721

1822
/**
1923
* Test suite for Archive indices backward compatibility with N-2 versions.
@@ -32,14 +36,19 @@ abstract class ArchiveIndexTestCase extends AbstractUpgradeCompatibilityTestCase
3236
}
3337

3438
protected ArchiveIndexTestCase(Version version, String indexCreatedVersion) {
35-
super(version, indexCreatedVersion);
39+
this(version, indexCreatedVersion, o -> {});
40+
}
41+
42+
protected ArchiveIndexTestCase(Version version, String indexCreatedVersion, Consumer<List<String>> consumer) {
43+
super(version, indexCreatedVersion, consumer);
3644
}
3745

3846
/**
3947
* Overrides the snapshot-restore operation for archive-indices scenario.
4048
*/
4149
@Override
42-
public void recover(RestClient client, String repository, String snapshot, String index) throws Exception {
50+
public void recover(RestClient client, String repository, String snapshot, String index, Consumer<List<String>> warningsConsumer)
51+
throws Exception {
4352
var request = new Request("POST", "/_snapshot/" + repository + "/" + snapshot + "/_restore");
4453
request.addParameter("wait_for_completion", "true");
4554
request.setJsonEntity(Strings.format("""
@@ -49,6 +58,9 @@ public void recover(RestClient client, String repository, String snapshot, Strin
4958
"rename_pattern": "(.+)",
5059
"include_aliases": false
5160
}""", index));
52-
createFromResponse(client.performRequest(request));
61+
request.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE));
62+
Response response = client.performRequest(request);
63+
assertOK(response);
64+
warningsConsumer.accept(response.getWarnings());
5365
}
5466
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.oldrepos.archiveindex;
9+
10+
import org.elasticsearch.oldrepos.TestSnapshotCases;
11+
import org.elasticsearch.test.cluster.util.Version;
12+
13+
/**
14+
* Test case restoring index created in ES_v5 - Custom-Analyzer - standard token filter
15+
*
16+
* PUT /index
17+
* {
18+
* "settings": {
19+
* "analysis": {
20+
* "analyzer": {
21+
* "custom_analyzer": {
22+
* "type": "custom",
23+
* "tokenizer": "standard",
24+
* "filter": [
25+
* "standard",
26+
* "lowercase"
27+
* ]
28+
* }
29+
* }
30+
* }
31+
* },
32+
* "mappings": {
33+
* "my_type": {
34+
* "properties": {
35+
* "content": {
36+
* "type": "text",
37+
* "analyzer": "custom_analyzer"
38+
* }
39+
* }
40+
* }
41+
* }
42+
* }
43+
*/
44+
public class RestoreFromVersion5CustomAnalyzerIT extends ArchiveIndexTestCase {
45+
46+
public RestoreFromVersion5CustomAnalyzerIT(Version version) {
47+
super(version, TestSnapshotCases.ES_VERSION_5_STANDARD_TOKEN_FILTER, warnings -> {
48+
assertEquals(1, warnings.size());
49+
assertEquals("The [standard] token filter is " + "deprecated and will be removed in a future version.", warnings.getFirst());
50+
});
51+
}
52+
}

x-pack/qa/repository-old-versions-compatibility/src/javaRestTest/java/org/elasticsearch/oldrepos/archiveindex/RestoreFromVersion5IT.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,38 @@
77

88
package org.elasticsearch.oldrepos.archiveindex;
99

10+
import org.elasticsearch.oldrepos.TestSnapshotCases;
1011
import org.elasticsearch.test.cluster.util.Version;
1112

13+
/**
14+
* Test case restoring snapshot created in ES_v5 - Basic mapping
15+
*
16+
* PUT /index
17+
* {
18+
* "settings": {
19+
* "number_of_shards": 1,
20+
* "number_of_replicas": 1
21+
* },
22+
* "mappings": {
23+
* "my_type": {
24+
* "properties": {
25+
* "title": {
26+
* "type": "text"
27+
* },
28+
* "created_at": {
29+
* "type": "date"
30+
* },
31+
* "views": {
32+
* "type": "integer"
33+
* }
34+
* }
35+
* }
36+
* }
37+
* }
38+
*/
1239
public class RestoreFromVersion5IT extends ArchiveIndexTestCase {
1340

1441
public RestoreFromVersion5IT(Version version) {
15-
super(version, "5");
42+
super(version, TestSnapshotCases.ES_VERSION_5);
1643
}
1744
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.oldrepos.archiveindex;
9+
10+
import org.elasticsearch.oldrepos.TestSnapshotCases;
11+
import org.elasticsearch.test.cluster.util.Version;
12+
13+
/**
14+
* Test case restoring index created in ES_v6 - Custom-Analyzer - standard token filter
15+
*
16+
* PUT /index
17+
* {
18+
* "settings": {
19+
* "analysis": {
20+
* "analyzer": {
21+
* "custom_analyzer": {
22+
* "type": "custom",
23+
* "tokenizer": "standard",
24+
* "filter": [
25+
* "standard",
26+
* "lowercase"
27+
* ]
28+
* }
29+
* }
30+
* }
31+
* },
32+
* "mappings": {
33+
* "_doc": {
34+
* "properties": {
35+
* "content": {
36+
* "type": "text",
37+
* "analyzer": "custom_analyzer"
38+
* }
39+
* }
40+
* }
41+
* }
42+
* }
43+
*/
44+
public class RestoreFromVersion6CustomAnalyzerIT extends ArchiveIndexTestCase {
45+
46+
public RestoreFromVersion6CustomAnalyzerIT(Version version) {
47+
super(version, TestSnapshotCases.ES_VERSION_6_STANDARD_TOKEN_FILTER, warnings -> {
48+
assertEquals(1, warnings.size());
49+
assertEquals("The [standard] token filter is " + "deprecated and will be removed in a future version.", warnings.getFirst());
50+
});
51+
}
52+
}

x-pack/qa/repository-old-versions-compatibility/src/javaRestTest/java/org/elasticsearch/oldrepos/archiveindex/RestoreFromVersion6IT.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,38 @@
77

88
package org.elasticsearch.oldrepos.archiveindex;
99

10+
import org.elasticsearch.oldrepos.TestSnapshotCases;
1011
import org.elasticsearch.test.cluster.util.Version;
1112

13+
/**
14+
* Test case restoring snapshot created in ES_v6 - Basic mapping
15+
*
16+
* PUT /index
17+
* {
18+
* "settings": {
19+
* "number_of_shards": 1,
20+
* "number_of_replicas": 1
21+
* },
22+
* "mappings": {
23+
* "_doc": {
24+
* "properties": {
25+
* "title": {
26+
* "type": "text"
27+
* },
28+
* "content": {
29+
* "type": "text"
30+
* },
31+
* "created_at": {
32+
* "type": "date"
33+
* }
34+
* }
35+
* }
36+
* }
37+
* }
38+
*/
1239
public class RestoreFromVersion6IT extends ArchiveIndexTestCase {
1340

1441
public RestoreFromVersion6IT(Version version) {
15-
super(version, "6");
42+
super(version, TestSnapshotCases.ES_VERSION_6);
1643
}
1744
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.oldrepos.searchablesnapshot;
9+
10+
import org.elasticsearch.oldrepos.TestSnapshotCases;
11+
import org.elasticsearch.test.cluster.util.Version;
12+
13+
/**
14+
* Test case mounting index created in ES_v5 - Custom-Analyzer - standard token filter
15+
*
16+
* PUT /index
17+
* {
18+
* "settings": {
19+
* "analysis": {
20+
* "analyzer": {
21+
* "custom_analyzer": {
22+
* "type": "custom",
23+
* "tokenizer": "standard",
24+
* "filter": [
25+
* "standard",
26+
* "lowercase"
27+
* ]
28+
* }
29+
* }
30+
* }
31+
* },
32+
* "mappings": {
33+
* "my_type": {
34+
* "properties": {
35+
* "content": {
36+
* "type": "text",
37+
* "analyzer": "custom_analyzer"
38+
* }
39+
* }
40+
* }
41+
* }
42+
* }
43+
*/
44+
public class MountFromVersion5CustomAnalyzerIT extends SearchableSnapshotTestCase {
45+
46+
public MountFromVersion5CustomAnalyzerIT(Version version) {
47+
super(version, TestSnapshotCases.ES_VERSION_5_STANDARD_TOKEN_FILTER, warnings -> {
48+
assertEquals(1, warnings.size());
49+
assertEquals("The [standard] token filter is " + "deprecated and will be removed in a future version.", warnings.getFirst());
50+
});
51+
}
52+
}

0 commit comments

Comments
 (0)