From aed466d5b6cf7e7e5f4f5ad63eccbdd8cc892d1b Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Mon, 6 Aug 2018 08:53:12 -0600 Subject: [PATCH] Remove ILM constructor hacks (#32597) This commit removes the hacks associated with mocking Response objects. Rather than parse a wrapped byte array, the constructors for `IndicesAliasesResponse` and `ResizeResponse` are made public Relates to #29823 --- .../admin/indices/alias/IndicesAliasesResponse.java | 4 ++-- .../action/admin/indices/shrink/ResizeResponse.java | 2 +- .../core/indexlifecycle/ShrinkSetAliasStepTests.java | 6 +----- .../xpack/core/indexlifecycle/ShrinkStepTests.java | 10 ++-------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java index 31ebcbf0f0a..dfb631a4b24 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/alias/IndicesAliasesResponse.java @@ -37,11 +37,11 @@ public class IndicesAliasesResponse extends AcknowledgedResponse { IndicesAliasesResponse() { } - IndicesAliasesResponse(boolean acknowledged) { + public IndicesAliasesResponse(boolean acknowledged) { super(acknowledged); } public static IndicesAliasesResponse fromXContent(XContentParser parser) { return new IndicesAliasesResponse(parseAcknowledged(parser)); } -} \ No newline at end of file +} diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ResizeResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ResizeResponse.java index c116bd896c8..ffe59f1e3ae 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ResizeResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/shrink/ResizeResponse.java @@ -38,7 +38,7 @@ public final class ResizeResponse extends CreateIndexResponse { ResizeResponse() { } - ResizeResponse(boolean acknowledged, boolean shardsAcknowledged, String index) { + public ResizeResponse(boolean acknowledged, boolean shardsAcknowledged, String index) { super(acknowledged, shardsAcknowledged, index); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkSetAliasStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkSetAliasStepTests.java index e368e9596e6..3afa673a61e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkSetAliasStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkSetAliasStepTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.core.indexlifecycle; import org.apache.lucene.util.SetOnce; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.admin.indices.alias.IndicesAliasesAction; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse; @@ -16,7 +15,6 @@ import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.xpack.core.indexlifecycle.AsyncActionStep.Listener; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.junit.Before; @@ -95,9 +93,7 @@ public class ShrinkSetAliasStepTests extends AbstractStepTestCase listener = (ActionListener) invocation.getArguments()[1]; - IndicesAliasesResponse response = IndicesAliasesAction.INSTANCE.newResponse(); - response.readFrom(StreamInput.wrap(new byte[] { 1 })); - listener.onResponse(response); + listener.onResponse(new IndicesAliasesResponse(true)); return null; } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java index 498c2f2def4..51ef2ea8d9e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java @@ -10,7 +10,6 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.rollover.RolloverResponse; -import org.elasticsearch.action.admin.indices.shrink.ResizeAction; import org.elasticsearch.action.admin.indices.shrink.ResizeRequest; import org.elasticsearch.action.admin.indices.shrink.ResizeResponse; import org.elasticsearch.client.AdminClient; @@ -18,7 +17,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.core.indexlifecycle.AsyncActionStep.Listener; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; @@ -124,9 +122,7 @@ public class ShrinkStepTests extends AbstractStepTestCase { .build())); assertThat(request.getTargetIndexRequest().settings() .getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), equalTo(step.getNumberOfShards())); - ResizeResponse resizeResponse = ResizeAction.INSTANCE.newResponse(); - resizeResponse.readFrom(StreamInput.wrap(new byte[] { 1, 1, 1, 1, 1 })); - listener.onResponse(resizeResponse); + listener.onResponse(new ResizeResponse(true, true, sourceIndexMetaData.getIndex().getName())); return null; } @@ -169,9 +165,7 @@ public class ShrinkStepTests extends AbstractStepTestCase { public Void answer(InvocationOnMock invocation) throws Throwable { @SuppressWarnings("unchecked") ActionListener listener = (ActionListener) invocation.getArguments()[1]; - ResizeResponse resizeResponse = ResizeAction.INSTANCE.newResponse(); - resizeResponse.readFrom(StreamInput.wrap(new byte[] { 0, 0, 0, 0, 0 })); - listener.onResponse(resizeResponse); + listener.onResponse(new ResizeResponse(false, false, indexMetaData.getIndex().getName())); return null; }