Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public String[] indices() {
return indices;
}

Settings settings() {
public Settings settings() {
return settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class UpdateSettingsResponse extends AcknowledgedResponse {
UpdateSettingsResponse() {
}

UpdateSettingsResponse(boolean acknowledged) {
public UpdateSettingsResponse(boolean acknowledged) {
super(acknowledged);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsTestHelper;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
Expand Down Expand Up @@ -39,8 +38,13 @@
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;

public class SetSingleNodeAllocateStepTests extends AbstractStepTestCase<SetSingleNodeAllocateStep> {

Expand Down Expand Up @@ -80,7 +84,18 @@ protected SetSingleNodeAllocateStep copyInstance(SetSingleNodeAllocateStep insta
return new SetSingleNodeAllocateStep(instance.getKey(), instance.getNextStepKey(), client);
}

public void testPerformActionNoAttrs() {
public static void assertSettingsRequestContainsValueFrom(UpdateSettingsRequest request, String settingsKey,
Set<String> acceptableValues, boolean assertOnlyKeyInSettings,
String... expectedIndices) {
assertNotNull(request);
assertArrayEquals(expectedIndices, request.indices());
assertThat(request.settings().get(settingsKey), anyOf(acceptableValues.stream().map(e -> equalTo(e)).collect(Collectors.toList())));
if (assertOnlyKeyInSettings) {
assertEquals(1, request.settings().size());
}
}

public void testPerformActionNoAttrs() throws IOException {
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
Index index = indexMetaData.getIndex();
Expand All @@ -101,7 +116,7 @@ public void testPerformActionNoAttrs() {
assertNodeSelected(indexMetaData, index, validNodeNames, nodes);
}

public void testPerformActionAttrsAllNodesValid() {
public void testPerformActionAttrsAllNodesValid() throws IOException {
int numAttrs = randomIntBetween(1, 10);
String[][] validAttrs = new String[numAttrs][2];
for (int i = 0; i < numAttrs; i++) {
Expand Down Expand Up @@ -132,7 +147,7 @@ public void testPerformActionAttrsAllNodesValid() {
assertNodeSelected(indexMetaData, index, validNodeNames, nodes);
}

public void testPerformActionAttrsSomeNodesValid() {
public void testPerformActionAttrsSomeNodesValid() throws IOException {
String[] validAttr = new String[] { "box_type", "valid" };
String[] invalidAttr = new String[] { "box_type", "not_valid" };
Settings.Builder indexSettings = settings(Version.CURRENT);
Expand Down Expand Up @@ -237,7 +252,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
UpdateSettingsTestHelper.assertSettingsRequestContainsValueFrom(request,
assertSettingsRequestContainsValueFrom(request,
IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", validNodeNames, true,
indexMetaData.getIndex().getName());
listener.onFailure(exception);
Expand Down Expand Up @@ -325,7 +340,8 @@ public void onFailure(Exception e) {
Mockito.verifyZeroInteractions(client);
}

private void assertNodeSelected(IndexMetaData indexMetaData, Index index, Set<String> validNodeNames, DiscoveryNodes.Builder nodes) {
private void assertNodeSelected(IndexMetaData indexMetaData, Index index,
Set<String> validNodeNames, DiscoveryNodes.Builder nodes) throws IOException {
ImmutableOpenMap.Builder<String, IndexMetaData> indices = ImmutableOpenMap.<String, IndexMetaData> builder().fPut(index.getName(),
indexMetaData);
IndexRoutingTable.Builder indexRoutingTable = IndexRoutingTable.builder(index)
Expand All @@ -340,17 +356,18 @@ private void assertNodeSelected(IndexMetaData indexMetaData, Index index, Set<St

Mockito.when(client.admin()).thenReturn(adminClient);
Mockito.when(adminClient.indices()).thenReturn(indicesClient);

Mockito.doAnswer(new Answer<Void>() {

@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
UpdateSettingsTestHelper.assertSettingsRequestContainsValueFrom(request,
assertSettingsRequestContainsValueFrom(request,
IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", validNodeNames, true,
indexMetaData.getIndex().getName());
listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
listener.onResponse(new UpdateSettingsResponse(true));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsTestHelper;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
Expand All @@ -24,6 +23,8 @@
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import static org.hamcrest.Matchers.equalTo;

public class UpdateSettingsStepTests extends AbstractStepTestCase<UpdateSettingsStep> {

private Client client;
Expand Down Expand Up @@ -70,7 +71,7 @@ public UpdateSettingsStep copyInstance(UpdateSettingsStep instance) {
return new UpdateSettingsStep(instance.getKey(), instance.getNextStepKey(), instance.getClient(), instance.getSettings());
}

public void testPerformAction() {
public void testPerformAction() throws Exception {
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();

Expand All @@ -81,15 +82,17 @@ public void testPerformAction() {

Mockito.when(client.admin()).thenReturn(adminClient);
Mockito.when(adminClient.indices()).thenReturn(indicesClient);

Mockito.doAnswer(new Answer<Void>() {

@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
UpdateSettingsTestHelper.assertSettingsRequest(request, step.getSettings(), indexMetaData.getIndex().getName());
listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
assertThat(request.settings(), equalTo(step.getSettings()));
assertThat(request.indices(), equalTo(new String[] {indexMetaData.getIndex().getName()}));
listener.onResponse(new UpdateSettingsResponse(true));
return null;
}

Expand Down Expand Up @@ -135,7 +138,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
UpdateSettingsTestHelper.assertSettingsRequest(request, step.getSettings(), indexMetaData.getIndex().getName());
assertThat(request.settings(), equalTo(step.getSettings()));
assertThat(request.indices(), equalTo(new String[] {indexMetaData.getIndex().getName()}));
listener.onFailure(exception);
return null;
}
Expand Down