Skip to content

Commit abcf1c4

Browse files
authored
Use ESSingleNodeTestCase instead of ESIntegTestCase (elastic#51345)
1 parent 6736cf5 commit abcf1c4

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

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

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,32 @@
2121
import org.elasticsearch.index.IndexModule;
2222
import org.elasticsearch.plugins.Plugin;
2323
import org.elasticsearch.script.ScriptService;
24-
import org.elasticsearch.test.ESIntegTestCase;
25-
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
24+
import org.elasticsearch.test.ESSingleNodeTestCase;
2625
import org.elasticsearch.threadpool.ThreadPool;
2726
import org.elasticsearch.watcher.ResourceWatcherService;
2827
import org.elasticsearch.xpack.core.ilm.AsyncActionStep;
2928
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
3029
import org.elasticsearch.xpack.core.ilm.UpdateSettingsStep;
3130
import org.junit.After;
3231

33-
import java.util.Arrays;
3432
import java.util.Collection;
35-
import java.util.Collections;
3633
import java.util.List;
3734
import java.util.concurrent.CountDownLatch;
3835
import java.util.concurrent.TimeUnit;
3936

40-
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
4137
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4238
import static org.elasticsearch.xpack.ilm.UpdateSettingsStepTests.SettingsTestingService.INVALID_VALUE;
4339
import static org.hamcrest.Matchers.is;
4440

45-
@ClusterScope(scope = SUITE, supportsDedicatedMasters = false, numDataNodes = 1, numClientNodes = 0)
46-
public class UpdateSettingsStepTests extends ESIntegTestCase {
47-
48-
@Override
49-
protected Collection<Class<? extends Plugin>> nodePlugins() {
50-
return Arrays.asList(SettingsListenerPlugin.class);
51-
}
41+
public class UpdateSettingsStepTests extends ESSingleNodeTestCase {
5242

5343
private static final SettingsTestingService service = new SettingsTestingService();
5444

5545
public static class SettingsListenerPlugin extends Plugin {
5646

5747
@Override
5848
public List<Setting<?>> getSettings() {
59-
return Arrays.asList(SettingsTestingService.VALUE);
49+
return List.of(SettingsTestingService.VALUE);
6050
}
6151

6252
@Override
@@ -69,13 +59,13 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
6959
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
7060
NamedXContentRegistry xContentRegistry, Environment environment,
7161
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
72-
return Collections.singletonList(service);
62+
return List.of(service);
7363
}
74-
}
7564

65+
}
7666
public static class SettingsListenerModule extends AbstractModule {
77-
private final SettingsTestingService service;
7867

68+
private final SettingsTestingService service;
7969
SettingsListenerModule(SettingsTestingService service) {
8070
this.service = service;
8171
}
@@ -84,12 +74,12 @@ public static class SettingsListenerModule extends AbstractModule {
8474
protected void configure() {
8575
bind(SettingsTestingService.class).toInstance(service);
8676
}
87-
}
8877

78+
}
8979
static class SettingsTestingService {
80+
9081
public static final String INVALID_VALUE = "INVALID";
9182
static Setting<String> VALUE = Setting.simpleString("index.test.setting", Property.Dynamic, Property.IndexScope);
92-
9383
public volatile String value;
9484

9585
void setValue(String value) {
@@ -105,21 +95,27 @@ void validate(String value) {
10595
void resetValues() {
10696
this.value = "";
10797
}
108-
}
10998

99+
}
110100
@After
111101
public void resetSettingValue() {
112102
service.resetValues();
113103
}
114104

105+
@Override
106+
protected Collection<Class<? extends Plugin>> getPlugins() {
107+
return List.of(SettingsListenerPlugin.class);
108+
}
109+
115110
public void testUpdateSettingsStepRetriesOnError() throws InterruptedException {
116111
assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder()
117112
.build()).get());
118113

119-
ClusterState state = clusterService().state();
114+
ClusterService clusterService = getInstanceFromNode(ClusterService.class);
115+
ClusterState state = clusterService.state();
120116
IndexMetaData indexMetaData = state.metaData().index("test");
121-
ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class);
122-
ClusterStateObserver observer = new ClusterStateObserver(clusterService(), null, logger, threadPool.getThreadContext());
117+
ThreadPool threadPool = getInstanceFromNode(ThreadPool.class);
118+
ClusterStateObserver observer = new ClusterStateObserver(clusterService, null, logger, threadPool.getThreadContext());
123119

124120
CountDownLatch latch = new CountDownLatch(2);
125121

@@ -162,11 +158,9 @@ public void onFailure(Exception e) {
162158
}
163159
});
164160

165-
166161
latch.await(10, TimeUnit.SECONDS);
167162

168-
for (SettingsTestingService instance : internalCluster().getDataNodeInstances(SettingsTestingService.class)) {
169-
assertThat(instance.value, is("valid"));
170-
}
163+
SettingsTestingService instance = getInstanceFromNode(SettingsTestingService.class);
164+
assertThat(instance.value, is("valid"));
171165
}
172166
}

0 commit comments

Comments
 (0)