21
21
import org .elasticsearch .Version ;
22
22
import org .elasticsearch .cluster .ClusterState ;
23
23
import org .elasticsearch .cluster .block .ClusterBlocks ;
24
+ import org .elasticsearch .cluster .coordination .CoordinationMetaData ;
24
25
import org .elasticsearch .cluster .metadata .IndexMetaData ;
25
26
import org .elasticsearch .cluster .metadata .MetaData ;
26
27
import org .elasticsearch .cluster .node .DiscoveryNode ;
36
37
import org .elasticsearch .test .ESTestCase ;
37
38
38
39
import java .io .IOException ;
40
+ import java .util .Arrays ;
39
41
import java .util .Collections ;
40
42
import java .util .Set ;
41
43
import java .util .function .BiConsumer ;
@@ -287,9 +289,18 @@ public void testDoNotHideStateIfRecovered() {
287
289
public void testHideStateIfNotRecovered () {
288
290
final IndexMetaData indexMetaData = createIndexMetaData ("test" ,
289
291
Settings .builder ().put (IndexMetaData .INDEX_READ_ONLY_SETTING .getKey (), true ).build ());
292
+ final String clusterUUID = UUIDs .randomBase64UUID ();
293
+ final CoordinationMetaData coordinationMetaData = new CoordinationMetaData (randomLong (),
294
+ new CoordinationMetaData .VotingConfiguration (Sets .newHashSet (generateRandomStringArray (5 , 5 , false ))),
295
+ new CoordinationMetaData .VotingConfiguration (Sets .newHashSet (generateRandomStringArray (5 , 5 , false ))),
296
+ Arrays .stream (generateRandomStringArray (5 , 5 , false ))
297
+ .map (id -> new CoordinationMetaData .VotingTombstone (id , id ))
298
+ .collect (Collectors .toSet ()));
290
299
final MetaData metaData = MetaData .builder ()
291
300
.persistentSettings (Settings .builder ().put (MetaData .SETTING_READ_ONLY_SETTING .getKey (), true ).build ())
292
301
.transientSettings (Settings .builder ().put (MetaData .SETTING_READ_ONLY_ALLOW_DELETE_SETTING .getKey (), true ).build ())
302
+ .clusterUUID (clusterUUID )
303
+ .coordinationMetaData (coordinationMetaData )
293
304
.put (indexMetaData , false )
294
305
.build ();
295
306
final ClusterState initialState = ClusterState .builder (ClusterState .EMPTY_STATE )
@@ -302,8 +313,12 @@ public void testHideStateIfNotRecovered() {
302
313
.andThen (state -> setLocalNode (state , localNode ))
303
314
.andThen (ClusterStateUpdaters ::recoverClusterBlocks )
304
315
.apply (initialState );
316
+
305
317
final ClusterState hiddenState = hideStateIfNotRecovered (updatedState );
306
- assertTrue (MetaData .isGlobalStateEquals (hiddenState .metaData (), MetaData .EMPTY_META_DATA ));
318
+
319
+ assertTrue (MetaData .isGlobalStateEquals (hiddenState .metaData (),
320
+ MetaData .builder ().coordinationMetaData (coordinationMetaData ).clusterUUID (clusterUUID ).build ()));
321
+ assertThat (hiddenState .metaData ().indices ().size (), is (0 ));
307
322
assertTrue (hiddenState .blocks ().hasGlobalBlock (STATE_NOT_RECOVERED_BLOCK ));
308
323
assertFalse (hiddenState .blocks ().hasGlobalBlock (MetaData .CLUSTER_READ_ONLY_BLOCK ));
309
324
assertFalse (hiddenState .blocks ().hasGlobalBlock (MetaData .CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK ));
0 commit comments