Assert that we fail the correct shard when a replication request fails

This commit adds an assertion to
TransportReplicationActionTests#runReplicateTest that when a replication
request fails, we fail the correct shard.
This commit is contained in:
Jason Tedor 2016-01-06 09:49:52 -05:00
parent e0599bfb66
commit cd56366378
2 changed files with 12 additions and 0 deletions

View File

@ -302,6 +302,10 @@ public class ShardStateAction extends AbstractComponent {
this.failure = failure;
}
public ShardRouting getShardRouting() {
return shardRouting;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);

View File

@ -418,6 +418,7 @@ public class TransportReplicationActionTests extends ESTestCase {
}
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/15790")
public void testReplication() throws ExecutionException, InterruptedException {
final String index = "test";
final ShardId shardId = new ShardId(index, 0);
@ -441,6 +442,7 @@ public class TransportReplicationActionTests extends ESTestCase {
runReplicateTest(shardRoutingTable, assignedReplicas, totalShards);
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/15790")
public void testReplicationWithShadowIndex() throws ExecutionException, InterruptedException {
final String index = "test";
final ShardId shardId = new ShardId(index, 0);
@ -511,6 +513,12 @@ public class TransportReplicationActionTests extends ESTestCase {
transport.clear();
assertEquals(1, shardFailedRequests.length);
CapturingTransport.CapturedRequest shardFailedRequest = shardFailedRequests[0];
// get the shard the request was sent to
ShardRouting routing = clusterService.state().getRoutingNodes().node(capturedRequest.node.id()).get(request.shardId.id());
// and the shard that was requested to be failed
ShardStateAction.ShardRoutingEntry shardRoutingEntry = (ShardStateAction.ShardRoutingEntry)shardFailedRequest.request;
// the shard the request was sent to and the shard to be failed should be the same
assertTrue(shardRoutingEntry.getShardRouting().isSameAllocation(routing));
failures.add(shardFailedRequest);
transport.handleResponse(shardFailedRequest.requestId, TransportResponse.Empty.INSTANCE);
}