diff --git a/rest-api-spec/test/cat.segments/10_basic.yaml b/rest-api-spec/test/cat.segments/10_basic.yaml index 5147057953a..72d9a5e379d 100755 --- a/rest-api-spec/test/cat.segments/10_basic.yaml +++ b/rest-api-spec/test/cat.segments/10_basic.yaml @@ -24,6 +24,14 @@ --- "Test cat segments output": + - do: + cat.segments: + v: false + + - match: + $body: | + /^$/ + - do: indices.create: index: index1 @@ -39,7 +47,7 @@ refresh: true - do: cluster.health: - wait_for_status: yellow + wait_for_status: green - do: cat.segments: v: false @@ -57,7 +65,7 @@ number_of_replicas: "0" - do: cluster.health: - wait_for_status: yellow + wait_for_status: green wait_for_relocating_shards: 0 - do: @@ -68,7 +76,7 @@ refresh: true - do: cluster.health: - wait_for_status: yellow + wait_for_status: green - do: @@ -85,3 +93,28 @@ - match: $body: | /^(index2 .+ \n?)$/ + +--- +"Test cat segments on closed index behaviour": + + - do: + indices.create: + index: index1 + body: + settings: + number_of_shards: "1" + number_of_replicas: "0" + + - do: + cluster.health: + wait_for_status: green + + - do: + indices.close: + index: index1 + + - do: + catch: forbidden + cat.segments: + index: index1 + v: false diff --git a/rest-api-spec/test/indices.segments/10_basic.yaml b/rest-api-spec/test/indices.segments/10_basic.yaml index 801982e45ad..26cd0e7d3a3 100644 --- a/rest-api-spec/test/indices.segments/10_basic.yaml +++ b/rest-api-spec/test/indices.segments/10_basic.yaml @@ -1,5 +1,75 @@ --- -"segments test": +"no segments test": - do: indices.segments: allow_no_indices: true + + - match: { _shards.total: 0} + - match: { indices: {}} + + - do: + catch: missing + indices.segments: + allow_no_indices: false + +--- +"basic segments test": + + - do: + indices.create: + index: index1 + body: + settings: + number_of_shards: "1" + number_of_replicas: "0" + - do: + index: + index: index1 + type: type + body: { foo: bar } + refresh: true + + - do: + cluster.health: + wait_for_status: green + + - do: + indices.segments: + index: index1 + + - match: { _shards.total: 1} + - match: { indices.index1.shards.0.0.routing.primary: true} + - match: { indices.index1.shards.0.0.segments._0.num_docs: 1} + +--- +"closed segments test": + + - do: + indices.create: + index: index1 + body: + settings: + number_of_shards: "1" + number_of_replicas: "0" + - do: + index: + index: index1 + type: type + body: { foo: bar } + refresh: true + + - do: + indices.close: + index: index1 + + - do: + catch: forbidden + indices.segments: + index: index1 + + - do: + indices.segments: + index: index1 + ignore_unavailable: true + + - match: { _shards.total: 0} diff --git a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java index b64582c2df9..cefc2ebc3bf 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentsRequest.java @@ -37,7 +37,6 @@ public class IndicesSegmentsRequest extends BroadcastOperationRequest segments = rsp.getIndices().get("test").iterator().next().getShards()[0].getSegments(); assertNotNull(segments.get(0).ramTree); } + + /** + * with the default IndicesOptions inherited from BroadcastOperationRequest this will raise an exception + */ + @Test(expected=org.elasticsearch.indices.IndexClosedException.class) + public void testRequestOnClosedIndex() { + client().admin().indices().prepareClose("test").get(); + client().admin().indices().prepareSegments("test").get(); + } + + /** + * setting the "ignoreUnavailable" option prevents IndexClosedException + */ + public void testRequestOnClosedIndexIgnoreUnavailable() { + client().admin().indices().prepareClose("test").get(); + IndicesOptions defaultOptions = new IndicesSegmentsRequest().indicesOptions(); + IndicesOptions testOptions = IndicesOptions.fromOptions(true, true, true, false, defaultOptions); + IndicesSegmentResponse rsp = client().admin().indices().prepareSegments("test").setIndicesOptions(testOptions).get(); + assertEquals(0, rsp.getIndices().size()); + } + + /** + * by default IndicesOptions setting IndicesSegmentsRequest should not throw exception when no index present + */ + public void testAllowNoIndex() { + client().admin().indices().prepareDelete("test").get(); + IndicesSegmentResponse rsp = client().admin().indices().prepareSegments().get(); + assertEquals(0, rsp.getIndices().size()); + } } diff --git a/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java b/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java index aa22547f2d7..0b85d136858 100644 --- a/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java +++ b/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationTests.java @@ -362,7 +362,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest verify(count(indices), false); verify(clearCache(indices), false); verify(_flush(indices),false); - verify(segments(indices), true); + verify(segments(indices), false); verify(stats(indices), false); verify(optimize(indices), false); verify(refresh(indices), false); @@ -437,7 +437,7 @@ public class IndicesOptionsIntegrationTests extends ElasticsearchIntegrationTest verify(count(indices), false, 1); verify(clearCache(indices), false); verify(_flush(indices),false); - verify(segments(indices), true); + verify(segments(indices), false); verify(stats(indices), false); verify(optimize(indices), false); verify(refresh(indices), false);