43
43
import org .elasticsearch .common .UUIDs ;
44
44
import org .elasticsearch .common .collect .ImmutableOpenMap ;
45
45
import org .elasticsearch .common .settings .Settings ;
46
+ import org .elasticsearch .common .util .concurrent .CountDown ;
46
47
import org .elasticsearch .index .Index ;
47
48
import org .elasticsearch .index .shard .ShardId ;
48
49
import org .elasticsearch .index .snapshots .IndexShardSnapshotStatus ;
@@ -179,10 +180,18 @@ public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, In
179
180
}
180
181
181
182
public void testErroneousSnapshotShardSizes () throws Exception {
182
- final AtomicInteger reroutes = new AtomicInteger ();
183
+ final int maxShardsToCreate = scaledRandomIntBetween (10 , 500 );
184
+
185
+ final PlainActionFuture <Void > waitForAllReroutesProcessed = new PlainActionFuture <>();
186
+ final CountDown reroutes = new CountDown (maxShardsToCreate );
183
187
final RerouteService rerouteService = (reason , priority , listener ) -> {
184
- reroutes .incrementAndGet ();
185
- listener .onResponse (clusterService .state ());
188
+ try {
189
+ listener .onResponse (clusterService .state ());
190
+ } finally {
191
+ if (reroutes .countDown ()) {
192
+ waitForAllReroutesProcessed .onResponse (null );
193
+ }
194
+ }
186
195
};
187
196
188
197
final InternalSnapshotsInfoService snapshotsInfoService =
@@ -208,7 +217,6 @@ public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, In
208
217
};
209
218
when (repositoriesService .repository ("_repo" )).thenReturn (mockRepository );
210
219
211
- final int maxShardsToCreate = scaledRandomIntBetween (10 , 500 );
212
220
final Thread addSnapshotRestoreIndicesThread = new Thread (() -> {
213
221
int remainingShards = maxShardsToCreate ;
214
222
while (remainingShards > 0 ) {
@@ -251,8 +259,9 @@ public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, In
251
259
success ? equalTo (results .get (snapshotShard .getKey ())) : equalTo (defaultValue ));
252
260
}
253
261
262
+ waitForAllReroutesProcessed .get (60L , TimeUnit .SECONDS );
254
263
assertThat ("Expecting all snapshot shard size fetches to provide a size" , results .size (), equalTo (maxShardsToCreate ));
255
- assertThat ("Expecting all snapshot shard size fetches to execute a Reroute" , reroutes .get (), equalTo ( maxShardsToCreate ));
264
+ assertTrue ("Expecting all snapshot shard size fetches to execute a Reroute" , reroutes .isCountedDown ( ));
256
265
}
257
266
258
267
public void testNoLongerMaster () throws Exception {
0 commit comments