|
5 | 5 | */ |
6 | 6 | package org.elasticsearch.xpack.ccr.action; |
7 | 7 |
|
| 8 | +import org.elasticsearch.action.ActionListener; |
8 | 9 | import org.elasticsearch.cluster.routing.ShardRouting; |
9 | 10 | import org.elasticsearch.cluster.routing.ShardRoutingState; |
10 | 11 | import org.elasticsearch.cluster.routing.TestShardRouting; |
11 | 12 | import org.elasticsearch.common.settings.Settings; |
12 | 13 | import org.elasticsearch.common.xcontent.XContentType; |
| 14 | +import org.elasticsearch.index.Index; |
| 15 | +import org.elasticsearch.index.IndexNotFoundException; |
13 | 16 | import org.elasticsearch.index.IndexService; |
14 | 17 | import org.elasticsearch.index.shard.IndexShard; |
15 | 18 | import org.elasticsearch.index.shard.IndexShardNotStartedException; |
| 19 | +import org.elasticsearch.index.shard.ShardId; |
| 20 | +import org.elasticsearch.index.shard.ShardNotFoundException; |
16 | 21 | import org.elasticsearch.index.translog.Translog; |
17 | 22 | import org.elasticsearch.test.ESSingleNodeTestCase; |
18 | 23 | import org.mockito.Mockito; |
19 | 24 |
|
20 | 25 | import java.util.Arrays; |
21 | 26 | import java.util.List; |
| 27 | +import java.util.concurrent.CountDownLatch; |
| 28 | +import java.util.concurrent.atomic.AtomicReference; |
22 | 29 | import java.util.stream.Collectors; |
23 | 30 | import java.util.stream.LongStream; |
24 | 31 |
|
25 | 32 | import static org.hamcrest.Matchers.equalTo; |
| 33 | +import static org.hamcrest.Matchers.instanceOf; |
26 | 34 |
|
27 | 35 | public class ShardChangesActionTests extends ESSingleNodeTestCase { |
28 | 36 |
|
| 37 | + @Override |
| 38 | + protected boolean resetNodeAfterTest() { |
| 39 | + return true; |
| 40 | + } |
| 41 | + |
29 | 42 | public void testGetOperations() throws Exception { |
30 | 43 | final Settings settings = Settings.builder() |
31 | 44 | .put("index.number_of_shards", 1) |
@@ -119,4 +132,52 @@ public void testGetOperationsAlwaysReturnAtLeastOneOp() throws Exception { |
119 | 132 | assertThat(operations[0].seqNo(), equalTo(0L)); |
120 | 133 | } |
121 | 134 |
|
| 135 | + public void testIndexNotFound() throws InterruptedException { |
| 136 | + final CountDownLatch latch = new CountDownLatch(1); |
| 137 | + final AtomicReference<Exception> reference = new AtomicReference<>(); |
| 138 | + final ShardChangesAction.TransportAction transportAction = node().injector().getInstance(ShardChangesAction.TransportAction.class); |
| 139 | + transportAction.execute( |
| 140 | + new ShardChangesAction.Request(new ShardId(new Index("non-existent", "uuid"), 0)), |
| 141 | + new ActionListener<ShardChangesAction.Response>() { |
| 142 | + @Override |
| 143 | + public void onResponse(final ShardChangesAction.Response response) { |
| 144 | + fail(); |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + public void onFailure(final Exception e) { |
| 149 | + reference.set(e); |
| 150 | + latch.countDown(); |
| 151 | + } |
| 152 | + }); |
| 153 | + latch.await(); |
| 154 | + assertNotNull(reference.get()); |
| 155 | + assertThat(reference.get(), instanceOf(IndexNotFoundException.class)); |
| 156 | + } |
| 157 | + |
| 158 | + public void testShardNotFound() throws InterruptedException { |
| 159 | + final int numberOfShards = randomIntBetween(1, 5); |
| 160 | + final IndexService indexService = createIndex("index", Settings.builder().put("index.number_of_shards", numberOfShards).build()); |
| 161 | + final CountDownLatch latch = new CountDownLatch(1); |
| 162 | + final AtomicReference<Exception> reference = new AtomicReference<>(); |
| 163 | + final ShardChangesAction.TransportAction transportAction = node().injector().getInstance(ShardChangesAction.TransportAction.class); |
| 164 | + transportAction.execute( |
| 165 | + new ShardChangesAction.Request(new ShardId(indexService.getMetaData().getIndex(), numberOfShards)), |
| 166 | + new ActionListener<ShardChangesAction.Response>() { |
| 167 | + @Override |
| 168 | + public void onResponse(final ShardChangesAction.Response response) { |
| 169 | + fail(); |
| 170 | + } |
| 171 | + |
| 172 | + @Override |
| 173 | + public void onFailure(final Exception e) { |
| 174 | + reference.set(e); |
| 175 | + latch.countDown(); |
| 176 | + } |
| 177 | + }); |
| 178 | + latch.await(); |
| 179 | + assertNotNull(reference.get()); |
| 180 | + assertThat(reference.get(), instanceOf(ShardNotFoundException.class)); |
| 181 | + } |
| 182 | + |
122 | 183 | } |
0 commit comments