From 0b11cacb8be66b0e98927a26cd418270f5277188 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Wed, 16 May 2018 14:17:08 +0100 Subject: [PATCH] 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 --- .../action/support/IndicesOptionsTests.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java b/server/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java index 49c78a4945ff1..d4dc32678252f 100644 --- a/server/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/IndicesOptionsTests.java @@ -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 { @@ -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_7_0_0_alpha1, 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(randomVersion(random())); + 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()));