/
IndicesSegmentsRequestTests.java
92 lines (81 loc) · 3.88 KB
/
IndicesSegmentsRequestTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.action.admin.indices.segments;
import org.elasticsearch.action.ListenableActionFuture;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.engine.Segment;
import org.elasticsearch.indices.IndexClosedException;
import org.elasticsearch.test.ElasticsearchSingleNodeTest;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
public class IndicesSegmentsRequestTests extends ElasticsearchSingleNodeTest {
@Before
public void setupIndex() {
Settings settings = ImmutableSettings.builder()
// don't allow any merges so that the num docs is the expected segments
.put("index.merge.policy.segments_per_tier", 1000000f)
.build();
createIndex("test", settings);
int numDocs = scaledRandomIntBetween(100, 1000);
for (int j = 0; j < numDocs; ++j) {
String id = Integer.toString(j);
client().prepareIndex("test", "type1", id).setSource("text", "sometext").get();
}
client().admin().indices().prepareFlush("test").get();
}
public void testBasic() {
IndicesSegmentResponse rsp = client().admin().indices().prepareSegments("test").get();
List<Segment> segments = rsp.getIndices().get("test").iterator().next().getShards()[0].getSegments();
assertNull(segments.get(0).ramTree);
}
public void testVerbose() {
IndicesSegmentResponse rsp = client().admin().indices().prepareSegments("test").setVerbose(true).get();
List<Segment> 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());
}
}