add phase and action timestamps to cluster-state (#3726)

This commit sets `index.lifecycle.phase_time` and `index.lifecycle.action_time`
appropriately during setPhase and setAction in IndexLifecycleContext.
This commit is contained in:
Tal Levy 2018-01-25 09:02:26 -08:00 committed by GitHub
parent faf067080b
commit ab49e40f91
11 changed files with 224 additions and 91 deletions

View File

@ -38,11 +38,21 @@ public interface IndexLifecycleContext {
*/
String getAction();
/**
* @return the start time of the current {@link LifecycleAction}.
*/
long getActionTime();
/**
* @return the current {@link Phase} name for the target.
*/
String getPhase();
/**
* @return the start time of the current {@link Phase}.
*/
long getPhaseTime();
/**
* @return the name of the target.
*/

View File

@ -17,6 +17,8 @@ public class LifecycleSettings {
public static final String LIFECYCLE_PHASE = "index.lifecycle.phase";
public static final String LIFECYCLE_ACTION = "index.lifecycle.action";
public static final String LIFECYCLE_INDEX_CREATION_DATE = "index.lifecycle.date";
public static final String LIFECYCLE_PHASE_TIME = "index.lifecycle.phase_time";
public static final String LIFECYCLE_ACTION_TIME = "index.lifecycle.action_time";
// NORELEASE: we should probably change the default to something other than three seconds for initial release
public static final Setting<TimeValue> LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL,
@ -29,4 +31,8 @@ public class LifecycleSettings {
Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<Long> LIFECYCLE_INDEX_CREATION_DATE_SETTING = Setting.longSetting(LIFECYCLE_INDEX_CREATION_DATE,
-1L, -1L, Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<Long> LIFECYCLE_PHASE_TIME_SETTING = Setting.longSetting(LIFECYCLE_PHASE_TIME,
-1L, -1L, Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<Long> LIFECYCLE_ACTION_TIME_SETTING = Setting.longSetting(LIFECYCLE_ACTION_TIME,
-1L, -1L, Setting.Property.Dynamic, Setting.Property.IndexScope);
}

View File

@ -5,6 +5,8 @@
*/
package org.elasticsearch.xpack.core.indexlifecycle;
import java.util.function.LongSupplier;
public abstract class MockIndexLifecycleContext implements IndexLifecycleContext {
private final String targetName;
@ -12,12 +14,19 @@ public abstract class MockIndexLifecycleContext implements IndexLifecycleContext
private String action;
private Exception exceptionToThrow;
private int numberOfReplicas;
private LongSupplier nowSupplier;
private long phaseTime;
private long actionTime;
public MockIndexLifecycleContext(String targetName, String initialPhase, String initialAction, int numberOfReplicas) {
public MockIndexLifecycleContext(String targetName, String initialPhase, String initialAction, int numberOfReplicas,
LongSupplier nowSupplier) {
this.targetName = targetName;
this.phase = initialPhase;
this.action = initialAction;
this.numberOfReplicas = numberOfReplicas;
this.nowSupplier = nowSupplier;
this.phaseTime = -1L;
this.actionTime = -1L;
}
public void failOnSetters(Exception exceptionToThrow) {
@ -31,7 +40,9 @@ public abstract class MockIndexLifecycleContext implements IndexLifecycleContext
return;
}
this.phase = phase;
this.phaseTime = nowSupplier.getAsLong();
this.action = "";
this.actionTime = -1L;
listener.onSuccess();
}
@ -42,6 +53,7 @@ public abstract class MockIndexLifecycleContext implements IndexLifecycleContext
return;
}
this.action = action;
this.actionTime = nowSupplier.getAsLong();
listener.onSuccess();
}
@ -50,11 +62,21 @@ public abstract class MockIndexLifecycleContext implements IndexLifecycleContext
return action;
}
@Override
public long getActionTime() {
return actionTime;
}
@Override
public String getPhase() {
return phase;
}
@Override
public long getPhaseTime() {
return phaseTime;
}
@Override
public String getLifecycleTarget() {
return targetName;

View File

@ -14,9 +14,10 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
public void testSetPhase() {
String targetName = randomAlphaOfLengthBetween(1, 20);
String newPhase = randomAlphaOfLengthBetween(1, 20);
long now = randomNonNegativeLong();
MockIndexLifecycleContext context = new MockIndexLifecycleContext(targetName,
randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10)) {
randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10), () -> now) {
@Override
public boolean canExecute(Phase phase) {
@ -43,6 +44,8 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
assertEquals(true, listenerCalled.get());
assertEquals(newPhase, context.getPhase());
assertEquals("", context.getAction());
assertEquals(now, context.getPhaseTime());
assertEquals(-1L, context.getActionTime());
assertEquals(targetName, context.getLifecycleTarget());
}
@ -50,7 +53,7 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
String phase = randomAlphaOfLengthBetween(1, 20);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(randomAlphaOfLengthBetween(1, 20), phase,
randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10)) {
randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10), () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -65,7 +68,7 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
int replicas = randomIntBetween(1, 10);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(randomAlphaOfLengthBetween(1, 20),
randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20), replicas) {
randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20), replicas, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -80,9 +83,10 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
String targetName = randomAlphaOfLengthBetween(1, 20);
String phase = randomAlphaOfLengthBetween(1, 20);
String newAction = randomAlphaOfLengthBetween(1, 20);
long now = randomNonNegativeLong();
MockIndexLifecycleContext context = new MockIndexLifecycleContext(targetName, phase,
randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10)) {
randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10), () -> now) {
@Override
public boolean canExecute(Phase phase) {
@ -109,6 +113,8 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
assertEquals(true, listenerCalled.get());
assertEquals(newAction, context.getAction());
assertEquals(phase, context.getPhase());
assertEquals(-1L, context.getPhaseTime()); // no setPhase was called to set this yet
assertEquals(now, context.getActionTime());
assertEquals(targetName, context.getLifecycleTarget());
}
@ -116,7 +122,7 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
String action = randomAlphaOfLengthBetween(1, 20);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(randomAlphaOfLengthBetween(1, 20),
randomAlphaOfLengthBetween(1, 20), action, randomIntBetween(0, 10)) {
randomAlphaOfLengthBetween(1, 20), action, randomIntBetween(0, 10), () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -130,7 +136,7 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
public void testGetLifecycleTarget() {
String target = randomAlphaOfLengthBetween(1, 20);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(target, randomAlphaOfLengthBetween(1, 20),
randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10)) {
randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10), () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -143,7 +149,7 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
public void testExecuteAction() {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(randomAlphaOfLengthBetween(1, 20),
randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10)) {
randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20), randomIntBetween(0, 10), () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -182,7 +188,7 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
String phase = randomAlphaOfLengthBetween(1, 20);
String action = randomAlphaOfLengthBetween(1, 20);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(randomAlphaOfLengthBetween(1, 20),
phase, action, randomIntBetween(0, 10)) {
phase, action, randomIntBetween(0, 10), () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -218,7 +224,7 @@ public class MockIndexLifecycleContextTests extends ESTestCase {
String action = randomAlphaOfLengthBetween(1, 20);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(randomAlphaOfLengthBetween(1, 20),
phase, action, randomIntBetween(0, 10)) {
phase, action, randomIntBetween(0, 10), () -> 0L) {
@Override
public boolean canExecute(Phase phase) {

View File

@ -22,8 +22,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.LongSupplier;
public class PhaseTests extends AbstractSerializingTestCase<Phase> {
private static final LongSupplier TEST_NOW_SUPPLIER = () -> 0L;
private String phaseName;
@Before
@ -125,7 +127,7 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -185,7 +187,7 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -244,7 +246,7 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -285,7 +287,7 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100));
Phase phase = new Phase(phaseName, after, Collections.emptyMap());
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -327,7 +329,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
};
Phase phase = new Phase(phaseName, after, Collections.emptyMap());
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, Phase.PHASE_COMPLETED, 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, Phase.PHASE_COMPLETED,
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -389,7 +392,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, firstAction.getWriteableName(), 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, firstAction.getWriteableName(),
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -480,7 +484,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, firstAction.getWriteableName(), 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, firstAction.getWriteableName(),
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -566,7 +571,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(), 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(),
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -652,7 +658,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, thirdAction.getWriteableName(), 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, thirdAction.getWriteableName(),
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -735,7 +742,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "does_not_exist", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "does_not_exist",
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -789,7 +797,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(), 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(),
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -914,7 +923,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(), 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(),
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -1038,7 +1048,8 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
actions.put(thirdAction.getWriteableName(), thirdAction);
Phase phase = new Phase(phaseName, after, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, thirdAction.getWriteableName(), 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, thirdAction.getWriteableName(),
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {

View File

@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.LongSupplier;
import java.util.stream.Collectors;
import static org.elasticsearch.xpack.core.indexlifecycle.TimeseriesLifecycleType.VALID_COLD_ACTIONS;
@ -44,6 +45,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
private static final ReplicasAction TEST_REPLICAS_ACTION = new ReplicasAction(1);
private static final RolloverAction TEST_ROLLOVER_ACTION = new RolloverAction("", new ByteSizeValue(1), null, null);
private static final ShrinkAction TEST_SHRINK_ACTION = new ShrinkAction(1);
private static final LongSupplier TEST_NOW_SUPPLIER = () -> 0L;
public void testGetFirstPhase() {
Map<String, Phase> phases = new HashMap<>();
@ -188,7 +190,8 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
Map<String, LifecycleAction> actions = VALID_HOT_ACTIONS
.stream().map(this::getTestAction).collect(Collectors.toMap(LifecycleAction::getWriteableName, Function.identity()));
Phase hotPhase = new Phase("hot", TimeValue.ZERO, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "",
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -209,7 +212,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
actions.put(ReplicasAction.NAME, TEST_REPLICAS_ACTION);
Phase warmPhase = new Phase("warm", TimeValue.ZERO, actions);
MockIndexLifecycleContext context =new MockIndexLifecycleContext(indexName, "", "",
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1) {
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -241,7 +244,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
actions.put(ReplicasAction.NAME, TEST_REPLICAS_ACTION);
Phase warmPhase = new Phase("warm", TimeValue.ZERO, actions);
MockIndexLifecycleContext context =new MockIndexLifecycleContext(indexName, "", "",
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1) {
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -253,7 +256,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
LifecyclePolicy.NextActionProvider provider = policy.getActionProvider(context, warmPhase);
assertThat(provider.next(null), equalTo(TEST_REPLICAS_ACTION));
context = new MockIndexLifecycleContext(indexName, "", "",
TEST_REPLICAS_ACTION.getNumberOfReplicas() - 1) {
TEST_REPLICAS_ACTION.getNumberOfReplicas() - 1, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -283,7 +286,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
actions.put(ReplicasAction.NAME, TEST_REPLICAS_ACTION);
Phase coldPhase = new Phase("cold", TimeValue.ZERO, actions);
MockIndexLifecycleContext context =new MockIndexLifecycleContext(indexName, "", "",
TEST_REPLICAS_ACTION.getNumberOfReplicas() - 1) {
TEST_REPLICAS_ACTION.getNumberOfReplicas() - 1, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -302,7 +305,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
}
context = new MockIndexLifecycleContext(indexName, "", "",
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1) {
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -327,7 +330,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
actions.put(ReplicasAction.NAME, TEST_REPLICAS_ACTION);
Phase coldPhase = new Phase("cold", TimeValue.ZERO, actions);
MockIndexLifecycleContext context =new MockIndexLifecycleContext(indexName, "", "",
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1) {
TEST_REPLICAS_ACTION.getNumberOfReplicas() + 1, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -339,7 +342,7 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
LifecyclePolicy.NextActionProvider provider = policy.getActionProvider(context, coldPhase);
assertThat(provider.next(null), equalTo(TEST_REPLICAS_ACTION));
context = new MockIndexLifecycleContext(indexName, "", "",
TEST_REPLICAS_ACTION.getNumberOfReplicas() - 1) {
TEST_REPLICAS_ACTION.getNumberOfReplicas() - 1, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {
@ -363,7 +366,8 @@ public class TimeseriesLifecycleTypeTests extends ESTestCase {
.stream().map(this::getTestAction).collect(Collectors.toMap(LifecycleAction::getWriteableName, Function.identity()));
Phase deletePhase = new Phase("delete", TimeValue.ZERO, actions);
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "",
0, TEST_NOW_SUPPLIER) {
@Override
public boolean canExecute(Phase phase) {

View File

@ -103,6 +103,8 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
LifecycleSettings.LIFECYCLE_NAME_SETTING,
LifecycleSettings.LIFECYCLE_PHASE_SETTING,
LifecycleSettings.LIFECYCLE_INDEX_CREATION_DATE_SETTING,
LifecycleSettings.LIFECYCLE_PHASE_TIME_SETTING,
LifecycleSettings.LIFECYCLE_ACTION_TIME_SETTING,
LifecycleSettings.LIFECYCLE_ACTION_SETTING);
}

View File

@ -54,8 +54,10 @@ public class InternalIndexLifecycleContext implements IndexLifecycleContext {
@Override
public void setPhase(String phase, Listener listener) {
Settings newLifecyclePhaseSettings = Settings.builder()
.put(LifecycleSettings.LIFECYCLE_PHASE_SETTING.getKey(), phase)
.put(LifecycleSettings.LIFECYCLE_ACTION_SETTING.getKey(), "").build();
.put(LifecycleSettings.LIFECYCLE_PHASE, phase)
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, nowSupplier.getAsLong())
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, -1L)
.put(LifecycleSettings.LIFECYCLE_ACTION, "").build();
writeSettings(index.getName(), newLifecyclePhaseSettings, listener);
}
@ -64,9 +66,17 @@ public class InternalIndexLifecycleContext implements IndexLifecycleContext {
return LifecycleSettings.LIFECYCLE_PHASE_SETTING.get(getIdxMetaData().getSettings());
}
@Override
public long getPhaseTime() {
return LifecycleSettings.LIFECYCLE_PHASE_TIME_SETTING.get(getIdxMetaData().getSettings());
}
@Override
public void setAction(String action, Listener listener) {
Settings newLifecycleActionSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_ACTION_SETTING.getKey(), action).build();
Settings newLifecycleActionSettings = Settings.builder()
.put(LifecycleSettings.LIFECYCLE_ACTION, action)
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, nowSupplier.getAsLong())
.build();
writeSettings(index.getName(), newLifecycleActionSettings, listener);
}
@ -75,6 +85,11 @@ public class InternalIndexLifecycleContext implements IndexLifecycleContext {
return LifecycleSettings.LIFECYCLE_ACTION_SETTING.get(getIdxMetaData().getSettings());
}
@Override
public long getActionTime() {
return LifecycleSettings.LIFECYCLE_ACTION_TIME_SETTING.get(getIdxMetaData().getSettings());
}
@Override
public String getLifecycleTarget() {
return index.getName();

View File

@ -97,7 +97,7 @@ public class IndexLifecycleServiceTests extends ESTestCase {
when(adminClient.indices()).thenReturn(indicesClient);
indexLifecycleService = new IndexLifecycleService(Settings.EMPTY, client, clusterService, clock,
threadPool, () -> now);
threadPool, () -> now);
Mockito.verify(clusterService).addListener(indexLifecycleService);
}
@ -320,8 +320,10 @@ public class IndexLifecycleServiceTests extends ESTestCase {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocationOnMock.getArguments()[0];
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocationOnMock.getArguments()[1];
UpdateSettingsTestHelper.assertSettingsRequest(request, Settings.builder()
.put(LifecycleSettings.LIFECYCLE_ACTION_SETTING.getKey(), "")
.put(LifecycleSettings.LIFECYCLE_PHASE_SETTING.getKey(), "phase").build(), index.getName());
.put(LifecycleSettings.LIFECYCLE_ACTION, "")
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, -1L)
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, now)
.put(LifecycleSettings.LIFECYCLE_PHASE, "phase").build(), index.getName());
phaseUpdated.set(true);
listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
return null;
@ -329,7 +331,8 @@ public class IndexLifecycleServiceTests extends ESTestCase {
UpdateSettingsRequest request = (UpdateSettingsRequest) invocationOnMock.getArguments()[0];
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocationOnMock.getArguments()[1];
UpdateSettingsTestHelper.assertSettingsRequest(request, Settings.builder()
.put(LifecycleSettings.LIFECYCLE_ACTION_SETTING.getKey(), MockAction.NAME).build(), index.getName());
.put(LifecycleSettings.LIFECYCLE_ACTION, MockAction.NAME)
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, now).build(), index.getName());
actionUpdated.set(true);
listener.onResponse(UpdateSettingsTestHelper.createMockResponse(true));
return null;
@ -398,7 +401,6 @@ public class IndexLifecycleServiceTests extends ESTestCase {
assertNull(dateUpdated.get());
assertThat(mockAction.getExecutedCount(), equalTo(1L));
}
/**

View File

@ -34,6 +34,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.util.Collections;
import java.util.function.LongSupplier;
public class InternalIndexLifecycleContextTests extends ESTestCase {
private static final Index TEST_INDEX = new Index("test", "test");
@ -47,16 +48,23 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
}
public void testSetPhase() {
long oldNow = randomNonNegativeLong();
long now = randomNonNegativeLong();
LongSupplier nowSupplier = () -> now;
long creationDate = randomNonNegativeLong();
String oldPhase = randomAlphaOfLengthBetween(1, 5);
String newPhase = randomAlphaOfLengthBetween(6, 10);
Settings expectedSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_PHASE, newPhase)
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, now)
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, -1L)
.put(LifecycleSettings.LIFECYCLE_ACTION, "").build();
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_PHASE, oldPhase)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_PHASE, oldPhase)
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, oldNow)
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, oldNow)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterState updatedClusterState = getClusterState(IndexMetaData.builder(idxMeta)
.settings(Settings.builder().put(idxMeta.getSettings()).put(expectedSettings)).build());
@ -84,9 +92,7 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
}
}).when(indicesClient).updateSettings(Mockito.any(), Mockito.any());
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, nowSupplier);
// Use setOnce so it throws an error if we call the listener multiple
// times
@ -114,13 +120,16 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
}
public void testSetPhaseNotAcknowledged() {
long now = randomNonNegativeLong();
LongSupplier nowSupplier = () -> now;
long creationDate = randomNonNegativeLong();
String newPhase = randomAlphaOfLengthBetween(1, 20);
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_PHASE, randomAlphaOfLengthBetween(1, 20))
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_PHASE, randomAlphaOfLengthBetween(1, 20))
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, now)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(clusterState);
@ -139,16 +148,16 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
Settings expectedSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_PHASE, newPhase)
.put(LifecycleSettings.LIFECYCLE_ACTION, "").build();
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, now)
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, -1L)
.put(LifecycleSettings.LIFECYCLE_ACTION, "").build();
UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, TEST_INDEX.getName());
listener.onResponse(UpdateSettingsTestHelper.createMockResponse(false));
return null;
}
}).when(indicesClient).updateSettings(Mockito.any(), Mockito.any());
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, nowSupplier);
// Use setOnce so it throws an error if we call the listener multiple
// times
@ -175,12 +184,15 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
}
public void testSetPhaseFailure() {
long now = randomNonNegativeLong();
LongSupplier nowSupplier = () -> now;
long creationDate = randomNonNegativeLong();
String newPhase = randomAlphaOfLengthBetween(1, 20);
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_PHASE, randomAlphaOfLengthBetween(1, 20))
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.put(LifecycleSettings.LIFECYCLE_PHASE, randomAlphaOfLengthBetween(1, 20))
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, now)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterService clusterService = Mockito.mock(ClusterService.class);
@ -202,16 +214,15 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
Settings expectedSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_PHASE, newPhase)
.put(LifecycleSettings.LIFECYCLE_ACTION, "").build();
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, -1L).put(LifecycleSettings.LIFECYCLE_PHASE_TIME, now)
.put(LifecycleSettings.LIFECYCLE_ACTION, "").build();
UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, TEST_INDEX.getName());
listener.onFailure(exception);
return null;
}
}).when(indicesClient).updateSettings(Mockito.any(), Mockito.any());
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, nowSupplier);
// Use setOnce so it throws an error if we call the listener multiple
// times
@ -255,6 +266,24 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
assertEquals(phase, context.getPhase());
}
public void testGetPhaseTime() {
long creationDate = randomNonNegativeLong();
long phaseTime = randomNonNegativeLong();
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, phaseTime).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(clusterState);
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, null, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
assertEquals(phaseTime, context.getPhaseTime());
}
public void testGetReplicas() {
int replicas = randomIntBetween(0, 5);
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
@ -272,13 +301,16 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
}
public void testSetAction() {
long now = randomNonNegativeLong();
LongSupplier nowSupplier = () -> now;
long creationDate = randomNonNegativeLong();
String oldAction = randomAlphaOfLengthBetween(1, 5);
String newAction = randomAlphaOfLengthBetween(6, 10);
Settings expectedSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_ACTION, newAction).build();
Settings expectedSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_ACTION, newAction)
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, now).build();
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_ACTION, oldAction).build())
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, now).put(LifecycleSettings.LIFECYCLE_ACTION, oldAction).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterState updatedClusterState = getClusterState(IndexMetaData.builder(idxMeta)
@ -305,9 +337,7 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
}
}).when(indicesClient).updateSettings(Mockito.any(), Mockito.any());
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, nowSupplier);
// Use setOnce so it throws an error if we call the listener multiple
// times
@ -334,13 +364,16 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
Mockito.verify(indicesClient, Mockito.only()).updateSettings(Mockito.any(), Mockito.any());
}
public void testSetActionNotAcknoledged() {
public void testSetActionNotAcknowledged() {
long now = randomNonNegativeLong();
LongSupplier nowSupplier = () -> now;
long creationDate = randomNonNegativeLong();
String newAction = randomAlphaOfLengthBetween(1, 20);
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, now)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(clusterState);
@ -359,16 +392,14 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
Settings expectedSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_ACTION, newAction)
.build();
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, now).build();
UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, TEST_INDEX.getName());
listener.onResponse(UpdateSettingsTestHelper.createMockResponse(false));
return null;
}
}).when(indicesClient).updateSettings(Mockito.any(), Mockito.any());
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, nowSupplier);
// Use setOnce so it throws an error if we call the listener multiple
// times
@ -395,12 +426,15 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
}
public void testSetActionFailure() {
long now = randomNonNegativeLong();
LongSupplier nowSupplier = () -> now;
long creationDate = randomNonNegativeLong();
String newAction = randomAlphaOfLengthBetween(1, 20);
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, now)
.put(LifecycleSettings.LIFECYCLE_ACTION, randomAlphaOfLengthBetween(1, 20)).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(clusterState);
@ -421,16 +455,14 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
@SuppressWarnings("unchecked")
ActionListener<UpdateSettingsResponse> listener = (ActionListener<UpdateSettingsResponse>) invocation.getArguments()[1];
Settings expectedSettings = Settings.builder().put(LifecycleSettings.LIFECYCLE_ACTION, newAction)
.build();
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, now).build();
UpdateSettingsTestHelper.assertSettingsRequest(request, expectedSettings, TEST_INDEX.getName());
listener.onFailure(exception);
return null;
}
}).when(indicesClient).updateSettings(Mockito.any(), Mockito.any());
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, client, clusterService, nowSupplier);
// Use setOnce so it throws an error if we call the listener multiple
// times
@ -474,6 +506,24 @@ public class InternalIndexLifecycleContextTests extends ESTestCase {
assertEquals(action, context.getAction());
}
public void testGetActionTime() {
long creationDate = randomNonNegativeLong();
long actionTime = randomNonNegativeLong();
IndexMetaData idxMeta = IndexMetaData.builder(TEST_INDEX.getName())
.settings(Settings.builder().put("index.version.created", 7000001L).put("index.creation_date", creationDate)
.put(LifecycleSettings.LIFECYCLE_ACTION_TIME, actionTime).build())
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = getClusterState(idxMeta);
ClusterService clusterService = Mockito.mock(ClusterService.class);
Mockito.when(clusterService.state()).thenReturn(clusterState);
InternalIndexLifecycleContext context = new InternalIndexLifecycleContext(TEST_INDEX, null, clusterService, () -> {
throw new AssertionError("nowSupplier should not be called");
});
assertEquals(actionTime, context.getActionTime());
}
public void testGetLifecycleTarget() {
long creationDate = randomNonNegativeLong();
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));

View File

@ -136,7 +136,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteNewIndexBeforeTrigger() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -163,7 +163,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteNewIndexAfterTrigger() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -190,7 +190,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteNewIndexAfterTriggerFailure() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "", "", 0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -221,7 +221,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteFirstPhase() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, firstPhase.getName(), "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, firstPhase.getName(), "", 0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -244,7 +244,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteSecondPhase() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, secondPhase.getName(), "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, secondPhase.getName(), "", 0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -267,7 +267,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteThirdPhase() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, thirdPhase.getName(), "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, thirdPhase.getName(), "", 0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -290,7 +290,7 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteMissingPhase() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "does_not_exist", "", 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, "does_not_exist", "", 0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -316,7 +316,8 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteFirstPhaseCompletedBeforeTrigger() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, firstPhase.getName(), Phase.PHASE_COMPLETED, 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, firstPhase.getName(), Phase.PHASE_COMPLETED,
0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -343,7 +344,8 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteFirstPhaseCompletedAfterTrigger() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, firstPhase.getName(), Phase.PHASE_COMPLETED, 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, firstPhase.getName(), Phase.PHASE_COMPLETED,
0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -370,7 +372,8 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteSecondPhaseCompletedBeforeTrigger() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, secondPhase.getName(), Phase.PHASE_COMPLETED, 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, secondPhase.getName(), Phase.PHASE_COMPLETED,
0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -397,7 +400,8 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteSecondPhaseCompletedAfterTrigger() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, secondPhase.getName(), Phase.PHASE_COMPLETED, 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, secondPhase.getName(), Phase.PHASE_COMPLETED,
0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
@ -424,7 +428,8 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
}
public void testExecuteThirdPhaseCompleted() throws Exception {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, thirdPhase.getName(), Phase.PHASE_COMPLETED, 0) {
MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, thirdPhase.getName(), Phase.PHASE_COMPLETED,
0, () -> 0L) {
@Override
public boolean canExecute(Phase phase) {
throw new AssertionError("canExecute should not have been called");