Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion server/src/main/java/org/elasticsearch/TransportVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public static TransportVersion fromBufferedReader(
Integer upperBound
) {
try {
String line = bufferedReader.readLine();
String line;
do {
line = bufferedReader.readLine();
} while (line.replaceAll("\\s+", "").startsWith("#"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this means we don't support comments anywhere in the file, only in the beginning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Since this is our internal format, I didn't think it was worth additional parsing complexity to make it work anywhere.

String[] parts = line.replaceAll("\\s+", "").split(",");
String check;
while ((check = bufferedReader.readLine()) != null) {
Expand Down
37 changes: 37 additions & 0 deletions server/src/test/java/org/elasticsearch/TransportVersionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,41 @@ public void testSupports() {
assertThat(new TransportVersion(null, 100001000, null).supports(test4), is(true));
assertThat(new TransportVersion(null, 100001001, null).supports(test4), is(true));
}

public void testComment() {
byte[] data1 = ("#comment" + System.lineSeparator() + "1000000").getBytes(StandardCharsets.UTF_8);
TransportVersion test1 = TransportVersion.fromBufferedReader(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: seems these are all exactly the same test, just with a different comment before the same id. perhaps it could be moved to a helper function that takes the data as a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see if I can make a helper in a separate PR for all the tests that use this byte array.

"<test>",
"testSupports3",
false,
true,
new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data1), StandardCharsets.UTF_8)),
5000000
);
assertThat(new TransportVersion(null, 1000000, null).supports(test1), is(true));

byte[] data2 = (" # comment" + System.lineSeparator() + "1000000").getBytes(StandardCharsets.UTF_8);
TransportVersion test2 = TransportVersion.fromBufferedReader(
"<test>",
"testSupports3",
false,
true,
new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data2), StandardCharsets.UTF_8)),
5000000
);
assertThat(new TransportVersion(null, 1000000, null).supports(test2), is(true));

byte[] data3 = ("#comment" + System.lineSeparator() + "# comment3" + System.lineSeparator() + "1000000").getBytes(
StandardCharsets.UTF_8
);
TransportVersion test3 = TransportVersion.fromBufferedReader(
"<test>",
"testSupports3",
false,
true,
new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data3), StandardCharsets.UTF_8)),
5000000
);
assertThat(new TransportVersion(null, 1000000, null).supports(test3), is(true));
}
}