Skip to content

Commit

Permalink
Fixes IndiceOptionsTests to serialise correctly (#30644)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
colings86 authored and dakrone committed May 16, 2018
1 parent 83f839f commit 554fad0
Showing 1 changed file with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.HashMap;
import java.util.Map;

import static org.elasticsearch.test.VersionUtils.randomVersion;
import static org.elasticsearch.test.VersionUtils.randomVersionBetween;
import static org.hamcrest.CoreMatchers.equalTo;

public class IndicesOptionsTests extends ESTestCase {
Expand All @@ -37,16 +37,43 @@ public class IndicesOptionsTests extends ESTestCase {
public void testSerialization() throws Exception {
int iterations = randomIntBetween(5, 20);
for (int i = 0; i < iterations; i++) {
Version version = randomVersionBetween(random(), Version.V_6_4_0, null);
IndicesOptions indicesOptions = IndicesOptions.fromOptions(
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());

BytesStreamOutput output = new BytesStreamOutput();
Version outputVersion = randomVersion(random());
output.setVersion(outputVersion);
output.setVersion(version);
indicesOptions.writeIndicesOptions(output);

StreamInput streamInput = output.bytes().streamInput();
streamInput.setVersion(outputVersion);
streamInput.setVersion(version);
IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(streamInput);

assertThat(indicesOptions2.ignoreUnavailable(), equalTo(indicesOptions.ignoreUnavailable()));
assertThat(indicesOptions2.allowNoIndices(), equalTo(indicesOptions.allowNoIndices()));
assertThat(indicesOptions2.expandWildcardsOpen(), equalTo(indicesOptions.expandWildcardsOpen()));
assertThat(indicesOptions2.expandWildcardsClosed(), equalTo(indicesOptions.expandWildcardsClosed()));

assertThat(indicesOptions2.forbidClosedIndices(), equalTo(indicesOptions.forbidClosedIndices()));
assertThat(indicesOptions2.allowAliasesToMultipleIndices(), equalTo(indicesOptions.allowAliasesToMultipleIndices()));

assertEquals(indicesOptions2.ignoreAliases(), indicesOptions.ignoreAliases());
}
}

public void testSerializationPre70() throws Exception {
int iterations = randomIntBetween(5, 20);
for (int i = 0; i < iterations; i++) {
Version version = randomVersionBetween(random(), null, Version.V_6_4_0);
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());

BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(version);
indicesOptions.writeIndicesOptions(output);

StreamInput streamInput = output.bytes().streamInput();
streamInput.setVersion(version);
IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(streamInput);

assertThat(indicesOptions2.ignoreUnavailable(), equalTo(indicesOptions.ignoreUnavailable()));
Expand Down

0 comments on commit 554fad0

Please sign in to comment.