Skip to content

Commit 2f7c240

Browse files
authored
[7.x] Use ESSingleNodeTestCase instead of ESIntegTestCase (elastic#51345) (elastic#51346)
* Use ESSingleNodeTestCase instead of ESIntegTestCase (elastic#51345) (cherry picked from commit abcf1c4) Signed-off-by: Andrei Dan <[email protected]>
1 parent c29b235 commit 2f7c240

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

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

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,33 @@
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;
3533
import java.util.Collections;
3634
import java.util.List;
3735
import java.util.concurrent.CountDownLatch;
3836
import java.util.concurrent.TimeUnit;
3937

40-
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
4138
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4239
import static org.elasticsearch.xpack.ilm.UpdateSettingsStepTests.SettingsTestingService.INVALID_VALUE;
4340
import static org.hamcrest.Matchers.is;
4441

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-
}
42+
public class UpdateSettingsStepTests extends ESSingleNodeTestCase {
5243

5344
private static final SettingsTestingService service = new SettingsTestingService();
5445

5546
public static class SettingsListenerPlugin extends Plugin {
5647

5748
@Override
5849
public List<Setting<?>> getSettings() {
59-
return Arrays.asList(SettingsTestingService.VALUE);
50+
return Collections.singletonList(SettingsTestingService.VALUE);
6051
}
6152

6253
@Override
@@ -71,11 +62,11 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
7162
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {
7263
return Collections.singletonList(service);
7364
}
74-
}
7565

66+
}
7667
public static class SettingsListenerModule extends AbstractModule {
77-
private final SettingsTestingService service;
7868

69+
private final SettingsTestingService service;
7970
SettingsListenerModule(SettingsTestingService service) {
8071
this.service = service;
8172
}
@@ -84,12 +75,12 @@ public static class SettingsListenerModule extends AbstractModule {
8475
protected void configure() {
8576
bind(SettingsTestingService.class).toInstance(service);
8677
}
87-
}
8878

79+
}
8980
static class SettingsTestingService {
81+
9082
public static final String INVALID_VALUE = "INVALID";
9183
static Setting<String> VALUE = Setting.simpleString("index.test.setting", Property.Dynamic, Property.IndexScope);
92-
9384
public volatile String value;
9485

9586
void setValue(String value) {
@@ -105,21 +96,27 @@ void validate(String value) {
10596
void resetValues() {
10697
this.value = "";
10798
}
108-
}
10999

100+
}
110101
@After
111102
public void resetSettingValue() {
112103
service.resetValues();
113104
}
114105

106+
@Override
107+
protected Collection<Class<? extends Plugin>> getPlugins() {
108+
return Collections.singletonList(SettingsListenerPlugin.class);
109+
}
110+
115111
public void testUpdateSettingsStepRetriesOnError() throws InterruptedException {
116112
assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder()
117113
.build()).get());
118114

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

124121
CountDownLatch latch = new CountDownLatch(2);
125122

@@ -162,11 +159,9 @@ public void onFailure(Exception e) {
162159
}
163160
});
164161

165-
166162
latch.await(10, TimeUnit.SECONDS);
167163

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

0 commit comments

Comments
 (0)