|
20 | 20 |
|
21 | 21 | import org.elasticsearch.action.support.PlainActionFuture;
|
22 | 22 | import org.elasticsearch.cluster.ClusterState;
|
| 23 | +import org.elasticsearch.cluster.metadata.IndexMetaData; |
23 | 24 | import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
24 | 25 | import org.elasticsearch.cluster.routing.ShardRouting;
|
25 | 26 | import org.elasticsearch.cluster.service.ClusterService;
|
26 | 27 | import org.elasticsearch.common.UUIDs;
|
27 | 28 | import org.elasticsearch.common.lease.Releasable;
|
| 29 | +import org.elasticsearch.common.settings.Settings; |
28 | 30 | import org.elasticsearch.common.xcontent.XContentType;
|
29 | 31 | import org.elasticsearch.index.IndexService;
|
30 | 32 | import org.elasticsearch.index.shard.IndexShard;
|
|
38 | 40 | import java.util.Map;
|
39 | 41 | import java.util.concurrent.ExecutionException;
|
40 | 42 |
|
| 43 | +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
| 44 | + |
41 | 45 | public class SyncedFlushSingleNodeTests extends ESSingleNodeTestCase {
|
42 | 46 |
|
43 | 47 | public void testModificationPreventsFlushing() throws InterruptedException {
|
@@ -130,22 +134,26 @@ public void testSyncFailsIfOperationIsInFlight() throws InterruptedException, Ex
|
130 | 134 | }
|
131 | 135 |
|
132 | 136 | public void testSyncFailsOnIndexClosedOrMissing() throws InterruptedException {
|
133 |
| - createIndex("test"); |
| 137 | + createIndex("test", Settings.builder() |
| 138 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 139 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 140 | + .build()); |
134 | 141 | IndexService test = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test"));
|
135 |
| - IndexShard shard = test.getShardOrNull(0); |
| 142 | + final IndexShard shard = test.getShardOrNull(0); |
| 143 | + assertNotNull(shard); |
| 144 | + final ShardId shardId = shard.shardId(); |
| 145 | + |
| 146 | + final SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class); |
136 | 147 |
|
137 |
| - SyncedFlushService flushService = getInstanceFromNode(SyncedFlushService.class); |
138 | 148 | SyncedFlushUtil.LatchedListener listener = new SyncedFlushUtil.LatchedListener();
|
139 |
| - flushService.attemptSyncedFlush(new ShardId("test", "_na_", 1), listener); |
| 149 | + flushService.attemptSyncedFlush(new ShardId(shard.shardId().getIndex(), 1), listener); |
140 | 150 | listener.latch.await();
|
141 | 151 | assertNotNull(listener.error);
|
142 | 152 | assertNull(listener.result);
|
143 | 153 | assertEquals(ShardNotFoundException.class, listener.error.getClass());
|
144 | 154 | assertEquals("no such shard", listener.error.getMessage());
|
145 | 155 |
|
146 |
| - final ShardId shardId = shard.shardId(); |
147 |
| - |
148 |
| - client().admin().indices().prepareClose("test").get(); |
| 156 | + assertAcked(client().admin().indices().prepareClose("test")); |
149 | 157 | listener = new SyncedFlushUtil.LatchedListener();
|
150 | 158 | flushService.attemptSyncedFlush(shardId, listener);
|
151 | 159 | listener.latch.await();
|
|
0 commit comments