21
21
import org .elasticsearch .index .IndexModule ;
22
22
import org .elasticsearch .plugins .Plugin ;
23
23
import org .elasticsearch .script .ScriptService ;
24
- import org .elasticsearch .test .ESIntegTestCase ;
25
- import org .elasticsearch .test .ESIntegTestCase .ClusterScope ;
24
+ import org .elasticsearch .test .ESSingleNodeTestCase ;
26
25
import org .elasticsearch .threadpool .ThreadPool ;
27
26
import org .elasticsearch .watcher .ResourceWatcherService ;
28
27
import org .elasticsearch .xpack .core .ilm .AsyncActionStep ;
29
28
import org .elasticsearch .xpack .core .ilm .Step .StepKey ;
30
29
import org .elasticsearch .xpack .core .ilm .UpdateSettingsStep ;
31
30
import org .junit .After ;
32
31
33
- import java .util .Arrays ;
34
32
import java .util .Collection ;
35
- import java .util .Collections ;
36
33
import java .util .List ;
37
34
import java .util .concurrent .CountDownLatch ;
38
35
import java .util .concurrent .TimeUnit ;
39
36
40
- import static org .elasticsearch .test .ESIntegTestCase .Scope .SUITE ;
41
37
import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertAcked ;
42
38
import static org .elasticsearch .xpack .ilm .UpdateSettingsStepTests .SettingsTestingService .INVALID_VALUE ;
43
39
import static org .hamcrest .Matchers .is ;
44
40
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 {
52
42
53
43
private static final SettingsTestingService service = new SettingsTestingService ();
54
44
55
45
public static class SettingsListenerPlugin extends Plugin {
56
46
57
47
@ Override
58
48
public List <Setting <?>> getSettings () {
59
- return Arrays . asList (SettingsTestingService .VALUE );
49
+ return List . of (SettingsTestingService .VALUE );
60
50
}
61
51
62
52
@ Override
@@ -69,13 +59,13 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
69
59
ResourceWatcherService resourceWatcherService , ScriptService scriptService ,
70
60
NamedXContentRegistry xContentRegistry , Environment environment ,
71
61
NodeEnvironment nodeEnvironment , NamedWriteableRegistry namedWriteableRegistry ) {
72
- return Collections . singletonList (service );
62
+ return List . of (service );
73
63
}
74
- }
75
64
65
+ }
76
66
public static class SettingsListenerModule extends AbstractModule {
77
- private final SettingsTestingService service ;
78
67
68
+ private final SettingsTestingService service ;
79
69
SettingsListenerModule (SettingsTestingService service ) {
80
70
this .service = service ;
81
71
}
@@ -84,12 +74,12 @@ public static class SettingsListenerModule extends AbstractModule {
84
74
protected void configure () {
85
75
bind (SettingsTestingService .class ).toInstance (service );
86
76
}
87
- }
88
77
78
+ }
89
79
static class SettingsTestingService {
80
+
90
81
public static final String INVALID_VALUE = "INVALID" ;
91
82
static Setting <String > VALUE = Setting .simpleString ("index.test.setting" , Property .Dynamic , Property .IndexScope );
92
-
93
83
public volatile String value ;
94
84
95
85
void setValue (String value ) {
@@ -105,21 +95,27 @@ void validate(String value) {
105
95
void resetValues () {
106
96
this .value = "" ;
107
97
}
108
- }
109
98
99
+ }
110
100
@ After
111
101
public void resetSettingValue () {
112
102
service .resetValues ();
113
103
}
114
104
105
+ @ Override
106
+ protected Collection <Class <? extends Plugin >> getPlugins () {
107
+ return List .of (SettingsListenerPlugin .class );
108
+ }
109
+
115
110
public void testUpdateSettingsStepRetriesOnError () throws InterruptedException {
116
111
assertAcked (client ().admin ().indices ().prepareCreate ("test" ).setSettings (Settings .builder ()
117
112
.build ()).get ());
118
113
119
- ClusterState state = clusterService ().state ();
114
+ ClusterService clusterService = getInstanceFromNode (ClusterService .class );
115
+ ClusterState state = clusterService .state ();
120
116
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 ());
123
119
124
120
CountDownLatch latch = new CountDownLatch (2 );
125
121
@@ -162,11 +158,9 @@ public void onFailure(Exception e) {
162
158
}
163
159
});
164
160
165
-
166
161
latch .await (10 , TimeUnit .SECONDS );
167
162
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" ));
171
165
}
172
166
}
0 commit comments