Skip to content

Commit 95ad9ab

Browse files
authored
Fixes IndiceOptionsTests to serialise correctly (#30644)
* Fixes IndiceOptionsTests to serialise correctly Previous to this change `IndicesOptionsTests.testSerialisation()` would select a complete random version for both the `StreamOutput` and the `StreamInput`. This meant that the output could be selected as 7.0+ while the input was selected as <7.0 causing the stream to be written in the new format and read in teh old format (or vica versa). This change splits the two cases into different test methods ensuring that the Streams are at least on compatibile versions even if they are on different versions. * Use same random version for input and output streams server/src/test/java/org/elasticsearch/action/support/IndicesOptionsTest s.java
1 parent 8e9d2b1 commit 95ad9ab

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

server/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.HashMap;
2929
import java.util.Map;
3030

31-
import static org.elasticsearch.test.VersionUtils.randomVersion;
31+
import static org.elasticsearch.test.VersionUtils.randomVersionBetween;
3232
import static org.hamcrest.CoreMatchers.equalTo;
3333

3434
public class IndicesOptionsTests extends ESTestCase {
@@ -37,16 +37,43 @@ public class IndicesOptionsTests extends ESTestCase {
3737
public void testSerialization() throws Exception {
3838
int iterations = randomIntBetween(5, 20);
3939
for (int i = 0; i < iterations; i++) {
40+
Version version = randomVersionBetween(random(), Version.V_7_0_0_alpha1, null);
4041
IndicesOptions indicesOptions = IndicesOptions.fromOptions(
4142
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
4243

4344
BytesStreamOutput output = new BytesStreamOutput();
44-
Version outputVersion = randomVersion(random());
45-
output.setVersion(outputVersion);
45+
output.setVersion(version);
4646
indicesOptions.writeIndicesOptions(output);
4747

4848
StreamInput streamInput = output.bytes().streamInput();
49-
streamInput.setVersion(randomVersion(random()));
49+
streamInput.setVersion(version);
50+
IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(streamInput);
51+
52+
assertThat(indicesOptions2.ignoreUnavailable(), equalTo(indicesOptions.ignoreUnavailable()));
53+
assertThat(indicesOptions2.allowNoIndices(), equalTo(indicesOptions.allowNoIndices()));
54+
assertThat(indicesOptions2.expandWildcardsOpen(), equalTo(indicesOptions.expandWildcardsOpen()));
55+
assertThat(indicesOptions2.expandWildcardsClosed(), equalTo(indicesOptions.expandWildcardsClosed()));
56+
57+
assertThat(indicesOptions2.forbidClosedIndices(), equalTo(indicesOptions.forbidClosedIndices()));
58+
assertThat(indicesOptions2.allowAliasesToMultipleIndices(), equalTo(indicesOptions.allowAliasesToMultipleIndices()));
59+
60+
assertEquals(indicesOptions2.ignoreAliases(), indicesOptions.ignoreAliases());
61+
}
62+
}
63+
64+
public void testSerializationPre70() throws Exception {
65+
int iterations = randomIntBetween(5, 20);
66+
for (int i = 0; i < iterations; i++) {
67+
Version version = randomVersionBetween(random(), null, Version.V_6_4_0);
68+
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
69+
randomBoolean(), randomBoolean(), randomBoolean());
70+
71+
BytesStreamOutput output = new BytesStreamOutput();
72+
output.setVersion(version);
73+
indicesOptions.writeIndicesOptions(output);
74+
75+
StreamInput streamInput = output.bytes().streamInput();
76+
streamInput.setVersion(version);
5077
IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(streamInput);
5178

5279
assertThat(indicesOptions2.ignoreUnavailable(), equalTo(indicesOptions.ignoreUnavailable()));

0 commit comments

Comments
 (0)