|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.action.admin.indices.segments; |
| 21 | + |
| 22 | +import org.apache.lucene.search.Sort; |
| 23 | +import org.apache.lucene.search.SortField; |
| 24 | +import org.elasticsearch.cluster.routing.ShardRouting; |
| 25 | +import org.elasticsearch.cluster.routing.ShardRoutingState; |
| 26 | +import org.elasticsearch.cluster.routing.TestShardRouting; |
| 27 | +import org.elasticsearch.common.xcontent.ToXContent; |
| 28 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 29 | +import org.elasticsearch.index.engine.Segment; |
| 30 | +import org.elasticsearch.test.ESTestCase; |
| 31 | + |
| 32 | +import java.util.Collections; |
| 33 | + |
| 34 | +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; |
| 35 | + |
| 36 | +public class IndicesSegmentResponseTests extends ESTestCase { |
| 37 | + |
| 38 | + public void testToXContentSerialiationWithSortedFields() throws Exception { |
| 39 | + ShardRouting shardRouting = TestShardRouting.newShardRouting("foo", 0, "node_id", true, ShardRoutingState.STARTED); |
| 40 | + Segment segment = new Segment("my"); |
| 41 | + |
| 42 | + SortField sortField = new SortField("foo", SortField.Type.STRING); |
| 43 | + sortField.setMissingValue(SortField.STRING_LAST); |
| 44 | + segment.segmentSort = new Sort(sortField); |
| 45 | + |
| 46 | + ShardSegments shardSegments = new ShardSegments(shardRouting, Collections.singletonList(segment)); |
| 47 | + IndicesSegmentResponse response = |
| 48 | + new IndicesSegmentResponse(new ShardSegments[] { shardSegments }, 1, 1, 0, Collections.emptyList()); |
| 49 | + try (XContentBuilder builder = jsonBuilder()) { |
| 50 | + response.toXContent(builder, ToXContent.EMPTY_PARAMS); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments