diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/PhaseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/PhaseTests.java index 87d5a8fe21a..aa70dd7b42a 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/PhaseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/PhaseTests.java @@ -40,7 +40,7 @@ public class PhaseTests extends AbstractSerializingTestCase { } Map actions = Collections.emptyMap(); if (randomBoolean()) { - actions = Collections.singletonMap(DeleteAction.NAME, new DeleteAction()); + actions = Collections.singletonMap(MockAction.NAME, new MockAction()); } return new Phase(phaseName, after, actions); } @@ -57,13 +57,13 @@ public class PhaseTests extends AbstractSerializingTestCase { protected NamedWriteableRegistry getNamedWriteableRegistry() { return new NamedWriteableRegistry(Arrays - .asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new))); + .asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new))); } @Override protected NamedXContentRegistry xContentRegistry() { List entries = new ArrayList<>(ClusterModule.getNamedXWriteables()); - entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse)); + entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(MockAction.NAME), MockAction::parse)); return new NamedXContentRegistry(entries); } @@ -81,8 +81,7 @@ public class PhaseTests extends AbstractSerializingTestCase { break; case 2: actions = new HashMap<>(actions); - // TODO(talevy): make real - actions.put(MockAction.NAME, new MockAction(Collections.emptyList())); + actions.put(MockAction.NAME + "another", new MockAction(Collections.emptyList())); break; default: throw new AssertionError("Illegal randomisation branch"); @@ -94,1046 +93,4 @@ public class PhaseTests extends AbstractSerializingTestCase { Phase phase = new Phase(randomAlphaOfLength(20), null, Collections.emptyMap()); assertEquals(TimeValue.ZERO, phase.getAfter()); } - -// public void testExecuteNewIndexCompleteActions() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(true); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// secondAction.setCompleteOnExecute(true); -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(true); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(Phase.PHASE_COMPLETED, context.getAction()); -// -// assertTrue(firstAction.wasCompleted()); -// assertEquals(1L, firstAction.getExecutedCount()); -// assertTrue(secondAction.wasCompleted()); -// assertEquals(1L, secondAction.getExecutedCount()); -// assertTrue(thirdAction.wasCompleted()); -// assertEquals(1L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteNewIndexIncompleteFirstAction() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(firstAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(1L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteNewIndexFailure() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// RuntimeException exception = new RuntimeException(); -// -// context.failOnSetters(exception); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals("", context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteNewIndexNoActions() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Phase phase = new Phase(phaseName, after, Collections.emptyMap()); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "", 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, a -> null); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(Phase.PHASE_COMPLETED, context.getAction()); -// } -// -// public void testExecutePhaseAlreadyComplete() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// List actions = new ArrayList<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// actions.add(firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// actions.add(secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// Phase phase = new Phase(phaseName, after, Collections.emptyMap()); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, Phase.PHASE_COMPLETED, -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(Phase.PHASE_COMPLETED, context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteFirstAction() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// secondAction.setCompleteOnExecute(false); -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(false); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, firstAction.getWriteableName(), -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(firstAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(1L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// -// firstAction.setCompleteOnExecute(true); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(secondAction.getWriteableName(), context.getAction()); -// -// assertTrue(firstAction.wasCompleted()); -// assertEquals(2L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(1L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteFirstActionIndexDoesNotSurvive() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// -// @Override -// public boolean indexSurvives() { -// return false; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// secondAction.setCompleteOnExecute(false); -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(false); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, firstAction.getWriteableName(), -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(firstAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(1L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// -// firstAction.setCompleteOnExecute(true); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(firstAction.getWriteableName(), context.getAction()); -// -// assertTrue(firstAction.wasCompleted()); -// assertEquals(2L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteSecondAction() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// secondAction.setCompleteOnExecute(false); -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(false); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(), -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(secondAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(1L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// -// secondAction.setCompleteOnExecute(true); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(thirdAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertTrue(secondAction.wasCompleted()); -// assertEquals(2L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(1L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteThirdAction() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// secondAction.setCompleteOnExecute(false); -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(false); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, thirdAction.getWriteableName(), -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(thirdAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(1L, thirdAction.getExecutedCount()); -// -// thirdAction.setCompleteOnExecute(true); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(Phase.PHASE_COMPLETED, context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertTrue(thirdAction.wasCompleted()); -// assertEquals(2L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteMissingAction() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, "does_not_exist", -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// IllegalStateException exception = expectThrows(IllegalStateException.class, () -> phase.execute(context, a -> firstAction)); -// assertEquals("Current action [" + "does_not_exist" + "] not found in phase [" + phaseName + "] for index [" + indexName + "]", -// exception.getMessage()); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals("does_not_exist", context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteActionFailure() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(false); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(), -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// // First check that if an exception is thrown when we execute the second -// // action, action is not completed and the phase and action are not -// // updated in the context -// Exception exception = new RuntimeException(); -// secondAction.setCompleteOnExecute(false); -// secondAction.setExceptionToThrow(exception); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(secondAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(1L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// -// // Now check that if an exception is thrown when we execute the second -// // action again, action is not completed even though it would normally -// // complete, also check the third action is not executed in this case -// // and the phase and action are not updated in the context -// secondAction.setCompleteOnExecute(true); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(secondAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(2L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// -// // Now check that if the action is run again without an exception thrown -// // then it completes successfully, the action and phase in the context -// // are updated and the third action is executed -// secondAction.setCompleteOnExecute(true); -// secondAction.setExceptionToThrow(null); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(thirdAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertTrue(secondAction.wasCompleted()); -// assertEquals(3L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(1L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteActionFailedSetAction() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// secondAction.setCompleteOnExecute(true); -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(false); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, secondAction.getWriteableName(), -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// // First check that if setting the new action fails we don't execute the -// // next phase -// Exception exception = new RuntimeException(); -// context.failOnSetters(exception); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(secondAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertTrue(secondAction.wasCompleted()); -// assertEquals(1L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// -// // Now check that if we execute the phase again the current action is -// // re-executed and if setting the new action fails again we still don't -// // execute the next action -// secondAction.setCompleteOnExecute(true); -// secondAction.resetCompleted(); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(secondAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertTrue(secondAction.wasCompleted()); -// assertEquals(2L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(0L, thirdAction.getExecutedCount()); -// -// // Now check that if we execute the phase again the current action is -// // re-executed and if setting the new action suceeds now the next action -// // is executed -// secondAction.setCompleteOnExecute(true); -// context.failOnSetters(null); -// secondAction.resetCompleted(); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(thirdAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertTrue(secondAction.wasCompleted()); -// assertEquals(3L, secondAction.getExecutedCount()); -// assertFalse(thirdAction.wasCompleted()); -// assertEquals(1L, thirdAction.getExecutedCount()); -// } -// -// public void testExecuteLastActionFailedSetAction() throws Exception { -// String indexName = randomAlphaOfLengthBetween(1, 20); -// String phaseName = randomAlphaOfLengthBetween(1, 20); -// TimeValue after = TimeValue.timeValueSeconds(randomIntBetween(10, 100)); -// Map actions = new HashMap<>(); -// MockAction firstAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "first_action"; -// } -// }; -// firstAction.setCompleteOnExecute(false); -// actions.put(firstAction.getWriteableName(), firstAction); -// MockAction secondAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "second_action"; -// } -// }; -// secondAction.setCompleteOnExecute(false); -// actions.put(secondAction.getWriteableName(), secondAction); -// MockAction thirdAction = new MockAction() { -// @Override -// public String getWriteableName() { -// return "third_action"; -// } -// }; -// thirdAction.setCompleteOnExecute(true); -// actions.put(thirdAction.getWriteableName(), thirdAction); -// Phase phase = new Phase(phaseName, after, actions); -// -// MockIndexLifecycleContext context = new MockIndexLifecycleContext(indexName, phaseName, thirdAction.getWriteableName(), -// 0, TEST_NOW_SUPPLIER) { -// -// @Override -// public boolean canExecute(Phase phase) { -// throw new AssertionError("canExecute should not have been called"); -// } -// }; -// -// // First check setting the ACTION_COMPLETED fails -// Exception exception = new RuntimeException(); -// context.failOnSetters(exception); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(thirdAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertTrue(thirdAction.wasCompleted()); -// assertEquals(1L, thirdAction.getExecutedCount()); -// -// // Now check the same happens if it fails again -// thirdAction.setCompleteOnExecute(true); -// thirdAction.resetCompleted(); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(thirdAction.getWriteableName(), context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertTrue(thirdAction.wasCompleted()); -// assertEquals(2L, thirdAction.getExecutedCount()); -// -// // Now check the action updates if we try again and setting the -// // PHASE_COMPLETED succeeds -// context.failOnSetters(null); -// thirdAction.resetCompleted(); -// -// phase.execute(context, current -> { -// if (current == null) { -// return firstAction; -// } else if ("first_action".equals(current.getWriteableName())) { -// return secondAction; -// } else if ("second_action".equals(current.getWriteableName())) { -// return thirdAction; -// } -// return null; -// }); -// -// assertEquals(indexName, context.getLifecycleTarget()); -// assertEquals(phaseName, context.getPhase()); -// assertEquals(Phase.PHASE_COMPLETED, context.getAction()); -// -// assertFalse(firstAction.wasCompleted()); -// assertEquals(0L, firstAction.getExecutedCount()); -// assertFalse(secondAction.wasCompleted()); -// assertEquals(0L, secondAction.getExecutedCount()); -// assertTrue(thirdAction.wasCompleted()); -// assertEquals(3L, thirdAction.getExecutedCount()); -// } - }