From 90b2e4d8c694724ec643e524de66d645a5751dad Mon Sep 17 00:00:00 2001 From: gaobinlong Date: Wed, 20 Mar 2024 23:48:46 +0800 Subject: [PATCH] Fix test issue in ForceMergeRequestTests (#12778) Signed-off-by: Gao Binlong --- .../forcemerge/ForceMergeRequestTests.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/server/src/test/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java index 430d600354e3b..1f45c9277fd0b 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeRequestTests.java @@ -97,23 +97,30 @@ public void testSerialization() throws Exception { public void testBwcSerialization() throws Exception { { final ForceMergeRequest sample = randomRequest(); - final Version compatibleVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); + final Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); try (BytesStreamOutput out = new BytesStreamOutput()) { - out.setVersion(compatibleVersion); + out.setVersion(version); sample.writeTo(out); try (StreamInput in = out.bytes().streamInput()) { - in.setVersion(Version.CURRENT); + in.setVersion(version); TaskId.readFromStream(in); in.readStringArray(); IndicesOptions.readIndicesOptions(in); int maxNumSegments = in.readInt(); boolean onlyExpungeDeletes = in.readBoolean(); boolean flush = in.readBoolean(); + boolean primaryOnly = false; + if (version.onOrAfter(Version.V_2_13_0)) { + primaryOnly = in.readBoolean(); + } String forceMergeUUID = in.readOptionalString(); assertEquals(sample.maxNumSegments(), maxNumSegments); assertEquals(sample.onlyExpungeDeletes(), onlyExpungeDeletes); assertEquals(sample.flush(), flush); + if (version.onOrAfter(Version.V_2_13_0)) { + assertEquals(sample.primaryOnly(), primaryOnly); + } assertEquals(sample.forceMergeUUID(), forceMergeUUID); } @@ -122,30 +129,30 @@ public void testBwcSerialization() throws Exception { { final ForceMergeRequest sample = randomRequest(); - final Version compatibleVersion = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); + final Version version = VersionUtils.randomCompatibleVersion(random(), Version.CURRENT); try (BytesStreamOutput out = new BytesStreamOutput()) { - out.setVersion(Version.CURRENT); + out.setVersion(version); sample.getParentTask().writeTo(out); out.writeStringArray(sample.indices()); sample.indicesOptions().writeIndicesOptions(out); out.writeInt(sample.maxNumSegments()); out.writeBoolean(sample.onlyExpungeDeletes()); out.writeBoolean(sample.flush()); - if (compatibleVersion.onOrAfter(Version.V_2_13_0)) { + if (version.onOrAfter(Version.V_2_13_0)) { out.writeBoolean(sample.primaryOnly()); } out.writeOptionalString(sample.forceMergeUUID()); final ForceMergeRequest deserializedRequest; try (StreamInput in = out.bytes().streamInput()) { - in.setVersion(compatibleVersion); + in.setVersion(version); deserializedRequest = new ForceMergeRequest(in); } assertEquals(sample.maxNumSegments(), deserializedRequest.maxNumSegments()); assertEquals(sample.onlyExpungeDeletes(), deserializedRequest.onlyExpungeDeletes()); assertEquals(sample.flush(), deserializedRequest.flush()); - if (compatibleVersion.onOrAfter(Version.V_2_13_0)) { + if (version.onOrAfter(Version.V_2_13_0)) { assertEquals(sample.primaryOnly(), deserializedRequest.primaryOnly()); } assertEquals(sample.forceMergeUUID(), deserializedRequest.forceMergeUUID());