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