summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java')
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java43
1 files changed, 38 insertions, 5 deletions
diff --git a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java
index c59405f234..8a13e6e6dd 100644
--- a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java
@@ -27,19 +27,19 @@ import org.elasticsearch.cluster.NotMasterException;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.IndexRoutingTable;
import org.elasticsearch.cluster.routing.RoutingService;
+import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardsIterator;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.discovery.Discovery;
+import org.elasticsearch.index.shard.ShardNotFoundException;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.cluster.TestClusterService;
import org.elasticsearch.test.transport.CapturingTransport;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.NodeDisconnectedException;
import org.elasticsearch.transport.NodeNotConnectedException;
-import org.elasticsearch.transport.RemoteTransportException;
-import org.elasticsearch.transport.SendRequestTransportException;
import org.elasticsearch.transport.TransportException;
import org.elasticsearch.transport.TransportResponse;
import org.elasticsearch.transport.TransportService;
@@ -48,8 +48,6 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import java.util.ArrayList;
-import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -72,7 +70,7 @@ public class ShardStateActionTests extends ESTestCase {
private static class TestShardStateAction extends ShardStateAction {
public TestShardStateAction(Settings settings, ClusterService clusterService, TransportService transportService, AllocationService allocationService, RoutingService routingService) {
- super(settings, clusterService, transportService, allocationService, routingService);
+ super(settings, clusterService, transportService, allocationService, routingService, THREAD_POOL);
}
private Runnable onBeforeWaitForNewMasterAndRetry;
@@ -293,6 +291,41 @@ public class ShardStateActionTests extends ESTestCase {
assertTrue(failure.get());
}
+ public void testShardNotFound() throws InterruptedException {
+ final String index = "test";
+
+ clusterService.setState(stateWithStartedPrimary(index, true, randomInt(5)));
+
+ String indexUUID = clusterService.state().metaData().index(index).getIndexUUID();
+
+ AtomicBoolean success = new AtomicBoolean();
+ CountDownLatch latch = new CountDownLatch(1);
+
+ ShardRouting failedShard = getRandomShardRouting(index);
+ RoutingTable routingTable = RoutingTable.builder(clusterService.state().getRoutingTable()).remove(index).build();
+ clusterService.setState(ClusterState.builder(clusterService.state()).routingTable(routingTable));
+ shardStateAction.shardFailed(failedShard, indexUUID, "test", getSimulatedFailure(), new ShardStateAction.Listener() {
+ @Override
+ public void onSuccess() {
+ success.set(true);
+ latch.countDown();
+ }
+
+ @Override
+ public void onFailure(Throwable t) {
+ success.set(false);
+ latch.countDown();
+ assert false;
+ }
+ });
+
+ CapturingTransport.CapturedRequest[] capturedRequests = transport.getCapturedRequestsAndClear();
+ transport.handleResponse(capturedRequests[0].requestId, TransportResponse.Empty.INSTANCE);
+
+ latch.await();
+ assertTrue(success.get());
+ }
+
private ShardRouting getRandomShardRouting(String index) {
IndexRoutingTable indexRoutingTable = clusterService.state().routingTable().index(index);
ShardsIterator shardsIterator = indexRoutingTable.randomAllActiveShardsIt();