Adds settings checking to tests

This isn’t an ideal solution so might well be temporary but at least the tests are checking the settings changes are correct now
This commit is contained in:
Colin Goodheart-Smithe 2017-11-24 10:10:46 +00:00
parent 016ba2a57d
commit 31ded906d0
2 changed files with 73 additions and 65 deletions

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.indexlifecycle;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; 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.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsTestHelper;
import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.IndicesAdminClient;
@ -32,8 +33,6 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
// NOCOMMIT this test needs some thinking about as currently it can't really test that the right thing is
// happening since we can't inspect the settings in the update request
public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecyclePolicy> { public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecyclePolicy> {
private NamedXContentRegistry registry; private NamedXContentRegistry registry;
@ -142,11 +141,11 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_PHASE_SETTING.getKey(), "first_phase")
assertEquals(indexName, request.indices()[0]); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), "").build();
// NOCOMMIT Need to check the settings in the request are UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// correct (i.e adds the name of the first action) listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
return null; return null;
} }
@ -206,11 +205,10 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), MockAction.NAME).build();
assertEquals(indexName, request.indices()[0]); UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// NOCOMMIT Need to check the settings in the request are listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
// correct (i.e adds the name of the first action)
return null; return null;
} }
@ -270,11 +268,10 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), MockAction.NAME).build();
assertEquals(indexName, request.indices()[0]); UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// NOCOMMIT Need to check the settings in the request are listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
// correct (i.e adds the name of the first action)
return null; return null;
} }
@ -334,11 +331,10 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), MockAction.NAME).build();
assertEquals(indexName, request.indices()[0]); UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// NOCOMMIT Need to check the settings in the request are listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
// correct (i.e adds the name of the first action)
return null; return null;
} }
@ -391,22 +387,6 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
Mockito.when(client.admin()).thenReturn(adminClient); Mockito.when(client.admin()).thenReturn(adminClient);
Mockito.when(adminClient.indices()).thenReturn(indicesClient); 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];
assertNotNull(request);
assertEquals(1, request.indices().length);
assertEquals(indexName, request.indices()[0]);
// NOCOMMIT Need to check the settings in the request are
// correct (i.e adds the name of the first action)
return null;
}
}).when(indicesClient).updateSettings(Mockito.any(), Mockito.any());
IllegalStateException exception = expectThrows(IllegalStateException.class, () -> policy.execute(idxMeta, client, () -> 0L)); IllegalStateException exception = expectThrows(IllegalStateException.class, () -> policy.execute(idxMeta, client, () -> 0L));
assertEquals( assertEquals(
@ -513,11 +493,11 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_PHASE_SETTING.getKey(), "second_phase")
assertEquals(indexName, request.indices()[0]); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), "").build();
// NOCOMMIT Need to check the settings in the request are UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// correct (i.e adds the name of the first action) listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
return null; return null;
} }
@ -627,11 +607,11 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_PHASE_SETTING.getKey(), "third_phase")
assertEquals(indexName, request.indices()[0]); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), "").build();
// NOCOMMIT Need to check the settings in the request are UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// correct (i.e adds the name of the first action) listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
return null; return null;
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.indexlifecycle;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; 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.UpdateSettingsResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsTestHelper;
import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient; import org.elasticsearch.client.IndicesAdminClient;
@ -144,11 +145,26 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
String phaseName = randomAlphaOfLengthBetween(1, 20); String phaseName = randomAlphaOfLengthBetween(1, 20);
TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100));
List<LifecycleAction> actions = new ArrayList<>(); List<LifecycleAction> actions = new ArrayList<>();
MockAction firstAction = new MockAction(); MockAction firstAction = new MockAction() {
@Override
public String getWriteableName() {
return "first_action";
}
};
actions.add(firstAction); actions.add(firstAction);
MockAction secondAction = new MockAction(); MockAction secondAction = new MockAction() {
@Override
public String getWriteableName() {
return "second_action";
}
};
actions.add(secondAction); actions.add(secondAction);
MockAction thirdAction = new MockAction(); MockAction thirdAction = new MockAction() {
@Override
public String getWriteableName() {
return "third_action";
}
};
actions.add(thirdAction); actions.add(thirdAction);
Phase phase = new Phase(phaseName, after, actions); Phase phase = new Phase(phaseName, after, actions);
@ -168,11 +184,10 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), "first_action").build();
assertEquals(indexName, request.indices()[0]); UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// NOCOMMIT Need to check the settings in the request are listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
// correct (i.e adds the name of the first action)
return null; return null;
} }
@ -211,11 +226,10 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0]; UpdateSettingsRequest request = (UpdateSettingsRequest) invocation.getArguments()[0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1]; ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
assertNotNull(request); Settings expectedSettings = Settings.builder()
assertEquals(1, request.indices().length); .put(IndexLifecycle.LIFECYCLE_TIMESERIES_ACTION_SETTING.getKey(), Phase.PHASE_COMPLETED).build();
assertEquals(indexName, request.indices()[0]); UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, indexName);
// NOCOMMIT Need to check the settings in the request are listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
// correct (i.e. sets the action to `ACTIONS COMPLETED`)
return null; return null;
} }
@ -233,12 +247,26 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
String phaseName = randomAlphaOfLengthBetween(1, 20); String phaseName = randomAlphaOfLengthBetween(1, 20);
TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100));
List<LifecycleAction> actions = new ArrayList<>(); List<LifecycleAction> actions = new ArrayList<>();
MockAction firstAction = new MockAction(); MockAction firstAction = new MockAction() {
@Override
public String getWriteableName() {
return "first_action";
}
};
actions.add(firstAction); actions.add(firstAction);
MockAction secondAction = new MockAction(); MockAction secondAction = new MockAction() {
@Override
public String getWriteableName() {
return "second_action";
}
};
actions.add(secondAction); actions.add(secondAction);
MockAction thirdAction = new MockAction(); MockAction thirdAction = new MockAction() {
actions.add(thirdAction); @Override
public String getWriteableName() {
return "third_action";
}
};
Phase phase = new Phase(phaseName, after, Collections.emptyList()); Phase phase = new Phase(phaseName, after, Collections.emptyList());
IndexMetaData idxMeta = IndexMetaData.builder(indexName) IndexMetaData idxMeta = IndexMetaData.builder(indexName)