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
This commit is contained in:
Lee Hinman 2018-08-06 08:53:12 -06:00 committed by GitHub
parent c13b85d6d3
commit aed466d5b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 16 deletions

View File

@ -37,7 +37,7 @@ public class IndicesAliasesResponse extends AcknowledgedResponse {
IndicesAliasesResponse() {
}
IndicesAliasesResponse(boolean acknowledged) {
public IndicesAliasesResponse(boolean acknowledged) {
super(acknowledged);
}

View File

@ -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);
}

View File

@ -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<ShrinkSetAlias
assertThat(request.getAliasActions(), equalTo(expectedAliasActions));
@SuppressWarnings("unchecked")
ActionListener<IndicesAliasesResponse> listener = (ActionListener<IndicesAliasesResponse>) 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;
}

View File

@ -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<ShrinkStep> {
.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<ShrinkStep> {
public Void answer(InvocationOnMock invocation) throws Throwable {
@SuppressWarnings("unchecked")
ActionListener<ResizeResponse> listener = (ActionListener<ResizeResponse>) 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;
}