@@ -98,39 +98,70 @@ public void testConditionMet() {
9898 new ClusterStateWaitStep .Result (true , null ));
9999 }
100100
101- public void testConditionMetOnlyOneCopyAllocated () {
101+ public void testRequireConditionMetOnlyOneCopyAllocated () {
102102 Index index = new Index (randomAlphaOfLengthBetween (1 , 20 ), randomAlphaOfLengthBetween (1 , 20 ));
103- Map <String , String > includes = AllocateActionTests .randomMap (1 , 5 );
104- Map <String , String > excludes = AllocateActionTests .randomMap (1 , 5 );
105- Map <String , String > requires = AllocateActionTests .randomMap (1 , 5 );
103+ Map <String , String > requires = Collections .singletonMap (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + "foo" , "bar" );
106104 Settings .Builder existingSettings = Settings .builder ().put (IndexMetaData .SETTING_VERSION_CREATED , Version .CURRENT .id )
107- .put (IndexMetaData .SETTING_INDEX_UUID , index .getUUID ());
108- Settings .Builder expectedSettings = Settings .builder ();
105+ .put (IndexMetaData .SETTING_INDEX_UUID , index .getUUID ());
109106 Settings .Builder node1Settings = Settings .builder ();
110- Settings .Builder node2Settings = Settings .builder ();
111- includes .forEach ((k , v ) -> {
112- existingSettings .put (IndexMetaData .INDEX_ROUTING_INCLUDE_GROUP_SETTING .getKey () + k , v );
113- expectedSettings .put (IndexMetaData .INDEX_ROUTING_INCLUDE_GROUP_SETTING .getKey () + k , v );
107+ requires .forEach ((k , v ) -> {
108+ existingSettings .put (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + k , v );
114109 node1Settings .put (Node .NODE_ATTRIBUTES .getKey () + k , v );
115110 });
111+
112+ boolean primaryOnNode1 = randomBoolean ();
113+ IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
114+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node1" , primaryOnNode1 , ShardRoutingState .STARTED ))
115+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node2" , primaryOnNode1 == false ,
116+ ShardRoutingState .STARTED ));
117+
118+ AllocationRoutedStep step = new AllocationRoutedStep (randomStepKey (), randomStepKey ());
119+ assertAllocateStatus (index , 1 , 0 , step , existingSettings , node1Settings , Settings .builder (), indexRoutingTable ,
120+ new ClusterStateWaitStep .Result (false , new AllocationRoutedStep .Info (0 , 1 , true )));
121+ }
122+
123+ public void testExcludeConditionMetOnlyOneCopyAllocated () {
124+ Index index = new Index (randomAlphaOfLengthBetween (1 , 20 ), randomAlphaOfLengthBetween (1 , 20 ));
125+ Map <String , String > excludes = Collections .singletonMap (IndexMetaData .INDEX_ROUTING_EXCLUDE_GROUP_SETTING .getKey () + "foo" , "bar" );
126+ Settings .Builder existingSettings = Settings .builder ().put (IndexMetaData .SETTING_VERSION_CREATED , Version .CURRENT .id )
127+ .put (IndexMetaData .SETTING_INDEX_UUID , index .getUUID ());
128+ Settings .Builder node1Settings = Settings .builder ();
116129 excludes .forEach ((k , v ) -> {
117130 existingSettings .put (IndexMetaData .INDEX_ROUTING_EXCLUDE_GROUP_SETTING .getKey () + k , v );
118- expectedSettings .put (IndexMetaData . INDEX_ROUTING_EXCLUDE_GROUP_SETTING .getKey () + k , v );
131+ node1Settings .put (Node . NODE_ATTRIBUTES .getKey () + k , v );
119132 });
120- requires .forEach ((k , v ) -> {
121- existingSettings .put (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + k , v );
122- expectedSettings .put (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + k , v );
133+
134+ boolean primaryOnNode1 = randomBoolean ();
135+ IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
136+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node1" , primaryOnNode1 , ShardRoutingState .STARTED ))
137+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node2" , primaryOnNode1 == false ,
138+ ShardRoutingState .STARTED ));
139+
140+ AllocationRoutedStep step = new AllocationRoutedStep (randomStepKey (), randomStepKey ());
141+ assertAllocateStatus (index , 1 , 0 , step , existingSettings , node1Settings , Settings .builder (), indexRoutingTable ,
142+ new ClusterStateWaitStep .Result (false , new AllocationRoutedStep .Info (0 , 1 , true )));
143+ }
144+
145+ public void testIncludeConditionMetOnlyOneCopyAllocated () {
146+ Index index = new Index (randomAlphaOfLengthBetween (1 , 20 ), randomAlphaOfLengthBetween (1 , 20 ));
147+ Map <String , String > includes = Collections .singletonMap (IndexMetaData .INDEX_ROUTING_INCLUDE_GROUP_SETTING .getKey () + "foo" , "bar" );
148+ Settings .Builder existingSettings = Settings .builder ().put (IndexMetaData .SETTING_VERSION_CREATED , Version .CURRENT .id )
149+ .put (IndexMetaData .SETTING_INDEX_UUID , index .getUUID ());
150+ Settings .Builder node1Settings = Settings .builder ();
151+ includes .forEach ((k , v ) -> {
152+ existingSettings .put (IndexMetaData .INDEX_ROUTING_INCLUDE_GROUP_SETTING .getKey () + k , v );
123153 node1Settings .put (Node .NODE_ATTRIBUTES .getKey () + k , v );
124154 });
155+
125156 boolean primaryOnNode1 = randomBoolean ();
126157 IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
127- .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node1" , primaryOnNode1 , ShardRoutingState .STARTED ))
128- .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node2" , primaryOnNode1 == false ,
129- ShardRoutingState .STARTED ));
158+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node1" , primaryOnNode1 , ShardRoutingState .STARTED ))
159+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node2" , primaryOnNode1 == false ,
160+ ShardRoutingState .STARTED ));
130161
131162 AllocationRoutedStep step = new AllocationRoutedStep (randomStepKey (), randomStepKey ());
132- assertAllocateStatus (index , 1 , 0 , step , existingSettings , node1Settings , node2Settings , indexRoutingTable ,
133- new ClusterStateWaitStep .Result (false , new AllocationRoutedStep .Info (0 , 1 , true )));
163+ assertAllocateStatus (index , 1 , 0 , step , existingSettings , node1Settings , Settings . builder () , indexRoutingTable ,
164+ new ClusterStateWaitStep .Result (false , new AllocationRoutedStep .Info (0 , 1 , true )));
134165 }
135166
136167 public void testConditionNotMetDueToRelocation () {
0 commit comments