4343import static org .elasticsearch .cluster .routing .ShardRoutingState .INITIALIZING ;
4444import static org .elasticsearch .cluster .routing .ShardRoutingState .STARTED ;
4545import static org .elasticsearch .cluster .routing .ShardRoutingState .UNASSIGNED ;
46+ import static org .hamcrest .Matchers .containsString ;
4647import static org .hamcrest .Matchers .equalTo ;
4748import static org .hamcrest .Matchers .not ;
4849
@@ -98,7 +99,7 @@ public void testSingleRetryOnIgnore() {
9899 assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
99100 assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).state (), INITIALIZING );
100101 assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations (), i +1 );
101- assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), "boom" + i );
102+ assertThat (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), containsString ( "boom" + i ) );
102103 }
103104 // now we go and check that we are actually stick to unassigned on the next failure
104105 List <FailedShard > failedShards = Collections .singletonList (
@@ -111,7 +112,7 @@ public void testSingleRetryOnIgnore() {
111112 assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
112113 assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations (), retries );
113114 assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).state (), UNASSIGNED );
114- assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), "boom" );
115+ assertThat (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), containsString ( "boom" ) );
115116
116117 // manual resetting of retry count
117118 newState = strategy .reroute (clusterState , new AllocationCommands (), false , true ).getClusterState ();
@@ -123,7 +124,7 @@ public void testSingleRetryOnIgnore() {
123124 assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
124125 assertEquals (0 , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations ());
125126 assertEquals (INITIALIZING , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).state ());
126- assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), "boom" );
127+ assertThat (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), containsString ( "boom" ) );
127128
128129 // again fail it N-1 times
129130 for (int i = 0 ; i < retries -1 ; i ++) {
@@ -138,7 +139,7 @@ public void testSingleRetryOnIgnore() {
138139 assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
139140 assertEquals (i + 1 , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations ());
140141 assertEquals (INITIALIZING , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).state ());
141- assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), "boom" );
142+ assertThat (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), containsString ( "boom" ) );
142143 }
143144
144145 // now we go and check that we are actually stick to unassigned on the next failure
@@ -152,7 +153,7 @@ public void testSingleRetryOnIgnore() {
152153 assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
153154 assertEquals (retries , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations ());
154155 assertEquals (UNASSIGNED , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).state ());
155- assertEquals ( "boom" , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage ());
156+ assertThat ( routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getMessage (), containsString ( "boom" ));
156157 }
157158
158159 public void testFailedAllocation () {
@@ -172,7 +173,7 @@ public void testFailedAllocation() {
172173 ShardRouting unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
173174 assertEquals (unassignedPrimary .state (), INITIALIZING );
174175 assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), i +1 );
175- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "boom" + i );
176+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "boom" + i ) );
176177 // MaxRetryAllocationDecider#canForceAllocatePrimary should return YES decisions because canAllocate returns YES here
177178 assertEquals (Decision .YES , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
178179 unassignedPrimary , null , new RoutingAllocation (null , null , clusterState , null , 0 )));
@@ -190,7 +191,7 @@ public void testFailedAllocation() {
190191 ShardRouting unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
191192 assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), retries );
192193 assertEquals (unassignedPrimary .state (), UNASSIGNED );
193- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "boom" );
194+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "boom" ) );
194195 // MaxRetryAllocationDecider#canForceAllocatePrimary should return a NO decision because canAllocate returns NO here
195196 assertEquals (Decision .NO , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
196197 unassignedPrimary , null , new RoutingAllocation (null , null , clusterState , null , 0 )));
@@ -212,7 +213,7 @@ public void testFailedAllocation() {
212213 ShardRouting unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
213214 assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), retries );
214215 assertEquals (unassignedPrimary .state (), INITIALIZING );
215- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "boom" );
216+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "boom" ) );
216217 // bumped up the max retry count, so canForceAllocatePrimary should return a YES decision
217218 assertEquals (Decision .YES , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
218219 routingTable .index ("idx" ).shard (0 ).shards ().get (0 ), null , new RoutingAllocation (null , null , clusterState , null , 0 )));
@@ -239,7 +240,7 @@ public void testFailedAllocation() {
239240 unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
240241 assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), 1 );
241242 assertEquals (unassignedPrimary .state (), UNASSIGNED );
242- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "ZOOOMG" );
243+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "ZOOOMG" ) );
243244 // Counter reset, so MaxRetryAllocationDecider#canForceAllocatePrimary should return a YES decision
244245 assertEquals (Decision .YES , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
245246 unassignedPrimary , null , new RoutingAllocation (null , null , clusterState , null , 0 )));
0 commit comments