Skip to content

Commit cb7d51b

Browse files
authored
[ML] use reset feature API for internal cluster ML tests (#71836)
Replaces the bespoke ML cleanup code with the feature reset API for internal cluster tests
1 parent 4db5284 commit cb7d51b

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlSingleNodeTestCase.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
package org.elasticsearch.xpack.ml;
88

99
import org.elasticsearch.action.ActionListener;
10+
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateAction;
11+
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateRequest;
1012
import org.elasticsearch.cluster.ClusterState;
1113
import org.elasticsearch.common.settings.Settings;
1214
import org.elasticsearch.common.unit.ByteSizeValue;
@@ -32,7 +34,6 @@
3234
import org.elasticsearch.xpack.datastreams.DataStreamsPlugin;
3335
import org.elasticsearch.xpack.ilm.IndexLifecycle;
3436

35-
import java.util.Arrays;
3637
import java.util.Collection;
3738
import java.util.Collections;
3839
import java.util.Map;
@@ -42,7 +43,6 @@
4243
import java.util.function.Consumer;
4344
import java.util.function.Function;
4445

45-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4646
import static org.mockito.Matchers.any;
4747
import static org.mockito.Mockito.doAnswer;
4848
import static org.mockito.Mockito.mock;
@@ -88,28 +88,11 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
8888
IndexLifecycle.class);
8989
}
9090

91-
/**
92-
* This cleanup is to fix the problem described in
93-
* https://github.com/elastic/elasticsearch/issues/38952
94-
*/
9591
@Override
9692
public void tearDown() throws Exception {
9793
try {
9894
logger.trace("[{}#{}]: ML-specific after test cleanup", getTestClass().getSimpleName(), getTestName());
99-
String[] nonAnnotationMlIndices;
100-
boolean mlAnnotationsIndexExists;
101-
do {
102-
String[] mlIndices = client().admin().indices().prepareGetIndex().addIndices(".ml-*").get().indices();
103-
nonAnnotationMlIndices = Arrays.stream(mlIndices).filter(name -> name.startsWith(".ml-annotations") == false)
104-
.toArray(String[]::new);
105-
mlAnnotationsIndexExists = mlIndices.length > nonAnnotationMlIndices.length;
106-
} while (nonAnnotationMlIndices.length > 0 && mlAnnotationsIndexExists == false);
107-
if (nonAnnotationMlIndices.length > 0) {
108-
// Delete the ML indices apart from the annotations index. The annotations index will be deleted by the
109-
// base class cleanup. We want to delete all the others first so that the annotations index doesn't get
110-
// automatically recreated.
111-
assertAcked(client().admin().indices().prepareDelete(nonAnnotationMlIndices).get());
112-
}
95+
client().execute(ResetFeatureStateAction.INSTANCE, new ResetFeatureStateRequest()).actionGet();
11396
} finally {
11497
super.tearDown();
11598
}

0 commit comments

Comments
 (0)