43
43
import static org .elasticsearch .cluster .routing .ShardRoutingState .INITIALIZING ;
44
44
import static org .elasticsearch .cluster .routing .ShardRoutingState .STARTED ;
45
45
import static org .elasticsearch .cluster .routing .ShardRoutingState .UNASSIGNED ;
46
+ import static org .hamcrest .Matchers .containsString ;
46
47
import static org .hamcrest .Matchers .equalTo ;
47
48
import static org .hamcrest .Matchers .not ;
48
49
@@ -98,7 +99,7 @@ public void testSingleRetryOnIgnore() {
98
99
assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
99
100
assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).state (), INITIALIZING );
100
101
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 ) );
102
103
}
103
104
// now we go and check that we are actually stick to unassigned on the next failure
104
105
List <FailedShard > failedShards = Collections .singletonList (
@@ -111,7 +112,7 @@ public void testSingleRetryOnIgnore() {
111
112
assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
112
113
assertEquals (routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations (), retries );
113
114
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" ) );
115
116
116
117
// manual resetting of retry count
117
118
newState = strategy .reroute (clusterState , new AllocationCommands (), false , true ).getClusterState ();
@@ -123,7 +124,7 @@ public void testSingleRetryOnIgnore() {
123
124
assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
124
125
assertEquals (0 , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations ());
125
126
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" ) );
127
128
128
129
// again fail it N-1 times
129
130
for (int i = 0 ; i < retries -1 ; i ++) {
@@ -138,7 +139,7 @@ public void testSingleRetryOnIgnore() {
138
139
assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
139
140
assertEquals (i + 1 , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations ());
140
141
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" ) );
142
143
}
143
144
144
145
// now we go and check that we are actually stick to unassigned on the next failure
@@ -152,7 +153,7 @@ public void testSingleRetryOnIgnore() {
152
153
assertEquals (routingTable .index ("idx" ).shards ().size (), 1 );
153
154
assertEquals (retries , routingTable .index ("idx" ).shard (0 ).shards ().get (0 ).unassignedInfo ().getNumFailedAllocations ());
154
155
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" ));
156
157
}
157
158
158
159
public void testFailedAllocation () {
@@ -172,7 +173,7 @@ public void testFailedAllocation() {
172
173
ShardRouting unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
173
174
assertEquals (unassignedPrimary .state (), INITIALIZING );
174
175
assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), i +1 );
175
- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "boom" + i );
176
+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "boom" + i ) );
176
177
// MaxRetryAllocationDecider#canForceAllocatePrimary should return YES decisions because canAllocate returns YES here
177
178
assertEquals (Decision .YES , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
178
179
unassignedPrimary , null , new RoutingAllocation (null , null , clusterState , null , 0 )));
@@ -190,7 +191,7 @@ public void testFailedAllocation() {
190
191
ShardRouting unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
191
192
assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), retries );
192
193
assertEquals (unassignedPrimary .state (), UNASSIGNED );
193
- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "boom" );
194
+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "boom" ) );
194
195
// MaxRetryAllocationDecider#canForceAllocatePrimary should return a NO decision because canAllocate returns NO here
195
196
assertEquals (Decision .NO , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
196
197
unassignedPrimary , null , new RoutingAllocation (null , null , clusterState , null , 0 )));
@@ -212,7 +213,7 @@ public void testFailedAllocation() {
212
213
ShardRouting unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
213
214
assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), retries );
214
215
assertEquals (unassignedPrimary .state (), INITIALIZING );
215
- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "boom" );
216
+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "boom" ) );
216
217
// bumped up the max retry count, so canForceAllocatePrimary should return a YES decision
217
218
assertEquals (Decision .YES , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
218
219
routingTable .index ("idx" ).shard (0 ).shards ().get (0 ), null , new RoutingAllocation (null , null , clusterState , null , 0 )));
@@ -239,7 +240,7 @@ public void testFailedAllocation() {
239
240
unassignedPrimary = routingTable .index ("idx" ).shard (0 ).shards ().get (0 );
240
241
assertEquals (unassignedPrimary .unassignedInfo ().getNumFailedAllocations (), 1 );
241
242
assertEquals (unassignedPrimary .state (), UNASSIGNED );
242
- assertEquals (unassignedPrimary .unassignedInfo ().getMessage (), "ZOOOMG" );
243
+ assertThat (unassignedPrimary .unassignedInfo ().getMessage (), containsString ( "ZOOOMG" ) );
243
244
// Counter reset, so MaxRetryAllocationDecider#canForceAllocatePrimary should return a YES decision
244
245
assertEquals (Decision .YES , new MaxRetryAllocationDecider (Settings .EMPTY ).canForceAllocatePrimary (
245
246
unassignedPrimary , null , new RoutingAllocation (null , null , clusterState , null , 0 )));
0 commit comments