Skip to content

Commit 46e4ba4

Browse files
committed
Drop integration test and add another unit test
1 parent 579c851 commit 46e4ba4

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MigrateActionTests.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
*/
77
package org.elasticsearch.xpack.core.ilm;
88

9+
import org.elasticsearch.Version;
10+
import org.elasticsearch.cluster.ClusterName;
11+
import org.elasticsearch.cluster.ClusterState;
12+
import org.elasticsearch.cluster.metadata.IndexMetadata;
13+
import org.elasticsearch.cluster.metadata.Metadata;
914
import org.elasticsearch.common.io.stream.Writeable.Reader;
1015
import org.elasticsearch.common.xcontent.XContentParser;
1116
import org.elasticsearch.xpack.cluster.routing.allocation.DataTierAllocationDecider;
@@ -14,6 +19,7 @@
1419
import java.io.IOException;
1520
import java.util.List;
1621

22+
import static org.elasticsearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
1723
import static org.elasticsearch.xpack.core.DataTier.DATA_COLD;
1824
import static org.elasticsearch.xpack.core.DataTier.DATA_HOT;
1925
import static org.elasticsearch.xpack.core.DataTier.DATA_WARM;
@@ -22,6 +28,8 @@
2228
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.DELETE_PHASE;
2329
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.HOT_PHASE;
2430
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.WARM_PHASE;
31+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_DIRECTORY_FACTORY_KEY;
32+
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants.SNAPSHOT_PARTIAL_SETTING;
2533
import static org.hamcrest.CoreMatchers.is;
2634

2735
public class MigrateActionTests extends AbstractActionTestCase<MigrateAction> {
@@ -106,4 +114,51 @@ public void testMigrateActionsConfiguresTierPreference() {
106114
is(DATA_COLD + "," + DATA_WARM + "," + DATA_HOT));
107115
}
108116
}
117+
118+
public void testMigrateActionWillSkipAPartiallyMountedIndex() {
119+
StepKey nextStepKey = new StepKey(randomAlphaOfLengthBetween(1, 10), randomAlphaOfLengthBetween(1, 10),
120+
randomAlphaOfLengthBetween(1, 10));
121+
MigrateAction action = new MigrateAction();
122+
123+
// does not skip an ordinary index
124+
{
125+
IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(5))
126+
.settings(settings(Version.CURRENT))
127+
.numberOfShards(1)
128+
.numberOfReplicas(2)
129+
.build();
130+
131+
ClusterState clusterState = ClusterState.builder(new ClusterName("_name"))
132+
.metadata(Metadata.builder().put(indexMetadata, true).build())
133+
.build();
134+
135+
List<Step> steps = action.toSteps(null, HOT_PHASE, nextStepKey);
136+
BranchingStep firstStep = (BranchingStep) steps.get(0);
137+
UpdateSettingsStep secondStep = (UpdateSettingsStep) steps.get(1);
138+
firstStep.performAction(indexMetadata.getIndex(), clusterState);
139+
140+
assertEquals(secondStep.getKey(), firstStep.getNextStepKey());
141+
}
142+
143+
// does skip a partially mounted
144+
{
145+
IndexMetadata indexMetadata = IndexMetadata.builder(randomAlphaOfLength(5))
146+
.settings(settings(Version.CURRENT)
147+
.put(INDEX_STORE_TYPE_SETTING.getKey(), SNAPSHOT_DIRECTORY_FACTORY_KEY)
148+
.put(SNAPSHOT_PARTIAL_SETTING.getKey(), true))
149+
.numberOfShards(1)
150+
.numberOfReplicas(2)
151+
.build();
152+
153+
ClusterState clusterState = ClusterState.builder(new ClusterName("_name"))
154+
.metadata(Metadata.builder().put(indexMetadata, true).build())
155+
.build();
156+
157+
List<Step> steps = action.toSteps(null, HOT_PHASE, nextStepKey);
158+
BranchingStep firstStep = (BranchingStep) steps.get(0);
159+
firstStep.performAction(indexMetadata.getIndex(), clusterState);
160+
161+
assertEquals(nextStepKey, firstStep.getNextStepKey());
162+
}
163+
}
109164
}

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
2929
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
3030
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
31-
import org.elasticsearch.xpack.core.ilm.MigrateAction;
3231
import org.elasticsearch.xpack.core.ilm.Phase;
3332
import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
3433
import org.elasticsearch.xpack.core.ilm.RolloverAction;
@@ -40,7 +39,6 @@
4039

4140
import java.io.IOException;
4241
import java.io.InputStream;
43-
import java.time.ZonedDateTime;
4442
import java.util.HashMap;
4543
import java.util.List;
4644
import java.util.Locale;
@@ -516,45 +514,4 @@ snapshotRepo, randomBoolean()))
516514
assertThat(hotIndexSettings.get(DataTierAllocationDecider.INDEX_ROUTING_PREFER),
517515
is("data_hot"));
518516
}
519-
520-
public void testSearchableSnapshotActionOverridesMigrateAction() throws Exception {
521-
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
522-
createPolicy(client(), policy,
523-
new Phase("hot", TimeValue.ZERO, Map.of(RolloverAction.NAME, new RolloverAction(null, null, null, 1L),
524-
SearchableSnapshotAction.NAME, new SearchableSnapshotAction(
525-
snapshotRepo, randomBoolean()))
526-
),
527-
new Phase("warm", TimeValue.ZERO, Map.of(MigrateAction.NAME, new MigrateAction(true))),
528-
null, null, null
529-
);
530-
531-
createComposableTemplate(client(), randomAlphaOfLengthBetween(5, 10).toLowerCase(), dataStream,
532-
new Template(Settings.builder()
533-
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
534-
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
535-
.build(), null, null)
536-
);
537-
538-
indexDocument(client(), dataStream, true);
539-
String firstGenIndex = DataStream.getDefaultBackingIndexName(dataStream, 1L);
540-
Map<String, Object> indexSettings = getIndexSettingsAsMap(firstGenIndex);
541-
// the searchable snapshot is allocated to the hot tier
542-
assertThat(indexSettings.get(DataTierAllocationDecider.INDEX_ROUTING_PREFER), is("data_hot"));
543-
544-
// rollover the data stream so searchable_snapshot can complete
545-
rolloverMaxOneDocCondition(client(), dataStream);
546-
547-
final String restoredIndex = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + firstGenIndex;
548-
assertBusy(() -> {
549-
logger.info("--> waiting for [{}] to exist...", restoredIndex);
550-
assertTrue(indexExists(restoredIndex));
551-
}, 30, TimeUnit.SECONDS);
552-
assertBusy(() -> assertThat(getStepKeyForIndex(client(), restoredIndex), is(PhaseCompleteStep.finalStep("warm").getKey())),
553-
30, TimeUnit.SECONDS);
554-
555-
Map<String, Object> warmIndexSettings = getIndexSettingsAsMap(restoredIndex);
556-
// the searchable snapshot continues on the to warm tier and onward
557-
assertThat(warmIndexSettings.get(DataTierAllocationDecider.INDEX_ROUTING_PREFER), is("data_warm,data_hot"));
558-
}
559-
560517
}

0 commit comments

Comments
 (0)