|
@@ -16,7 +16,6 @@ import org.elasticsearch.cluster.service.ClusterService;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.test.ClusterServiceUtils;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
-import org.elasticsearch.test.junit.annotations.TestIssueLogging;
|
|
|
import org.elasticsearch.threadpool.TestThreadPool;
|
|
|
import org.elasticsearch.threadpool.ThreadPool;
|
|
|
import org.elasticsearch.xpack.core.ilm.OperationMode;
|
|
@@ -99,9 +98,9 @@ public class SnapshotLifecycleServiceTests extends ESTestCase {
|
|
|
try (ClusterService clusterService = ClusterServiceUtils.createClusterService(initialState, threadPool);
|
|
|
SnapshotLifecycleService sls = new SnapshotLifecycleService(Settings.EMPTY,
|
|
|
() -> new FakeSnapshotTask(e -> logger.info("triggered")), clusterService, clock)) {
|
|
|
-
|
|
|
+
|
|
|
sls.offMaster();
|
|
|
-
|
|
|
+
|
|
|
SnapshotLifecyclePolicyMetadata newPolicy = SnapshotLifecyclePolicyMetadata.builder()
|
|
|
.setPolicy(createPolicy("foo", "*/1 * * * * ?"))
|
|
|
.setHeaders(Collections.emptyMap())
|
|
@@ -114,27 +113,27 @@ public class SnapshotLifecycleServiceTests extends ESTestCase {
|
|
|
createState(new SnapshotLifecycleMetadata(Collections.emptyMap(), OperationMode.RUNNING, new SnapshotLifecycleStats()));
|
|
|
ClusterState state =
|
|
|
createState(new SnapshotLifecycleMetadata(policies, OperationMode.RUNNING, new SnapshotLifecycleStats()));
|
|
|
-
|
|
|
+
|
|
|
sls.clusterChanged(new ClusterChangedEvent("1", state, emptyState));
|
|
|
-
|
|
|
+
|
|
|
// Since the service does not think it is master, it should not be triggered or scheduled
|
|
|
assertThat(sls.getScheduler().scheduledJobIds(), equalTo(Collections.emptySet()));
|
|
|
-
|
|
|
+
|
|
|
sls.onMaster();
|
|
|
assertThat(sls.getScheduler().scheduledJobIds(), equalTo(Collections.singleton("initial-1")));
|
|
|
-
|
|
|
+
|
|
|
state = createState(new SnapshotLifecycleMetadata(policies, OperationMode.STOPPING, new SnapshotLifecycleStats()));
|
|
|
sls.clusterChanged(new ClusterChangedEvent("2", state, emptyState));
|
|
|
-
|
|
|
+
|
|
|
// Since the service is stopping, jobs should have been cancelled
|
|
|
assertThat(sls.getScheduler().scheduledJobIds(), equalTo(Collections.emptySet()));
|
|
|
-
|
|
|
+
|
|
|
state = createState(new SnapshotLifecycleMetadata(policies, OperationMode.STOPPED, new SnapshotLifecycleStats()));
|
|
|
sls.clusterChanged(new ClusterChangedEvent("3", state, emptyState));
|
|
|
-
|
|
|
+
|
|
|
// Since the service is stopped, jobs should have been cancelled
|
|
|
assertThat(sls.getScheduler().scheduledJobIds(), equalTo(Collections.emptySet()));
|
|
|
-
|
|
|
+
|
|
|
// No jobs should be scheduled when service is closed
|
|
|
state = createState(new SnapshotLifecycleMetadata(policies, OperationMode.RUNNING, new SnapshotLifecycleStats()));
|
|
|
sls.close();
|