-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Reinstate BYTE_SIZE_VALUE_ALWAYS_USES_BYTES #122964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
219256d
Reinstate BYTE_SIZE_VALUE_ALWAYS_USES_BYTES
prdoyle 071c1e8
Merge branch 'main' into es-10585
prdoyle f7c98d0
[CI] Auto commit changes from spotless
e6a68ef
Refactor alwaysUseBytes
prdoyle dfcbe82
Merge remote-tracking branch 'origin/es-10585' into es-10585
prdoyle fcf1045
Merge branch 'main' into es-10585
prdoyle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,6 @@ | |
|
|
||
| import org.elasticsearch.ElasticsearchParseException; | ||
| import org.elasticsearch.TransportVersion; | ||
| import org.elasticsearch.TransportVersions; | ||
| import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable.Reader; | ||
| import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
|
@@ -22,6 +21,10 @@ | |
| import java.util.List; | ||
| import java.util.function.Function; | ||
|
|
||
| import static org.elasticsearch.TransportVersions.BYTE_SIZE_VALUE_ALWAYS_USES_BYTES; | ||
| import static org.elasticsearch.TransportVersions.BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_90; | ||
| import static org.elasticsearch.TransportVersions.INITIAL_ELASTICSEARCH_9_0; | ||
| import static org.elasticsearch.TransportVersions.V_8_16_0; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
@@ -520,44 +523,43 @@ protected void assertEqualInstances(ByteSizeValue expectedInstance, ByteSizeValu | |
|
|
||
| public void testBWCTransportFormat() throws IOException { | ||
| var tenMegs = ByteSizeValue.ofMb(10); | ||
| try (BytesStreamOutput expected = new BytesStreamOutput(); BytesStreamOutput actual = new BytesStreamOutput()) { | ||
| expected.writeZLong(10); | ||
| ByteSizeUnit.MB.writeTo(expected); | ||
| actual.setTransportVersion(TransportVersions.V_8_16_0); | ||
| tenMegs.writeTo(actual); | ||
| assertArrayEquals( | ||
| "Size denominated in the desired unit for backward compatibility", | ||
| expected.bytes().array(), | ||
| actual.bytes().array() | ||
| ); | ||
| for (var tv : List.of(V_8_16_0, INITIAL_ELASTICSEARCH_9_0)) { | ||
| try (BytesStreamOutput expected = new BytesStreamOutput(); BytesStreamOutput actual = new BytesStreamOutput()) { | ||
| expected.writeZLong(10); | ||
| ByteSizeUnit.MB.writeTo(expected); | ||
| actual.setTransportVersion(tv); | ||
| tenMegs.writeTo(actual); | ||
| assertArrayEquals( | ||
| "Size denominated in the desired unit for backward compatibility", | ||
| expected.bytes().array(), | ||
| actual.bytes().array() | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @see TransportVersions#REVERT_BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_1 | ||
| */ | ||
| @AwaitsFix(bugUrl = "https://elasticco.atlassian.net/browse/ES-10585") | ||
| public void testTwoDigitTransportRoundTrips() throws IOException { | ||
| TransportVersion tv = TransportVersion.current(); | ||
| for (var desiredUnit : ByteSizeUnit.values()) { | ||
| if (desiredUnit == ByteSizeUnit.BYTES) { | ||
| continue; | ||
| } | ||
| checkTransportRoundTrip(ByteSizeValue.parseBytesSizeValue("23" + desiredUnit.getSuffix(), "test"), tv); | ||
| for (int tenths = 1; tenths <= 9; tenths++) { | ||
| checkTransportRoundTrip(ByteSizeValue.parseBytesSizeValue("23." + tenths + desiredUnit.getSuffix(), "test"), tv); | ||
| for (int hundredths = 1; hundredths <= 9; hundredths++) { | ||
| checkTransportRoundTrip( | ||
| ByteSizeValue.parseBytesSizeValue("23." + tenths + hundredths + desiredUnit.getSuffix(), "test"), | ||
| tv | ||
| ); | ||
| for (var tv : List.of(TransportVersion.current(), BYTE_SIZE_VALUE_ALWAYS_USES_BYTES, BYTE_SIZE_VALUE_ALWAYS_USES_BYTES_90)) { | ||
| for (var desiredUnit : ByteSizeUnit.values()) { | ||
| if (desiredUnit == ByteSizeUnit.BYTES) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we skip bytes?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't have a fraction of a byte, but you can have a fraction of any other unit. |
||
| continue; | ||
| } | ||
| checkTransportRoundTrip(ByteSizeValue.parseBytesSizeValue("23" + desiredUnit.getSuffix(), "test"), tv); | ||
| for (int tenths = 1; tenths <= 9; tenths++) { | ||
| checkTransportRoundTrip(ByteSizeValue.parseBytesSizeValue("23." + tenths + desiredUnit.getSuffix(), "test"), tv); | ||
| for (int hundredths = 1; hundredths <= 9; hundredths++) { | ||
| checkTransportRoundTrip( | ||
| ByteSizeValue.parseBytesSizeValue("23." + tenths + hundredths + desiredUnit.getSuffix(), "test"), | ||
| tv | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void testIntegerTransportRoundTrips() throws IOException { | ||
| for (var tv : List.of(TransportVersion.current(), TransportVersions.V_8_16_0)) { | ||
| for (var tv : List.of(TransportVersion.current(), V_8_16_0)) { | ||
| checkTransportRoundTrip(ByteSizeValue.ONE, tv); | ||
| checkTransportRoundTrip(ByteSizeValue.ZERO, tv); | ||
| checkTransportRoundTrip(ByteSizeValue.MINUS_ONE, tv); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.