Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package org.elasticsearch.xpack.ml;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateAction;
import org.elasticsearch.action.admin.cluster.snapshots.features.ResetFeatureStateRequest;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
Expand All @@ -32,7 +34,6 @@
import org.elasticsearch.xpack.datastreams.DataStreamsPlugin;
import org.elasticsearch.xpack.ilm.IndexLifecycle;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand All @@ -42,7 +43,6 @@
import java.util.function.Consumer;
import java.util.function.Function;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -88,28 +88,11 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
IndexLifecycle.class);
}

/**
* This cleanup is to fix the problem described in
* https://github.com/elastic/elasticsearch/issues/38952
*/
@Override
public void tearDown() throws Exception {
try {
logger.trace("[{}#{}]: ML-specific after test cleanup", getTestClass().getSimpleName(), getTestName());
String[] nonAnnotationMlIndices;
boolean mlAnnotationsIndexExists;
do {
String[] mlIndices = client().admin().indices().prepareGetIndex().addIndices(".ml-*").get().indices();
nonAnnotationMlIndices = Arrays.stream(mlIndices).filter(name -> name.startsWith(".ml-annotations") == false)
.toArray(String[]::new);
mlAnnotationsIndexExists = mlIndices.length > nonAnnotationMlIndices.length;
} while (nonAnnotationMlIndices.length > 0 && mlAnnotationsIndexExists == false);
if (nonAnnotationMlIndices.length > 0) {
// Delete the ML indices apart from the annotations index. The annotations index will be deleted by the
// base class cleanup. We want to delete all the others first so that the annotations index doesn't get
// automatically recreated.
assertAcked(client().admin().indices().prepareDelete(nonAnnotationMlIndices).get());
}
client().execute(ResetFeatureStateAction.INSTANCE, new ResetFeatureStateRequest()).actionGet();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should also delete the comment on lines 91-94, as this cleanup is now doing more than what that comment says. It will mean that in the future it will be possible to use this base class for tests that might leave jobs running when they complete.

} finally {
super.tearDown();
}
Expand Down