41
41
import org .apache .solr .cluster .placement .plugins .MinimizeCoresPlacementFactory ;
42
42
import org .apache .solr .common .cloud .ClusterState ;
43
43
import org .apache .solr .common .cloud .DocCollection ;
44
- import org .apache .solr .common .util .TimeSource ;
45
44
import org .apache .solr .core .CoreContainer ;
46
45
import org .apache .solr .util .LogLevel ;
47
- import org .apache .solr .util .TimeOut ;
48
46
49
47
import org .junit .After ;
50
48
import org .junit .BeforeClass ;
51
49
import org .junit .Test ;
52
- import org .slf4j .Logger ;
53
- import org .slf4j .LoggerFactory ;
54
50
55
- import java .lang .invoke .MethodHandles ;
56
51
import java .util .Arrays ;
57
52
import java .util .HashMap ;
58
53
import java .util .HashSet ;
59
54
import java .util .Map ;
60
55
import java .util .Optional ;
61
56
import java .util .Set ;
57
+ import java .util .concurrent .Phaser ;
62
58
import java .util .concurrent .TimeUnit ;
63
59
import java .util .concurrent .TimeoutException ;
64
60
import java .util .concurrent .atomic .AtomicInteger ;
70
66
*/
71
67
@ LogLevel ("org.apache.solr.cluster.placement.impl=DEBUG" )
72
68
public class PlacementPluginIntegrationTest extends SolrCloudTestCase {
73
- private static final Logger log = LoggerFactory .getLogger (MethodHandles .lookup ().lookupClass ());
74
-
75
69
private static final String COLLECTION = PlacementPluginIntegrationTest .class .getSimpleName () + "_collection" ;
76
70
77
71
private static SolrCloudManager cloudManager ;
@@ -145,14 +139,15 @@ public void testMinimizeCores() throws Exception {
145
139
}
146
140
147
141
@ Test
148
- @ SuppressWarnings ("unchecked" )
149
142
public void testDynamicReconfiguration () throws Exception {
150
143
PlacementPluginFactory <? extends PlacementPluginConfig > pluginFactory = cc .getPlacementPluginFactory ();
151
144
assertTrue ("wrong type " + pluginFactory .getClass ().getName (), pluginFactory instanceof DelegatingPlacementPluginFactory );
152
145
DelegatingPlacementPluginFactory wrapper = (DelegatingPlacementPluginFactory ) pluginFactory ;
146
+ Phaser phaser = new Phaser ();
147
+ wrapper .setDelegationPhaser (phaser );
153
148
154
- int version = wrapper . getVersion ();
155
- log . debug ( "--initial version={}" , version );
149
+ int version = phaser . getPhase ();
150
+ assertTrue ( "wrong version " + version , version > - 1 );
156
151
157
152
PluginMeta plugin = new PluginMeta ();
158
153
plugin .name = PlacementPluginFactory .PLUGIN_NAME ;
@@ -164,9 +159,7 @@ public void testDynamicReconfiguration() throws Exception {
164
159
.build ();
165
160
req .process (cluster .getSolrClient ());
166
161
167
- version = waitForVersionChange (version , wrapper , 10 );
168
-
169
- assertTrue ("wrong version " + version , version > 0 );
162
+ version = phaser .awaitAdvanceInterruptibly (version , 10 , TimeUnit .SECONDS );
170
163
PlacementPluginFactory <? extends PlacementPluginConfig > factory = wrapper .getDelegate ();
171
164
assertTrue ("wrong type " + factory .getClass ().getName (), factory instanceof MinimizeCoresPlacementFactory );
172
165
@@ -180,7 +173,7 @@ public void testDynamicReconfiguration() throws Exception {
180
173
.build ();
181
174
req .process (cluster .getSolrClient ());
182
175
183
- version = waitForVersionChange (version , wrapper , 10 );
176
+ version = phaser . awaitAdvanceInterruptibly (version , 10 , TimeUnit . SECONDS );
184
177
185
178
factory = wrapper .getDelegate ();
186
179
assertTrue ("wrong type " + factory .getClass ().getName (), factory instanceof AffinityPlacementFactory );
@@ -197,7 +190,7 @@ public void testDynamicReconfiguration() throws Exception {
197
190
.build ();
198
191
req .process (cluster .getSolrClient ());
199
192
200
- version = waitForVersionChange (version , wrapper , 10 );
193
+ version = phaser . awaitAdvanceInterruptibly (version , 10 , TimeUnit . SECONDS );
201
194
factory = wrapper .getDelegate ();
202
195
assertTrue ("wrong type " + factory .getClass ().getName (), factory instanceof AffinityPlacementFactory );
203
196
config = ((AffinityPlacementFactory ) factory ).getConfig ();
@@ -212,22 +205,16 @@ public void testDynamicReconfiguration() throws Exception {
212
205
.withPayload (singletonMap ("add" , plugin ))
213
206
.build ();
214
207
req .process (cluster .getSolrClient ());
215
- try {
216
- int newVersion = waitForVersionChange (version , wrapper , 5 );
217
- if (newVersion != version ) {
218
- fail ("factory configuration updated but plugin name was wrong: " + plugin );
219
- }
220
- } catch (TimeoutException te ) {
221
- // expected
222
- }
208
+ final int oldVersion = version ;
209
+ expectThrows (TimeoutException .class , () -> phaser .awaitAdvanceInterruptibly (oldVersion , 5 , TimeUnit .SECONDS ));
223
210
// remove plugin
224
211
req = new V2Request .Builder ("/cluster/plugin" )
225
212
.forceV2 (true )
226
213
.POST ()
227
214
.withPayload ("{remove: '" + PlacementPluginFactory .PLUGIN_NAME + "'}" )
228
215
.build ();
229
216
req .process (cluster .getSolrClient ());
230
- waitForVersionChange (version , wrapper , 10 );
217
+ phaser . awaitAdvanceInterruptibly (version , 10 , TimeUnit . SECONDS );
231
218
factory = wrapper .getDelegate ();
232
219
assertNull ("no factory should be present" , factory );
233
220
}
@@ -237,9 +224,10 @@ public void testWithCollectionIntegration() throws Exception {
237
224
PlacementPluginFactory <? extends PlacementPluginConfig > pluginFactory = cc .getPlacementPluginFactory ();
238
225
assertTrue ("wrong type " + pluginFactory .getClass ().getName (), pluginFactory instanceof DelegatingPlacementPluginFactory );
239
226
DelegatingPlacementPluginFactory wrapper = (DelegatingPlacementPluginFactory ) pluginFactory ;
227
+ Phaser phaser = new Phaser ();
228
+ wrapper .setDelegationPhaser (phaser );
240
229
241
- int version = wrapper .getVersion ();
242
- log .debug ("--initial version={}" , version );
230
+ int version = phaser .getPhase ();
243
231
244
232
Set <String > nodeSet = new HashSet <>();
245
233
for (String node : cloudManager .getClusterStateProvider ().getLiveNodes ()) {
@@ -261,7 +249,7 @@ public void testWithCollectionIntegration() throws Exception {
261
249
.build ();
262
250
req .process (cluster .getSolrClient ());
263
251
264
- version = waitForVersionChange (version , wrapper , 10 );
252
+ phaser . awaitAdvanceInterruptibly (version , 10 , TimeUnit . SECONDS );
265
253
266
254
CollectionAdminResponse rsp = CollectionAdminRequest .createCollection (SECONDARY_COLLECTION , "conf" , 1 , 3 )
267
255
.process (cluster .getSolrClient ());
@@ -398,21 +386,4 @@ public void testAttributeFetcherImpl() throws Exception {
398
386
});
399
387
});
400
388
}
401
-
402
- private int waitForVersionChange (int currentVersion , DelegatingPlacementPluginFactory wrapper , int timeoutSec ) throws Exception {
403
- TimeOut timeout = new TimeOut (timeoutSec , TimeUnit .SECONDS , TimeSource .NANO_TIME );
404
-
405
- while (!timeout .hasTimedOut ()) {
406
- int newVersion = wrapper .getVersion ();
407
- if (newVersion < currentVersion ) {
408
- throw new Exception ("Invalid version - went back! currentVersion=" + currentVersion +
409
- " newVersion=" + newVersion );
410
- } else if (currentVersion < newVersion ) {
411
- log .debug ("--current version was {}, new version is {}" , currentVersion , newVersion );
412
- return newVersion ;
413
- }
414
- timeout .sleep (200 );
415
- }
416
- throw new TimeoutException ("version didn't change in time, currentVersion=" + currentVersion );
417
- }
418
389
}
0 commit comments