Skip to content

Commit 76e3f0d

Browse files
committed
move examples to tests
1 parent a19caac commit 76e3f0d

File tree

18 files changed

+99
-115
lines changed

18 files changed

+99
-115
lines changed

server/src/main/java/org/elasticsearch/TransportVersion.java

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,7 @@
6969
* different version value. If you need to know whether the cluster as a whole speaks a new enough {@link TransportVersion} to understand a
7070
* newly-added feature, use {@link org.elasticsearch.cluster.ClusterState#getMinTransportVersion}.
7171
*/
72-
public class TransportVersion implements VersionId<TransportVersion> {
73-
74-
private final String name;
75-
private final int id;
76-
private final TransportVersion nextPatchVersion;
77-
78-
public TransportVersion(int id) {
79-
this(null, id, null);
80-
}
81-
82-
public TransportVersion(String name, int id, TransportVersion patchVersion) {
83-
this.name = name;
84-
this.id = id;
85-
this.nextPatchVersion = patchVersion;
86-
}
87-
88-
public String name() {
89-
return name;
90-
}
91-
92-
public int id() {
93-
return id;
94-
}
95-
96-
public TransportVersion nextPatchVersion() {
97-
return nextPatchVersion;
98-
}
72+
public record TransportVersion(String name, int id, TransportVersion nextPatchVersion) implements VersionId<TransportVersion> {
9973

10074
private static final ParseField NAME = new ParseField("name");
10175
private static final ParseField IDS = new ParseField("ids");
@@ -288,7 +262,7 @@ public int hashCode() {
288262

289263
@Override
290264
public String toString() {
291-
return "" + id;
265+
return Integer.toString(id);
292266
}
293267

294268
private static class VersionsHolder {
@@ -332,38 +306,56 @@ private static class VersionsHolder {
332306
private static Map<String, TransportVersion> loadTransportVersionsByName() {
333307
Map<String, TransportVersion> transportVersions = new HashMap<>();
334308

335-
String latestLocation = "/transport/latest/" + Version.CURRENT.major + "." + Version.CURRENT.minor + "-LATEST.json";
336-
int latestId;
309+
String latestLocation = "/transport/latest/" + Version.CURRENT.major + "." + Version.CURRENT.minor + ".json";
310+
int latestId = -1;
337311
try (InputStream inputStream = TransportVersion.class.getResourceAsStream(latestLocation)) {
338-
TransportVersion latest = fromXContent(inputStream, Integer.MAX_VALUE);
339-
if (latest == null) {
340-
throw new IllegalStateException(
341-
"invalid latest transport version for release version [" + Version.CURRENT.major + "." + Version.CURRENT.minor + "]"
342-
);
312+
// this check is required until bootstrapping for the new transport versions format is completed;
313+
// when load is false, we will only use the transport versions in the legacy format;
314+
// load becomes false if we don't find the latest or manifest files required for the new format
315+
if (inputStream != null) {
316+
TransportVersion latest = fromXContent(inputStream, Integer.MAX_VALUE);
317+
if (latest == null) {
318+
throw new IllegalStateException(
319+
"invalid latest transport version for release version ["
320+
+ Version.CURRENT.major
321+
+ "."
322+
+ Version.CURRENT.minor
323+
+ "]"
324+
);
325+
}
326+
latestId = latest.id();
343327
}
344-
latestId = latest.id();
345328
} catch (IOException ioe) {
346329
throw new UncheckedIOException("latest transport version file not found at [" + latestLocation + "]", ioe);
347330
}
348331

349-
String manifestLocation = "/transport/generated/generated-transport-versions-files-manifest.txt";
350-
List<String> versionFileNames;
351-
try (InputStream transportVersionsManifest = TransportVersion.class.getResourceAsStream(manifestLocation)) {
352-
BufferedReader reader = new BufferedReader(new InputStreamReader(transportVersionsManifest, StandardCharsets.UTF_8));
353-
versionFileNames = reader.lines().filter(line -> line.isBlank() == false).toList();
354-
} catch (IOException ioe) {
355-
throw new UncheckedIOException("transport version manifest file not found at [" + manifestLocation + "]", ioe);
332+
String manifestLocation = "/transport/constant/constant-transport-versions-files-manifest.txt";
333+
List<String> versionFileNames = null;
334+
if (latestId > -1) {
335+
try (InputStream inputStream = TransportVersion.class.getResourceAsStream(manifestLocation)) {
336+
if (inputStream == null) {
337+
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
338+
versionFileNames = reader.lines().filter(line -> line.isBlank() == false).toList();
339+
}
340+
} catch (IOException ioe) {
341+
throw new UncheckedIOException("transport version manifest file not found at [" + manifestLocation + "]", ioe);
342+
}
356343
}
357344

358-
for (String name : versionFileNames) {
359-
String versionLocation = "/transport/generated/" + name;
360-
try (InputStream inputStream = TransportVersion.class.getResourceAsStream(versionLocation)) {
361-
TransportVersion transportVersion = TransportVersion.fromXContent(inputStream, latestId);
362-
if (transportVersion != null) {
363-
transportVersions.put(transportVersion.name(), transportVersion);
345+
if (versionFileNames != null) {
346+
for (String name : versionFileNames) {
347+
String versionLocation = "/transport/constant/" + name;
348+
try (InputStream inputStream = TransportVersion.class.getResourceAsStream(versionLocation)) {
349+
if (inputStream == null) {
350+
throw new IllegalStateException("transport version file not found at [" + versionLocation + "]");
351+
}
352+
TransportVersion transportVersion = TransportVersion.fromXContent(inputStream, latestId);
353+
if (transportVersion != null) {
354+
transportVersions.put(transportVersion.name(), transportVersion);
355+
}
356+
} catch (IOException ioe) {
357+
throw new UncheckedIOException("transport version file not found at [ " + versionLocation + "]", ioe);
364358
}
365-
} catch (IOException ioe) {
366-
throw new UncheckedIOException("transport version set file not found at [ " + versionLocation + "]", ioe);
367359
}
368360
}
369361

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static TransportVersion def(int id) {
209209
public static final TransportVersion ML_INFERENCE_COHERE_API_VERSION_8_19 = def(8_841_0_60);
210210
public static final TransportVersion ESQL_DOCUMENTS_FOUND_AND_VALUES_LOADED_8_19 = def(8_841_0_61);
211211
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN_8_19 = def(8_841_0_62);
212+
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES_8_19 = def(8_841_0_63);
212213
public static final TransportVersion ESQL_FIXED_INDEX_LIKE_8_19 = def(8_841_0_64);
213214
public static final TransportVersion V_9_0_0 = def(9_000_0_09);
214215
public static final TransportVersion INITIAL_ELASTICSEARCH_9_0_1 = def(9_000_0_10);
@@ -326,12 +327,14 @@ static TransportVersion def(int id) {
326327
public static final TransportVersion ML_INFERENCE_COHERE_API_VERSION = def(9_110_0_00);
327328
public static final TransportVersion ESQL_PROFILE_INCLUDE_PLAN = def(9_111_0_00);
328329
public static final TransportVersion MAPPINGS_IN_DATA_STREAMS = def(9_112_0_00);
330+
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES_9_1 = def(9_112_0_01);
329331
public static final TransportVersion ESQL_FIXED_INDEX_LIKE_9_1 = def(9_112_0_02);
330332
public static final TransportVersion ESQL_SAMPLE_OPERATOR_STATUS_9_1 = def(9_112_0_03);
331333
// Below is the first version in 9.2 and NOT in 9.1.
332334
public static final TransportVersion PROJECT_STATE_REGISTRY_RECORDS_DELETIONS = def(9_113_0_00);
333335
public static final TransportVersion ESQL_SERIALIZE_TIMESERIES_FIELD_TYPE = def(9_114_0_00);
334336
public static final TransportVersion ML_INFERENCE_IBM_WATSONX_COMPLETION_ADDED = def(9_115_0_00);
337+
public static final TransportVersion ESQL_SPLIT_ON_BIG_VALUES = def(9_116_0_00);
335338
public static final TransportVersion ESQL_LOCAL_RELATION_WITH_NEW_BLOCKS = def(9_117_0_00);
336339
public static final TransportVersion ML_INFERENCE_CUSTOM_SERVICE_EMBEDDING_TYPE = def(9_118_0_00);
337340
public static final TransportVersion ESQL_FIXED_INDEX_LIKE = def(9_119_0_00);
@@ -344,6 +347,7 @@ static TransportVersion def(int id) {
344347
public static final TransportVersion SHARD_WRITE_LOAD_IN_CLUSTER_INFO = def(9_126_0_00);
345348
public static final TransportVersion ESQL_SAMPLE_OPERATOR_STATUS = def(9_127_0_00);
346349
public static final TransportVersion ESQL_TOPN_TIMINGS = def(9_128_0_00);
350+
347351
/*
348352
* STOP! READ THIS FIRST! No, really,
349353
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

server/src/main/resources/transport/generated/esql-split-on-big-values.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

server/src/main/resources/transport/generated/esql-topn-timings.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

server/src/main/resources/transport/generated/generated-transport-versions-files-manifest.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/src/main/resources/transport/generated/ml-inference-azure-ai-studio-rerank-added.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

server/src/main/resources/transport/latest/9.2-LATEST.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

server/src/test/java/org/elasticsearch/TransportVersionTests.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ public void testVersionComparison() {
5353
}
5454

5555
public static class CorrectFakeVersion {
56-
public static final TransportVersion V_0_00_01 = new TransportVersion(199);
57-
public static final TransportVersion V_0_000_002 = new TransportVersion(2);
58-
public static final TransportVersion V_0_000_003 = new TransportVersion(3);
59-
public static final TransportVersion V_0_000_004 = new TransportVersion(4);
56+
public static final TransportVersion V_0_00_01 = new TransportVersion(null, 199, null);
57+
public static final TransportVersion V_0_000_002 = new TransportVersion(null, 2, null);
58+
public static final TransportVersion V_0_000_003 = new TransportVersion(null, 3, null);
59+
public static final TransportVersion V_0_000_004 = new TransportVersion(null, 4, null);
6060
}
6161

6262
public static class DuplicatedIdFakeVersion {
63-
public static final TransportVersion V_0_000_001 = new TransportVersion(1);
64-
public static final TransportVersion V_0_000_002 = new TransportVersion(2);
65-
public static final TransportVersion V_0_000_003 = new TransportVersion(2);
63+
public static final TransportVersion V_0_000_001 = new TransportVersion(null, 1, null);
64+
public static final TransportVersion V_0_000_002 = new TransportVersion(null, 2, null);
65+
public static final TransportVersion V_0_000_003 = new TransportVersion(null, 2, null);
6666
}
6767

6868
public void testStaticTransportVersionChecks() {
@@ -220,24 +220,4 @@ public void testDuplicateConstants() {
220220
previous = next;
221221
}
222222
}
223-
224-
public void testNamedVersions() {
225-
assertEquals(
226-
new TransportVersion("esql-split-on-big-values", 9116000, null),
227-
TransportVersion.fromName("esql-split-on-big-values")
228-
);
229-
assertEquals(
230-
new TransportVersion("esql-split-on-big-values", 9112001, null),
231-
TransportVersion.fromName("esql-split-on-big-values").nextPatchVersion()
232-
);
233-
assertEquals(
234-
new TransportVersion("esql-split-on-big-values", 8841063, null),
235-
TransportVersion.fromName("esql-split-on-big-values").nextPatchVersion().nextPatchVersion()
236-
);
237-
assertEquals(
238-
new TransportVersion("ml-inference-azure-ai-studio-rerank-added", 9123000, null),
239-
TransportVersion.fromName("ml-inference-azure-ai-studio-rerank-added")
240-
);
241-
assertEquals(new TransportVersion("esql-topn-timings", 9128000, null), TransportVersion.fromName("esql-topn-timings"));
242-
}
243223
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test-0.json
2+
test-1.json
3+
test-2.json
4+
test-3.json
5+
test-4.json
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "test-0",
3+
"ids": [
4+
]
5+
}

0 commit comments

Comments
 (0)